diff --git a/ThermoRawFileReader/XRawFileIO.cs b/ThermoRawFileReader/XRawFileIO.cs index 8221350..6d44d83 100644 --- a/ThermoRawFileReader/XRawFileIO.cs +++ b/ThermoRawFileReader/XRawFileIO.cs @@ -198,6 +198,16 @@ public int ScanInfoCacheMaxSize /// public bool TraceMode { get; set; } + /// + /// When true, the file has no MS device + /// + public bool HasNoMSDevice { get; private set; } + + /// + /// When true, the file has non-MS devices that may have data + /// + public bool HasNonMSDataDevice { get; private set; } + /// /// Report an error message to the error event handler /// @@ -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; @@ -649,7 +689,7 @@ private bool FillFileInfo() GetTuneData(); } - return true; + return !HasNoMSDevice; } catch (Exception ex) { @@ -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) @@ -2015,6 +2055,35 @@ private bool SetMSController() return hasMsData; } + /// + /// Select the first device of available devices with data + /// + /// true if a device with data was found + 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; + } + /// /// Examines filterText to validate that it is a supported MS1 scan type (MS, SIM, or MRMQMS, or SRM scan) /// @@ -2789,6 +2858,11 @@ public bool OpenRawFile(string filePath) if (!FillFileInfo()) { + if (HasNoMSDevice && HasNonMSDataDevice) + { + return false; + } + RawFilePath = string.Empty; return false; } diff --git a/ThermoRawFileReader/version.json b/ThermoRawFileReader/version.json index 872c1b9..c16db24 100644 --- a/ThermoRawFileReader/version.json +++ b/ThermoRawFileReader/version.json @@ -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" },