Skip to content

Commit

Permalink
Allow loading raw files with no MS device
Browse files Browse the repository at this point in the history
But try to keep existing behavior, with additional flags
  • Loading branch information
FarmGeek4Life committed Oct 27, 2023
1 parent 10abc98 commit 20a6575
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 4 deletions.
80 changes: 77 additions & 3 deletions ThermoRawFileReader/XRawFileIO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,16 @@ public int ScanInfoCacheMaxSize
/// </summary>
public bool TraceMode { get; set; }

/// <summary>
/// When true, the file has no MS device
/// </summary>
public bool HasNoMSDevice { get; private set; }

/// <summary>
/// When true, the file has non-MS devices that may have data
/// </summary>
public bool HasNonMSDataDevice { get; private set; }

/// <summary>
/// Report an error message to the error event handler
/// </summary>
Expand Down Expand Up @@ -564,18 +574,48 @@ private bool FillFileInfo()
FileInfo.Devices.Add(item.Key, item.Value);
}

HasNoMSDevice = false;
HasNonMSDataDevice = false;

if (FileInfo.Devices.Count == 0)
{
RaiseWarningMessage("File does not have data from any devices");
}
else if (FileInfo.Devices.All(x => x.Key != Device.MS))
{
RaiseWarningMessage("File does not have data from any MS devices");
HasNoMSDevice = true;
}

if (FileInfo.Devices.Any(x => x.Key is Device.MSAnalog or Device.Analog or Device.UV or Device.Pda))
{
HasNonMSDataDevice = true;
}

// Make sure the MS controller is selected
if (!SetMSController())
if (!HasNoMSDevice && !SetMSController())
{
FileInfo.CorruptFile = true;
return false;
}

if (HasNoMSDevice)
{
// Set this to true to maintain certain existing behavior (as of Oct. 2023)
FileInfo.CorruptFile = true;

if (!HasNonMSDataDevice)
{
return false;
}

// If we have non-MS data devices, then select the first one according to a priority list
if (!SetFirstDataController())
{
return false;
}
}

FileInfo.CreationDate = DateTime.MinValue;
FileInfo.CreationDate = mXRawFileHeader.CreationDate;

Expand Down Expand Up @@ -649,7 +689,7 @@ private bool FillFileInfo()
GetTuneData();
}

return true;
return !HasNoMSDevice;
}
catch (Exception ex)
{
Expand Down Expand Up @@ -2002,7 +2042,7 @@ private static bool ScanIsFTMS(string filterText)

private bool SetMSController()
{
mXRawFile.SelectInstrument(Device.MS, 1);
//mXRawFile.SelectInstrument(Device.MS, 1); // Throws an exception if there is no MS device, and .SelectMsData() does the same work without the exception
var hasMsData = mXRawFile.SelectMsData();

if (!hasMsData)
Expand All @@ -2015,6 +2055,35 @@ private bool SetMSController()
return hasMsData;
}

/// <summary>
/// Select the first device of available devices with data
/// </summary>
/// <returns>true if a device with data was found</returns>
private bool SetFirstDataController()
{
var hasMsData = mXRawFile.SelectMsData();

if (!hasMsData)
{
if (FileInfo.Devices.Count > 0)
{
var deviceTypePriority = new[] { Device.MSAnalog, Device.UV, Device.Pda, Device.Analog };
foreach (var deviceType in deviceTypePriority.Where(x => FileInfo.Devices.ContainsKey(x)))
{
// Get first device with the highest-priority device type available
mXRawFile.SelectInstrument(deviceType, 1);
HasNoMSDevice = true;
return true;
}
}

// Either the file is corrupt, or it simply doesn't have Mass Spec data
mCorruptMemoryEncountered = true;
}

return hasMsData;
}

/// <summary>
/// Examines filterText to validate that it is a supported MS1 scan type (MS, SIM, or MRMQMS, or SRM scan)
/// </summary>
Expand Down Expand Up @@ -2789,6 +2858,11 @@ public bool OpenRawFile(string filePath)

if (!FillFileInfo())
{
if (HasNoMSDevice && HasNonMSDataDevice)
{
return false;
}

RawFilePath = string.Empty;
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion ThermoRawFileReader/version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json",
"version": "4.1",
"version": "4.2",
"assemblyVersion": {
"precision": "revision"
},
Expand Down

0 comments on commit 20a6575

Please sign in to comment.