From 8cceaf952725da9cebdcad235622cc72d0b87701 Mon Sep 17 00:00:00 2001 From: "heting.zhao" Date: Fri, 24 Feb 2023 01:07:26 +0000 Subject: [PATCH 01/28] ZSPACE-12104 Remove reduncant properties. --- Writer/MetadataWriter.cs | 62 ++++++++++++++++------------------------ 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/Writer/MetadataWriter.cs b/Writer/MetadataWriter.cs index 14e2b8c..e77d72a 100644 --- a/Writer/MetadataWriter.cs +++ b/Writer/MetadataWriter.cs @@ -154,7 +154,6 @@ private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int last // File Properties string filePath = rawFile.FileName; metadata.addFileProperty(new CVTerm("NCIT:C47922", "NCIT", "Pathname", filePath)); - metadata.addFileProperty(new CVTerm("NCIT:*****************", "NCIT", "File Name", filePath.Substring(0, filePath.LastIndexOf(".")).Remove(0, filePath.LastIndexOf("\\") + 1))); metadata.addFileProperty(new CVTerm("NCIT:C25714", "NCIT", "Version", rawFile.FileHeader.Revision.ToString())); metadata.addFileProperty(new CVTerm("NCIT:C69199", "NCIT", "Content Creation Date", @@ -229,20 +228,20 @@ private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int last // Sample Data if (!rawFile.SampleInformation.SampleName.IsNullOrEmpty()) { - metadata.addSampleProperty(new CVTerm("MS:1000002", "MS", "sample name", + metadata.addSampleProperty(new CVTerm("MS:1000002", "MS", "Sample Name", rawFile.SampleInformation.SampleName)); } if (!rawFile.SampleInformation.SampleId.IsNullOrEmpty()) { - metadata.addSampleProperty(new CVTerm("MS:1000001", "MS", "sample number", + metadata.addSampleProperty(new CVTerm("MS:1000001", "MS", "Sample Number", rawFile.SampleInformation.SampleId)); } if (!rawFile.SampleInformation.SampleType.ToString().IsNullOrEmpty() && !rawFile.SampleInformation.SampleType.ToString().Equals("Unknown")) { - metadata.addSampleProperty(new CVTerm("NCIT:C25284", "NCIT", "Type", + metadata.addSampleProperty(new CVTerm("NCIT:C25284", "NCIT", "Sample Type", rawFile.SampleInformation.SampleType.ToString())); } @@ -260,13 +259,13 @@ private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int last if (rawFile.SampleInformation.SampleVolume != 0) { - metadata.addSampleProperty(new CVTerm("MS:1000005", "MS", "sample volume", + metadata.addSampleProperty(new CVTerm("MS:1000005", "MS", "Sample Volume", rawFile.SampleInformation.SampleVolume.ToString(CultureInfo.InvariantCulture))); } if (rawFile.SampleInformation.InjectionVolume != 0) { - metadata.addSampleProperty(new CVTerm("AFR:0001577", "AFO", "injection volume setting", + metadata.addSampleProperty(new CVTerm("AFR:0001577", "AFO", "Injection Volume", rawFile.SampleInformation.InjectionVolume.ToString(CultureInfo.InvariantCulture))); } @@ -278,38 +277,33 @@ private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int last if (rawFile.SampleInformation.DilutionFactor != 0) { - metadata.addSampleProperty(new CVTerm("AFQ:0000178", "AFO", "dilution factor", + metadata.addSampleProperty(new CVTerm("AFQ:0000178", "AFO", "Dilution Factor", rawFile.SampleInformation.DilutionFactor.ToString(CultureInfo.InvariantCulture))); } - if (!rawFile.SampleInformation.Path.IsNullOrEmpty()) - { - metadata.addSampleProperty(new CVTerm("AFQ:**********************", "AFO", "Path", rawFile.SampleInformation.Path)); - } - if (!rawFile.SampleInformation.InstrumentMethodFile.IsNullOrEmpty()) { - metadata.addSampleProperty(new CVTerm("AFQ:******************", "AFO", "Instrument Method", rawFile.SampleInformation.InstrumentMethodFile)); + metadata.addSampleProperty(new CVTerm("AFR:0002045", "AFO", "Device Acquisition Method", rawFile.SampleInformation.InstrumentMethodFile)); } if (rawFile.SampleInformation.IstdAmount != 0) { - metadata.addSampleProperty(new CVTerm("AFQ:****************", "AFO", "Istd Amount", rawFile.SampleInformation.IstdAmount.ToString())); + metadata.addSampleProperty(new CVTerm("", "", "Internal Standard Amount", rawFile.SampleInformation.IstdAmount.ToString())); } if (!rawFile.SampleInformation.CalibrationLevel.IsNullOrEmpty()) { - metadata.addSampleProperty(new CVTerm("AFQ:****************", "AFO", "Calibration Level", rawFile.SampleInformation.CalibrationLevel)); + metadata.addSampleProperty(new CVTerm("AFR:0001849", "AFO", "Calibration Level", rawFile.SampleInformation.CalibrationLevel)); } if (!rawFile.SampleInformation.ProcessingMethodFile.IsNullOrEmpty()) { - metadata.addSampleProperty(new CVTerm("AFQ:****************", "AFO", "Processing Method", rawFile.SampleInformation.ProcessingMethodFile)); + metadata.addSampleProperty(new CVTerm("AFR:0002175", "AFO", "Data Processing Method", rawFile.SampleInformation.ProcessingMethodFile)); } if (rawFile.SampleInformation.SampleWeight != 0) { - metadata.addSampleProperty(new CVTerm("AFQ:****************", "AFO", "Processing Method", rawFile.SampleInformation.SampleWeight.ToString())); + metadata.addSampleProperty(new CVTerm("", "", "Sample Weight", rawFile.SampleInformation.SampleWeight.ToString())); } string[] userLabels = rawFile.UserLabel; @@ -324,7 +318,7 @@ private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int last { if (!userTexts[i].IsNullOrEmpty()) { - metadata.addSampleProperty(new CVTerm("AFQ:****************", "AFO", userLabels[i], userTexts[i])); + metadata.addSampleProperty(new CVTerm("", "", userLabels[i], userTexts[i])); } } } @@ -354,8 +348,7 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la var output = new List { "#FileProperties", - "RAW file path=" + filePath, - "RAW file name=" + filePath.Substring(0, filePath.LastIndexOf(".")).Remove(0, filePath.LastIndexOf("\\") + 1), + "RAW File Path=" + filePath, "RAW file version=" + rawFile.FileHeader.Revision, "Creation date=" + rawFile.FileHeader.CreationDate }; @@ -422,53 +415,53 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la if (!rawFile.SampleInformation.SampleName.IsNullOrEmpty()) { - output.Add("Sample name=" + rawFile.SampleInformation.SampleName); + output.Add("Sample Name=" + rawFile.SampleInformation.SampleName); } if (!rawFile.SampleInformation.SampleId.IsNullOrEmpty()) { - output.Add("Sample id=" + rawFile.SampleInformation.SampleId); + output.Add("Sample Number=" + rawFile.SampleInformation.SampleId); } if (!rawFile.SampleInformation.SampleType.ToString().IsNullOrEmpty() && !rawFile.SampleInformation.SampleType.ToString().Equals("Unknown")) { - output.Add("Sample type=" + rawFile.SampleInformation.SampleType); + output.Add("Sample Type=" + rawFile.SampleInformation.SampleType); } if (!rawFile.SampleInformation.Comment.IsNullOrEmpty()) { - output.Add("Sample comment=" + rawFile.SampleInformation.Comment); + output.Add("Comment=" + rawFile.SampleInformation.Comment); } if (!rawFile.SampleInformation.Vial.IsNullOrEmpty()) { - output.Add("Sample vial=" + rawFile.SampleInformation.Vial); + output.Add("Vial=" + rawFile.SampleInformation.Vial); } if (rawFile.SampleInformation.SampleVolume != 0) { - output.Add("Sample volume=" + rawFile.SampleInformation.SampleVolume); + output.Add("Sample Volume=" + rawFile.SampleInformation.SampleVolume); } if (rawFile.SampleInformation.InjectionVolume != 0) { - output.Add("Sample injection volume=" + rawFile.SampleInformation.InjectionVolume); + output.Add("Injection Volume=" + rawFile.SampleInformation.InjectionVolume); } if (rawFile.SampleInformation.RowNumber != 0) { - output.Add("Sample row number=" + rawFile.SampleInformation.RowNumber); + output.Add("Sample Row Number=" + rawFile.SampleInformation.RowNumber); } if (rawFile.SampleInformation.DilutionFactor != 0) { - output.Add("Sample dilution factor=" + rawFile.SampleInformation.DilutionFactor); + output.Add("Dilution Factor=" + rawFile.SampleInformation.DilutionFactor); } if (rawFile.SampleInformation.IstdAmount != 0) { - output.Add("Istd Amount=" + rawFile.SampleInformation.IstdAmount); + output.Add("Internal Standard Amount=" + rawFile.SampleInformation.IstdAmount); } if (!rawFile.SampleInformation.CalibrationLevel.IsNullOrEmpty()) @@ -478,7 +471,7 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la if (!rawFile.SampleInformation.InstrumentMethodFile.IsNullOrEmpty()) { - output.Add("Instrument Method=" + rawFile.SampleInformation.InstrumentMethodFile); + output.Add("Device Acquisition Method=" + rawFile.SampleInformation.InstrumentMethodFile); } if (rawFile.SampleInformation.SampleWeight != 0) @@ -488,12 +481,7 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la if (!rawFile.SampleInformation.ProcessingMethodFile.IsNullOrEmpty()) { - output.Add("Processing Method=" + rawFile.SampleInformation.ProcessingMethodFile); - } - - if (!rawFile.SampleInformation.Path.IsNullOrEmpty()) - { - output.Add("Path=" + rawFile.SampleInformation.Path); + output.Add("Data Processing Method=" + rawFile.SampleInformation.ProcessingMethodFile); } string[] userLabels = rawFile.UserLabel; From 04b1c61c1d658070319c3d665a056d449face8ad Mon Sep 17 00:00:00 2001 From: "heting.zhao" Date: Fri, 24 Feb 2023 01:18:55 +0000 Subject: [PATCH 02/28] ZSPACE-12104 Remove reduncant properties. --- MainClass.cs | 9 +++++---- Writer/MetadataWriter.cs | 6 ++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/MainClass.cs b/MainClass.cs index 19df55a..91c9a79 100644 --- a/MainClass.cs +++ b/MainClass.cs @@ -51,10 +51,10 @@ public static void Main(string[] args) private static void XicParametersParsing(string[] args) { XicParameters parameters = new XicParameters(); - string singleFile = "D:\\ht\\testdata\\Columbo-PM-22-291-MetIDEFatePhoto-07092022-MA-04B.raw"; + string singleFile = null; string fileDirectory = null; string outputFile = null; - string outputDirectory = "D:\\ht\\testdata"; + string outputDirectory = null; string logFormatString = null; var optionSet = new OptionSet @@ -486,7 +486,7 @@ private static void RegularParametersParsing(string[] args) var help = false; var version = false; string outputFormatString = null; - string metadataFormatString = null; + string metadataFormatString = "1"; string logFormatString = null; var parseInput = new ParseInput(); @@ -613,7 +613,8 @@ private static void RegularParametersParsing(string[] args) { // parse the command line var extra = optionSet.Parse(args); - + parseInput.RawDirectoryPath = "D:\\ht\\testdata"; + parseInput.OutputDirectory = "D:\\ht\\testdata\\output"; if (!extra.IsNullOrEmpty()) { throw new OptionException("Unexpected extra arguments", null); diff --git a/Writer/MetadataWriter.cs b/Writer/MetadataWriter.cs index e77d72a..f1911a4 100644 --- a/Writer/MetadataWriter.cs +++ b/Writer/MetadataWriter.cs @@ -152,8 +152,7 @@ private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int last var metadata = new Metadata(); // File Properties - string filePath = rawFile.FileName; - metadata.addFileProperty(new CVTerm("NCIT:C47922", "NCIT", "Pathname", filePath)); + metadata.addFileProperty(new CVTerm("NCIT:C47922", "NCIT", "Pathname", rawFile.FileName)); metadata.addFileProperty(new CVTerm("NCIT:C25714", "NCIT", "Version", rawFile.FileHeader.Revision.ToString())); metadata.addFileProperty(new CVTerm("NCIT:C69199", "NCIT", "Content Creation Date", @@ -342,13 +341,12 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la // Get the start and end time from the RAW file var startTime = rawFile.RunHeaderEx.StartTime; var endTime = rawFile.RunHeaderEx.EndTime; - string filePath = rawFile.FileName; // File Properties var output = new List { "#FileProperties", - "RAW File Path=" + filePath, + "RAW File Path=" + rawFile.FileName, "RAW file version=" + rawFile.FileHeader.Revision, "Creation date=" + rawFile.FileHeader.CreationDate }; From ac97343f10f71f7ee4afcaf3779b8b308f85651d Mon Sep 17 00:00:00 2001 From: "heting.zhao" Date: Fri, 24 Feb 2023 01:23:28 +0000 Subject: [PATCH 03/28] ZSPACE-12104 Remove reduncant properties. --- MainClass.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MainClass.cs b/MainClass.cs index 91c9a79..dd681df 100644 --- a/MainClass.cs +++ b/MainClass.cs @@ -486,7 +486,7 @@ private static void RegularParametersParsing(string[] args) var help = false; var version = false; string outputFormatString = null; - string metadataFormatString = "1"; + string metadataFormatString = null; string logFormatString = null; var parseInput = new ParseInput(); @@ -613,8 +613,6 @@ private static void RegularParametersParsing(string[] args) { // parse the command line var extra = optionSet.Parse(args); - parseInput.RawDirectoryPath = "D:\\ht\\testdata"; - parseInput.OutputDirectory = "D:\\ht\\testdata\\output"; if (!extra.IsNullOrEmpty()) { throw new OptionException("Unexpected extra arguments", null); From 40404df32a20fe95f5609c75a0d94ac750f4abac Mon Sep 17 00:00:00 2001 From: "heting.zhao" Date: Fri, 24 Feb 2023 01:26:05 +0000 Subject: [PATCH 04/28] ZSPACE-12104 Remove reduncant properties. --- MainClass.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/MainClass.cs b/MainClass.cs index dd681df..7ece9cf 100644 --- a/MainClass.cs +++ b/MainClass.cs @@ -613,6 +613,7 @@ private static void RegularParametersParsing(string[] args) { // parse the command line var extra = optionSet.Parse(args); + if (!extra.IsNullOrEmpty()) { throw new OptionException("Unexpected extra arguments", null); From 9c1e63605c70412135a04a407f0b32c838558f3c Mon Sep 17 00:00:00 2001 From: "Heting.Zhao" Date: Mon, 27 Feb 2023 06:23:44 +0000 Subject: [PATCH 05/28] ZSPACE-12104 Solve code review issues. --- Writer/MetadataWriter.cs | 59 ++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 32 deletions(-) diff --git a/Writer/MetadataWriter.cs b/Writer/MetadataWriter.cs index f1911a4..38007df 100644 --- a/Writer/MetadataWriter.cs +++ b/Writer/MetadataWriter.cs @@ -227,20 +227,20 @@ private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int last // Sample Data if (!rawFile.SampleInformation.SampleName.IsNullOrEmpty()) { - metadata.addSampleProperty(new CVTerm("MS:1000002", "MS", "Sample Name", + metadata.addSampleProperty(new CVTerm("MS:1000002", "MS", "sample name", rawFile.SampleInformation.SampleName)); } if (!rawFile.SampleInformation.SampleId.IsNullOrEmpty()) { - metadata.addSampleProperty(new CVTerm("MS:1000001", "MS", "Sample Number", + metadata.addSampleProperty(new CVTerm("MS:1000001", "MS", "sample number", rawFile.SampleInformation.SampleId)); } if (!rawFile.SampleInformation.SampleType.ToString().IsNullOrEmpty() && !rawFile.SampleInformation.SampleType.ToString().Equals("Unknown")) { - metadata.addSampleProperty(new CVTerm("NCIT:C25284", "NCIT", "Sample Type", + metadata.addSampleProperty(new CVTerm("NCIT:C25284", "NCIT", "Type", rawFile.SampleInformation.SampleType.ToString())); } @@ -258,13 +258,13 @@ private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int last if (rawFile.SampleInformation.SampleVolume != 0) { - metadata.addSampleProperty(new CVTerm("MS:1000005", "MS", "Sample Volume", + metadata.addSampleProperty(new CVTerm("MS:1000005", "MS", "sample volume", rawFile.SampleInformation.SampleVolume.ToString(CultureInfo.InvariantCulture))); } if (rawFile.SampleInformation.InjectionVolume != 0) { - metadata.addSampleProperty(new CVTerm("AFR:0001577", "AFO", "Injection Volume", + metadata.addSampleProperty(new CVTerm("AFR:0001577", "AFO", "injection volume setting", rawFile.SampleInformation.InjectionVolume.ToString(CultureInfo.InvariantCulture))); } @@ -276,53 +276,48 @@ private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int last if (rawFile.SampleInformation.DilutionFactor != 0) { - metadata.addSampleProperty(new CVTerm("AFQ:0000178", "AFO", "Dilution Factor", + metadata.addSampleProperty(new CVTerm("AFQ:0000178", "AFO", "dilution factor", rawFile.SampleInformation.DilutionFactor.ToString(CultureInfo.InvariantCulture))); } if (!rawFile.SampleInformation.InstrumentMethodFile.IsNullOrEmpty()) { - metadata.addSampleProperty(new CVTerm("AFR:0002045", "AFO", "Device Acquisition Method", rawFile.SampleInformation.InstrumentMethodFile)); + metadata.addSampleProperty(new CVTerm("AFR:0002045", "AFO", "device acquisition method", rawFile.SampleInformation.InstrumentMethodFile)); } if (rawFile.SampleInformation.IstdAmount != 0) { - metadata.addSampleProperty(new CVTerm("", "", "Internal Standard Amount", rawFile.SampleInformation.IstdAmount.ToString())); + metadata.addSampleProperty(new CVTerm("", "", "internal standard amount", rawFile.SampleInformation.IstdAmount.ToString())); } if (!rawFile.SampleInformation.CalibrationLevel.IsNullOrEmpty()) { - metadata.addSampleProperty(new CVTerm("AFR:0001849", "AFO", "Calibration Level", rawFile.SampleInformation.CalibrationLevel)); + metadata.addSampleProperty(new CVTerm("AFR:0001849", "AFO", "calibration level", rawFile.SampleInformation.CalibrationLevel)); } if (!rawFile.SampleInformation.ProcessingMethodFile.IsNullOrEmpty()) { - metadata.addSampleProperty(new CVTerm("AFR:0002175", "AFO", "Data Processing Method", rawFile.SampleInformation.ProcessingMethodFile)); + metadata.addSampleProperty(new CVTerm("AFR:0002175", "AFO", "data processing method", rawFile.SampleInformation.ProcessingMethodFile)); } if (rawFile.SampleInformation.SampleWeight != 0) { - metadata.addSampleProperty(new CVTerm("", "", "Sample Weight", rawFile.SampleInformation.SampleWeight.ToString())); + metadata.addSampleProperty(new CVTerm("AFR:0001982", "AFO", "sample weight", rawFile.SampleInformation.SampleWeight.ToString())); } string[] userLabels = rawFile.UserLabel; string[] userTexts = rawFile.SampleInformation.UserText; if (!userLabels.IsNullOrEmpty() && !userTexts.IsNullOrEmpty()) { - if (userLabels.Length > userTexts.Length) - { - throw new RawFileParserException(); - } for (int i = 0; i < userLabels.Length; i++) { - if (!userTexts[i].IsNullOrEmpty()) + if (i < userTexts.Length && !userTexts[i].IsNullOrEmpty()) { metadata.addSampleProperty(new CVTerm("", "", userLabels[i], userTexts[i])); } } } - // Write the meta data to file var json = JsonConvert.SerializeObject(metadata); json.Replace("\r\n", "\n"); @@ -346,7 +341,7 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la var output = new List { "#FileProperties", - "RAW File Path=" + rawFile.FileName, + "RAW file path=" + rawFile.FileName, "RAW file version=" + rawFile.FileHeader.Revision, "Creation date=" + rawFile.FileHeader.CreationDate }; @@ -413,73 +408,73 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la if (!rawFile.SampleInformation.SampleName.IsNullOrEmpty()) { - output.Add("Sample Name=" + rawFile.SampleInformation.SampleName); + output.Add("Sample name=" + rawFile.SampleInformation.SampleName); } if (!rawFile.SampleInformation.SampleId.IsNullOrEmpty()) { - output.Add("Sample Number=" + rawFile.SampleInformation.SampleId); + output.Add("Sample id=" + rawFile.SampleInformation.SampleId); } if (!rawFile.SampleInformation.SampleType.ToString().IsNullOrEmpty() && !rawFile.SampleInformation.SampleType.ToString().Equals("Unknown")) { - output.Add("Sample Type=" + rawFile.SampleInformation.SampleType); + output.Add("Sample type=" + rawFile.SampleInformation.SampleType); } if (!rawFile.SampleInformation.Comment.IsNullOrEmpty()) { - output.Add("Comment=" + rawFile.SampleInformation.Comment); + output.Add("Sample comment=" + rawFile.SampleInformation.Comment); } if (!rawFile.SampleInformation.Vial.IsNullOrEmpty()) { - output.Add("Vial=" + rawFile.SampleInformation.Vial); + output.Add("Sample vial=" + rawFile.SampleInformation.Vial); } if (rawFile.SampleInformation.SampleVolume != 0) { - output.Add("Sample Volume=" + rawFile.SampleInformation.SampleVolume); + output.Add("Sample volume=" + rawFile.SampleInformation.SampleVolume); } if (rawFile.SampleInformation.InjectionVolume != 0) { - output.Add("Injection Volume=" + rawFile.SampleInformation.InjectionVolume); + output.Add("Sample injection volume=" + rawFile.SampleInformation.InjectionVolume); } if (rawFile.SampleInformation.RowNumber != 0) { - output.Add("Sample Row Number=" + rawFile.SampleInformation.RowNumber); + output.Add("Sample row number=" + rawFile.SampleInformation.RowNumber); } if (rawFile.SampleInformation.DilutionFactor != 0) { - output.Add("Dilution Factor=" + rawFile.SampleInformation.DilutionFactor); + output.Add("Sample dilution factor=" + rawFile.SampleInformation.DilutionFactor); } if (rawFile.SampleInformation.IstdAmount != 0) { - output.Add("Internal Standard Amount=" + rawFile.SampleInformation.IstdAmount); + output.Add("Internal standard amount=" + rawFile.SampleInformation.IstdAmount); } if (!rawFile.SampleInformation.CalibrationLevel.IsNullOrEmpty()) { - output.Add("Calibration Level=" + rawFile.SampleInformation.CalibrationLevel); + output.Add("Calibration level=" + rawFile.SampleInformation.CalibrationLevel); } if (!rawFile.SampleInformation.InstrumentMethodFile.IsNullOrEmpty()) { - output.Add("Device Acquisition Method=" + rawFile.SampleInformation.InstrumentMethodFile); + output.Add("Device acquisition method=" + rawFile.SampleInformation.InstrumentMethodFile); } if (rawFile.SampleInformation.SampleWeight != 0) { - output.Add("Sample Weight=" + rawFile.SampleInformation.SampleWeight); + output.Add("Sample weight=" + rawFile.SampleInformation.SampleWeight); } if (!rawFile.SampleInformation.ProcessingMethodFile.IsNullOrEmpty()) { - output.Add("Data Processing Method=" + rawFile.SampleInformation.ProcessingMethodFile); + output.Add("Data processing method=" + rawFile.SampleInformation.ProcessingMethodFile); } string[] userLabels = rawFile.UserLabel; From dc22d8741da2d11a6ccb64a186673f0e6c62b704 Mon Sep 17 00:00:00 2001 From: "Heting.Zhao" Date: Mon, 27 Feb 2023 06:31:44 +0000 Subject: [PATCH 06/28] ZSPACE-12104 Solve code review issues. --- Writer/MetadataWriter.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Writer/MetadataWriter.cs b/Writer/MetadataWriter.cs index 38007df..c76cd7a 100644 --- a/Writer/MetadataWriter.cs +++ b/Writer/MetadataWriter.cs @@ -481,13 +481,9 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la string[] userTexts = rawFile.SampleInformation.UserText; if (!userLabels.IsNullOrEmpty() && !userTexts.IsNullOrEmpty()) { - if (userLabels.Length > userTexts.Length) - { - throw new RawFileParserException(); - } for (int i = 0; i < userLabels.Length; i++) { - if (!userTexts[i].IsNullOrEmpty()) + if (i < userTexts.Length && !userTexts[i].IsNullOrEmpty()) { output.Add(userLabels[i] + "=" + userTexts[i]); } From 467506bc2438daa15caa89f128ea32fd05c1070f Mon Sep 17 00:00:00 2001 From: "MEMBER\\Heting.Zhao" Date: Fri, 3 Mar 2023 11:18:40 +0800 Subject: [PATCH 07/28] ZSPACE-12467 Check if the file is MS type --- RawFileParser.cs | 27 +++-- Writer/MetadataWriter.cs | 219 ++++++++++++++++++++------------------- 2 files changed, 131 insertions(+), 115 deletions(-) diff --git a/RawFileParser.cs b/RawFileParser.cs index 8ac667d..9916612 100644 --- a/RawFileParser.cs +++ b/RawFileParser.cs @@ -136,27 +136,32 @@ private static void ProcessFile(ParseInput parseInput) // Get the number of instruments (controllers) present in the RAW file and set the // selected instrument to the MS instrument, first instance of it - rawFile.SelectInstrument(Device.MS, 1); + var firstScanNumber = -1; + var lastScanNumber = -1; + if (rawFile.GetInstrumentCountOfType(Device.MS) != 0) + { + rawFile.SelectInstrument(Device.MS, 1); - rawFile.IncludeReferenceAndExceptionData = !parseInput.ExData; + rawFile.IncludeReferenceAndExceptionData = !parseInput.ExData; - // Get the first and last scan from the RAW file - var firstScanNumber = rawFile.RunHeaderEx.FirstSpectrum; - var lastScanNumber = rawFile.RunHeaderEx.LastSpectrum; + // Get the first and last scan from the RAW file + firstScanNumber = rawFile.RunHeaderEx.FirstSpectrum; + lastScanNumber = rawFile.RunHeaderEx.LastSpectrum; - // Check for empty file - if (lastScanNumber < 1) - { - throw new RawFileParserException("Empty RAW file, no output will be produced"); + // Check for empty file + if (lastScanNumber < 1) + { + throw new RawFileParserException("Empty RAW file, no output will be produced"); + } } - + if (parseInput.MetadataFormat != MetadataFormat.NONE) { MetadataWriter metadataWriter = new MetadataWriter(parseInput); metadataWriter.WriteMetadata(rawFile, firstScanNumber, lastScanNumber); } - if (parseInput.OutputFormat != OutputFormat.NONE) + if (rawFile.SelectMsData() && parseInput.OutputFormat != OutputFormat.NONE) { SpectrumWriter spectrumWriter; switch (parseInput.OutputFormat) diff --git a/Writer/MetadataWriter.cs b/Writer/MetadataWriter.cs index e7554ce..be161a1 100644 --- a/Writer/MetadataWriter.cs +++ b/Writer/MetadataWriter.cs @@ -46,73 +46,74 @@ public MetadataWriter(ParseInput parseInput) /// public void WriteMetadata(IRawDataPlus rawFile, int firstScanNumber, int lastScanNumber) { - // Get the start and end time from the RAW file - var startTime = rawFile.RunHeaderEx.StartTime; - var endTime = rawFile.RunHeaderEx.EndTime; - - for (var scanNumber = firstScanNumber; scanNumber <= lastScanNumber; scanNumber++) + if (rawFile.SelectMsData()) { - var time = rawFile.RetentionTimeFromScanNumber(scanNumber); - - // Get the scan filter for this scan number - var scanFilter = rawFile.GetFilterForScanNumber(scanNumber); + for (var scanNumber = firstScanNumber; scanNumber <= lastScanNumber; scanNumber++) + { + var time = rawFile.RetentionTimeFromScanNumber(scanNumber); - // Get the scan event for this scan number - var scanEvent = rawFile.GetScanEventForScanNumber(scanNumber); + // Get the scan filter for this scan number + var scanFilter = rawFile.GetFilterForScanNumber(scanNumber); - // Keep track of the number of MS spectra - if (msTypes.ContainsKey(scanFilter.MSOrder.ToString())) - { - var value = msTypes[scanFilter.MSOrder.ToString()]; - value += 1; - msTypes[scanFilter.MSOrder.ToString()] = value; - } - else - msTypes.Add(scanFilter.MSOrder.ToString(), 1); + // Get the scan event for this scan number + var scanEvent = rawFile.GetScanEventForScanNumber(scanNumber); - if (time > maxTime) - maxTime = time; - if (time < minTime) - minTime = time; + // Keep track of the number of MS spectra + if (msTypes.ContainsKey(scanFilter.MSOrder.ToString())) + { + var value = msTypes[scanFilter.MSOrder.ToString()]; + value += 1; + msTypes[scanFilter.MSOrder.ToString()] = value; + } + else + msTypes.Add(scanFilter.MSOrder.ToString(), 1); - if (scanFilter.MSOrder == MSOrderType.Ms2) - { - fragmentationTypes.Add(ParseActivationType(scanFilter.GetActivation(0))); + if (time > maxTime) + maxTime = time; + if (time < minTime) + minTime = time; - if (scanEvent.ScanData == ScanDataType.Centroid || (scanEvent.ScanData == ScanDataType.Profile)) + if (scanFilter.MSOrder == MSOrderType.Ms2) { - try - { - var reaction = scanEvent.GetReaction(0); - var precursorMass = reaction.PrecursorMass; - if (precursorMass > maxMz) - maxMz = precursorMass; - if (precursorMass < minMz) - minMz = precursorMass; - } - catch (ArgumentOutOfRangeException) - { - Log.Warn("No reaction found for scan " + scanNumber); - _parseInput.NewWarn(); - } + fragmentationTypes.Add(ParseActivationType(scanFilter.GetActivation(0))); - // trailer extra data list - var trailerData = rawFile.GetTrailerExtraInformation(scanNumber); - for (var i = 0; i < trailerData.Length; i++) + if (scanEvent.ScanData == ScanDataType.Centroid || (scanEvent.ScanData == ScanDataType.Profile)) { - if (trailerData.Labels[i] == "Charge State:") + try { - if (int.Parse(trailerData.Values[i]) > maxCharge) - maxCharge = int.Parse(trailerData.Values[i]); + var reaction = scanEvent.GetReaction(0); + var precursorMass = reaction.PrecursorMass; + if (precursorMass > maxMz) + maxMz = precursorMass; + if (precursorMass < minMz) + minMz = precursorMass; + } + catch (ArgumentOutOfRangeException) + { + Log.Warn("No reaction found for scan " + scanNumber); + _parseInput.NewWarn(); + } - if (int.Parse(trailerData.Values[i]) < minCharge) - minCharge = int.Parse(trailerData.Values[i]); + // trailer extra data list + var trailerData = rawFile.GetTrailerExtraInformation(scanNumber); + for (var i = 0; i < trailerData.Length; i++) + { + if (trailerData.Labels[i] == "Charge State:") + { + if (int.Parse(trailerData.Values[i]) > maxCharge) + maxCharge = int.Parse(trailerData.Values[i]); + + if (int.Parse(trailerData.Values[i]) < minCharge) + minCharge = int.Parse(trailerData.Values[i]); + } } } } } } + + if (minCharge == 100000000000000) { minCharge = 0; @@ -145,10 +146,6 @@ public void WriteMetadata(IRawDataPlus rawFile, int firstScanNumber, int lastSca /// private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int lastScanNumber) { - // Get the start and end time from the RAW file - var startTime = rawFile.RunHeaderEx.StartTime; - var endTime = rawFile.RunHeaderEx.EndTime; - var metadata = new Metadata(); // File Properties @@ -164,20 +161,23 @@ private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int last } // Instrument Properties - metadata.addInstrumentProperty(new CVTerm("MS:1000494", "MS", "Thermo Scientific instrument model", - rawFile.GetInstrumentData().Model)); - metadata.addInstrumentProperty(new CVTerm("MS:1000496", "MS", "instrument attribute", - rawFile.GetInstrumentData().Name)); - metadata.addInstrumentProperty(new CVTerm("MS:1000529", "MS", "instrument serial number", - rawFile.GetInstrumentData().SerialNumber)); - metadata.addInstrumentProperty(new CVTerm("NCIT:C111093", "NCIT", "Software Version", - rawFile.GetInstrumentData().SoftwareVersion)); - if (!rawFile.GetInstrumentData().HardwareVersion.IsNullOrEmpty()) + if (rawFile.SelectMsData()) { - metadata.addInstrumentProperty(new CVTerm("AFR:0001259", "AFO", "firmware version", - rawFile.GetInstrumentData().HardwareVersion)); + metadata.addInstrumentProperty(new CVTerm("MS:1000494", "MS", "Thermo Scientific instrument model", + rawFile.GetInstrumentData().Model)); + metadata.addInstrumentProperty(new CVTerm("MS:1000496", "MS", "instrument attribute", + rawFile.GetInstrumentData().Name)); + metadata.addInstrumentProperty(new CVTerm("MS:1000529", "MS", "instrument serial number", + rawFile.GetInstrumentData().SerialNumber)); + metadata.addInstrumentProperty(new CVTerm("NCIT:C111093", "NCIT", "Software Version", + rawFile.GetInstrumentData().SoftwareVersion)); + if (!rawFile.GetInstrumentData().HardwareVersion.IsNullOrEmpty()) + { + metadata.addInstrumentProperty(new CVTerm("AFR:0001259", "AFO", "firmware version", + rawFile.GetInstrumentData().HardwareVersion)); + } } - + // MS Data foreach (KeyValuePair entry in msTypes) { @@ -208,21 +208,27 @@ private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int last maxMz.ToString(CultureInfo.InvariantCulture))); // Scan Settings - metadata.addScanSetting(new CVTerm("MS:1000016", "MS", "scan start time", - startTime.ToString(CultureInfo.InvariantCulture))); - metadata.addScanSetting(new CVTerm("MS:1000011", "MS", "mass resolution", - rawFile.RunHeaderEx.MassResolution.ToString(CultureInfo.InvariantCulture))); - metadata.addScanSetting(new CVTerm("UO:0000002", "MS", "mass unit", - rawFile.GetInstrumentData().Units.ToString())); - metadata.addScanSetting(new CVTerm("PRIDE:0000478", "PRIDE", "Number of scans", - rawFile.RunHeaderEx.SpectraCount.ToString())); - metadata.addScanSetting(new CVTerm("PRIDE:0000479", "PRIDE", "MS scan range", - firstScanNumber + ":" + lastScanNumber)); - metadata.addScanSetting(new CVTerm("PRIDE:0000484", "PRIDE", "Retention time range", - startTime + ":" + endTime)); - metadata.addScanSetting(new CVTerm("PRIDE:0000485", "PRIDE", "Mz range", - rawFile.RunHeaderEx.LowMass + ":" + rawFile.RunHeaderEx.HighMass)); - metadata.addScanSetting(fragmentationTypes); + if (rawFile.SelectMsData()) + { + // Get the start and end time from the RAW file + var startTime = rawFile.RunHeaderEx.StartTime; + var endTime = rawFile.RunHeaderEx.EndTime; + metadata.addScanSetting(new CVTerm("MS:1000016", "MS", "scan start time", + startTime.ToString(CultureInfo.InvariantCulture))); + metadata.addScanSetting(new CVTerm("MS:1000011", "MS", "mass resolution", + rawFile.RunHeaderEx.MassResolution.ToString(CultureInfo.InvariantCulture))); + metadata.addScanSetting(new CVTerm("UO:0000002", "MS", "mass unit", + rawFile.GetInstrumentData().Units.ToString())); + metadata.addScanSetting(new CVTerm("PRIDE:0000478", "PRIDE", "Number of scans", + rawFile.RunHeaderEx.SpectraCount.ToString())); + metadata.addScanSetting(new CVTerm("PRIDE:0000479", "PRIDE", "MS scan range", + firstScanNumber + ":" + lastScanNumber)); + metadata.addScanSetting(new CVTerm("PRIDE:0000484", "PRIDE", "Retention time range", + startTime + ":" + endTime)); + metadata.addScanSetting(new CVTerm("PRIDE:0000485", "PRIDE", "Mz range", + rawFile.RunHeaderEx.LowMass + ":" + rawFile.RunHeaderEx.HighMass)); + metadata.addScanSetting(fragmentationTypes); + } // Sample Data if (!rawFile.SampleInformation.SampleName.IsNullOrEmpty()) @@ -296,10 +302,6 @@ private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int last /// private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int lastScanNumber) { - // Get the start and end time from the RAW file - var startTime = rawFile.RunHeaderEx.StartTime; - var endTime = rawFile.RunHeaderEx.EndTime; - // File Properties var output = new List { @@ -314,18 +316,21 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la } // Instrument Properties - output.Add("#InstrumentProperties"); - output.AddRange(new List + if (rawFile.SelectMsData()) + { + output.Add("#InstrumentProperties"); + output.AddRange(new List { $"Instrument model=[MS, MS:1000494, Thermo Scientific instrument model, {rawFile.GetInstrumentData().Model}]", "Instrument name=" + rawFile.GetInstrumentData().Name, $"Instrument serial number=[MS, MS:1000529, instrument serial number, {rawFile.GetInstrumentData().SerialNumber}]", $"Software version=[NCIT, NCIT:C111093, Software Version, {rawFile.GetInstrumentData().SoftwareVersion}]", } - ); - if (!rawFile.GetInstrumentData().HardwareVersion.IsNullOrEmpty()) - { - output.Add("Firmware version=" + rawFile.GetInstrumentData().HardwareVersion); + ); + if (!rawFile.GetInstrumentData().HardwareVersion.IsNullOrEmpty()) + { + output.Add("Firmware version=" + rawFile.GetInstrumentData().HardwareVersion); + } } // MS Data @@ -352,19 +357,25 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la ); // Scan Settings - output.AddRange(new List - { - "#ScanSettings", - $"Scan start time={startTime.ToString(CultureInfo.InvariantCulture)}", - $"Mass resolution=[MS, MS:1000011, mass resolution, {rawFile.RunHeaderEx.MassResolution.ToString(CultureInfo.InvariantCulture)}]", - "Units=" + rawFile.GetInstrumentData().Units, - $"Number of scans={rawFile.RunHeaderEx.SpectraCount}", - $"Scan range={firstScanNumber};{lastScanNumber}", - $"Time range={startTime.ToString(CultureInfo.InvariantCulture)};{endTime.ToString(CultureInfo.InvariantCulture)}", - $"Mass range={rawFile.RunHeaderEx.LowMass.ToString(CultureInfo.InvariantCulture)};{rawFile.RunHeaderEx.HighMass.ToString(CultureInfo.InvariantCulture)}", - "Fragmentation types=" + String.Join(", ", fragmentationTypes.Select(f => f.value)) - } - ); + if (rawFile.SelectMsData()) + { + // Get the start and end time from the RAW file + var startTime = rawFile.RunHeaderEx.StartTime; + var endTime = rawFile.RunHeaderEx.EndTime; + output.AddRange(new List + { + "#ScanSettings", + $"Scan start time={startTime.ToString(CultureInfo.InvariantCulture)}", + $"Mass resolution=[MS, MS:1000011, mass resolution, {rawFile.RunHeaderEx.MassResolution.ToString(CultureInfo.InvariantCulture)}]", + "Units=" + rawFile.GetInstrumentData().Units, + $"Number of scans={rawFile.RunHeaderEx.SpectraCount}", + $"Scan range={firstScanNumber};{lastScanNumber}", + $"Time range={startTime.ToString(CultureInfo.InvariantCulture)};{endTime.ToString(CultureInfo.InvariantCulture)}", + $"Mass range={rawFile.RunHeaderEx.LowMass.ToString(CultureInfo.InvariantCulture)};{rawFile.RunHeaderEx.HighMass.ToString(CultureInfo.InvariantCulture)}", + "Fragmentation types=" + String.Join(", ", fragmentationTypes.Select(f => f.value)) + } + ); + } // Sample Data output.Add("#SampleData"); From 65f14e541ea7c758be056d23c8009806cb220fbc Mon Sep 17 00:00:00 2001 From: "MEMBER\\Heting.Zhao" Date: Thu, 9 Mar 2023 16:00:14 +0800 Subject: [PATCH 08/28] ZSPACE-12467 Solve code review issues. --- RawFileParser.cs | 2 +- Writer/MgfSpectrumWriter.cs | 301 ++++++++++++++++---------------- Writer/MzMlSpectrumWriter.cs | 231 ++++++++++++------------ Writer/ParquetSpectrumWriter.cs | 90 +++++----- 4 files changed, 322 insertions(+), 302 deletions(-) diff --git a/RawFileParser.cs b/RawFileParser.cs index 9916612..5e8f938 100644 --- a/RawFileParser.cs +++ b/RawFileParser.cs @@ -161,7 +161,7 @@ private static void ProcessFile(ParseInput parseInput) metadataWriter.WriteMetadata(rawFile, firstScanNumber, lastScanNumber); } - if (rawFile.SelectMsData() && parseInput.OutputFormat != OutputFormat.NONE) + if (parseInput.OutputFormat != OutputFormat.NONE) { SpectrumWriter spectrumWriter; switch (parseInput.OutputFormat) diff --git a/Writer/MgfSpectrumWriter.cs b/Writer/MgfSpectrumWriter.cs index c347944..abc07ff 100644 --- a/Writer/MgfSpectrumWriter.cs +++ b/Writer/MgfSpectrumWriter.cs @@ -41,208 +41,211 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc ConfigureWriter(".mgf"); using (Writer) { - Log.Info("Processing " + (lastScanNumber - firstScanNumber + 1) + " scans"); - - var lastScanProgress = 0; - for (var scanNumber = firstScanNumber; scanNumber <= lastScanNumber; scanNumber++) + if (rawFile.SelectMsData()) { - if (ParseInput.LogFormat == LogFormat.DEFAULT) + Log.Info("Processing " + (lastScanNumber - firstScanNumber + 1) + " scans"); + + var lastScanProgress = 0; + for (var scanNumber = firstScanNumber; scanNumber <= lastScanNumber; scanNumber++) { - var scanProgress = (int) ((double) scanNumber / (lastScanNumber - firstScanNumber + 1) * 100); - if (scanProgress % ProgressPercentageStep == 0) + if (ParseInput.LogFormat == LogFormat.DEFAULT) { - if (scanProgress != lastScanProgress) + var scanProgress = (int)((double)scanNumber / (lastScanNumber - firstScanNumber + 1) * 100); + if (scanProgress % ProgressPercentageStep == 0) { - Console.Write("" + scanProgress + "% "); - lastScanProgress = scanProgress; + if (scanProgress != lastScanProgress) + { + Console.Write("" + scanProgress + "% "); + lastScanProgress = scanProgress; + } } } - } - _precursorScanNumber = 0; + _precursorScanNumber = 0; - // Get the scan from the RAW file - var scan = Scan.FromFile(rawFile, scanNumber); + // Get the scan from the RAW file + var scan = Scan.FromFile(rawFile, scanNumber); - // Get the retention time - var retentionTime = rawFile.RetentionTimeFromScanNumber(scanNumber); + // Get the retention time + var retentionTime = rawFile.RetentionTimeFromScanNumber(scanNumber); - // Get the scan filter for this scan number - var scanFilter = rawFile.GetFilterForScanNumber(scanNumber); + // Get the scan filter for this scan number + var scanFilter = rawFile.GetFilterForScanNumber(scanNumber); - // Get the scan event for this scan number - var scanEvent = rawFile.GetScanEventForScanNumber(scanNumber); + // Get the scan event for this scan number + var scanEvent = rawFile.GetScanEventForScanNumber(scanNumber); - // Trailer extra data list - ScanTrailer trailerData; + // Trailer extra data list + ScanTrailer trailerData; - try - { - trailerData = new ScanTrailer(rawFile.GetTrailerExtraInformation(scanNumber)); - } - catch (Exception ex) - { - Log.WarnFormat("Cannot load trailer infromation for scan {0} due to following exception\n{1}", scanNumber, ex.Message); - ParseInput.NewWarn(); - trailerData = new ScanTrailer(); - } - - // Get scan ms level - var msLevel = (int)scanFilter.MSOrder; - - // Construct the precursor reference string for the title - var precursorReference = ""; - - if (ParseInput.MgfPrecursor) - { - if (msLevel == 1) + try { - // Keep track of the MS1 scan number for precursor reference - _precursorScanNumbers[""] = scanNumber; + trailerData = new ScanTrailer(rawFile.GetTrailerExtraInformation(scanNumber)); } - else + catch (Exception ex) { - // Keep track of scan number and isolation m/z for precursor reference - var result = _filterStringIsolationMzPattern.Match(scanEvent.ToString()); - if (result.Success) - { - if (_precursorScanNumbers.ContainsKey(result.Groups[1].Value)) - { - _precursorScanNumbers.Remove(result.Groups[1].Value); - } + Log.WarnFormat("Cannot load trailer infromation for scan {0} due to following exception\n{1}", scanNumber, ex.Message); + ParseInput.NewWarn(); + trailerData = new ScanTrailer(); + } - _precursorScanNumbers.Add(result.Groups[1].Value, scanNumber); - } + // Get scan ms level + var msLevel = (int)scanFilter.MSOrder; + + // Construct the precursor reference string for the title + var precursorReference = ""; - //update precursor scan if it is provided in trailer data - var trailerMasterScan = trailerData.AsPositiveInt("Master Scan Number:"); - if (trailerMasterScan.HasValue) + if (ParseInput.MgfPrecursor) + { + if (msLevel == 1) { - _precursorScanNumber = trailerMasterScan.Value; + // Keep track of the MS1 scan number for precursor reference + _precursorScanNumbers[""] = scanNumber; } - else //try getting it from the scan filter + else { - var parts = Regex.Split(result.Groups[1].Value, " "); - - //find the position of the first (from the end) precursor with a different mass - //to account for possible supplementary activations written in the filter - var lastIonMass = parts.Last().Split('@').First(); - int last = parts.Length; - while (last > 0 && - parts[last - 1].Split('@').First() == lastIonMass) + // Keep track of scan number and isolation m/z for precursor reference + var result = _filterStringIsolationMzPattern.Match(scanEvent.ToString()); + if (result.Success) { - last--; + if (_precursorScanNumbers.ContainsKey(result.Groups[1].Value)) + { + _precursorScanNumbers.Remove(result.Groups[1].Value); + } + + _precursorScanNumbers.Add(result.Groups[1].Value, scanNumber); } - string parentFilter = String.Join(" ", parts.Take(last)); - if (_precursorScanNumbers.ContainsKey(parentFilter)) + //update precursor scan if it is provided in trailer data + var trailerMasterScan = trailerData.AsPositiveInt("Master Scan Number:"); + if (trailerMasterScan.HasValue) { - _precursorScanNumber = _precursorScanNumbers[parentFilter]; + _precursorScanNumber = trailerMasterScan.Value; + } + else //try getting it from the scan filter + { + var parts = Regex.Split(result.Groups[1].Value, " "); + + //find the position of the first (from the end) precursor with a different mass + //to account for possible supplementary activations written in the filter + var lastIonMass = parts.Last().Split('@').First(); + int last = parts.Length; + while (last > 0 && + parts[last - 1].Split('@').First() == lastIonMass) + { + last--; + } + + string parentFilter = String.Join(" ", parts.Take(last)); + if (_precursorScanNumbers.ContainsKey(parentFilter)) + { + _precursorScanNumber = _precursorScanNumbers[parentFilter]; + } + } + + if (_precursorScanNumber > 0) + { + precursorReference = ConstructSpectrumTitle((int)Device.MS, 1, _precursorScanNumber); + } + else + { + Log.Error($"Failed finding precursor for {scanNumber}"); + ParseInput.NewError(); } } + } - if (_precursorScanNumber > 0) + if (ParseInput.MsLevel.Contains(msLevel)) + { + var reaction = GetReaction(scanEvent, scanNumber); + + Writer.WriteLine("BEGIN IONS"); + if (!ParseInput.MgfPrecursor) { - precursorReference = ConstructSpectrumTitle((int)Device.MS, 1, _precursorScanNumber); + Writer.WriteLine($"TITLE={ConstructSpectrumTitle((int)Device.MS, 1, scanNumber)}"); } else { - Log.Error($"Failed finding precursor for {scanNumber}"); - ParseInput.NewError(); + Writer.WriteLine( + $"TITLE={ConstructSpectrumTitle((int)Device.MS, 1, scanNumber)} [PRECURSOR={precursorReference}]"); } - } - } - if (ParseInput.MsLevel.Contains(msLevel)) - { - var reaction = GetReaction(scanEvent, scanNumber); - - Writer.WriteLine("BEGIN IONS"); - if (!ParseInput.MgfPrecursor) - { - Writer.WriteLine($"TITLE={ConstructSpectrumTitle((int) Device.MS, 1, scanNumber)}"); - } - else - { + Writer.WriteLine($"SCANS={scanNumber}"); Writer.WriteLine( - $"TITLE={ConstructSpectrumTitle((int) Device.MS, 1, scanNumber)} [PRECURSOR={precursorReference}]"); - } - - Writer.WriteLine($"SCANS={scanNumber}"); - Writer.WriteLine( - $"RTINSECONDS={(retentionTime * 60).ToString(CultureInfo.InvariantCulture)}"); + $"RTINSECONDS={(retentionTime * 60).ToString(CultureInfo.InvariantCulture)}"); - int? charge = trailerData.AsPositiveInt("Charge State:"); - double? monoisotopicMz = trailerData.AsDouble("Monoisotopic M/Z:"); - double? isolationWidth = - trailerData.AsDouble("MS" + msLevel + " Isolation Width:"); + int? charge = trailerData.AsPositiveInt("Charge State:"); + double? monoisotopicMz = trailerData.AsDouble("Monoisotopic M/Z:"); + double? isolationWidth = + trailerData.AsDouble("MS" + msLevel + " Isolation Width:"); - if (reaction != null) - { - var selectedIonMz = - CalculateSelectedIonMz(reaction, monoisotopicMz, isolationWidth); + if (reaction != null) + { + var selectedIonMz = + CalculateSelectedIonMz(reaction, monoisotopicMz, isolationWidth); - Writer.WriteLine("PEPMASS=" + - selectedIonMz.ToString(CultureInfo.InvariantCulture)); - } + Writer.WriteLine("PEPMASS=" + + selectedIonMz.ToString(CultureInfo.InvariantCulture)); + } - // Charge - if (charge != null) - { - // Scan polarity - var polarity = PositivePolarity; - if (scanFilter.Polarity == PolarityType.Negative) + // Charge + if (charge != null) { - polarity = NegativePolarity; - } + // Scan polarity + var polarity = PositivePolarity; + if (scanFilter.Polarity == PolarityType.Negative) + { + polarity = NegativePolarity; + } - Writer.WriteLine($"CHARGE={charge}{polarity}"); - } + Writer.WriteLine($"CHARGE={charge}{polarity}"); + } - // Write the filter string - //Writer.WriteLine($"SCANEVENT={scanEvent.ToString()}"); + // Write the filter string + //Writer.WriteLine($"SCANEVENT={scanEvent.ToString()}"); - double[] masses; - double[] intensities; + double[] masses; + double[] intensities; - if (!ParseInput.NoPeakPicking.Contains(msLevel)) - { - // Check if the scan has a centroid stream - if (scan.HasCentroidStream) + if (!ParseInput.NoPeakPicking.Contains(msLevel)) { - masses = scan.CentroidScan.Masses; - intensities = scan.CentroidScan.Intensities; + // Check if the scan has a centroid stream + if (scan.HasCentroidStream) + { + masses = scan.CentroidScan.Masses; + intensities = scan.CentroidScan.Intensities; + } + else // Otherwise take segmented (low res) scan data + { + // If the spectrum is profile perform centroiding + var segmentedScan = scanEvent.ScanData == ScanDataType.Profile + ? Scan.ToCentroid(scan).SegmentedScan + : scan.SegmentedScan; + + masses = segmentedScan.Positions; + intensities = segmentedScan.Intensities; + } } - else // Otherwise take segmented (low res) scan data + else // Use the segmented data as is { - // If the spectrum is profile perform centroiding - var segmentedScan = scanEvent.ScanData == ScanDataType.Profile - ? Scan.ToCentroid(scan).SegmentedScan - : scan.SegmentedScan; - - masses = segmentedScan.Positions; - intensities = segmentedScan.Intensities; + masses = scan.SegmentedScan.Positions; + intensities = scan.SegmentedScan.Intensities; } - } - else // Use the segmented data as is - { - masses = scan.SegmentedScan.Positions; - intensities = scan.SegmentedScan.Intensities; - } - - if (!(masses is null) && masses.Length > 0) - { - Array.Sort(masses, intensities); - for (var i = 0; i < masses.Length; i++) + if (!(masses is null) && masses.Length > 0) { - Writer.WriteLine(String.Format("{0:f5} {1:f3}", masses[i], intensities[i])); + Array.Sort(masses, intensities); + + for (var i = 0; i < masses.Length; i++) + { + Writer.WriteLine(String.Format("{0:f5} {1:f3}", masses[i], intensities[i])); + } } - } - Writer.WriteLine("END IONS"); + Writer.WriteLine("END IONS"); - Log.Debug("Spectrum written to file -- SCAN# " + scanNumber); + Log.Debug("Spectrum written to file -- SCAN# " + scanNumber); + } } } diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index c830677..08ccab3 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -229,27 +229,32 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc _writer.WriteEndElement(); // sourceFileList _writer.WriteEndElement(); // fileDescription - var instrumentData = _rawFile.GetInstrumentData(); + if (_rawFile.SelectMsData()) + { + var instrumentData = _rawFile.GetInstrumentData(); - // ReferenceableParamGroupList - _writer.WriteStartElement("referenceableParamGroupList"); - _writer.WriteAttributeString("count", "1"); - // ReferenceableParamGroup - _writer.WriteStartElement("referenceableParamGroup"); - _writer.WriteAttributeString("id", "commonInstrumentParams"); + // ReferenceableParamGroupList + _writer.WriteStartElement("referenceableParamGroupList"); + _writer.WriteAttributeString("count", "1"); + // ReferenceableParamGroup + _writer.WriteStartElement("referenceableParamGroup"); + _writer.WriteAttributeString("id", "commonInstrumentParams"); - var instrumentModel = OntologyMapping.getInstrumentModel(instrumentData.Name); - SerializeCvParam(instrumentModel); + var instrumentModel = OntologyMapping.getInstrumentModel(instrumentData.Name); + SerializeCvParam(instrumentModel); - SerializeCvParam(new CVParamType - { - cvRef = "MS", - accession = "MS:1000529", - name = "instrument serial number", - value = instrumentData.SerialNumber - }); - _writer.WriteEndElement(); // referenceableParamGroup - _writer.WriteEndElement(); // referenceableParamGroupList + SerializeCvParam(new CVParamType + { + cvRef = "MS", + accession = "MS:1000529", + name = "instrument serial number", + value = instrumentData.SerialNumber + }); + _writer.WriteEndElement(); // referenceableParamGroup + _writer.WriteEndElement(); // referenceableParamGroupList + + PopulateInstrumentConfigurationList(firstScanNumber, lastScanNumber, instrumentModel); + } // SoftwareList _writer.WriteStartElement("softwareList"); @@ -267,7 +272,6 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc _writer.WriteEndElement(); // software _writer.WriteEndElement(); // softwareList - PopulateInstrumentConfigurationList(firstScanNumber, lastScanNumber, instrumentModel); // DataProcessingList _writer.WriteStartElement("dataProcessingList"); @@ -324,63 +328,67 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc var index = 0; var lastScanProgress = 0; - Log.Info(String.Format("Processing {0} MS scans", +(1 + lastScanNumber - firstScanNumber))); - - for (var scanNumber = firstScanNumber; scanNumber <= lastScanNumber; scanNumber++) + if (_rawFile.SelectMsData()) { - if (ParseInput.LogFormat == LogFormat.DEFAULT) + Log.Info(String.Format("Processing {0} MS scans", +(1 + lastScanNumber - firstScanNumber))); + + for (var scanNumber = firstScanNumber; scanNumber <= lastScanNumber; scanNumber++) { - var scanProgress = (int) ((double) scanNumber / (lastScanNumber - firstScanNumber + 1) * 100); - if (scanProgress % ProgressPercentageStep == 0) + if (ParseInput.LogFormat == LogFormat.DEFAULT) { - if (scanProgress != lastScanProgress) + var scanProgress = (int)((double)scanNumber / (lastScanNumber - firstScanNumber + 1) * 100); + if (scanProgress % ProgressPercentageStep == 0) { - Console.Write("" + scanProgress + "% "); - lastScanProgress = scanProgress; + if (scanProgress != lastScanProgress) + { + Console.Write("" + scanProgress + "% "); + lastScanProgress = scanProgress; + } } } - } - SpectrumType spectrum = null; + SpectrumType spectrum = null; - try - { - spectrum = ConstructMSSpectrum(scanNumber); - } - catch (Exception ex) - { - Log.Error($"Scan #{scanNumber} cannot be processed because of the following exception: {ex.Message}\n{ex.StackTrace}"); - ParseInput.NewError(); - } + try + { + spectrum = ConstructMSSpectrum(scanNumber); + } + catch (Exception ex) + { + Log.Error($"Scan #{scanNumber} cannot be processed because of the following exception: {ex.Message}\n{ex.StackTrace}"); + ParseInput.NewError(); + } - var level = spectrum != null ? int.Parse(spectrum.cvParam.Where(p => p.accession == "MS:1000511").First().value) : 0; - - if (spectrum != null && ParseInput.MsLevel.Contains(level)) //applying MS level filter - { - spectrum.index = index.ToString(); - if (_doIndexing) + var level = spectrum != null ? int.Parse(spectrum.cvParam.Where(p => p.accession == "MS:1000511").First().value) : 0; + + if (spectrum != null && ParseInput.MsLevel.Contains(level)) //applying MS level filter { - // 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 + spectrum.index = index.ToString(); + if (_doIndexing) { - spectrumOffSets.Add(spectrum.id, Writer.BaseStream.Position + 7 + _osOffset); + // 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); + Serialize(serializer, spectrum); - Log.Debug("Spectrum added to list of spectra -- ID " + spectrum.id); + Log.Debug("Spectrum added to list of spectra -- ID " + spectrum.id); - index++; + index++; + } } } + if (ParseInput.LogFormat == LogFormat.DEFAULT) { @@ -464,7 +472,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc _writer.WriteEndElement(); // spectrumList index = 0; - var chromatograms = ConstructChromatograms(firstScanNumber, lastScanNumber); + var chromatograms = ConstructChromatograms(); if (!chromatograms.IsNullOrEmpty()) { // ChromatogramList @@ -624,20 +632,21 @@ private string GetTotalScanNumber() var lastSelectedInstrument = _rawFile.SelectedInstrument; var numScans = 0; - _rawFile.SelectInstrument(Device.MS, 1); - - var levelFilter = _rawFile.GetFilterFromString(""); - - foreach (var level in ParseInput.MsLevel) + if(_rawFile.GetInstrumentCountOfType(Device.MS) != 0) { - levelFilter.MSOrder = (MSOrderType) level; + _rawFile.SelectInstrument(Device.MS, 1); + var levelFilter = _rawFile.GetFilterFromString(""); - var filteredScans = _rawFile.GetFilteredScansListByScanRange(levelFilter, - _rawFile.RunHeader.FirstSpectrum, _rawFile.RunHeader.LastSpectrum); + foreach (var level in ParseInput.MsLevel) + { + levelFilter.MSOrder = (MSOrderType)level; - numScans += filteredScans.Count; - } + var filteredScans = _rawFile.GetFilteredScansListByScanRange(levelFilter, + _rawFile.RunHeader.FirstSpectrum, _rawFile.RunHeader.LastSpectrum); + numScans += filteredScans.Count; + } + } if (ParseInput.AllDetectors) { @@ -649,7 +658,7 @@ private string GetTotalScanNumber() } // Return instrument to last selected one - if (lastSelectedInstrument != null) + if (lastSelectedInstrument != null && lastSelectedInstrument.DeviceType != Device.None && lastSelectedInstrument.InstrumentIndex != -1) _rawFile.SelectInstrument(lastSelectedInstrument.DeviceType, lastSelectedInstrument.InstrumentIndex); return numScans.ToString(); @@ -831,49 +840,53 @@ private void Serialize(XmlSerializer serializer, T t) /// the first scan number /// the last scan number /// a list of chromatograms - private List ConstructChromatograms(int firstScanNumber, int lastScanNumber) + private List ConstructChromatograms() { 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); + if (_rawFile.GetInstrumentCountOfType(Device.MS) != 0) + { + _rawFile.SelectInstrument(Device.MS, 1); - // Get the chromatogram from the RAW file. - var data = _rawFile.GetChromatogramData(new IChromatogramSettings[] {settings}, -1, -1); + // Define the settings for getting the Base Peak chromatogram + var settings = new ChromatogramTraceSettings(TraceType.BasePeak); - // Split the data into the chromatograms - var trace = ChromatogramSignal.FromChromatogramData(data); + // Get the chromatogram from the RAW file. + var data = _rawFile.GetChromatogramData(new IChromatogramSettings[] { settings }, -1, -1); - for (var i = 0; i < trace.Length; i++) - { - if (trace[i].Length > 0) + // Split the data into the chromatograms + var trace = ChromatogramSignal.FromChromatogramData(data); + + for (var i = 0; i < trace.Length; i++) { - // CV Data for Base Peak Chromatogram - var chroType = new CVParamType + if (trace[i].Length > 0) { - accession = "MS:1000628", - name = "basepeak chromatogram", - cvRef = "MS", - value = "" - }; + // CV Data for Base Peak Chromatogram + var chroType = new CVParamType + { + accession = "MS:1000628", + name = "basepeak chromatogram", + cvRef = "MS", + value = "" + }; - var intensType = new CVParamType - { - accession = "MS:1000515", - name = "intensity array", - cvRef = "MS", - unitName = "number of counts", - value = "", - unitCvRef = "MS", - unitAccession = "MS:1000131" - }; + var intensType = new CVParamType + { + accession = "MS:1000515", + name = "intensity array", + cvRef = "MS", + unitName = "number of counts", + value = "", + unitCvRef = "MS", + unitAccession = "MS:1000131" + }; - var chromatogram = TraceToChromatogram(trace[i], "BasePeak_" + i.ToString(), chroType, intensType); + var chromatogram = TraceToChromatogram(trace[i], "BasePeak_" + i.ToString(), chroType, intensType); - chromatograms.Add(chromatogram); + chromatograms.Add(chromatogram); + } } } @@ -886,11 +899,11 @@ private List ConstructChromatograms(int firstScanNumber, int l var instData = _rawFile.GetInstrumentData(); - settings = new ChromatogramTraceSettings(TraceType.TotalAbsorbance); + var settings = new ChromatogramTraceSettings(TraceType.TotalAbsorbance); - data = _rawFile.GetChromatogramData(new IChromatogramSettings[] {settings}, -1, -1); + var data = _rawFile.GetChromatogramData(new IChromatogramSettings[] {settings}, -1, -1); - trace = ChromatogramSignal.FromChromatogramData(data); + var trace = ChromatogramSignal.FromChromatogramData(data); for (var i = 0; i < trace.Length; i++) { @@ -932,11 +945,11 @@ private List ConstructChromatograms(int firstScanNumber, int l { var channelName = instData.ChannelLabels[channel]; - settings = new ChromatogramTraceSettings(TraceType.StartUVChromatogramTraces + channel + 1); + var settings = new ChromatogramTraceSettings(TraceType.StartUVChromatogramTraces + channel + 1); - data = _rawFile.GetChromatogramData(new IChromatogramSettings[] {settings}, -1, -1); + var data = _rawFile.GetChromatogramData(new IChromatogramSettings[] {settings}, -1, -1); - trace = ChromatogramSignal.FromChromatogramData(data); + var trace = ChromatogramSignal.FromChromatogramData(data); for (var i = 0; i < trace.Length; i++) { @@ -981,12 +994,12 @@ private List ConstructChromatograms(int firstScanNumber, int l if (channelName.ToLower().Contains("pressure")) { - settings = new ChromatogramTraceSettings(TraceType.StartPCA2DChromatogramTraces + channel + + var settings = new ChromatogramTraceSettings(TraceType.StartPCA2DChromatogramTraces + channel + 1); - data = _rawFile.GetChromatogramData(new IChromatogramSettings[] {settings}, -1, -1); + var data = _rawFile.GetChromatogramData(new IChromatogramSettings[] {settings}, -1, -1); - trace = ChromatogramSignal.FromChromatogramData(data); + var trace = ChromatogramSignal.FromChromatogramData(data); for (var i = 0; i < trace.Length; i++) { diff --git a/Writer/ParquetSpectrumWriter.cs b/Writer/ParquetSpectrumWriter.cs index ced94be..f2ad5c1 100644 --- a/Writer/ParquetSpectrumWriter.cs +++ b/Writer/ParquetSpectrumWriter.cs @@ -43,64 +43,68 @@ private static void WritePScans(string outputDirectory, string fileName, IRawDataPlus raw, List scans) { - var enumerator = raw.GetFilteredScanEnumerator(" "); - - foreach (var scanNumber in enumerator - ) // note in my tests serial is faster than Parallel.Foreach() (this involves disk access, so it makes sense) + if (raw.SelectMsData()) { - //trailer information is extracted via index - var trailers = raw.GetTrailerExtraValues(scanNumber); - var trailerLabels = raw.GetTrailerExtraInformation(scanNumber); - object chargeState = 0; - for (int i = 0; i < trailerLabels.Labels.Length; i++) + var enumerator = raw.GetFilteredScanEnumerator(" "); + + foreach (var scanNumber in enumerator + ) // note in my tests serial is faster than Parallel.Foreach() (this involves disk access, so it makes sense) { - if (trailerLabels.Labels[i] == "Charge State:") + //trailer information is extracted via index + var trailers = raw.GetTrailerExtraValues(scanNumber); + var trailerLabels = raw.GetTrailerExtraInformation(scanNumber); + object chargeState = 0; + for (int i = 0; i < trailerLabels.Labels.Length; i++) { - chargeState = raw.GetTrailerExtraValue(scanNumber, i); - break; + if (trailerLabels.Labels[i] == "Charge State:") + { + chargeState = raw.GetTrailerExtraValue(scanNumber, i); + break; + } } - } - var scanFilter = raw.GetFilterForScanNumber(scanNumber); - var scanStats = raw.GetScanStatsForScanNumber(scanNumber); + var scanFilter = raw.GetFilterForScanNumber(scanNumber); + var scanStats = raw.GetScanStatsForScanNumber(scanNumber); - CentroidStream centroidStream = new CentroidStream(); + CentroidStream centroidStream = new CentroidStream(); - //check for FT mass analyzer data - if (scanFilter.MassAnalyzer == MassAnalyzerType.MassAnalyzerFTMS) - { - centroidStream = raw.GetCentroidStream(scanNumber, false); - } + //check for FT mass analyzer data + if (scanFilter.MassAnalyzer == MassAnalyzerType.MassAnalyzerFTMS) + { + centroidStream = raw.GetCentroidStream(scanNumber, false); + } - //check for IT mass analyzer data - if (scanFilter.MassAnalyzer == MassAnalyzerType.MassAnalyzerITMS) - { - var scanData = raw.GetSimplifiedScan(scanNumber); - centroidStream.Masses = scanData.Masses; - centroidStream.Intensities = scanData.Intensities; - } + //check for IT mass analyzer data + if (scanFilter.MassAnalyzer == MassAnalyzerType.MassAnalyzerITMS) + { + var scanData = raw.GetSimplifiedScan(scanNumber); + centroidStream.Masses = scanData.Masses; + centroidStream.Intensities = scanData.Intensities; + } - var msOrder = raw.GetScanEventForScanNumber(scanNumber).MSOrder; + var msOrder = raw.GetScanEventForScanNumber(scanNumber).MSOrder; - if (msOrder == MSOrderType.Ms) - { - var pscan = GetPScan(scanStats, centroidStream, fileName, Convert.ToInt32(chargeState)); - scans.Add(pscan); - } + if (msOrder == MSOrderType.Ms) + { + var pscan = GetPScan(scanStats, centroidStream, fileName, Convert.ToInt32(chargeState)); + scans.Add(pscan); + } - if (msOrder == MSOrderType.Ms2) - { - var precursorMz = raw.GetScanEventForScanNumber(scanNumber).GetReaction(0).PrecursorMass; - var pscan = GetPScan(scanStats, centroidStream, fileName, precursorMz, - Convert.ToInt32(chargeState)); - scans.Add(pscan); + if (msOrder == MSOrderType.Ms2) + { + var precursorMz = raw.GetScanEventForScanNumber(scanNumber).GetReaction(0).PrecursorMass; + var pscan = GetPScan(scanStats, centroidStream, fileName, precursorMz, + Convert.ToInt32(chargeState)); + scans.Add(pscan); + } + + var t = raw.GetTrailerExtraValues(scanNumber); } - var t = raw.GetTrailerExtraValues(scanNumber); + WriteScans(outputDirectory, scans, fileName); } - - WriteScans(outputDirectory, scans, fileName); } + private static PScan GetPScan(ScanStatistics scanStats, CentroidStream centroidStream, string fileName, double? precursorMz = null, int? precursorCharge = null) From bceb3ddf2b609bfcf87313278d89884e19d4ba98 Mon Sep 17 00:00:00 2001 From: "MEMBER\\Heting.Zhao" Date: Fri, 10 Mar 2023 17:31:54 +0800 Subject: [PATCH 09/28] ZSPACE-12467 Fix code review issues. --- Writer/MzMlSpectrumWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index 08ccab3..1c8ef08 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -229,7 +229,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc _writer.WriteEndElement(); // sourceFileList _writer.WriteEndElement(); // fileDescription - if (_rawFile.SelectMsData()) + if (_rawFile.SelectedInstrument.DeviceType != Device.None && _rawFile.SelectedInstrument.InstrumentIndex != -1) { var instrumentData = _rawFile.GetInstrumentData(); From cfa25a2abba930fe97788595b9f9cb4cfa43547c Mon Sep 17 00:00:00 2001 From: "MEMBER\\Heting.Zhao" Date: Tue, 14 Mar 2023 11:23:48 +0800 Subject: [PATCH 10/28] ZSPACE-12467 Remove ms data for not MS type. --- Writer/MetadataWriter.cs | 96 ++++++++++++++++++++-------------------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/Writer/MetadataWriter.cs b/Writer/MetadataWriter.cs index be161a1..b224d1f 100644 --- a/Writer/MetadataWriter.cs +++ b/Writer/MetadataWriter.cs @@ -177,39 +177,39 @@ private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int last rawFile.GetInstrumentData().HardwareVersion)); } } - + // MS Data - foreach (KeyValuePair entry in msTypes) + if (rawFile.SelectMsData()) { - if (entry.Key.Equals(MSOrderType.Ms.ToString())) - metadata.addMSData(new CVTerm("PRIDE:0000481", "PRIDE", "Number of MS1 spectra", - entry.Value.ToString())); - if (entry.Key.Equals(MSOrderType.Ms2.ToString())) - metadata.addMSData(new CVTerm("PRIDE:0000482", "PRIDE", "Number of MS2 spectra", - entry.Value.ToString())); - if (entry.Key.Equals(MSOrderType.Ms3.ToString())) - metadata.addMSData(new CVTerm("PRIDE:0000483", "PRIDE", "Number of MS3 spectra", - entry.Value.ToString())); - } + foreach (KeyValuePair entry in msTypes) + { + if (entry.Key.Equals(MSOrderType.Ms.ToString())) + metadata.addMSData(new CVTerm("PRIDE:0000481", "PRIDE", "Number of MS1 spectra", + entry.Value.ToString())); + if (entry.Key.Equals(MSOrderType.Ms2.ToString())) + metadata.addMSData(new CVTerm("PRIDE:0000482", "PRIDE", "Number of MS2 spectra", + entry.Value.ToString())); + if (entry.Key.Equals(MSOrderType.Ms3.ToString())) + metadata.addMSData(new CVTerm("PRIDE:0000483", "PRIDE", "Number of MS3 spectra", + entry.Value.ToString())); + } - metadata.addMSData(new CVTerm("PRIDE:0000472", "PRIDE", "MS min charge", - minCharge.ToString(CultureInfo.InvariantCulture))); - metadata.addMSData(new CVTerm("PRIDE:0000473", "PRIDE", "MS max charge", - maxCharge.ToString(CultureInfo.InvariantCulture))); + metadata.addMSData(new CVTerm("PRIDE:0000472", "PRIDE", "MS min charge", + minCharge.ToString(CultureInfo.InvariantCulture))); + metadata.addMSData(new CVTerm("PRIDE:0000473", "PRIDE", "MS max charge", + maxCharge.ToString(CultureInfo.InvariantCulture))); - metadata.addMSData(new CVTerm("PRIDE:0000474", "PRIDE", "MS min RT", - minTime.ToString(CultureInfo.InvariantCulture))); - metadata.addMSData(new CVTerm("PRIDE:0000475", "PRIDE", "MS max RT", - maxTime.ToString(CultureInfo.InvariantCulture))); + metadata.addMSData(new CVTerm("PRIDE:0000474", "PRIDE", "MS min RT", + minTime.ToString(CultureInfo.InvariantCulture))); + metadata.addMSData(new CVTerm("PRIDE:0000475", "PRIDE", "MS max RT", + maxTime.ToString(CultureInfo.InvariantCulture))); - metadata.addMSData(new CVTerm("PRIDE:0000476", "PRIDE", "MS min MZ", - minMz.ToString(CultureInfo.InvariantCulture))); - metadata.addMSData(new CVTerm("PRIDE:0000477", "PRIDE", "MS max MZ", - maxMz.ToString(CultureInfo.InvariantCulture))); + metadata.addMSData(new CVTerm("PRIDE:0000476", "PRIDE", "MS min MZ", + minMz.ToString(CultureInfo.InvariantCulture))); + metadata.addMSData(new CVTerm("PRIDE:0000477", "PRIDE", "MS max MZ", + maxMz.ToString(CultureInfo.InvariantCulture))); - // Scan Settings - if (rawFile.SelectMsData()) - { + // Scan Settings // Get the start and end time from the RAW file var startTime = rawFile.RunHeaderEx.StartTime; var endTime = rawFile.RunHeaderEx.EndTime; @@ -334,31 +334,31 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la } // MS Data - output.Add("#MsData"); - foreach (KeyValuePair entry in msTypes) + if (rawFile.SelectMsData()) { - if (entry.Key.Equals(MSOrderType.Ms.ToString())) - output.Add("Number of MS1 spectra=" + entry.Value); - if (entry.Key.Equals(MSOrderType.Ms2.ToString())) - output.Add("Number of MS2 spectra=" + entry.Value); - if (entry.Key.Equals(MSOrderType.Ms3.ToString())) - output.Add("Number of MS3 spectra=" + entry.Value); - } - - output.AddRange(new List + output.Add("#MsData"); + foreach (KeyValuePair entry in msTypes) { - "MS min charge=" + minCharge.ToString(CultureInfo.InvariantCulture), - "MS max charge=" + maxCharge.ToString(CultureInfo.InvariantCulture), - $"MS min RT={minTime.ToString(CultureInfo.InvariantCulture)}", - $"MS max RT={maxTime.ToString(CultureInfo.InvariantCulture)}", - $"MS min MZ={minMz.ToString(CultureInfo.InvariantCulture)}", - $"MS max MZ={maxMz.ToString(CultureInfo.InvariantCulture)}" + if (entry.Key.Equals(MSOrderType.Ms.ToString())) + output.Add("Number of MS1 spectra=" + entry.Value); + if (entry.Key.Equals(MSOrderType.Ms2.ToString())) + output.Add("Number of MS2 spectra=" + entry.Value); + if (entry.Key.Equals(MSOrderType.Ms3.ToString())) + output.Add("Number of MS3 spectra=" + entry.Value); } - ); - // Scan Settings - if (rawFile.SelectMsData()) - { + output.AddRange(new List + { + "MS min charge=" + minCharge.ToString(CultureInfo.InvariantCulture), + "MS max charge=" + maxCharge.ToString(CultureInfo.InvariantCulture), + $"MS min RT={minTime.ToString(CultureInfo.InvariantCulture)}", + $"MS max RT={maxTime.ToString(CultureInfo.InvariantCulture)}", + $"MS min MZ={minMz.ToString(CultureInfo.InvariantCulture)}", + $"MS max MZ={maxMz.ToString(CultureInfo.InvariantCulture)}" + } + ); + + // Scan Settings // Get the start and end time from the RAW file var startTime = rawFile.RunHeaderEx.StartTime; var endTime = rawFile.RunHeaderEx.EndTime; From a29ac4c51ff634481f8844002b558cd9f5be272e Mon Sep 17 00:00:00 2001 From: "MEMBER\\Heting.Zhao" Date: Tue, 14 Mar 2023 14:43:09 +0800 Subject: [PATCH 11/28] ZSPACE-12467 Solve code review issues. --- Writer/MzMlSpectrumWriter.cs | 88 +++++++++++++++++++++++++++--------- 1 file changed, 66 insertions(+), 22 deletions(-) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index 1c8ef08..9568e72 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -141,29 +141,32 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc // fileContent _writer.WriteStartElement("fileContent"); // MS1 - SerializeCvParam(new CVParamType + if (rawFile.SelectMsData()) { - accession = "MS:1000579", - name = "MS1 spectrum", - cvRef = "MS", - value = "" - }); - // MSn - SerializeCvParam(new CVParamType - { - accession = "MS:1000580", - name = "MSn spectrum", - cvRef = "MS", - value = "" - }); - // Ion current chromatogram - SerializeCvParam(new CVParamType - { - accession = "MS:1000810", - name = "ion current chromatogram", - cvRef = "MS", - value = "" - }); + SerializeCvParam(new CVParamType + { + accession = "MS:1000579", + name = "MS1 spectrum", + cvRef = "MS", + value = "" + }); + // MSn + SerializeCvParam(new CVParamType + { + accession = "MS:1000580", + name = "MSn spectrum", + 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) @@ -1032,6 +1035,47 @@ private List ConstructChromatograms() } } } + + for (int nrI = 1; nrI < _rawFile.GetInstrumentCountOfType(Device.MSAnalog) + 1; nrI++) + { + _rawFile.SelectInstrument(Device.MSAnalog, nrI); + + var instData = _rawFile.GetInstrumentData(); + + for (int channel = 0; channel < instData.ChannelLabels.Length; channel++) + { + var channelName = instData.ChannelLabels[channel]; + + var settings = new ChromatogramTraceSettings(TraceType.StartAnalogChromatogramTraces + channel + + 1); + + var data = _rawFile.GetChromatogramData(new IChromatogramSettings[] { settings }, -1, -1); + + var trace = ChromatogramSignal.FromChromatogramData(data); + + for (var i = 0; i < trace.Length; i++) + { + // CV Data for Chromatogram + var chroType = new CVParamType + { + name = channelName + " chromatogram", + value = "" + }; + + var intensType = new CVParamType + { + name = channelName + " array", + value = instData.Units.ToString(), + }; + + var chromatogram = TraceToChromatogram(trace[i], + String.Format("AD#{0}_{1}_{2}", nrI, channelName, i), + chroType, intensType); + + chromatograms.Add(chromatogram); + } + } + } } return chromatograms; From adc3417fb07aae0b214bc183eda55f1e7f0287dc Mon Sep 17 00:00:00 2001 From: "MEMBER\\Heting.Zhao" Date: Tue, 14 Mar 2023 14:48:58 +0800 Subject: [PATCH 12/28] ZSPACE-12467 Replace whitespace with underscore. --- Writer/MzMlSpectrumWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index 9568e72..5643ddf 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -1069,7 +1069,7 @@ private List ConstructChromatograms() }; var chromatogram = TraceToChromatogram(trace[i], - String.Format("AD#{0}_{1}_{2}", nrI, channelName, i), + String.Format("AD#{0}_{1}_{2}", nrI, channelName.Replace(" ", "_"), i), chroType, intensType); chromatograms.Add(chromatogram); From 1a4c9a193f74cd9853fd29e502631d01500928c6 Mon Sep 17 00:00:00 2001 From: Wolfgang Colsman <52833340+wolfgangcolsman@users.noreply.github.com> Date: Tue, 14 Mar 2023 02:54:56 -0400 Subject: [PATCH 13/28] cleanup code --- Writer/MzMlSpectrumWriter.cs | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index 5643ddf..b204e29 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -195,6 +195,25 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc value = "" }); } + + // Pressure chromatogram + if (_rawFile.GetInstrumentCountOfType(Device.Analog) > 0) + { + SerializeCvParam(new CVParamType + { + accession = "MS:1003019", + name = "pressure chromatogram", + cvRef = "MS", + value = "" + }); + } + + // MSAnalog chromatogram + if (_rawFile.GetInstrumentCountOfType(Device.MSAnalog) > 0) + { + // TODO Write MSAnalog fileContent + // e.g. Front FID or Back FID + } } _writer.WriteEndElement(); // fileContent @@ -893,7 +912,7 @@ private List ConstructChromatograms() } } - // Chromatograms from other devices: UV, PDA + // Chromatograms from other devices: UV, PDA, Analog, MSAnalog if (ParseInput.AllDetectors) { for (int nrI = 1; nrI < _rawFile.GetInstrumentCountOfType(Device.Pda) + 1; nrI++) @@ -1006,7 +1025,7 @@ private List ConstructChromatograms() for (var i = 0; i < trace.Length; i++) { - // CV Data for Absorbance Chromatogram + // CV Data for Pressure Chromatogram var chroType = new CVParamType { accession = "MS:1003019", @@ -1069,7 +1088,7 @@ private List ConstructChromatograms() }; var chromatogram = TraceToChromatogram(trace[i], - String.Format("AD#{0}_{1}_{2}", nrI, channelName.Replace(" ", "_"), i), + String.Format("MSAD#{0}_{1}_{2}", nrI, channelName.Replace(" ", "_"), i), chroType, intensType); chromatograms.Add(chromatogram); From 93a5974a3bae35c965028ec084b5fa1d2a4bb0bb Mon Sep 17 00:00:00 2001 From: Wolfgang Colsman <52833340+wolfgangcolsman@users.noreply.github.com> Date: Sun, 19 Mar 2023 20:12:31 -0400 Subject: [PATCH 14/28] handle empty channel name --- Writer/MzMlSpectrumWriter.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index b204e29..66c6985 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -1065,6 +1065,11 @@ private List ConstructChromatograms() { var channelName = instData.ChannelLabels[channel]; + if (channelName.IsNullOrEmpty()) + { + channelName = "Channel " + channel; + } + var settings = new ChromatogramTraceSettings(TraceType.StartAnalogChromatogramTraces + channel + 1); From 878596b68c7190921a7f17d73df45ca524ef4037 Mon Sep 17 00:00:00 2001 From: Wolfgang Colsman <52833340+wolfgangcolsman@users.noreply.github.com> Date: Sun, 19 Mar 2023 20:17:49 -0400 Subject: [PATCH 15/28] add unitAccession for Volts --- Writer/MzMlSpectrumWriter.cs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index 66c6985..0c94bc5 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -1086,11 +1086,25 @@ private List ConstructChromatograms() value = "" }; - var intensType = new CVParamType + var intensType = new CVParamType(); + if (instData.Units.ToString().Equals("Volts")) { - name = channelName + " array", - value = instData.Units.ToString(), - }; + intensType = new CVParamType + { + name = channelName + " array", + unitAccession = "UO:0000218", + unitName = "volt", + unitCvRef = "UO" + }; + } + else + { + intensType = new CVParamType + { + name = channelName + " array", + value = instData.Units.ToString(), + }; + } var chromatogram = TraceToChromatogram(trace[i], String.Format("MSAD#{0}_{1}_{2}", nrI, channelName.Replace(" ", "_"), i), From 61530395e3c86c0370c33c1f04bbaa9fad0a5c5b Mon Sep 17 00:00:00 2001 From: Wolfgang Colsman <52833340+wolfgangcolsman@users.noreply.github.com> Date: Mon, 10 Apr 2023 08:43:53 -0400 Subject: [PATCH 16/28] unique channel name --- Writer/MzMlSpectrumWriter.cs | 71 ++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index 0c94bc5..6838511 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -81,7 +81,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc ConfigureWriter(".mzML"); XmlSerializer serializer; - var settings = new XmlWriterSettings {Indent = true, Encoding = new UTF8Encoding()}; + var settings = new XmlWriterSettings { Indent = true, Encoding = new UTF8Encoding() }; var sha1 = SHA1.Create(); CryptoStream cryptoStream = null; if (_doIndexing) @@ -410,7 +410,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc } } } - + if (ParseInput.LogFormat == LogFormat.DEFAULT) { @@ -435,7 +435,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc if (ParseInput.LogFormat == LogFormat.DEFAULT) { var scanProgress = - (int) ((double) scanNumber / (lastScanNumber - firstScanNumber + 1) * 100); + (int)((double)scanNumber / (lastScanNumber - firstScanNumber + 1) * 100); if (scanProgress % ProgressPercentageStep == 0) { if (scanProgress != lastScanProgress) @@ -654,7 +654,7 @@ private string GetTotalScanNumber() var lastSelectedInstrument = _rawFile.SelectedInstrument; var numScans = 0; - if(_rawFile.GetInstrumentCountOfType(Device.MS) != 0) + if (_rawFile.GetInstrumentCountOfType(Device.MS) != 0) { _rawFile.SelectInstrument(Device.MS, 1); var levelFilter = _rawFile.GetFilterFromString(""); @@ -923,7 +923,7 @@ private List ConstructChromatograms() var settings = new ChromatogramTraceSettings(TraceType.TotalAbsorbance); - var data = _rawFile.GetChromatogramData(new IChromatogramSettings[] {settings}, -1, -1); + var data = _rawFile.GetChromatogramData(new IChromatogramSettings[] { settings }, -1, -1); var trace = ChromatogramSignal.FromChromatogramData(data); @@ -969,7 +969,7 @@ private List ConstructChromatograms() var settings = new ChromatogramTraceSettings(TraceType.StartUVChromatogramTraces + channel + 1); - var data = _rawFile.GetChromatogramData(new IChromatogramSettings[] {settings}, -1, -1); + var data = _rawFile.GetChromatogramData(new IChromatogramSettings[] { settings }, -1, -1); var trace = ChromatogramSignal.FromChromatogramData(data); @@ -1019,7 +1019,7 @@ private List ConstructChromatograms() var settings = new ChromatogramTraceSettings(TraceType.StartPCA2DChromatogramTraces + channel + 1); - var data = _rawFile.GetChromatogramData(new IChromatogramSettings[] {settings}, -1, -1); + var data = _rawFile.GetChromatogramData(new IChromatogramSettings[] { settings }, -1, -1); var trace = ChromatogramSignal.FromChromatogramData(data); @@ -1055,6 +1055,7 @@ private List ConstructChromatograms() } } + var channelNameIndex = 1 for (int nrI = 1; nrI < _rawFile.GetInstrumentCountOfType(Device.MSAnalog) + 1; nrI++) { _rawFile.SelectInstrument(Device.MSAnalog, nrI); @@ -1067,7 +1068,7 @@ private List ConstructChromatograms() if (channelName.IsNullOrEmpty()) { - channelName = "Channel " + channel; + channelName = "Channel " + channelNameIndex++; } var settings = new ChromatogramTraceSettings(TraceType.StartAnalogChromatogramTraces + channel + @@ -1153,7 +1154,7 @@ private ChromatogramType TraceToChromatogram(ChromatogramSignal trace, string ch : GetZLib64BitArray(trace.Times) }; timesBinaryData.encodedLength = - (4 * Math.Ceiling((double) timesBinaryData + (4 * Math.Ceiling((double)timesBinaryData .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); var timesBinaryDataCvParams = new List { @@ -1218,7 +1219,7 @@ private ChromatogramType TraceToChromatogram(ChromatogramSignal trace, string ch : GetZLib64BitArray(trace.Intensities) }; intensitiesBinaryData.encodedLength = - (4 * Math.Ceiling((double) intensitiesBinaryData + (4 * Math.Ceiling((double)intensitiesBinaryData .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); var intensitiesBinaryDataCvParams = new List { @@ -1291,7 +1292,7 @@ private SpectrumType ConstructMSSpectrum(int scanNumber) var scanEvent = _rawFile.GetScanEventForScanNumber(scanNumber); var spectrum = new SpectrumType { - id = ConstructSpectrumTitle((int) Device.MS, 1, scanNumber), + id = ConstructSpectrumTitle((int)Device.MS, 1, scanNumber), defaultArrayLength = 0 }; @@ -1324,7 +1325,7 @@ private SpectrumType ConstructMSSpectrum(int scanNumber) int? charge = trailerData.AsPositiveInt("Charge State:"); double? monoisotopicMz = trailerData.AsDouble("Monoisotopic M/Z:"); double? ionInjectionTime = trailerData.AsDouble("Ion Injection Time (ms):"); - double? isolationWidth = trailerData.AsDouble("MS" + (int) scanFilter.MSOrder + " Isolation Width:"); + double? isolationWidth = trailerData.AsDouble("MS" + (int)scanFilter.MSOrder + " Isolation Width:"); double? FAIMSCV = null; if (trailerData.AsBool("FAIMS Voltage On:").GetValueOrDefault(false)) FAIMSCV = trailerData.AsDouble("FAIMS CV:"); @@ -1336,7 +1337,7 @@ private SpectrumType ConstructMSSpectrum(int scanNumber) foreach (var label in trailerData.MatchKeys(_spSentry)) { var mass = trailerData.AsDouble(label).GetValueOrDefault(0); - if (mass > 0) SPSMasses.Add((double) mass); //zero means mass does not exist + if (mass > 0) SPSMasses.Add((double)mass); //zero means mass does not exist } } @@ -1346,7 +1347,7 @@ private SpectrumType ConstructMSSpectrum(int scanNumber) foreach (var labelvalue in trailerData.MatchValues(_spSentry3)) { foreach (var mass in labelvalue.Trim() - .Split(new char[] {','}, StringSplitOptions.RemoveEmptyEntries)) + .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { SPSMasses.Add(double.Parse(mass)); } @@ -1375,14 +1376,14 @@ private SpectrumType ConstructMSSpectrum(int scanNumber) } else if (msLevel > 1) - { + { spectrumCvParams.Add(new CVParamType - { - accession = "MS:1000580", - cvRef = "MS", - name = "MSn spectrum", - value = "" - }); + { + accession = "MS:1000580", + cvRef = "MS", + name = "MSn spectrum", + value = "" + }); // Keep track of scan number and isolation m/z for precursor reference var result = _filterStringIsolationMzPattern.Match(scanEvent.ToString()); @@ -1450,7 +1451,7 @@ private SpectrumType ConstructMSSpectrum(int scanNumber) _precursorTree[scanNumber] = new PrecursorInfo(_precursorScanNumber, 1, 0, new PrecursorType[0]); } - + } else { @@ -1525,7 +1526,7 @@ private SpectrumType ConstructMSSpectrum(int scanNumber) double[] masses; double[] intensities; - if (!ParseInput.NoPeakPicking.Contains((int) scanFilter.MSOrder)) + if (!ParseInput.NoPeakPicking.Contains((int)scanFilter.MSOrder)) { //Spectrum will be centroided spectrumCvParams.Add(new CVParamType @@ -1688,7 +1689,7 @@ private SpectrumType ConstructMSSpectrum(int scanNumber) binary = ParseInput.NoZlibCompression ? Get64BitArray(masses) : GetZLib64BitArray(masses) }; massesBinaryData.encodedLength = - (4 * Math.Ceiling((double) massesBinaryData + (4 * Math.Ceiling((double)massesBinaryData .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); var massesBinaryDataCvParams = new List { @@ -1750,7 +1751,7 @@ private SpectrumType ConstructMSSpectrum(int scanNumber) : GetZLib64BitArray(intensities) }; intensitiesBinaryData.encodedLength = - (4 * Math.Ceiling((double) intensitiesBinaryData + (4 * Math.Ceiling((double)intensitiesBinaryData .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); var intensitiesBinaryDataCvParams = new List { @@ -1993,7 +1994,7 @@ private SpectrumType ConstructPDASpectrum(int scanNumber, int instrumentNumber) var spectrum = new SpectrumType { - id = ConstructSpectrumTitle((int) Device.Pda, instrumentNumber, scanNumber), + id = ConstructSpectrumTitle((int)Device.Pda, instrumentNumber, scanNumber), defaultArrayLength = 0 }; @@ -2112,7 +2113,7 @@ private SpectrumType ConstructPDASpectrum(int scanNumber, int instrumentNumber) binary = ParseInput.NoZlibCompression ? Get64BitArray(positions) : GetZLib64BitArray(positions) }; positionsBinaryData.encodedLength = - (4 * Math.Ceiling((double) positionsBinaryData + (4 * Math.Ceiling((double)positionsBinaryData .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); var positionsBinaryDataCvParams = new List { @@ -2173,7 +2174,7 @@ private SpectrumType ConstructPDASpectrum(int scanNumber, int instrumentNumber) : GetZLib64BitArray(intensities) }; intensitiesBinaryData.encodedLength = - (4 * Math.Ceiling((double) intensitiesBinaryData + (4 * Math.Ceiling((double)intensitiesBinaryData .binary.Length / 3)).ToString(CultureInfo.InvariantCulture); var intensitiesBinaryDataCvParams = new List { @@ -2256,16 +2257,16 @@ private PrecursorListType ConstructPrecursorList(int precursorScanNumber, IScanE spectrumRef = ConstructSpectrumTitle((int)Device.MS, 1, precursorScanNumber); reaction = scanEvent.GetReaction(reactionCount); - + precursorMz = reaction.PrecursorMass; //if isolation width was not found in the trailer, try to get one from the reaction if (isolationWidth == null) isolationWidth = reaction.IsolationWidth; - + var precursor = new PrecursorType { selectedIonList = - new SelectedIonListType {count = "1", selectedIon = new ParamGroupType[1]}, + new SelectedIonListType { count = "1", selectedIon = new ParamGroupType[1] }, spectrumRef = spectrumRef }; @@ -2475,7 +2476,7 @@ private PrecursorListType ConstructPrecursorList(int precursorScanNumber, IScanE var SPSPrecursor = new PrecursorType { selectedIonList = - new SelectedIonListType {count = "1", selectedIon = new ParamGroupType[1]}, + new SelectedIonListType { count = "1", selectedIon = new ParamGroupType[1] }, spectrumRef = spectrumRef }; @@ -2784,7 +2785,7 @@ private static byte[] Get64BitArray(ICollection array) memoryStream.Position = 0; bytes = memoryStream.ToArray(); } - } + } return (byte[])bytes; } @@ -2804,8 +2805,8 @@ private static byte[] GetZLib64BitArray(ICollection array) using (var memoryStream = new MemoryStream()) using (var outZStream = new ZOutputStream(memoryStream, zlibConst.Z_DEFAULT_COMPRESSION)) { - outZStream.Write(bytes, 0, bytes.Length); - + outZStream.Write(bytes, 0, bytes.Length); + outZStream.finish(); memoryStream.Position = 0; bytes = memoryStream.ToArray(); From abc6be5b8a0366095601b15368d8fe1a73a980b2 Mon Sep 17 00:00:00 2001 From: Wolfgang Colsman <52833340+wolfgangcolsman@users.noreply.github.com> Date: Mon, 10 Apr 2023 08:56:55 -0400 Subject: [PATCH 17/28] fix --- Writer/MzMlSpectrumWriter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index 6838511..3d4a6a7 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -1055,7 +1055,7 @@ private List ConstructChromatograms() } } - var channelNameIndex = 1 + var channelNameIndex = 0; for (int nrI = 1; nrI < _rawFile.GetInstrumentCountOfType(Device.MSAnalog) + 1; nrI++) { _rawFile.SelectInstrument(Device.MSAnalog, nrI); From 8530c38edf467b49159a2cbc3a796de0d896c3db Mon Sep 17 00:00:00 2001 From: Wolfgang Colsman <52833340+wolfgangcolsman@users.noreply.github.com> Date: Sun, 9 Jul 2023 22:29:35 -0400 Subject: [PATCH 18/28] add expected runtime --- Writer/MetadataWriter.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Writer/MetadataWriter.cs b/Writer/MetadataWriter.cs index e7554ce..b3b9232 100644 --- a/Writer/MetadataWriter.cs +++ b/Writer/MetadataWriter.cs @@ -210,6 +210,8 @@ private void WriteJsonMetada(IRawDataPlus rawFile, int firstScanNumber, int last // Scan Settings metadata.addScanSetting(new CVTerm("MS:1000016", "MS", "scan start time", startTime.ToString(CultureInfo.InvariantCulture))); + metadata.addScanSetting(new CVTerm("", "", "expected runtime", + rawFile.RunHeader.ExpectedRuntime.ToString(CultureInfo.InvariantCulture))); metadata.addScanSetting(new CVTerm("MS:1000011", "MS", "mass resolution", rawFile.RunHeaderEx.MassResolution.ToString(CultureInfo.InvariantCulture))); metadata.addScanSetting(new CVTerm("UO:0000002", "MS", "mass unit", From e94cf149338428d0788ceb27208f3838a6a0b4b9 Mon Sep 17 00:00:00 2001 From: "MEMBER\\Heting.Zhao" Date: Thu, 10 Aug 2023 11:25:33 +0800 Subject: [PATCH 19/28] Treat as if it is never set when last spectrum is set as 0. --- RawFileParser.cs | 8 ++++---- Writer/MzMlSpectrumWriter.cs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/RawFileParser.cs b/RawFileParser.cs index c233af1..fec56bd 100755 --- a/RawFileParser.cs +++ b/RawFileParser.cs @@ -148,10 +148,10 @@ private static void ProcessFile(ParseInput parseInput) lastScanNumber = rawFile.RunHeaderEx.LastSpectrum; // Check for empty file - if (lastScanNumber < 1) - { - throw new RawFileParserException("Empty RAW file, no output will be produced"); - } + //if (lastScanNumber < 1) + //{ + //throw new RawFileParserException("Empty RAW file, no output will be produced"); + //} } if (parseInput.MetadataFormat != MetadataFormat.NONE) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index cae5dce..47921d8 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -466,7 +466,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc _writer.WriteEndElement(); // spectrumList index = 0; - var chromatograms = ConstructChromatograms(firstScanNumber, lastScanNumber); + var chromatograms = ConstructChromatograms(); if (!chromatograms.IsNullOrEmpty()) { // ChromatogramList @@ -841,7 +841,7 @@ private void Serialize(XmlSerializer serializer, T t) /// the first scan number /// the last scan number /// a list of chromatograms - private List ConstructChromatograms(int firstScanNumber, int lastScanNumber) + private List ConstructChromatograms() { var chromatograms = new List(); From 2e4e8c7acb058f7af40c18727c93ecfa8f5a82f8 Mon Sep 17 00:00:00 2001 From: "MEMBER\\Heting.Zhao" Date: Thu, 10 Aug 2023 17:33:05 +0800 Subject: [PATCH 20/28] Treat as if it is never set when last spectrum is set as 0. --- RawFileParser.cs | 6 ------ 1 file changed, 6 deletions(-) diff --git a/RawFileParser.cs b/RawFileParser.cs index fec56bd..2d94031 100755 --- a/RawFileParser.cs +++ b/RawFileParser.cs @@ -146,12 +146,6 @@ private static void ProcessFile(ParseInput parseInput) // Get the first and last scan from the RAW file firstScanNumber = rawFile.RunHeaderEx.FirstSpectrum; lastScanNumber = rawFile.RunHeaderEx.LastSpectrum; - - // Check for empty file - //if (lastScanNumber < 1) - //{ - //throw new RawFileParserException("Empty RAW file, no output will be produced"); - //} } if (parseInput.MetadataFormat != MetadataFormat.NONE) From 099a11cf3773e30828d94189cedd383575d7f518 Mon Sep 17 00:00:00 2001 From: caetera Date: Tue, 5 Mar 2024 19:59:52 +0100 Subject: [PATCH 21/28] Advanced MSLevel filter --- MainClass.cs | 2 ++ ParseInput.cs | 3 +++ Writer/MzMlSpectrumWriter.cs | 9 ++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/MainClass.cs b/MainClass.cs index 4ccf364..702741b 100644 --- a/MainClass.cs +++ b/MainClass.cs @@ -766,6 +766,8 @@ private static void RegularParametersParsing(string[] args) if (parseInput.OutputFormat == OutputFormat.IndexMzML) parseInput.OutputFormat = OutputFormat.MzML; } + parseInput.MaxLevel = parseInput.MsLevel.Max(); + if (parseInput.S3Url != null && parseInput.S3AccessKeyId != null && parseInput.S3SecretAccessKey != null && parseInput.BucketName != null) if (Uri.IsWellFormedUriString(parseInput.S3Url, UriKind.Absolute)) diff --git a/ParseInput.cs b/ParseInput.cs index e6b6475..2172a8c 100644 --- a/ParseInput.cs +++ b/ParseInput.cs @@ -96,6 +96,8 @@ public int Warnings public HashSet MsLevel { get; set; } + public int MaxLevel { get; set; } + public bool MgfPrecursor { get; set; } public bool NoiseData { get; set; } @@ -136,6 +138,7 @@ public ParseInput() Vigilant = false; _errors = 0; _warnings = 0; + MaxLevel = 10; } public ParseInput(string rawFilePath, string rawDirectoryPath, string outputDirectory, OutputFormat outputFormat diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index 411f2dc..b16046d 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -401,10 +401,13 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc SpectrumType spectrum = null; + int level; try { - spectrum = ConstructMSSpectrum(scanNumber); + level = (int) _rawFile.GetScanEventForScanNumber(scanNumber).MSOrder; //applying MS level pre filter + if (level <= ParseInput.MaxLevel) + spectrum = ConstructMSSpectrum(scanNumber); } catch (Exception ex) { @@ -412,9 +415,9 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc ParseInput.NewError(); } - var level = spectrum != null ? int.Parse(spectrum.cvParam.Where(p => p.accession == "MS:1000511").First().value) : 0; + level = spectrum != null ? int.Parse(spectrum.cvParam.Where(p => p.accession == "MS:1000511").First().value) : 0; - if (spectrum != null && ParseInput.MsLevel.Contains(level)) //applying MS level filter + if (spectrum != null && ParseInput.MsLevel.Contains(level)) //applying final MS filter { spectrum.index = index.ToString(); if (_doIndexing) From 75934f8c2312e69b48e4fc85c98c1492d5dde855 Mon Sep 17 00:00:00 2001 From: Andre Schoengraf Date: Sun, 17 Mar 2024 17:33:40 +0100 Subject: [PATCH 22/28] Bugfix command line options --- MainClass.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/MainClass.cs b/MainClass.cs index 7ece9cf..df49e70 100644 --- a/MainClass.cs +++ b/MainClass.cs @@ -63,15 +63,15 @@ private static void XicParametersParsing(string[] args) "h|help", "Prints out the options.", h => parameters.help = h != null }, - { - "i=|input=", "The raw file input (Required). Specify this or an input directory -d", - v => singleFile = v - }, { "d=|input_directory=", "The directory containing the raw files (Required). Specify this or an input file -i.", v => fileDirectory = v }, + { + "i=|input=", "The raw file input (Required). Specify this or an input directory -d", + v => singleFile = v + }, { "j=|json=", "The json input file (Required).", @@ -83,12 +83,12 @@ private static void XicParametersParsing(string[] args) v => parameters.printJsonExample = v != null }, { - "o=|output=", + "o=|output_directory=", "The output directory. Specify this or an output file. Specifying neither writes to the input directory.", v => outputDirectory = v }, { - "b=|output_file", + "b=|output=", "The output file. Specify this or an output directory. Specifying neither writes to the input directory.", v => outputFile = v }, From 7dcd12574cba6f54f77ace33c8b55c3577487e66 Mon Sep 17 00:00:00 2001 From: caetera Date: Wed, 20 Mar 2024 19:28:02 +0100 Subject: [PATCH 23/28] Missing SA fix --- MainClass.cs | 2 +- Writer/MzMlSpectrumWriter.cs | 100 +++++++++++++++++------------------ 2 files changed, 50 insertions(+), 52 deletions(-) diff --git a/MainClass.cs b/MainClass.cs index 702741b..c628f99 100644 --- a/MainClass.cs +++ b/MainClass.cs @@ -20,7 +20,7 @@ public static class MainClass private static readonly ILog Log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); - public const string Version = "1.4.3"; + public const string Version = "1.4.4"; public static void Main(string[] args) { // Set Invariant culture as default for all further processing diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index b16046d..82f9a21 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -2393,66 +2393,64 @@ private PrecursorListType ConstructPrecursorList(int precursorScanNumber, IScanE //increase reaction count after successful parsing reactionCount++; - if (scanEvent.SupplementalActivation == TriState.On) - //the property is On if *at least* one of the levels had SA (i.e. not necissirily the last one), thus we need to try (and posibly fail) + //Sometimes the property of supplemental activation is not set (Tune v4 on Tribrid), + //or is On if *at least* one of the levels had SA (i.e. not necissirily the last one), thus we need to try (and posibly fail) + try { - try - { - reaction = scanEvent.GetReaction(reactionCount); + reaction = scanEvent.GetReaction(reactionCount); - if (reaction != null) + if (reaction != null) + { + if (reaction.CollisionEnergyValid) { - if (reaction.CollisionEnergyValid) - { - activationCvParams.Add( - new CVParamType - { - accession = "MS:1002680", - name = "supplemental collision energy", - cvRef = "MS", - value = reaction.CollisionEnergy.ToString(CultureInfo.InvariantCulture), - unitCvRef = "UO", - unitAccession = "UO:0000266", - unitName = "electronvolt" - }); - } + activationCvParams.Add( + new CVParamType + { + accession = "MS:1002680", + name = "supplemental collision energy", + cvRef = "MS", + value = reaction.CollisionEnergy.ToString(CultureInfo.InvariantCulture), + unitCvRef = "UO", + unitAccession = "UO:0000266", + unitName = "electronvolt" + }); + } - // Add the supplemental CV term - switch (reaction.ActivationType) - { - case ActivationType.HigherEnergyCollisionalDissociation: - activationCvParams.Add(new CVParamType - { - accession = "MS:1002678", - name = "supplemental beam-type collision-induced dissociation", - cvRef = "MS", - value = "" - }); break; - - case ActivationType.CollisionInducedDissociation: - activationCvParams.Add(new CVParamType - { - accession = "MS:1002679", - name = "supplemental collision-induced dissociation", - cvRef = "MS", - value = "" - }); break; + // Add the supplemental CV term + switch (reaction.ActivationType) + { + case ActivationType.HigherEnergyCollisionalDissociation: + activationCvParams.Add(new CVParamType + { + accession = "MS:1002678", + name = "supplemental beam-type collision-induced dissociation", + cvRef = "MS", + value = "" + }); break; - default: - Log.Warn($"Unknown supplemental activation type: {reaction.ActivationType}"); - ParseInput.NewWarn(); - break; + case ActivationType.CollisionInducedDissociation: + activationCvParams.Add(new CVParamType + { + accession = "MS:1002679", + name = "supplemental collision-induced dissociation", + cvRef = "MS", + value = "" + }); break; - } + default: + Log.Warn($"Unknown supplemental activation type: {reaction.ActivationType}"); + ParseInput.NewWarn(); + break; - //increase reaction count after successful parsing - reactionCount++; } + + //increase reaction count after successful parsing + reactionCount++; } - catch (ArgumentOutOfRangeException) - { - // If we failed do nothing - } + } + catch (ArgumentOutOfRangeException) + { + // If we failed do nothing } precursor.activation = From 4e47244a0ee67048a631ebf906e9a4590c6ea1be Mon Sep 17 00:00:00 2001 From: caetera Date: Thu, 21 Mar 2024 16:42:28 +0100 Subject: [PATCH 24/28] Use CVTerm "Orbitrap" for FTMS scans in Orbitrap-based instruments --- Writer/MzMlSpectrumWriter.cs | 3 +++ Writer/OntologyMapping.cs | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index 82f9a21..c8d47ad 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -279,6 +279,9 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc instrumentModel = OntologyMapping.GetInstrumentModel(instrumentData.Model); SerializeCvParam(instrumentModel); + //Update the definition of FTMS + OntologyMapping.UpdateFTMSDefinition(instrumentData.Model); + SerializeCvParam(new CVParamType { cvRef = "MS", diff --git a/Writer/OntologyMapping.cs b/Writer/OntologyMapping.cs index bece09f..be9072f 100644 --- a/Writer/OntologyMapping.cs +++ b/Writer/OntologyMapping.cs @@ -718,6 +718,38 @@ public static CVParamType GetInstrumentModel(string instrumentName) return instrumentModel; } + /// + /// Changes the mapping of `MassAnalyserFTMS` for Orbitrap-based instruments + /// updates OntologyMapping dictionarty in place + /// + /// the instrument name + /// Void + public static void UpdateFTMSDefinition(string instrumentName) + { + instrumentName = instrumentName.ToUpper(); + + if (instrumentName.Contains("ORBITRAP") || instrumentName.Contains("EXACTIVE")) + { + MassAnalyzerTypes[MassAnalyzerType.MassAnalyzerFTMS] = new CVParamType + { + accession = "MS:1000484", + name = "orbitrap", + cvRef = "MS", + value = "" + }; + } + else + { + MassAnalyzerTypes[MassAnalyzerType.MassAnalyzerFTMS] = new CVParamType + { + accession = "MS:1000079", + name = "fourier transform ion cyclotron resonance mass spectrometer", + cvRef = "MS", + value = "" + }; + } + } + /// /// Get a list of detectors for the given instrument /// From 908709a8d6dc31f3f969e620cfda3f88f6b5956e Mon Sep 17 00:00:00 2001 From: Andre Schoengraf Date: Sun, 7 Apr 2024 22:48:49 +0200 Subject: [PATCH 25/28] cmdline options changed --- MainClass.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/MainClass.cs b/MainClass.cs index 4ccf364..b563982 100644 --- a/MainClass.cs +++ b/MainClass.cs @@ -63,15 +63,15 @@ private static void XicParametersParsing(string[] args) "h|help", "Prints out the options.", h => parameters.help = h != null }, - { - "i=|input=", "The raw file input (Required). Specify this or an input directory -d", - v => singleFile = v - }, { "d=|input_directory=", "The directory containing the raw files (Required). Specify this or an input file -i.", v => fileDirectory = v }, + { + "i=|input=", "The raw file input (Required). Specify this or an input directory -d", + v => singleFile = v + }, { "j=|json=", "The json input file (Required).", @@ -83,12 +83,12 @@ private static void XicParametersParsing(string[] args) v => parameters.printJsonExample = v != null }, { - "o=|output=", + "o=|output_directory=", "The output directory. Specify this or an output file. Specifying neither writes to the input directory.", v => outputDirectory = v }, { - "b=|output_file", + "b=|output=", "The output file. Specify this or an output directory. Specifying neither writes to the input directory.", v => outputFile = v }, @@ -103,7 +103,7 @@ private static void XicParametersParsing(string[] args) v => parameters.stdout = v != null }, { - "w|warningsAreErrors", "Return non-zero exit code for warnings; default only for errors", + "w|warningsAreErrors", "Return non-zero exit code for warnings; default only for errors", v => parameters.Vigilant = v != null }, { From c5cfc871b9d2af5e24d857c67c12d1f1ef393769 Mon Sep 17 00:00:00 2001 From: caetera Date: Thu, 11 Apr 2024 19:38:01 +0200 Subject: [PATCH 26/28] Small fixes --- Writer/MetadataWriter.cs | 12 +++------ Writer/MgfSpectrumWriter.cs | 2 -- Writer/MzMlSpectrumWriter.cs | 48 +++++++++++------------------------- Writer/SpectrumWriter.cs | 2 +- 4 files changed, 19 insertions(+), 45 deletions(-) diff --git a/Writer/MetadataWriter.cs b/Writer/MetadataWriter.cs index 29ee34f..ed9a76d 100644 --- a/Writer/MetadataWriter.cs +++ b/Writer/MetadataWriter.cs @@ -4,7 +4,6 @@ using System.IO; using System.Linq; using System.Reflection; -using System.Web.WebSockets; using log4net; using Newtonsoft.Json; using ThermoFisher.CommonCore.Data; @@ -122,16 +121,14 @@ public void WriteMetadata(IRawDataPlus rawFile, int firstScanNumber, int lastSca switch (_parseInput.MetadataFormat) { case MetadataFormat.JSON: - _metadataFileName = _parseInput.MetadataOutputFile != null - ? _parseInput.MetadataOutputFile - : Path.Combine(_parseInput.OutputDirectory, _parseInput.RawFileNameWithoutExtension) + + _metadataFileName = _parseInput.MetadataOutputFile ?? + Path.Combine(_parseInput.OutputDirectory, _parseInput.RawFileNameWithoutExtension) + "-metadata.json"; WriteJsonMetada(rawFile, firstScanNumber, lastScanNumber); break; case MetadataFormat.TXT: - _metadataFileName = _parseInput.MetadataOutputFile != null - ? _parseInput.MetadataOutputFile - : Path.Combine(_parseInput.OutputDirectory, _parseInput.RawFileNameWithoutExtension) + + _metadataFileName = _parseInput.MetadataOutputFile ?? + Path.Combine(_parseInput.OutputDirectory, _parseInput.RawFileNameWithoutExtension) + "-metadata.txt"; WriteTextMetadata(rawFile, firstScanNumber, lastScanNumber); break; @@ -371,7 +368,6 @@ private void WriteTextMetadata(IRawDataPlus rawFile, int firstScanNumber, int la output.Add("Firmware version=" + rawFile.GetInstrumentData().HardwareVersion); } - // MS Data output.Add("#MsData"); foreach (KeyValuePair entry in msTypes) diff --git a/Writer/MgfSpectrumWriter.cs b/Writer/MgfSpectrumWriter.cs index 0c86189..a6449bf 100644 --- a/Writer/MgfSpectrumWriter.cs +++ b/Writer/MgfSpectrumWriter.cs @@ -5,11 +5,9 @@ using System.Reflection; using System.Text.RegularExpressions; using log4net; -using ThermoFisher.CommonCore.Data; using ThermoFisher.CommonCore.Data.Business; using ThermoFisher.CommonCore.Data.FilterEnums; using ThermoFisher.CommonCore.Data.Interfaces; -using ThermoRawFileParser.Util; namespace ThermoRawFileParser.Writer { diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index c8d47ad..fc7848e 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -1,8 +1,6 @@ using System; using System.Collections.Generic; using System.Collections.Specialized; -using System.Diagnostics; -using System.Diagnostics.Eventing.Reader; using System.Globalization; using System.IO; using System.IO.Compression; @@ -527,7 +525,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc _writer.WriteEndElement(); // spectrumList index = 0; - var chromatograms = ConstructChromatograms(firstScanNumber, lastScanNumber); + var chromatograms = ConstructChromatograms(); if (!chromatograms.IsNullOrEmpty()) { // ChromatogramList @@ -914,7 +912,7 @@ private void Serialize(XmlSerializer serializer, T t) /// the first scan number /// the last scan number /// a list of chromatograms - private List ConstructChromatograms(int firstScanNumber, int lastScanNumber) + private List ConstructChromatograms() { var chromatograms = new List(); @@ -2470,15 +2468,14 @@ private PrecursorListType ConstructPrecursorList(int precursorScanNumber, IScanE var SPSPrecursor = new PrecursorType { selectedIonList = - new SelectedIonListType {count = "1", selectedIon = new ParamGroupType[1]}, - spectrumRef = spectrumRef - }; - - //Isolation window for SPS masses is the same as for the first precursor - SPSPrecursor.isolationWindow = + new SelectedIonListType { count = "1", selectedIon = new ParamGroupType[1] }, + spectrumRef = spectrumRef, + //Isolation window for SPS masses is the same as for the first precursor + isolationWindow = new ParamGroupType { cvParam = new CVParamType[3] + } }; SPSPrecursor.isolationWindow.cvParam[0] = @@ -2755,14 +2752,13 @@ private ScanListType ConstructScanList(int scanNumber, Scan scan) var scanType = new ScanType { - cvParam = scanTypeCvParams.ToArray() - }; - - // Scan window list - scanType.scanWindowList = new ScanWindowListType - { - count = 1, - scanWindow = new ParamGroupType[1] + cvParam = scanTypeCvParams.ToArray(), + // Scan window list + scanWindowList = new ScanWindowListType + { + count = 1, + scanWindow = new ParamGroupType[1] + } }; var scanWindow = new ParamGroupType { @@ -2853,22 +2849,6 @@ private static byte[] GetZLib64BitArray(ICollection array) return bytes; } - /// - /// Calculate the RAW file checksum - /// - /// the checksum string - private string CalculateMD5Checksum() - { - using (var md5 = MD5.Create()) - { - using (var stream = File.OpenRead(ParseInput.RawFilePath)) - { - var hash = md5.ComputeHash(stream); - return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); - } - } - } - /// /// Calculate the RAW file checksum /// diff --git a/Writer/SpectrumWriter.cs b/Writer/SpectrumWriter.cs index 3002308..3b1d02b 100644 --- a/Writer/SpectrumWriter.cs +++ b/Writer/SpectrumWriter.cs @@ -107,7 +107,7 @@ private string NormalizeFileName(string outputFile, string extension, bool gzip) string tail = ""; string[] extensions; - if (ParseInput.Gzip) + if (gzip) extensions = new string[] { ".gz", extension }; else extensions = new string[] { extension }; From 376036fa6ac1566baa23f51219f95417c75ff447 Mon Sep 17 00:00:00 2001 From: caetera Date: Tue, 16 Apr 2024 19:11:08 +0200 Subject: [PATCH 27/28] CVParamType comparer --- Util/CVHelpers.cs | 16 +++++++++++++++- Writer/MzMlSpectrumWriter.cs | 3 ++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/Util/CVHelpers.cs b/Util/CVHelpers.cs index cf7c617..62232b5 100644 --- a/Util/CVHelpers.cs +++ b/Util/CVHelpers.cs @@ -1,4 +1,5 @@ -using ThermoRawFileParser.Writer.MzML; +using System.Collections.Generic; +using ThermoRawFileParser.Writer.MzML; namespace ThermoRawFileParser.Util { @@ -18,4 +19,17 @@ public static CVParamType Copy (this CVParamType old) }; } } + + public class CVComparer : IEqualityComparer + { + public bool Equals(CVParamType cv1, CVParamType cv2) + { + return cv1.accession == cv2.accession; + } + + public int GetHashCode(CVParamType cv) + { + return cv.accession.GetHashCode(); + } + } } diff --git a/Writer/MzMlSpectrumWriter.cs b/Writer/MzMlSpectrumWriter.cs index fc7848e..e16c107 100644 --- a/Writer/MzMlSpectrumWriter.cs +++ b/Writer/MzMlSpectrumWriter.cs @@ -16,6 +16,7 @@ using ThermoFisher.CommonCore.Data.Business; using ThermoFisher.CommonCore.Data.FilterEnums; using ThermoFisher.CommonCore.Data.Interfaces; +using ThermoRawFileParser.Util; using ThermoRawFileParser.Writer.MzML; using zlib; @@ -143,7 +144,7 @@ public override void Write(IRawDataPlus rawFile, int firstScanNumber, int lastSc _writer.WriteStartElement("fileContent"); //accumulating different types of file content - HashSet content = new HashSet(); + HashSet content = new HashSet(new CVComparer()); if (_rawFile.HasMsData) { From fb5d7bbcec3b507a5e813a16a7e4e0206e4826a7 Mon Sep 17 00:00:00 2001 From: caetera Date: Thu, 18 Apr 2024 19:14:03 +0200 Subject: [PATCH 28/28] Unify command line arguments Unify command line parameters for all modes and update the readme accordingly --- MainClass.cs | 32 ++++++++++++++++---------------- README.md | 20 +++++++++++--------- 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/MainClass.cs b/MainClass.cs index c718f34..e2e346d 100644 --- a/MainClass.cs +++ b/MainClass.cs @@ -63,15 +63,15 @@ private static void XicParametersParsing(string[] args) "h|help", "Prints out the options.", h => parameters.help = h != null }, + { + "i=|input=", "The raw file input (Required). Specify this or an input directory -d", + v => singleFile = v + }, { "d=|input_directory=", "The directory containing the raw files (Required). Specify this or an input file -i.", v => fileDirectory = v }, - { - "i=|input=", "The raw file input (Required). Specify this or an input directory -d", - v => singleFile = v - }, { "j=|json=", "The json input file (Required).", @@ -82,16 +82,16 @@ private static void XicParametersParsing(string[] args) "Show a json input file example.", v => parameters.printJsonExample = v != null }, - { - "o=|output_directory=", - "The output directory. Specify this or an output file. Specifying neither writes to the input directory.", - v => outputDirectory = v - }, { "b=|output=", "The output file. Specify this or an output directory. Specifying neither writes to the input directory.", v => outputFile = v }, + { + "o=|output_directory=", + "The output directory. Specify this or an output file. Specifying neither writes to the input directory.", + v => outputDirectory = v + }, { "6|base64", "Encodes the content of the xic vectors as base 64 encoded string.", @@ -338,7 +338,7 @@ private static void SpectrumQueryParametersParsing(string[] args) v => parameters.scans = v }, { - "b=|output_file", + "b=|output=", "The output file. Specifying none writes the output file to the input file parent directory.", v => parameters.outputFile = v }, @@ -510,15 +510,15 @@ private static void RegularParametersParsing(string[] args) v => parseInput.RawDirectoryPath = v }, { - "o=|output=", - "The output directory. Specify this or an output file -b. Specifying neither writes to the input directory.", - v => parseInput.OutputDirectory = v - }, - { - "b=|output_file", + "b=|output=", "The output file. Specify this or an output directory -o. Specifying neither writes to the input directory.", v => parseInput.OutputFile = v }, + { + "o=|output_directory=", + "The output directory. Specify this or an output file -b. Specifying neither writes to the input directory.", + v => parseInput.OutputDirectory = v + }, { "s|stdout", "Write to standard output. Cannot be combined with file or directory output. Implies silent logging, i.e. logging level 0", diff --git a/README.md b/README.md index e9b35b6..c382b22 100644 --- a/README.md +++ b/README.md @@ -59,12 +59,13 @@ optional subcommands are xic|query (use [subcommand] -h for more info]): -d, --input_directory=VALUE The directory containing the raw files (Required). Specify this or an input raw file -i. - -o, --output=VALUE The output directory. Specify this or an output - file -b. Specifying neither writes to the input - directory. - -b, --output_file=VALUE The output file. Specify this or an output + -b, --output=VALUE The output file. Specify this or an output directory -o. Specifying neither writes to the input directory. + -o, --output_directory=VALUE + The output directory. Specify this or an output + file -b. Specifying neither writes to the input + directory. -s, --stdout Write to standard output. Cannot be combined with file or directory output. Implies silent logging, i.e. logging level 0 @@ -137,7 +138,7 @@ usage is: -h, --help Prints out the options. -i, --input=VALUE The raw file input (Required). -n, --scans=VALUE The scan numbers. e.g. "1-5, 20, 25-30" - -b, --output_file=VALUE The output file. Specifying none writes the output + -b, --output=VALUE The output file. Specifying none writes the output file to the input file parent directory. -p, --noPeakPicking Don't use the peak picking provided by the native Thermo library. By default peak picking is @@ -169,12 +170,13 @@ ThermoRawFileParser.exe xic --help Specify this or an input file -i. -j, --json=VALUE The json input file (Required). -p, --print_example Show a json input file example. - -o, --output=VALUE The output directory. Specify this or an output - file. Specifying neither writes to the input - directory. - -b, --output_file=VALUE The output file. Specify this or an output + -b, --output=VALUE The output file. Specify this or an output directory. Specifying neither writes to the input directory. + -o, --output_directory=VALUE + The output directory. Specify this or an output + file. Specifying neither writes to the input + directory. -6, --base64 Encodes the content of the xic vectors as base 64 encoded string. -s, --stdout Pipes the output into standard output. Logging is