private static void ProcessFile(IRawDataPlus rawFile, int firstScanNumber, int lastScanNumber, ParseInput parseInput) { if (parseInput.MetadataFormat != MetadataFormat.NONE) { MetadataWriter metadataWriter; if (parseInput.MetadataOutputFile != null) { metadataWriter = new MetadataWriter(null, parseInput.MetadataOutputFile); } else { metadataWriter = new MetadataWriter(parseInput.OutputDirectory, parseInput.RawFileNameWithoutExtension); } switch (parseInput.MetadataFormat) { case MetadataFormat.JSON: metadataWriter.WriteJsonMetada(rawFile, firstScanNumber, lastScanNumber); break; case MetadataFormat.TXT: metadataWriter.WriteMetadata(rawFile, firstScanNumber, lastScanNumber); break; } } if (parseInput.OutputFormat != OutputFormat.NONE) { SpectrumWriter spectrumWriter; switch (parseInput.OutputFormat) { case OutputFormat.MGF: spectrumWriter = new MgfSpectrumWriter(rawFile, parseInput); spectrumWriter.Write(firstScanNumber, lastScanNumber); break; case OutputFormat.MzML: case OutputFormat.IndexMzML: spectrumWriter = new MzMlSpectrumWriter(rawFile, parseInput); spectrumWriter.Write(firstScanNumber, lastScanNumber); break; case OutputFormat.Parquet: spectrumWriter = new ParquetSpectrumWriter(rawFile, parseInput); spectrumWriter.Write(firstScanNumber, lastScanNumber); break; } } //Log.Info("Finished parsing " + parseInput.RawFilePath); Console.WriteLine("Finished parsing " + parseInput.RawFilePath); }
/// <summary> /// Extract the RAW file metadata and spectra in MGF format. /// </summary> /// <param name="parseInput">the parse input object</param> public static void Parse(ParseInput parseInput) { // Check to see if the RAW file name was supplied as an argument to the program if (string.IsNullOrEmpty(parseInput.RawFilePath)) { throw new Exception("No RAW file specified!"); } // Check to see if the specified RAW file exists if (!File.Exists(parseInput.RawFilePath)) { throw new Exception(@"The file doesn't exist in the specified location - " + parseInput.RawFilePath); } Log.Info("Started parsing " + parseInput.RawFilePath); // Create the IRawDataPlus object for accessing the RAW file //var rawFile = RawFileReaderAdapter.FileFactory(rawFilePath); IRawDataPlus rawFile; using (rawFile = RawFileReaderFactory.ReadFile(parseInput.RawFilePath)) { if (!rawFile.IsOpen) { throw new Exception("Unable to access the RAW file using the RawFileReader class!"); } // Check for any errors in the RAW file if (rawFile.IsError) { throw new Exception($"Error opening ({rawFile.FileError}) - {parseInput.RawFilePath}"); } // Check if the RAW file is being acquired if (rawFile.InAcquisition) { throw new Exception("RAW file still being acquired - " + parseInput.RawFilePath); } // 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); // Get the first and last scan from the RAW file var firstScanNumber = rawFile.RunHeaderEx.FirstSpectrum; var lastScanNumber = rawFile.RunHeaderEx.LastSpectrum; if (parseInput.OutputMetadata != MetadataFormat.NON) { var metadataWriter = new MetadataWriter(parseInput.OutputDirectory, parseInput.RawFileNameWithoutExtension); if (parseInput.OutputMetadata == MetadataFormat.JSON) { metadataWriter.WriteJsonMetada(rawFile, firstScanNumber, lastScanNumber); } if (parseInput.OutputMetadata == MetadataFormat.TXT) { metadataWriter.WriteMetada(rawFile, firstScanNumber, lastScanNumber); } } if (parseInput.OutputFormat != OutputFormat.NON) { SpectrumWriter spectrumWriter; switch (parseInput.OutputFormat) { case OutputFormat.Mgf: spectrumWriter = new MgfSpectrumWriter(parseInput); spectrumWriter.Write(rawFile, firstScanNumber, lastScanNumber); break; case OutputFormat.Mzml: spectrumWriter = new MzMlSpectrumWriter(parseInput); spectrumWriter.Write(rawFile, firstScanNumber, lastScanNumber); break; case OutputFormat.Parquet: spectrumWriter = new ParquetSpectrumWriter(parseInput); spectrumWriter.Write(rawFile, firstScanNumber, lastScanNumber); break; } } Log.Info("Finished parsing " + parseInput.RawFilePath); } }
/// <summary> /// Process and extract the given RAW file. /// </summary> /// <param name="parseInput">the parse input object</param> private static void ProcessFile(ParseInput parseInput) { // Create the IRawDataPlus object for accessing the RAW file IRawDataPlus rawFile; using (rawFile = RawFileReaderFactory.ReadFile(parseInput.RawFilePath)) { if (!rawFile.IsOpen) { throw new RawFileParserException("Unable to access the RAW file using the native Thermo library."); } // Check for any errors in the RAW file if (rawFile.IsError) { throw new RawFileParserException($"Error opening ({rawFile.FileError}) - {parseInput.RawFilePath}"); } // Check if the RAW file is being acquired if (rawFile.InAcquisition) { throw new RawFileParserException("RAW file still being acquired - " + parseInput.RawFilePath); } // 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); rawFile.IncludeReferenceAndExceptionData = parseInput.ExData; // Get the first and last scan from the RAW file var firstScanNumber = rawFile.RunHeaderEx.FirstSpectrum; var lastScanNumber = rawFile.RunHeaderEx.LastSpectrum; if (parseInput.MetadataFormat != MetadataFormat.NONE) { MetadataWriter metadataWriter; if (parseInput.MetadataOutputFile != null) { metadataWriter = new MetadataWriter(null, parseInput.MetadataOutputFile); } else { metadataWriter = new MetadataWriter(parseInput.OutputDirectory, parseInput.RawFileNameWithoutExtension); } switch (parseInput.MetadataFormat) { case MetadataFormat.JSON: metadataWriter.WriteJsonMetada(rawFile, firstScanNumber, lastScanNumber); break; case MetadataFormat.TXT: metadataWriter.WriteMetadata(rawFile, firstScanNumber, lastScanNumber); break; } } if (parseInput.OutputFormat != OutputFormat.NONE) { SpectrumWriter spectrumWriter; switch (parseInput.OutputFormat) { case OutputFormat.MGF: spectrumWriter = new MgfSpectrumWriter(parseInput); spectrumWriter.Write(rawFile, firstScanNumber, lastScanNumber); break; case OutputFormat.MzML: case OutputFormat.IndexMzML: spectrumWriter = new MzMlSpectrumWriter(parseInput); spectrumWriter.Write(rawFile, firstScanNumber, lastScanNumber); break; case OutputFormat.Parquet: spectrumWriter = new ParquetSpectrumWriter(parseInput); spectrumWriter.Write(rawFile, firstScanNumber, lastScanNumber); break; } } Log.Info("Finished parsing " + parseInput.RawFilePath); } }