From 0a1934c82584ad8ca13c077bc00dc42506cf7e81 Mon Sep 17 00:00:00 2001 From: caetera Date: Thu, 14 May 2020 22:59:06 +0200 Subject: [PATCH 01/15] Total Absorbance Chromatogram --- MainClass.cs | 5 ++ ParseInput.cs | 3 + Writer/MzMlSpectrumWriter.cs | 164 ++++++++++++++++++++++++++++++++++- 3 files changed, 170 insertions(+), 2 deletions(-) diff --git a/MainClass.cs b/MainClass.cs index 10ef6e9..821d56b 100644 --- a/MainClass.cs +++ b/MainClass.cs @@ -409,6 +409,11 @@ private static void RegularParametersParsing(string[] args) "Don't use zlib compression for the m/z ratios and intensities. By default zlib compression is enabled.", v => parseInput.NoZlibCompression = v != null }, + { + "a|allDetectors", + "Extract additonal detector data: UV/PDA etc", + v => parseInput.AllDetectors = v != null + }, { "l=|logging=", "Optional logging level: 0 for silent, 1 for verbose.", v => logFormatString = v diff --git a/ParseInput.cs b/ParseInput.cs index d6f29d1..def88bb 100644 --- a/ParseInput.cs +++ b/ParseInput.cs @@ -65,6 +65,8 @@ public string RawFilePath public bool NoZlibCompression { get; set; } + public bool AllDetectors { get; set; } + public LogFormat LogFormat { get; set; } public bool IgnoreInstrumentErrors { get; set; } @@ -98,6 +100,7 @@ public ParseInput() NoZlibCompression = false; LogFormat = LogFormat.DEFAULT; IgnoreInstrumentErrors = false; + AllDetectors = false; } public ParseInput(string rawFilePath, string rawDirectoryPath, string outputDirectory, OutputFormat outputFormat diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index 87bb38d..c1ecd5b 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -640,6 +640,7 @@ private List ConstructChromatograms(int firstScanNumber, int l { var chromatograms = new List(); + //MS chromatograms // Define the settings for getting the Base Peak chromatogram var settings = new ChromatogramTraceSettings(TraceType.BasePeak); @@ -671,8 +672,8 @@ private List ConstructChromatograms(int firstScanNumber, int l }; chromatogram.cvParam[0] = new CVParamType { - accession = "MS:1000235", - name = "total ion current chromatogram", + accession = "MS:1000628", + name = "basepeak chromatogram", cvRef = "MS", value = "" }; @@ -791,8 +792,167 @@ private List ConstructChromatograms(int firstScanNumber, int l chromatograms.Add(chromatogram); } + } + //UV chromatograms + if (ParseInput.AllDetectors) + { + for (int nrI = 0; nrI < _rawFile.GetInstrumentCountOfType(Device.Pda); nrI++) + { + _rawFile.SelectInstrument(Device.Pda, nrI + 1); + + var settingsPDA = new ChromatogramTraceSettings(TraceType.TotalAbsorbance); + + var dataPDA = _rawFile.GetChromatogramData(new IChromatogramSettings[] { settingsPDA }, + firstScanNumber, lastScanNumber); + + var tracePDA = ChromatogramSignal.FromChromatogramData(dataPDA); + + for (var i = 0; i < tracePDA.Length; i++) + { + if (tracePDA[i].Length > 0) + { + // Binary data array list + var binaryData = new List(); + + var chromatogram = new ChromatogramType + { + index = i.ToString(), + id = String.Format("PDA_{0}_TotalAbsorbance_{1}", nrI, i), + defaultArrayLength = 0, + binaryDataArrayList = new BinaryDataArrayListType + { + count = "2", + binaryDataArray = new BinaryDataArrayType[2] + }, + cvParam = new CVParamType[1] + }; + chromatogram.cvParam[0] = new CVParamType + { + accession = "MS:1000812", + name = "absorption chromatogram", + cvRef = "MS", + value = "" + }; + + // Chromatogram times + if (!trace[i].Times.IsNullOrEmpty()) + { + // Set the chromatogram default array length + chromatogram.defaultArrayLength = trace[i].Times.Count; + + var timesBinaryData = + new BinaryDataArrayType + { + binary = ParseInput.NoZlibCompression + ? Get64BitArray(trace[i].Times) + : GetZLib64BitArray(trace[i].Times) + }; + timesBinaryData.encodedLength = + (4 * Math.Ceiling((double)timesBinaryData + .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); + var timesBinaryDataCvParams = new List + { + new CVParamType + { + accession = "MS:1000595", + name = "time array", + cvRef = "MS", + unitName = "minute", + value = "", + unitCvRef = "UO", + unitAccession = "UO:0000031" + }, + new CVParamType + { + accession = "MS:1000523", name = "64-bit float", cvRef = "MS", value = "" + } + }; + if (!ParseInput.NoZlibCompression) + { + timesBinaryDataCvParams.Add( + new CVParamType + { + accession = "MS:1000574", + name = "zlib compression", + cvRef = "MS", + value = "" + }); + } + + timesBinaryData.cvParam = timesBinaryDataCvParams.ToArray(); + + binaryData.Add(timesBinaryData); + } + + // Chromatogram intensities + if (!trace[i].Times.IsNullOrEmpty()) + { + // Set the spectrum default array length if necessary + if (chromatogram.defaultArrayLength == 0) + { + chromatogram.defaultArrayLength = trace[i].Intensities.Count; + } + + var intensitiesBinaryData = + new BinaryDataArrayType + { + binary = ParseInput.NoZlibCompression + ? Get64BitArray(trace[i].Intensities) + : GetZLib64BitArray(trace[i].Intensities) + }; + intensitiesBinaryData.encodedLength = + (4 * Math.Ceiling((double)intensitiesBinaryData + .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); + var intensitiesBinaryDataCvParams = new List + { + new CVParamType + { + accession = "MS:1000515", + name = "intensity array", + cvRef = "MS", + unitName = "absorbance unit", + value = "", + unitCvRef = "UO", + unitAccession = "UO:0000269" + }, + new CVParamType + { + accession = "MS:1000523", name = "64-bit float", cvRef = "MS", value = "" + } + }; + if (!ParseInput.NoZlibCompression) + { + intensitiesBinaryDataCvParams.Add( + new CVParamType + { + accession = "MS:1000574", + name = "zlib compression", + cvRef = "MS", + value = "" + }); + } + + intensitiesBinaryData.cvParam = intensitiesBinaryDataCvParams.ToArray(); + + binaryData.Add(intensitiesBinaryData); + } + + if (!binaryData.IsNullOrEmpty()) + { + chromatogram.binaryDataArrayList = new BinaryDataArrayListType + { + count = binaryData.Count.ToString(), + binaryDataArray = binaryData.ToArray() + }; + } + + chromatograms.Add(chromatogram); + } + } + } + } return chromatograms; } From e277779f50c07934f7afa344ccc68cbf2f488302 Mon Sep 17 00:00:00 2001 From: caetera Date: Fri, 15 May 2020 22:18:45 +0200 Subject: [PATCH 02/15] Unified chromatogram creation --- Writer/MzMlSpectrumWriter.cs | 383 +++++++++++++---------------------- 1 file changed, 141 insertions(+), 242 deletions(-) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index c1ecd5b..4c1354c 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -645,8 +645,7 @@ private List ConstructChromatograms(int firstScanNumber, int l var settings = new ChromatogramTraceSettings(TraceType.BasePeak); // Get the chromatogram from the RAW file. - var data = _rawFile.GetChromatogramData(new IChromatogramSettings[] {settings}, firstScanNumber, - lastScanNumber); + var data = _rawFile.GetChromatogramData(new IChromatogramSettings[] {settings}, -1, -1); // Split the data into the chromatograms var trace = ChromatogramSignal.FromChromatogramData(data); @@ -655,22 +654,8 @@ private List ConstructChromatograms(int firstScanNumber, int l { if (trace[i].Length > 0) { - // Binary data array list - var binaryData = new List(); - - var chromatogram = new ChromatogramType - { - index = i.ToString(), - id = "base_peak_" + i, - defaultArrayLength = 0, - binaryDataArrayList = new BinaryDataArrayListType - { - count = "2", - binaryDataArray = new BinaryDataArrayType[2] - }, - cvParam = new CVParamType[1] - }; - chromatogram.cvParam[0] = new CVParamType + // CV Data for Base Peak Chromatogram + var chroType = new CVParamType { accession = "MS:1000628", name = "basepeak chromatogram", @@ -678,117 +663,18 @@ private List ConstructChromatograms(int firstScanNumber, int l value = "" }; - // Chromatogram times - if (!trace[i].Times.IsNullOrEmpty()) + var intensType = new CVParamType { - // Set the chromatogram default array length - chromatogram.defaultArrayLength = trace[i].Times.Count; - - var timesBinaryData = - new BinaryDataArrayType - { - binary = ParseInput.NoZlibCompression - ? Get64BitArray(trace[i].Times) - : GetZLib64BitArray(trace[i].Times) - }; - timesBinaryData.encodedLength = - (4 * Math.Ceiling((double) timesBinaryData - .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); - var timesBinaryDataCvParams = new List - { - new CVParamType - { - accession = "MS:1000595", - name = "time array", - cvRef = "MS", - unitName = "minute", - value = "", - unitCvRef = "UO", - unitAccession = "UO:0000031" - }, - new CVParamType - { - accession = "MS:1000523", name = "64-bit float", cvRef = "MS", value = "" - } - }; - if (!ParseInput.NoZlibCompression) - { - timesBinaryDataCvParams.Add( - new CVParamType - { - accession = "MS:1000574", - name = "zlib compression", - cvRef = "MS", - value = "" - }); - } - - timesBinaryData.cvParam = timesBinaryDataCvParams.ToArray(); - - binaryData.Add(timesBinaryData); - } - - // Chromatogram intensities - if (!trace[i].Times.IsNullOrEmpty()) - { - // Set the spectrum default array length if necessary - if (chromatogram.defaultArrayLength == 0) - { - chromatogram.defaultArrayLength = trace[i].Intensities.Count; - } - - var intensitiesBinaryData = - new BinaryDataArrayType - { - binary = ParseInput.NoZlibCompression - ? Get64BitArray(trace[i].Intensities) - : GetZLib64BitArray(trace[i].Intensities) - }; - intensitiesBinaryData.encodedLength = - (4 * Math.Ceiling((double) intensitiesBinaryData - .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); - var intensitiesBinaryDataCvParams = new List - { - new CVParamType - { - accession = "MS:1000515", - name = "intensity array", - cvRef = "MS", - unitName = "number of counts", - value = "", - unitCvRef = "MS", - unitAccession = "MS:1000131" - }, - new CVParamType - { - accession = "MS:1000523", name = "64-bit float", cvRef = "MS", value = "" - } - }; - if (!ParseInput.NoZlibCompression) - { - intensitiesBinaryDataCvParams.Add( - new CVParamType - { - accession = "MS:1000574", - name = "zlib compression", - cvRef = "MS", - value = "" - }); - } - - intensitiesBinaryData.cvParam = intensitiesBinaryDataCvParams.ToArray(); - - binaryData.Add(intensitiesBinaryData); - } + accession = "MS:1000515", + name = "intensity array", + cvRef = "MS", + unitName = "number of counts", + value = "", + unitCvRef = "MS", + unitAccession = "MS:1000131" + }; - if (!binaryData.IsNullOrEmpty()) - { - chromatogram.binaryDataArrayList = new BinaryDataArrayListType - { - count = binaryData.Count.ToString(), - binaryDataArray = binaryData.ToArray() - }; - } + var chromatogram = TraceToChromatogram(trace[i], "BasePeak_" + i.ToString(), chroType, intensType); chromatograms.Add(chromatogram); } @@ -805,54 +691,80 @@ private List ConstructChromatograms(int firstScanNumber, int l var settingsPDA = new ChromatogramTraceSettings(TraceType.TotalAbsorbance); var dataPDA = _rawFile.GetChromatogramData(new IChromatogramSettings[] { settingsPDA }, - firstScanNumber, lastScanNumber); + -1, -1); var tracePDA = ChromatogramSignal.FromChromatogramData(dataPDA); for (var i = 0; i < tracePDA.Length; i++) { - if (tracePDA[i].Length > 0) + // CV Data for Total Absorbance Chromatogram + var chroType = new CVParamType { - // Binary data array list - var binaryData = new List(); + accession = "MS:1000812", + name = "absorption chromatogram", + cvRef = "MS", + value = "" + }; - var chromatogram = new ChromatogramType - { - index = i.ToString(), - id = String.Format("PDA_{0}_TotalAbsorbance_{1}", nrI, i), - defaultArrayLength = 0, - binaryDataArrayList = new BinaryDataArrayListType - { - count = "2", - binaryDataArray = new BinaryDataArrayType[2] - }, - cvParam = new CVParamType[1] - }; - chromatogram.cvParam[0] = new CVParamType - { - accession = "MS:1000812", - name = "absorption chromatogram", - cvRef = "MS", - value = "" - }; + var intensType = new CVParamType + { + accession = "MS:1000515", + name = "intensity array", + cvRef = "MS", + unitName = "absorbance unit", + value = "", + unitCvRef = "UO", + unitAccession = "UO:0000269" + }; - // Chromatogram times - if (!trace[i].Times.IsNullOrEmpty()) - { - // Set the chromatogram default array length - chromatogram.defaultArrayLength = trace[i].Times.Count; - - var timesBinaryData = - new BinaryDataArrayType - { - binary = ParseInput.NoZlibCompression - ? Get64BitArray(trace[i].Times) - : GetZLib64BitArray(trace[i].Times) - }; - timesBinaryData.encodedLength = - (4 * Math.Ceiling((double)timesBinaryData - .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); - var timesBinaryDataCvParams = new List + var chromatogram = TraceToChromatogram(trace[i], String.Format("PDA{0}_{1}", nrI, i.ToString()), + chroType, intensType); + + chromatograms.Add(chromatogram); + } + } + } + + return chromatograms; + } + + private ChromatogramType TraceToChromatogram(ChromatogramSignal trace, string chromatogramId, + CVParamType chromatogramType, CVParamType intensityType) + { + var binaryData = new List(); + + var chromatogram = new ChromatogramType + { + index = String.Empty, //index will be overwritten during serialization + id = chromatogramId, + defaultArrayLength = 0, + binaryDataArrayList = new BinaryDataArrayListType + { + count = "2", + binaryDataArray = new BinaryDataArrayType[2] + }, + cvParam = new CVParamType[1] + }; + + chromatogram.cvParam[0] = chromatogramType; + + // Chromatogram times + if (!trace.Times.IsNullOrEmpty()) + { + // Set the chromatogram default array length + chromatogram.defaultArrayLength = trace.Times.Count; + + var timesBinaryData = + new BinaryDataArrayType + { + binary = ParseInput.NoZlibCompression + ? Get64BitArray(trace.Times) + : GetZLib64BitArray(trace.Times) + }; + timesBinaryData.encodedLength = + (4 * Math.Ceiling((double)timesBinaryData + .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); + var timesBinaryDataCvParams = new List { new CVParamType { @@ -869,91 +781,78 @@ private List ConstructChromatograms(int firstScanNumber, int l accession = "MS:1000523", name = "64-bit float", cvRef = "MS", value = "" } }; - if (!ParseInput.NoZlibCompression) - { - timesBinaryDataCvParams.Add( - new CVParamType - { - accession = "MS:1000574", - name = "zlib compression", - cvRef = "MS", - value = "" - }); - } - - timesBinaryData.cvParam = timesBinaryDataCvParams.ToArray(); - - binaryData.Add(timesBinaryData); - } + if (!ParseInput.NoZlibCompression) + { + timesBinaryDataCvParams.Add( + new CVParamType + { + accession = "MS:1000574", + name = "zlib compression", + cvRef = "MS", + value = "" + }); + } - // Chromatogram intensities - if (!trace[i].Times.IsNullOrEmpty()) - { - // Set the spectrum default array length if necessary - if (chromatogram.defaultArrayLength == 0) - { - chromatogram.defaultArrayLength = trace[i].Intensities.Count; - } - - var intensitiesBinaryData = - new BinaryDataArrayType - { - binary = ParseInput.NoZlibCompression - ? Get64BitArray(trace[i].Intensities) - : GetZLib64BitArray(trace[i].Intensities) - }; - intensitiesBinaryData.encodedLength = - (4 * Math.Ceiling((double)intensitiesBinaryData - .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); - var intensitiesBinaryDataCvParams = new List + timesBinaryData.cvParam = timesBinaryDataCvParams.ToArray(); + + binaryData.Add(timesBinaryData); + } + + // Chromatogram intensities + if (!trace.Intensities.IsNullOrEmpty()) + { + // Set the spectrum default array length if necessary + //Is it necessary? + if (chromatogram.defaultArrayLength == 0) + { + chromatogram.defaultArrayLength = trace.Intensities.Count; + } + + var intensitiesBinaryData = + new BinaryDataArrayType + { + binary = ParseInput.NoZlibCompression + ? Get64BitArray(trace.Intensities) + : GetZLib64BitArray(trace.Intensities) + }; + intensitiesBinaryData.encodedLength = + (4 * Math.Ceiling((double)intensitiesBinaryData + .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); + var intensitiesBinaryDataCvParams = new List { - new CVParamType - { - accession = "MS:1000515", - name = "intensity array", - cvRef = "MS", - unitName = "absorbance unit", - value = "", - unitCvRef = "UO", - unitAccession = "UO:0000269" - }, + intensityType, new CVParamType { accession = "MS:1000523", name = "64-bit float", cvRef = "MS", value = "" } }; - if (!ParseInput.NoZlibCompression) - { - intensitiesBinaryDataCvParams.Add( - new CVParamType - { - accession = "MS:1000574", - name = "zlib compression", - cvRef = "MS", - value = "" - }); - } - - intensitiesBinaryData.cvParam = intensitiesBinaryDataCvParams.ToArray(); - - binaryData.Add(intensitiesBinaryData); - } + if (!ParseInput.NoZlibCompression) + { + intensitiesBinaryDataCvParams.Add( + new CVParamType + { + accession = "MS:1000574", + name = "zlib compression", + cvRef = "MS", + value = "" + }); + } - if (!binaryData.IsNullOrEmpty()) - { - chromatogram.binaryDataArrayList = new BinaryDataArrayListType - { - count = binaryData.Count.ToString(), - binaryDataArray = binaryData.ToArray() - }; - } + intensitiesBinaryData.cvParam = intensitiesBinaryDataCvParams.ToArray(); - chromatograms.Add(chromatogram); - } - } - } + binaryData.Add(intensitiesBinaryData); } - return chromatograms; + + if (!binaryData.IsNullOrEmpty()) + { + chromatogram.binaryDataArrayList = new BinaryDataArrayListType + { + count = binaryData.Count.ToString(), + binaryDataArray = binaryData.ToArray() + }; + } + + return chromatogram; } /// From d60d3209e65210c273587483532d218e110ea6f5 Mon Sep 17 00:00:00 2001 From: caetera Date: Tue, 19 May 2020 21:52:05 +0200 Subject: [PATCH 03/15] Start adding PDA specta export --- ThermoRawFileParser.csproj.user | 2 +- Writer/MgfSpectrumWriter.cs | 2 +- Writer/MzMlSpectrumWriter.cs | 378 +++++++++++++++++++++++++++++++- Writer/SpectrumWriter.cs | 4 +- 4 files changed, 376 insertions(+), 10 deletions(-) diff --git a/ThermoRawFileParser.csproj.user b/ThermoRawFileParser.csproj.user index 359e1b0..626950b 100644 --- a/ThermoRawFileParser.csproj.user +++ b/ThermoRawFileParser.csproj.user @@ -1,6 +1,6 @@  - -i=C:\Users\Iman\Desktop\RawFiles\FileReaderTest\blacktea_1.raw -f=2 -o .\ + -i=C:\Code\QC_MSDDA_UV.raw -f=1 -o=C:\Code -a \ No newline at end of file diff --git a/Writer/MgfSpectrumWriter.cs b/Writer/MgfSpectrumWriter.cs index f151b52..445edd8 100644 --- a/Writer/MgfSpectrumWriter.cs +++ b/Writer/MgfSpectrumWriter.cs @@ -65,7 +65,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc IReaction reaction = GetReaction(scanEvent, scanNumber); Writer.WriteLine("BEGIN IONS"); - Writer.WriteLine($"TITLE={ConstructSpectrumTitle(scanNumber)}"); + Writer.WriteLine($"TITLE={ConstructSpectrumTitle((int)Device.MS, 1, scanNumber)}"); Writer.WriteLine($"SCANS={scanNumber}"); Writer.WriteLine( $"RTINSECONDS={(time * 60).ToString(CultureInfo.InvariantCulture)}"); diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index 4c1354c..41d3de0 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -264,6 +264,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc serializer = _factory.CreateSerializer(typeof(SpectrumType)); + //MS Spectra var index = 0; var lastScanProgress = 0; for (var scanNumber = firstScanNumber; scanNumber <= lastScanNumber; scanNumber++) @@ -281,7 +282,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc } } - var spectrum = ConstructSpectrum(scanNumber); + var spectrum = ConstructMSSpectrum(scanNumber); if (spectrum != null) { spectrum.index = index.ToString(); @@ -308,6 +309,59 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc } } + // PDA spectra + if (ParseInput.AllDetectors && _rawFile.GetInstrumentCountOfType(Device.Pda) > 0) + { + for (int nrI = 0; nrI < _rawFile.GetInstrumentCountOfType(Device.Pda); nrI++) + { + _rawFile.SelectInstrument(Device.Pda, nrI + 1); + firstScanNumber = _rawFile.RunHeader.FirstSpectrum; + lastScanNumber = _rawFile.RunHeader.LastSpectrum; + lastScanProgress = 0; + + for (var scanNumber = firstScanNumber; scanNumber <= lastScanNumber; scanNumber++) + { + if (ParseInput.LogFormat == LogFormat.DEFAULT) + { + var scanProgress = (int)((double)scanNumber / (lastScanNumber - firstScanNumber + 1) * 100); + if (scanProgress % ProgressPercentageStep == 0) + { + if (scanProgress != lastScanProgress) + { + Console.Write("" + scanProgress + "% "); + lastScanProgress = scanProgress; + } + } + } + + var spectrum = ConstructPDASpectrum(scanNumber, nrI + 1); + if (spectrum != null) + { + spectrum.index = index.ToString(); + if (_doIndexing) + { + // flush the writers before getting the position + _writer.Flush(); + Writer.Flush(); + if (spectrumOffSets.Count != 0) + { + spectrumOffSets.Add(spectrum.id, Writer.BaseStream.Position + 6 + _osOffset); + } + else + { + spectrumOffSets.Add(spectrum.id, Writer.BaseStream.Position + 7 + _osOffset); + } + } + + Serialize(serializer, spectrum); + + Log.Debug("Spectrum added to list of spectra -- ID " + spectrum.id); + + index++; + } + } + } + } if (ParseInput.LogFormat == LogFormat.DEFAULT) { Console.WriteLine(); @@ -717,7 +771,7 @@ private List ConstructChromatograms(int firstScanNumber, int l unitAccession = "UO:0000269" }; - var chromatogram = TraceToChromatogram(trace[i], String.Format("PDA{0}_{1}", nrI, i.ToString()), + var chromatogram = TraceToChromatogram(tracePDA[i], String.Format("PDA{0}_{1}", nrI, i.ToString()), chroType, intensType); chromatograms.Add(chromatogram); @@ -860,7 +914,7 @@ private ChromatogramType TraceToChromatogram(ChromatogramSignal trace, string ch /// /// the scan number /// The SpectrumType object - private SpectrumType ConstructSpectrum(int scanNumber) + private SpectrumType ConstructMSSpectrum(int scanNumber) { // Get each scan from the RAW file var scan = Scan.FromFile(_rawFile, scanNumber); @@ -872,7 +926,7 @@ private SpectrumType ConstructSpectrum(int scanNumber) var scanEvent = _rawFile.GetScanEventForScanNumber(scanNumber); var spectrum = new SpectrumType { - id = ConstructSpectrumTitle(scanNumber), + id = ConstructSpectrumTitle((int)Device.MS, 1, scanNumber), defaultArrayLength = 0 }; @@ -1288,6 +1342,237 @@ private SpectrumType ConstructSpectrum(int scanNumber) return spectrum; } + private SpectrumType ConstructPDASpectrum(int scanNumber, int instrumentNumber) + { + // Get each scan from the RAW file + var scan = Scan.FromFile(_rawFile, scanNumber); + + var spectrum = new SpectrumType + { + id = ConstructSpectrumTitle((int)Device.Pda, instrumentNumber, scanNumber), + defaultArrayLength = 0 + }; + + // Keep the CV params in a list and convert to array afterwards + var spectrumCvParams = new List + { + new CVParamType + { + name = "electromagnetic radiation spectrum", + accession = "MS:1000804", + value = String.Empty, + cvRef = "MS" + } + }; + + // Construct and set the scan list element of the spectrum + var scanListType = ConstructScanList(scanNumber, scan); + spectrum.scanList = scanListType; + + + // Total ion current + spectrumCvParams.Add(new CVParamType + { + name = "total ion current", + accession = "MS:1000285", + value = scan.ScanStatistics.TIC.ToString(CultureInfo.InvariantCulture), + cvRef = "MS" + }); + + //Scan data + double? basePeakMass = null; + double? basePeakIntensity = null; + double? lowestObservedMz = null; + double? highestObservedMz = null; + double[] masses = null; + double[] intensities = null; + + + basePeakMass = scan.ScanStatistics.BasePeakMass; + basePeakIntensity = scan.ScanStatistics.BasePeakIntensity; + + if (scan.SegmentedScan.Positions.Length > 0) + { + lowestObservedMz = scan.SegmentedScan.Positions[0]; + highestObservedMz = scan.SegmentedScan.Positions[scan.SegmentedScan.Positions.Length - 1]; + masses = scan.SegmentedScan.Positions; + intensities = scan.SegmentedScan.Intensities; + } + + + // Base peak m/z + if (basePeakMass != null) + { + spectrumCvParams.Add(new CVParamType + { + name = "base peak m/z", + accession = "MS:1000504", + value = basePeakMass.Value.ToString(CultureInfo.InvariantCulture), + unitCvRef = "MS", + unitName = "m/z", + unitAccession = "MS:1000040", + cvRef = "MS" + }); + } + + // Base peak intensity + if (basePeakIntensity != null) + { + spectrumCvParams.Add(new CVParamType + { + name = "base peak intensity", + accession = "MS:1000505", + value = basePeakIntensity.Value.ToString(CultureInfo.InvariantCulture), + unitCvRef = "MS", + unitName = "number of detector counts", + unitAccession = "MS:1000131", + cvRef = "MS" + }); + } + + // Lowest observed mz + if (lowestObservedMz != null) + { + spectrumCvParams.Add(new CVParamType + { + name = "lowest observed m/z", + accession = "MS:1000528", + value = lowestObservedMz.Value.ToString(CultureInfo.InvariantCulture), + unitCvRef = "MS", + unitAccession = "MS:1000040", + unitName = "m/z", + cvRef = "MS" + }); + } + + // Highest observed mz + if (highestObservedMz != null) + { + spectrumCvParams.Add(new CVParamType + { + name = "highest observed m/z", + accession = "MS:1000527", + value = highestObservedMz.Value.ToString(CultureInfo.InvariantCulture), + unitAccession = "MS:1000040", + unitName = "m/z", + unitCvRef = "MS", + cvRef = "MS" + }); + } + + // Add the CV params to the spectrum + spectrum.cvParam = spectrumCvParams.ToArray(); + + // Binary data array list + var binaryData = new List(); + + // M/Z Data + if (!masses.IsNullOrEmpty()) + { + // Set the spectrum default array length + spectrum.defaultArrayLength = masses.Length; + + var massesBinaryData = + new BinaryDataArrayType + { + binary = ParseInput.NoZlibCompression ? Get64BitArray(masses) : GetZLib64BitArray(masses) + }; + massesBinaryData.encodedLength = + (4 * Math.Ceiling((double)massesBinaryData + .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); + var massesBinaryDataCvParams = new List + { + new CVParamType + { + accession = "MS:1000514", + name = "m/z array", + cvRef = "MS", + unitName = "m/z", + value = "", + unitCvRef = "MS", + unitAccession = "MS:1000040" + }, + new CVParamType {accession = "MS:1000523", name = "64-bit float", cvRef = "MS", value = ""} + }; + if (!ParseInput.NoZlibCompression) + { + massesBinaryDataCvParams.Add( + new CVParamType + { + accession = "MS:1000574", + name = "zlib compression", + cvRef = "MS", + value = "" + }); + } + + massesBinaryData.cvParam = massesBinaryDataCvParams.ToArray(); + + binaryData.Add(massesBinaryData); + } + + // Intensity Data + if (!intensities.IsNullOrEmpty()) + { + // Set the spectrum default array length if necessary + if (spectrum.defaultArrayLength == 0) + { + spectrum.defaultArrayLength = masses.Length; + } + + var intensitiesBinaryData = + new BinaryDataArrayType + { + binary = ParseInput.NoZlibCompression + ? Get64BitArray(intensities) + : GetZLib64BitArray(intensities) + }; + intensitiesBinaryData.encodedLength = + (4 * Math.Ceiling((double)intensitiesBinaryData + .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); + var intensitiesBinaryDataCvParams = new List + { + new CVParamType + { + accession = "MS:1000515", + name = "intensity array", + cvRef = "MS", + unitCvRef = "MS", + unitAccession = "MS:1000131", + unitName = "number of counts", + value = "" + }, + new CVParamType {accession = "MS:1000523", name = "64-bit float", cvRef = "MS", value = ""} + }; + if (!ParseInput.NoZlibCompression) + { + intensitiesBinaryDataCvParams.Add( + new CVParamType + { + accession = "MS:1000574", + name = "zlib compression", + cvRef = "MS", + value = "" + }); + } + + intensitiesBinaryData.cvParam = intensitiesBinaryDataCvParams.ToArray(); + + binaryData.Add(intensitiesBinaryData); + } + + if (!binaryData.IsNullOrEmpty()) + { + spectrum.binaryDataArrayList = new BinaryDataArrayListType + { + count = binaryData.Count.ToString(), + binaryDataArray = binaryData.ToArray() + }; + } + + return spectrum; + } + /// /// Populate the precursor list element /// @@ -1316,7 +1601,7 @@ private PrecursorListType ConstructPrecursorList(IScanEventBase scanEvent, int? switch (msLevel) { case MSOrderType.Ms2: - spectrumRef = ConstructSpectrumTitle(_precursorMs1ScanNumber); + spectrumRef = ConstructSpectrumTitle((int)Device.MS, 1, _precursorMs1ScanNumber); reaction = scanEvent.GetReaction(0); precursorScanNumber = _precursorMs1ScanNumber; break; @@ -1326,7 +1611,7 @@ private PrecursorListType ConstructPrecursorList(IScanEventBase scanEvent, int? scanEvent.ToString().Contains(isolationMz)); if (!precursorMs2ScanNumber.IsNullOrEmpty()) { - spectrumRef = ConstructSpectrumTitle(_precursorMs2ScanNumbers[precursorMs2ScanNumber]); + spectrumRef = ConstructSpectrumTitle((int)Device.MS, 1, _precursorMs2ScanNumbers[precursorMs2ScanNumber]); reaction = scanEvent.GetReaction(1); precursorScanNumber = _precursorMs1ScanNumber; } @@ -1661,6 +1946,87 @@ private ScanListType ConstructScanList(int scanNumber, Scan scan, IScanFilter sc return scanList; } + private ScanListType ConstructScanList(int scanNumber, Scan scan) + { + // Scan list + var scanList = new ScanListType + { + count = "1", + scan = new ScanType[1], + cvParam = new CVParamType[1] + }; + + scanList.cvParam[0] = new CVParamType + { + accession = "MS:1000795", + cvRef = "MS", + name = "no combination", + value = "" + }; + + var scanTypeCvParams = new List + { + new CVParamType + { + name = "scan start time", + accession = "MS:1000016", + value = _rawFile.RetentionTimeFromScanNumber(scanNumber) + .ToString(CultureInfo.InvariantCulture), + unitCvRef = "UO", + unitAccession = "UO:0000031", + unitName = "minute", + cvRef = "MS" + } + }; + + // Scan start time + + // Scan filter string + + var scanType = new ScanType + { + instrumentConfigurationRef = "null", + cvParam = scanTypeCvParams.ToArray() + }; + + // Scan window list + scanType.scanWindowList = new ScanWindowListType + { + count = 1, + scanWindow = new ParamGroupType[1] + }; + var scanWindow = new ParamGroupType + { + cvParam = new CVParamType[2] + }; + scanWindow.cvParam[0] = new CVParamType + { + name = "scan window lower limit", + accession = "MS:1000501", + value = scan.ScanStatistics.LowMass.ToString(CultureInfo.InvariantCulture), + cvRef = "MS", + unitAccession = "MS:1000040", + unitCvRef = "MS", + unitName = "m/z" + }; + scanWindow.cvParam[1] = new CVParamType + { + name = "scan window upper limit", + accession = "MS:1000500", + value = scan.ScanStatistics.HighMass.ToString(CultureInfo.InvariantCulture), + cvRef = "MS", + unitAccession = "MS:1000040", + unitCvRef = "MS", + unitName = "m/z" + }; + + scanType.scanWindowList.scanWindow[0] = scanWindow; + + scanList.scan[0] = scanType; + + return scanList; + } + /// /// Convert the double array into a byte array /// diff --git a/Writer/SpectrumWriter.cs b/Writer/SpectrumWriter.cs index 8027add..530111d 100644 --- a/Writer/SpectrumWriter.cs +++ b/Writer/SpectrumWriter.cs @@ -97,9 +97,9 @@ protected void ConfigureWriter(string extension) /// Construct the spectrum title. /// /// the spectrum scan number - protected static string ConstructSpectrumTitle(int scanNumber) + protected static string ConstructSpectrumTitle(int instrumentType, int instrumentNumber, int scanNumber) { - return "controllerType=0 controllerNumber=1 scan=" + scanNumber; + return String.Format("controllerType={0} controllerNumber={1} scan={2}", instrumentType, instrumentNumber, scanNumber); } /// From 229e1f003156422b32c160f8009d52b12f24b99c Mon Sep 17 00:00:00 2001 From: caetera Date: Thu, 21 May 2020 17:27:52 +0200 Subject: [PATCH 04/15] PDA scans refine + selected ion intensity --- Writer/MzMlSpectrumWriter.cs | 143 ++++++++++++++++++++--------------- Writer/SpectrumWriter.cs | 55 +++++--------- 2 files changed, 102 insertions(+), 96 deletions(-) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index 41d3de0..bc47cac 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -91,8 +91,6 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc try { - Log.Info("Processing " + (lastScanNumber - firstScanNumber) + " scans"); - _writer.WriteStartDocument(); if (_doIndexing) @@ -267,6 +265,9 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc //MS Spectra var index = 0; var lastScanProgress = 0; + + Log.Info("Processing " + (lastScanNumber - firstScanNumber) + " MS scans"); + for (var scanNumber = firstScanNumber; scanNumber <= lastScanNumber; scanNumber++) { if (ParseInput.LogFormat == LogFormat.DEFAULT) @@ -309,6 +310,11 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc } } + if (ParseInput.LogFormat == LogFormat.DEFAULT) + { + Console.WriteLine(); + } + // PDA spectra if (ParseInput.AllDetectors && _rawFile.GetInstrumentCountOfType(Device.Pda) > 0) { @@ -319,6 +325,8 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc lastScanNumber = _rawFile.RunHeader.LastSpectrum; lastScanProgress = 0; + Log.Info("Processing " + (lastScanNumber - firstScanNumber) + " PDA scans from Device #" + (nrI + 1)); + for (var scanNumber = firstScanNumber; scanNumber <= lastScanNumber; scanNumber++) { if (ParseInput.LogFormat == LogFormat.DEFAULT) @@ -362,6 +370,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc } } } + if (ParseInput.LogFormat == LogFormat.DEFAULT) { Console.WriteLine(); @@ -373,7 +382,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc var chromatograms = ConstructChromatograms(firstScanNumber, lastScanNumber); if (!chromatograms.IsNullOrEmpty()) { - // chromatogramList + //chromatogramList _writer.WriteStartElement("chromatogramList"); _writer.WriteAttributeString("count", chromatograms.Count.ToString()); _writer.WriteAttributeString("defaultDataProcessingRef", "ThermoRawFileParserProcessing"); @@ -1380,34 +1389,34 @@ private SpectrumType ConstructPDASpectrum(int scanNumber, int instrumentNumber) }); //Scan data - double? basePeakMass = null; + double? basePeakPosition = null; double? basePeakIntensity = null; - double? lowestObservedMz = null; - double? highestObservedMz = null; - double[] masses = null; + double? lowestPosition = null; + double? highestPosition = null; + double[] positions = null; double[] intensities = null; - basePeakMass = scan.ScanStatistics.BasePeakMass; + basePeakPosition = scan.ScanStatistics.BasePeakMass; basePeakIntensity = scan.ScanStatistics.BasePeakIntensity; if (scan.SegmentedScan.Positions.Length > 0) { - lowestObservedMz = scan.SegmentedScan.Positions[0]; - highestObservedMz = scan.SegmentedScan.Positions[scan.SegmentedScan.Positions.Length - 1]; - masses = scan.SegmentedScan.Positions; + lowestPosition = scan.SegmentedScan.Positions[0]; + highestPosition = scan.SegmentedScan.Positions[scan.SegmentedScan.Positions.Length - 1]; + positions = scan.SegmentedScan.Positions; intensities = scan.SegmentedScan.Intensities; } // Base peak m/z - if (basePeakMass != null) + if (basePeakPosition != null) { spectrumCvParams.Add(new CVParamType { name = "base peak m/z", accession = "MS:1000504", - value = basePeakMass.Value.ToString(CultureInfo.InvariantCulture), + value = basePeakPosition.Value.ToString(CultureInfo.InvariantCulture), unitCvRef = "MS", unitName = "m/z", unitAccession = "MS:1000040", @@ -1430,32 +1439,32 @@ private SpectrumType ConstructPDASpectrum(int scanNumber, int instrumentNumber) }); } - // Lowest observed mz - if (lowestObservedMz != null) + // Lowest observed wavelength + if (lowestPosition != null) { spectrumCvParams.Add(new CVParamType { - name = "lowest observed m/z", - accession = "MS:1000528", - value = lowestObservedMz.Value.ToString(CultureInfo.InvariantCulture), + name = "lowest observed wavelength", + accession = "MS:1000619", + value = lowestPosition.Value.ToString(CultureInfo.InvariantCulture), unitCvRef = "MS", - unitAccession = "MS:1000040", - unitName = "m/z", - cvRef = "MS" + unitAccession = "UO:0000018", + unitName = "nanometer", + cvRef = "UO" }); } - // Highest observed mz - if (highestObservedMz != null) + // Highest observed wavelength + if (highestPosition != null) { spectrumCvParams.Add(new CVParamType { - name = "highest observed m/z", - accession = "MS:1000527", - value = highestObservedMz.Value.ToString(CultureInfo.InvariantCulture), - unitAccession = "MS:1000040", - unitName = "m/z", - unitCvRef = "MS", + name = "highest observed wavelength", + accession = "MS:1000618", + value = highestPosition.Value.ToString(CultureInfo.InvariantCulture), + unitAccession = "UO:0000018", + unitName = "nanometer", + unitCvRef = "UO", cvRef = "MS" }); } @@ -1466,37 +1475,37 @@ private SpectrumType ConstructPDASpectrum(int scanNumber, int instrumentNumber) // Binary data array list var binaryData = new List(); - // M/Z Data - if (!masses.IsNullOrEmpty()) + // Spectral data + if (!positions.IsNullOrEmpty()) { // Set the spectrum default array length - spectrum.defaultArrayLength = masses.Length; + spectrum.defaultArrayLength = positions.Length; - var massesBinaryData = + var positionsBinaryData = new BinaryDataArrayType { - binary = ParseInput.NoZlibCompression ? Get64BitArray(masses) : GetZLib64BitArray(masses) + binary = ParseInput.NoZlibCompression ? Get64BitArray(positions) : GetZLib64BitArray(positions) }; - massesBinaryData.encodedLength = - (4 * Math.Ceiling((double)massesBinaryData + positionsBinaryData.encodedLength = + (4 * Math.Ceiling((double)positionsBinaryData .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); - var massesBinaryDataCvParams = new List + var positionsBinaryDataCvParams = new List { new CVParamType { - accession = "MS:1000514", - name = "m/z array", + accession = "MS:1000617", + name = "wavelength array", cvRef = "MS", - unitName = "m/z", + unitName = "nanometer", value = "", - unitCvRef = "MS", - unitAccession = "MS:1000040" + unitCvRef = "UO", + unitAccession = "UO:0000018" }, new CVParamType {accession = "MS:1000523", name = "64-bit float", cvRef = "MS", value = ""} }; if (!ParseInput.NoZlibCompression) { - massesBinaryDataCvParams.Add( + positionsBinaryDataCvParams.Add( new CVParamType { accession = "MS:1000574", @@ -1506,9 +1515,9 @@ private SpectrumType ConstructPDASpectrum(int scanNumber, int instrumentNumber) }); } - massesBinaryData.cvParam = massesBinaryDataCvParams.ToArray(); + positionsBinaryData.cvParam = positionsBinaryDataCvParams.ToArray(); - binaryData.Add(massesBinaryData); + binaryData.Add(positionsBinaryData); } // Intensity Data @@ -1517,7 +1526,7 @@ private SpectrumType ConstructPDASpectrum(int scanNumber, int instrumentNumber) // Set the spectrum default array length if necessary if (spectrum.defaultArrayLength == 0) { - spectrum.defaultArrayLength = masses.Length; + spectrum.defaultArrayLength = intensities.Length; } var intensitiesBinaryData = @@ -1537,9 +1546,9 @@ private SpectrumType ConstructPDASpectrum(int scanNumber, int instrumentNumber) accession = "MS:1000515", name = "intensity array", cvRef = "MS", - unitCvRef = "MS", - unitAccession = "MS:1000131", - unitName = "number of counts", + unitCvRef = "UO", + unitAccession = "UO:0000269", + unitName = "absorbance unit", value = "" }, new CVParamType {accession = "MS:1000523", name = "64-bit float", cvRef = "MS", value = ""} @@ -1670,6 +1679,21 @@ private PrecursorListType ConstructPrecursorList(IScanEventBase scanEvent, int? cvRef = "MS" }); } + + if (selectedIonMz > ZeroDelta) + { + var selectedIonIntensity = CalculatePrecursorPeakIntensity(_rawFile, precursorScanNumber, selectedIonMz); + ionCvParams.Add(new CVParamType + { + name = "peak intensity", + value = selectedIonIntensity.ToString(), + accession = "MS:1000042", + cvRef = "MS", + unitAccession = "MS:1000131", + unitCvRef = "MS", + unitName = "number of detector counts" + }); + } precursor.selectedIonList.selectedIon[0].cvParam = ionCvParams.ToArray(); @@ -1964,6 +1988,7 @@ private ScanListType ConstructScanList(int scanNumber, Scan scan) value = "" }; + //scan start time var scanTypeCvParams = new List { new CVParamType @@ -1979,10 +2004,6 @@ private ScanListType ConstructScanList(int scanNumber, Scan scan) } }; - // Scan start time - - // Scan filter string - var scanType = new ScanType { instrumentConfigurationRef = "null", @@ -2003,21 +2024,21 @@ private ScanListType ConstructScanList(int scanNumber, Scan scan) { name = "scan window lower limit", accession = "MS:1000501", - value = scan.ScanStatistics.LowMass.ToString(CultureInfo.InvariantCulture), + value = scan.ScanStatistics.ShortWavelength.ToString(CultureInfo.InvariantCulture), cvRef = "MS", - unitAccession = "MS:1000040", - unitCvRef = "MS", - unitName = "m/z" + unitAccession = "UO:0000018", + unitCvRef = "UO", + unitName = "nanometer" }; scanWindow.cvParam[1] = new CVParamType { name = "scan window upper limit", accession = "MS:1000500", - value = scan.ScanStatistics.HighMass.ToString(CultureInfo.InvariantCulture), + value = scan.ScanStatistics.LongWavelength.ToString(CultureInfo.InvariantCulture), cvRef = "MS", - unitAccession = "MS:1000040", - unitCvRef = "MS", - unitName = "m/z" + unitAccession = "UO:0000018", + unitCvRef = "UO", + unitName = "nanometer" }; scanType.scanWindowList.scanWindow[0] = scanWindow; diff --git a/Writer/SpectrumWriter.cs b/Writer/SpectrumWriter.cs index 530111d..490d388 100644 --- a/Writer/SpectrumWriter.cs +++ b/Writer/SpectrumWriter.cs @@ -179,51 +179,36 @@ public static IReaction GetReaction(IScanEvent scanEvent, int scanNumber) { double? precursorIntensity = null; - // Get the scan from the RAW file + // Get the precursor scan from the RAW file var scan = Scan.FromFile(rawFile, precursorScanNumber); - // Check if the scan has a centroid stream + //Select centroid stream if it exists, otherwise use profile one + double[] masses; + double[] intensities; + if (scan.HasCentroidStream) { - var centroidStream = rawFile.GetCentroidStream(precursorScanNumber, false); - if (scan.CentroidScan.Length > 0) - { - for (var i = 0; i < centroidStream.Length; i++) - { - if (Math.Abs(precursorMass - centroidStream.Masses[i]) < Tolerance) - { - //Console.WriteLine(Math.Abs(precursorMass - centroidStream.Masses[i])); - //Console.WriteLine(precursorMass + " - " + centroidStream.Masses[i] + " - " + - // centroidStream.Intensities[i]); - precursorIntensity = centroidStream.Intensities[i]; - break; - } - } - } + masses = scan.CentroidScan.Masses; + intensities = scan.CentroidScan.Intensities; } else { - rawFile.SelectInstrument(Device.MS, 1); - - IChromatogramSettings[] allSettings = - { - new ChromatogramTraceSettings(TraceType.BasePeak) - { - Filter = MsFilter, - MassRanges = new[] - { - new Range(precursorMass, precursorMass) - } - } - }; + masses = scan.SegmentedScan.Positions; + intensities = scan.SegmentedScan.Intensities; + } - var data = rawFile.GetChromatogramData(allSettings, precursorScanNumber, - precursorScanNumber); - var chromatogramTrace = ChromatogramSignal.FromChromatogramData(data); - if (!chromatogramTrace.IsNullOrEmpty()) + //find closest peak in a stream + var bestDelta = Tolerance; + for (var i = 0; i < masses.Length; i++) + { + var delta = precursorMass - masses[i]; + if (Math.Abs(delta) < bestDelta) { - precursorIntensity = chromatogramTrace[0].Intensities[0]; + bestDelta = delta; + precursorIntensity = intensities[i]; } + + if (delta < -1 * Tolerance) break; } return precursorIntensity; From 3102c484a14678a31e45e08d5206d01d0862e9b9 Mon Sep 17 00:00:00 2001 From: caetera Date: Thu, 21 May 2020 17:46:25 +0200 Subject: [PATCH 05/15] Null check --- Writer/MzMlSpectrumWriter.cs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index bc47cac..8099d4d 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -1683,16 +1683,19 @@ private PrecursorListType ConstructPrecursorList(IScanEventBase scanEvent, int? if (selectedIonMz > ZeroDelta) { var selectedIonIntensity = CalculatePrecursorPeakIntensity(_rawFile, precursorScanNumber, selectedIonMz); - ionCvParams.Add(new CVParamType + if (selectedIonIntensity != null) { - name = "peak intensity", - value = selectedIonIntensity.ToString(), - accession = "MS:1000042", - cvRef = "MS", - unitAccession = "MS:1000131", - unitCvRef = "MS", - unitName = "number of detector counts" - }); + ionCvParams.Add(new CVParamType + { + name = "peak intensity", + value = selectedIonIntensity.ToString(), + accession = "MS:1000042", + cvRef = "MS", + unitAccession = "MS:1000131", + unitCvRef = "MS", + unitName = "number of detector counts" + }); + } } precursor.selectedIonList.selectedIon[0].cvParam = ionCvParams.ToArray(); From ec418d54ed6bbfa616c7a8a617d46bdb3decf15d Mon Sep 17 00:00:00 2001 From: caetera Date: Thu, 21 May 2020 21:27:35 +0200 Subject: [PATCH 06/15] UV and pressure chromatograms --- .gitignore | 4 +- ThermoRawFileParser.csproj.user | 6 - Writer/MzMlSpectrumWriter.cs | 232 ++++++++++++++++++++++++++++---- 3 files changed, 205 insertions(+), 37 deletions(-) delete mode 100644 ThermoRawFileParser.csproj.user diff --git a/.gitignore b/.gitignore index 3fa351d..481e710 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,6 @@ bin/ obj/ *.log -ThermoRawFileParser.sln.DotSettings.user +*.sln.DotSettings.user .vs/ - +*.csproj.user diff --git a/ThermoRawFileParser.csproj.user b/ThermoRawFileParser.csproj.user deleted file mode 100644 index 626950b..0000000 --- a/ThermoRawFileParser.csproj.user +++ /dev/null @@ -1,6 +0,0 @@ - - - - -i=C:\Code\QC_MSDDA_UV.raw -f=1 -o=C:\Code -a - - \ No newline at end of file diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index 8099d4d..8a8c20f 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -151,6 +151,42 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc cvRef = "MS", value = "" }); + //ion current chromatogram + SerializeCvParam(new CVParamType + { + accession = "MS:1000810", + name = "ion current chromatogram", + cvRef = "MS", + value = "" + }); + + //other detector data + if(ParseInput.AllDetectors) + { + //PDA spectrum + if(_rawFile.GetInstrumentCountOfType(Device.Pda) > 0) + { + SerializeCvParam(new CVParamType + { + accession = "MS:1000806", + name = "absorption spectrum", + cvRef = "MS", + value = "" + }); + } + + //absorption chromatogram + if (_rawFile.GetInstrumentCountOfType(Device.Pda) > 0 || _rawFile.GetInstrumentCountOfType(Device.UV) > 0) + { + SerializeCvParam(new CVParamType + { + accession = "MS:1000812", + name = "absorption chromatogram", + cvRef = "MS", + value = "" + }); + } + } _writer.WriteEndElement(); // fileContent // sourceFileList @@ -244,6 +280,19 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc name = "Conversion to mzML", value = "" }); + if (!ParseInput.NoPeakPicking) + { + _writer.WriteStartElement("processingMethod"); + _writer.WriteAttributeString("order", "1"); + _writer.WriteAttributeString("softwareRef", "ThermoRawFileParser"); + SerializeCvParam(new CVParamType + { + accession = "MS:1000035", + cvRef = "MS", + name = "peak picking", + value = "" + }); + } _writer.WriteEndElement(); // processingMethod _writer.WriteEndElement(); // dataProcessing _writer.WriteEndElement(); // dataProcessingList @@ -257,7 +306,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc _writer.WriteAttributeString("defaultSourceFileRef", SourceFileId); // spectrumList _writer.WriteStartElement("spectrumList"); - _writer.WriteAttributeString("count", _rawFile.RunHeaderEx.SpectraCount.ToString()); + _writer.WriteAttributeString("count", GetTotalScanNumber()); _writer.WriteAttributeString("defaultDataProcessingRef", "ThermoRawFileParserProcessing"); serializer = _factory.CreateSerializer(typeof(SpectrumType)); @@ -266,7 +315,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc var index = 0; var lastScanProgress = 0; - Log.Info("Processing " + (lastScanNumber - firstScanNumber) + " MS scans"); + Log.Info(String.Format("Processing {0} MS scans", + (1 + lastScanNumber - firstScanNumber))); for (var scanNumber = firstScanNumber; scanNumber <= lastScanNumber; scanNumber++) { @@ -318,14 +367,14 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc // PDA spectra if (ParseInput.AllDetectors && _rawFile.GetInstrumentCountOfType(Device.Pda) > 0) { - for (int nrI = 0; nrI < _rawFile.GetInstrumentCountOfType(Device.Pda); nrI++) + for (int nrI = 1; nrI < _rawFile.GetInstrumentCountOfType(Device.Pda) + 1; nrI++) { - _rawFile.SelectInstrument(Device.Pda, nrI + 1); + _rawFile.SelectInstrument(Device.Pda, nrI); firstScanNumber = _rawFile.RunHeader.FirstSpectrum; lastScanNumber = _rawFile.RunHeader.LastSpectrum; lastScanProgress = 0; - Log.Info("Processing " + (lastScanNumber - firstScanNumber) + " PDA scans from Device #" + (nrI + 1)); + Log.Info(String.Format("Processing {0} PDA scans from Device #{1}", (1 + lastScanNumber - firstScanNumber), nrI)); for (var scanNumber = firstScanNumber; scanNumber <= lastScanNumber; scanNumber++) { @@ -342,7 +391,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc } } - var spectrum = ConstructPDASpectrum(scanNumber, nrI + 1); + var spectrum = ConstructPDASpectrum(scanNumber, nrI); if (spectrum != null) { spectrum.index = index.ToString(); @@ -532,6 +581,32 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc } } + private string GetTotalScanNumber() + { + //save instrument that was selected last time + var lastSelectedInstrument =_rawFile.SelectedInstrument; + var numScans = 0; + + _rawFile.SelectInstrument(Device.MS, 1); + + numScans += 1 + _rawFile.RunHeader.LastSpectrum - _rawFile.RunHeader.FirstSpectrum; + + if (ParseInput.AllDetectors) + { + for (int nrI = 1; nrI < _rawFile.GetInstrumentCountOfType(Device.Pda) + 1; nrI++) + { + _rawFile.SelectInstrument(Device.Pda, nrI); + numScans += 1 + _rawFile.RunHeader.LastSpectrum - _rawFile.RunHeader.FirstSpectrum; + } + } + + //return instrument to last selected one + if (lastSelectedInstrument != null) + _rawFile.SelectInstrument(lastSelectedInstrument.DeviceType, lastSelectedInstrument.InstrumentIndex); + + return numScans.ToString(); + } + /// /// Populate the instrument configuration list /// @@ -704,6 +779,8 @@ private List ConstructChromatograms(int firstScanNumber, int l var chromatograms = new List(); //MS chromatograms + //Reselect MS device + _rawFile.SelectInstrument(Device.MS, 1); // Define the settings for getting the Base Peak chromatogram var settings = new ChromatogramTraceSettings(TraceType.BasePeak); @@ -744,21 +821,22 @@ private List ConstructChromatograms(int firstScanNumber, int l } - //UV chromatograms + //Chromatograms from other devices: UV, PDA if (ParseInput.AllDetectors) { - for (int nrI = 0; nrI < _rawFile.GetInstrumentCountOfType(Device.Pda); nrI++) + for (int nrI = 1; nrI < _rawFile.GetInstrumentCountOfType(Device.Pda) + 1; nrI++) { - _rawFile.SelectInstrument(Device.Pda, nrI + 1); + _rawFile.SelectInstrument(Device.Pda, nrI); - var settingsPDA = new ChromatogramTraceSettings(TraceType.TotalAbsorbance); + var instData = _rawFile.GetInstrumentData(); - var dataPDA = _rawFile.GetChromatogramData(new IChromatogramSettings[] { settingsPDA }, - -1, -1); + settings = new ChromatogramTraceSettings(TraceType.TotalAbsorbance); - var tracePDA = ChromatogramSignal.FromChromatogramData(dataPDA); + data = _rawFile.GetChromatogramData(new IChromatogramSettings[] { settings }, -1, -1); - for (var i = 0; i < tracePDA.Length; i++) + trace = ChromatogramSignal.FromChromatogramData(data); + + for (var i = 0; i < trace.Length; i++) { // CV Data for Total Absorbance Chromatogram var chroType = new CVParamType @@ -775,17 +853,115 @@ private List ConstructChromatograms(int firstScanNumber, int l name = "intensity array", cvRef = "MS", unitName = "absorbance unit", - value = "", + value = instData.Units.ToString(), unitCvRef = "UO", unitAccession = "UO:0000269" }; - var chromatogram = TraceToChromatogram(tracePDA[i], String.Format("PDA{0}_{1}", nrI, i.ToString()), - chroType, intensType); + var chromatogram = TraceToChromatogram(trace[i], + String.Format("PDA#{0}_TotalAbsorbance_{1}", nrI, i), + chroType, intensType); chromatograms.Add(chromatogram); } } + + for (int nrI = 1; nrI < _rawFile.GetInstrumentCountOfType(Device.UV) + 1; nrI++) + { + _rawFile.SelectInstrument(Device.UV, nrI); + + var instData = _rawFile.GetInstrumentData(); + + for (int channel = 0; channel < instData.ChannelLabels.Length; channel++) + { + var channelName = instData.ChannelLabels[channel]; + + settings = new ChromatogramTraceSettings(TraceType.StartUVChromatogramTraces + channel + 1); + + data = _rawFile.GetChromatogramData(new IChromatogramSettings[] { settings }, -1, -1); + + trace = ChromatogramSignal.FromChromatogramData(data); + + for (var i = 0; i < trace.Length; i++) + { + // CV Data for Absorbance Chromatogram + var chroType = new CVParamType + { + accession = "MS:1000812", + name = "absorption chromatogram", + cvRef = "MS", + value = "" + }; + + var intensType = new CVParamType + { + accession = "MS:1000515", + name = "intensity array", + cvRef = "MS", + unitName = "absorbance unit", + value = instData.Units.ToString(), + unitCvRef = "UO", + unitAccession = "UO:0000269" + }; + + var chromatogram = TraceToChromatogram(trace[i], + String.Format("UV#{0}_{1}_{2}", nrI, channelName, i), + chroType, intensType); + + chromatograms.Add(chromatogram); + } + } + } + + for (int nrI = 1; nrI < _rawFile.GetInstrumentCountOfType(Device.Analog) + 1; nrI++) + { + _rawFile.SelectInstrument(Device.Analog, nrI); + + var instData = _rawFile.GetInstrumentData(); + + for (int channel = 0; channel < instData.ChannelLabels.Length; channel++) + { + var channelName = instData.ChannelLabels[channel]; + + if (channelName.ToLower().Contains("pressure")) + { + settings = new ChromatogramTraceSettings(TraceType.StartPCA2DChromatogramTraces + channel + 1); + + data = _rawFile.GetChromatogramData(new IChromatogramSettings[] { settings }, -1, -1); + + trace = ChromatogramSignal.FromChromatogramData(data); + + for (var i = 0; i < trace.Length; i++) + { + // CV Data for Absorbance Chromatogram + var chroType = new CVParamType + { + accession = "MS:1003019", + name = "pressure chromatogram", + cvRef = "MS", + value = "" + }; + + var intensType = new CVParamType + { + accession = "MS:1000821", + name = "pressure array", + cvRef = "MS", + unitName = "pressure unit", + value = "", + unitCvRef = "UO", + unitAccession = "UO:0000109" + }; + + var chromatogram = TraceToChromatogram(trace[i], + String.Format("AD#{0}_{1}_{2}", nrI, channelName, i), + chroType, intensType); + + chromatograms.Add(chromatogram); + } + } + } + } } return chromatograms; @@ -1295,7 +1471,7 @@ private SpectrumType ConstructMSSpectrum(int scanNumber) // Set the spectrum default array length if necessary if (spectrum.defaultArrayLength == 0) { - spectrum.defaultArrayLength = masses.Length; + spectrum.defaultArrayLength = intensities.Length; } var intensitiesBinaryData = @@ -1377,17 +1553,7 @@ private SpectrumType ConstructPDASpectrum(int scanNumber, int instrumentNumber) // Construct and set the scan list element of the spectrum var scanListType = ConstructScanList(scanNumber, scan); spectrum.scanList = scanListType; - - // Total ion current - spectrumCvParams.Add(new CVParamType - { - name = "total ion current", - accession = "MS:1000285", - value = scan.ScanStatistics.TIC.ToString(CultureInfo.InvariantCulture), - cvRef = "MS" - }); - //Scan data double? basePeakPosition = null; double? basePeakIntensity = null; @@ -1845,7 +2011,8 @@ private PrecursorListType ConstructPrecursorList(IScanEventBase scanEvent, int? } /// - /// Populate the scan list element + /// Populate the scan list element. Full version used for mass spectra, + /// having Scan Event, scan Filter etc /// /// the scan number /// the scan object @@ -1973,6 +2140,13 @@ private ScanListType ConstructScanList(int scanNumber, Scan scan, IScanFilter sc return scanList; } + /// + /// Populate the scan list element. Simple version used for PDA spectra, + /// without Scan Event and other parameters + /// + /// the scan number + /// the scan object + /// private ScanListType ConstructScanList(int scanNumber, Scan scan) { // Scan list From da280b91d8e85d7429115e6fc60a53973fa37861 Mon Sep 17 00:00:00 2001 From: caetera Date: Fri, 22 May 2020 12:26:01 +0200 Subject: [PATCH 07/15] fix dataProcessingMethod --- MainClass.cs | 2 +- Writer/MzMlSpectrumWriter.cs | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/MainClass.cs b/MainClass.cs index 821d56b..cf370ec 100644 --- a/MainClass.cs +++ b/MainClass.cs @@ -17,7 +17,7 @@ public static class MainClass private static readonly ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - public const string Version = "1.2.3"; + public const string Version = "1.3.0-pre"; public static void Main(string[] args) { diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index 8a8c20f..5981b60 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -280,6 +280,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc name = "Conversion to mzML", value = "" }); + _writer.WriteEndElement(); // processingMethod if (!ParseInput.NoPeakPicking) { _writer.WriteStartElement("processingMethod"); From 472d7ca6af98f634b5f9c6d7dfb0d65ff65c059a Mon Sep 17 00:00:00 2001 From: caetera Date: Fri, 22 May 2020 13:37:34 +0200 Subject: [PATCH 08/15] Precursor intensity for low res scans --- ThermoRawFileParserTest/WriterTests.cs | 36 ++++++++++++++++++++++++++ Writer/SpectrumWriter.cs | 7 +++-- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/ThermoRawFileParserTest/WriterTests.cs b/ThermoRawFileParserTest/WriterTests.cs index 180d3fe..9e6f107 100644 --- a/ThermoRawFileParserTest/WriterTests.cs +++ b/ThermoRawFileParserTest/WriterTests.cs @@ -1,7 +1,10 @@ using System; using System.IO; +using System.Linq; +using System.Net.PeerToPeer.Collaboration; using System.Xml.Serialization; using IO.Mgf; +using MzLibUtil; using NUnit.Framework; using ThermoRawFileParser; using ThermoRawFileParser.Writer.MzML; @@ -66,6 +69,8 @@ public void TestMzml() Assert.AreEqual("1", testMzMl.run.chromatogramList.count); Assert.AreEqual(1, testMzMl.run.chromatogramList.chromatogram.Length); + + Assert.AreEqual(48, testMzMl.run.chromatogramList.chromatogram[0].defaultArrayLength); } [Test] @@ -98,5 +103,36 @@ public void TestIndexedMzML() Assert.AreEqual("chromatogram", testMzMl.indexList.index[1].name.ToString()); Assert.AreEqual(1, testMzMl.indexList.index[1].offset.Length); } + + [Test] + public void TestMzML_MS2() + { + // Get temp path for writing the test mzML + var tempFilePath = Path.GetTempPath(); + + var testRawFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Data/small2.RAW"); + var parseInput = new ParseInput(testRawFile, null, tempFilePath, OutputFormat.MzML); + + RawFileParser.Parse(parseInput); + + // Deserialize the mzML file + var xmlSerializer = new XmlSerializer(typeof(mzMLType)); + var testMzMl = (mzMLType)xmlSerializer.Deserialize(new FileStream( + Path.Combine(tempFilePath, "small2.mzML"), FileMode.Open, FileAccess.Read, FileShare.ReadWrite)); + + Assert.AreEqual(95, testMzMl.run.spectrumList.spectrum.Length); + + var precursor = testMzMl.run.spectrumList.spectrum[16].precursorList.precursor[0].selectedIonList.selectedIon[0]; + var selectedMz = Double.Parse(precursor.cvParam.Where(cv => cv.accession == "MS:1000744").First().value); + Assert.IsTrue(selectedMz - 604.7592 < 0.001); + + var selectedZ = int.Parse(precursor.cvParam.Where(cv => cv.accession == "MS:1000041").First().value); + Assert.AreEqual(selectedZ , 2); + + var selectedI = Double.Parse(precursor.cvParam.Where(cv => cv.accession == "MS:1000042").First().value); + Assert.IsTrue(selectedI - 10073 < 1); + + Assert.AreEqual(95, testMzMl.run.chromatogramList.chromatogram[0].defaultArrayLength); + } } } \ No newline at end of file diff --git a/Writer/SpectrumWriter.cs b/Writer/SpectrumWriter.cs index 490d388..6e07455 100644 --- a/Writer/SpectrumWriter.cs +++ b/Writer/SpectrumWriter.cs @@ -178,6 +178,7 @@ public static IReaction GetReaction(IScanEvent scanEvent, int scanNumber) double precursorMass) { double? precursorIntensity = null; + double tolerance; // Get the precursor scan from the RAW file var scan = Scan.FromFile(rawFile, precursorScanNumber); @@ -190,15 +191,17 @@ public static IReaction GetReaction(IScanEvent scanEvent, int scanNumber) { masses = scan.CentroidScan.Masses; intensities = scan.CentroidScan.Intensities; + tolerance = 0.01; //high resolution scan } else { masses = scan.SegmentedScan.Positions; intensities = scan.SegmentedScan.Intensities; + tolerance = 0.5; //low resolution scan } //find closest peak in a stream - var bestDelta = Tolerance; + var bestDelta = tolerance; for (var i = 0; i < masses.Length; i++) { var delta = precursorMass - masses[i]; @@ -208,7 +211,7 @@ public static IReaction GetReaction(IScanEvent scanEvent, int scanNumber) precursorIntensity = intensities[i]; } - if (delta < -1 * Tolerance) break; + if (delta < -1 * tolerance) break; } return precursorIntensity; From 55e02d14df685b959bdc1e0eb3461605821567e6 Mon Sep 17 00:00:00 2001 From: caetera Date: Fri, 22 May 2020 18:03:21 +0200 Subject: [PATCH 09/15] null instrument config reference --- Writer/MzMlSpectrumWriter.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index 5981b60..c2b1a91 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -2184,7 +2184,6 @@ private ScanListType ConstructScanList(int scanNumber, Scan scan) var scanType = new ScanType { - instrumentConfigurationRef = "null", cvParam = scanTypeCvParams.ToArray() }; From 29f192f8705970103a45747a08ee66b523332229 Mon Sep 17 00:00:00 2001 From: caetera Date: Fri, 29 May 2020 11:38:11 +0200 Subject: [PATCH 10/15] empty outputDirectory fix --- MainClass.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MainClass.cs b/MainClass.cs index cf370ec..d68b876 100644 --- a/MainClass.cs +++ b/MainClass.cs @@ -504,7 +504,7 @@ private static void RegularParametersParsing(string[] args) { if (parseInput.RawFilePath != null) { - parseInput.OutputDirectory = Path.GetDirectoryName(parseInput.RawFilePath); + parseInput.OutputDirectory = Path.GetDirectoryName(Path.GetFullPath(parseInput.RawFilePath)); } else if (parseInput.RawDirectoryPath != null) { From 7f804554f60de5a90528b55bfbbb2d94eff5c99a Mon Sep 17 00:00:00 2001 From: caetera Date: Wed, 1 Jul 2020 11:22:31 +0200 Subject: [PATCH 11/15] Ontology update --- Writer/MzMlSpectrumWriter.cs | 2 +- Writer/OntologyMapping.cs | 132 +++++++++++++++++++++++++++++++++-- 2 files changed, 126 insertions(+), 8 deletions(-) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index c2b1a91..0226deb 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -119,7 +119,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc URI = @"https://raw.githubusercontent.com/HUPO-PSI/psi-ms-CV/master/psi-ms.obo", fullName = "Mass spectrometry ontology", id = "MS", - version = "4.1.12" + version = "4.1.38" }); Serialize(serializer, new CVType { diff --git a/Writer/OntologyMapping.cs b/Writer/OntologyMapping.cs index 2277e20..fbd456d 100644 --- a/Writer/OntologyMapping.cs +++ b/Writer/OntologyMapping.cs @@ -227,6 +227,15 @@ public static class OntologyMapping value = "" } }, + { + "LTQ ORBITRAP CLASSIC", new CVParamType + { + accession = "MS:1002835", + name = "LTQ Orbitrap Classic", + cvRef = "MS", + value = "" + } + }, { "LTQ ORBITRAP DISCOVERY", new CVParamType { @@ -272,6 +281,33 @@ public static class OntologyMapping value = "" } }, + { + "ORBITRAP VELOS", new CVParamType + { + accession = "MS:1001742", + name = "LTQ Orbitrap Velos", + cvRef = "MS", + value = "" + } + }, + { + "LTQ ORBITRAP VELOS PRO", new CVParamType + { + accession = "MS:1003096", + name = "LTQ Orbitrap Velos Pro", + cvRef = "MS", + value = "" + } + }, + { + "ORBITRAP VELOS PRO", new CVParamType + { + accession = "MS:1003096", + name = "LTQ Orbitrap Velos Pro", + cvRef = "MS", + value = "" + } + }, { "LTQ ORBITRAP ELITE", new CVParamType { @@ -281,6 +317,15 @@ public static class OntologyMapping value = "" } }, + { + "ORBITRAP ELITE", new CVParamType + { + accession = "MS:1001910", + name = "LTQ Orbitrap Elite", + cvRef = "MS", + value = "" + } + }, { "LTQ", new CVParamType { @@ -299,6 +344,15 @@ public static class OntologyMapping value = "" } }, + { + "LTQ XL", new CVParamType + { + accession = "MS:1000854", + name = "LTQ XL", + cvRef = "MS", + value = "" + } + }, { "LTQ XL ETD", new CVParamType { @@ -326,6 +380,15 @@ public static class OntologyMapping value = "" } }, + { + "LTQ VELOS ETD", new CVParamType + { + accession = "MS:1000856", + name = "LTQ Velos ETD", + cvRef = "MS", + value = "" + } + }, { "ORBITRAP FUSION", new CVParamType { @@ -353,6 +416,33 @@ public static class OntologyMapping value = "" } }, + { + "ORBITRAP ECLIPSE", new CVParamType + { + accession = "MS:1003029", + name = "Orbitrap Eclipse", + cvRef = "MS", + value = "" + } + }, + { + "ORBITRAP EXPLORIS 120", new CVParamType + { + accession = "MS:1003095", + name = "Orbitrap Exploris 120", + cvRef = "MS", + value = "" + } + }, + { + "ORBITRAP EXPLORIS 240", new CVParamType + { + accession = "MS:1003094", + name = "Orbitrap Exploris 240", + cvRef = "MS", + value = "" + } + }, { "ORBITRAP EXPLORIS 480", new CVParamType { @@ -371,6 +461,15 @@ public static class OntologyMapping value = "" } }, + { + "EXACTIVE PLUS", new CVParamType + { + accession = "MS:1002526", + name = "Exactive Plus", + cvRef = "MS", + value = "" + } + }, { "Q EXACTIVE", new CVParamType { @@ -392,8 +491,8 @@ public static class OntologyMapping { "Q EXACTIVE PLUS ORBITRAP", new CVParamType { - accession = "MS:1001911", - name = "Q Exactive", + accession = "MS:1002634", + name = "Q Exactive Plus", cvRef = "MS", value = "" } @@ -435,13 +534,14 @@ public static class OntologyMapping public static CVParamType getInstrumentModel(string instrumentName) { CVParamType instrumentModel; + instrumentName = instrumentName.ToUpper(); if (OntologyMapping.InstrumentModels.ContainsKey(instrumentName)) { - instrumentModel = OntologyMapping.InstrumentModels[instrumentName.ToUpper()]; + instrumentModel = OntologyMapping.InstrumentModels[instrumentName]; } else { - var longestMatch = InstrumentModels.Where(pair => instrumentName.ToUpper().Contains(pair.Key)) + var longestMatch = InstrumentModels.Where(pair => instrumentName.Contains(pair.Key)) .Select(pair => pair.Key) .Aggregate("", (max, current) => max.Length > current.Length ? max : current); if (!longestMatch.IsNullOrEmpty()) @@ -477,8 +577,10 @@ public static List GetDetectors(string instrumentAccession) case "MS:1000448": // LTQ FT ULTRA case "MS:1000557": - // LTQ ORBITRAP + // LTQ ORBITRAP case "MS:1000449": + // LTQ ORBITRAP CLASSIC + case "MS:1002835": // LTQ ORBITRAP DISCOVERY case "MS:1000555": // LTQ ORBITRAP XL @@ -489,6 +591,8 @@ public static List GetDetectors(string instrumentAccession) case "MS:1000643": // LTQ ORBITRAP VELOS case "MS:1001742": + // LTQ ORBITRAP VELOS PRO + case "MS:1003096": // LTQ ORBITRAP ELITE case "MS:1001910": // ORBITRAP FUSION @@ -497,7 +601,13 @@ public static List GetDetectors(string instrumentAccession) case "MS:1002417": // ORBITRAP FUSION LUMOS case "MS:1002732": - // ORBITRAP EXPLORIS 480 + // ORBITRAP ECLIPSE + case "MS:1003029": + // ORBITRAP EXPLORIS 120 + case "MS:1003095": + // ORBITRAP EXPLORIS 240 + case "MS:1003094": + // ORBITRAP EXPLORIS 480 case "MS:1003028": detectors = new List { @@ -519,6 +629,8 @@ public static List GetDetectors(string instrumentAccession) break; // EXACTIVE case "MS:1000649": + // EXACTIVE PLUS + case "MS:1002526": // Q EXACTIVE case "MS:1001911": // Q EXACTIVE HF @@ -540,9 +652,15 @@ public static List GetDetectors(string instrumentAccession) break; // LTQ case "MS:1000447": + // LTQ VELOS + case "MS:1000855": + // LTQ VELOS ETD + case "MS:1000856": // LXQ case "MS:1000450": - // LTQ XL ETD + // LTQ XL + case "MS:1000854": + // LTQ XL ETD case "MS:1000638": // MALDI LTQ XL case "MS:1000642": From a6f0d12d702825cda5448d7044a730c53b33ce66 Mon Sep 17 00:00:00 2001 From: caetera Date: Fri, 3 Jul 2020 13:29:20 +0200 Subject: [PATCH 12/15] disable precursor intensity --- Writer/MzMlSpectrumWriter.cs | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index 0226deb..b5d1e18 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -1847,23 +1847,24 @@ private PrecursorListType ConstructPrecursorList(IScanEventBase scanEvent, int? }); } - if (selectedIonMz > ZeroDelta) - { - var selectedIonIntensity = CalculatePrecursorPeakIntensity(_rawFile, precursorScanNumber, selectedIonMz); - if (selectedIonIntensity != null) - { - ionCvParams.Add(new CVParamType - { - name = "peak intensity", - value = selectedIonIntensity.ToString(), - accession = "MS:1000042", - cvRef = "MS", - unitAccession = "MS:1000131", - unitCvRef = "MS", - unitName = "number of detector counts" - }); - } - } + //Precursor intensity is disabled for now + //if (selectedIonMz > ZeroDelta) + //{ + // var selectedIonIntensity = CalculatePrecursorPeakIntensity(_rawFile, precursorScanNumber, selectedIonMz); + // if (selectedIonIntensity != null) + // { + // ionCvParams.Add(new CVParamType + // { + // name = "peak intensity", + // value = selectedIonIntensity.ToString(), + // accession = "MS:1000042", + // cvRef = "MS", + // unitAccession = "MS:1000131", + // unitCvRef = "MS", + // unitName = "number of detector counts" + // }); + // } + //} precursor.selectedIonList.selectedIon[0].cvParam = ionCvParams.ToArray(); From ded99533446b8211cae26f59d3a2984f8294873c Mon Sep 17 00:00:00 2001 From: caetera Date: Sat, 1 Aug 2020 20:03:33 +0200 Subject: [PATCH 13/15] Add Orbitrap ID-X --- Writer/MzMlSpectrumWriter.cs | 2 +- Writer/OntologyMapping.cs | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index b5d1e18..ea3c38f 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -119,7 +119,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc URI = @"https://raw.githubusercontent.com/HUPO-PSI/psi-ms-CV/master/psi-ms.obo", fullName = "Mass spectrometry ontology", id = "MS", - version = "4.1.38" + version = "4.1.41" }); Serialize(serializer, new CVType { diff --git a/Writer/OntologyMapping.cs b/Writer/OntologyMapping.cs index fbd456d..6042a69 100644 --- a/Writer/OntologyMapping.cs +++ b/Writer/OntologyMapping.cs @@ -523,6 +523,15 @@ public static class OntologyMapping cvRef = "MS", value = "" } + }, + { + "ORBITRAP ID-X", new CVParamType + { + accession = "MS:1003112", + name = "Orbitrap ID-X", + cvRef = "MS", + value = "" + } } }; From 64ce15ee23adb5413636ed8d402c25b5c641db11 Mon Sep 17 00:00:00 2001 From: Vladimir Gorshkov Date: Wed, 26 Aug 2020 11:26:43 +0200 Subject: [PATCH 14/15] update help --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index b7b9de9..4c048e9 100644 --- a/README.md +++ b/README.md @@ -71,6 +71,7 @@ optional subcommands are xic|query (use [subcommand] -h for more info]): -z, --noZlibCompression Don't use zlib compression for the m/z ratios and intensities. By default zlib compression is enabled. + -a, --allDetectors Extract additonal detector data: UV/PDA etc -l, --logging=VALUE Optional logging level: 0 for silent, 1 for verbose. -e, --ignoreInstrumentErrors From a15670178252348a3d8701400063399e8a8fa17a Mon Sep 17 00:00:00 2001 From: Vladimir Gorshkov Date: Wed, 26 Aug 2020 19:32:32 +0200 Subject: [PATCH 15/15] Preparing for release --- MainClass.cs | 2 +- ThermoRawFileParserTest/WriterTests.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MainClass.cs b/MainClass.cs index d68b876..cbe8597 100644 --- a/MainClass.cs +++ b/MainClass.cs @@ -17,7 +17,7 @@ public static class MainClass private static readonly ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - public const string Version = "1.3.0-pre"; + public const string Version = "1.3.0"; public static void Main(string[] args) { diff --git a/ThermoRawFileParserTest/WriterTests.cs b/ThermoRawFileParserTest/WriterTests.cs index 9e6f107..1e63789 100644 --- a/ThermoRawFileParserTest/WriterTests.cs +++ b/ThermoRawFileParserTest/WriterTests.cs @@ -129,8 +129,8 @@ public void TestMzML_MS2() var selectedZ = int.Parse(precursor.cvParam.Where(cv => cv.accession == "MS:1000041").First().value); Assert.AreEqual(selectedZ , 2); - var selectedI = Double.Parse(precursor.cvParam.Where(cv => cv.accession == "MS:1000042").First().value); - Assert.IsTrue(selectedI - 10073 < 1); + //var selectedI = Double.Parse(precursor.cvParam.Where(cv => cv.accession == "MS:1000042").First().value); + //Assert.IsTrue(selectedI - 10073 < 1); Assert.AreEqual(95, testMzMl.run.chromatogramList.chromatogram[0].defaultArrayLength); }