/// <summary> /// Writes the opening tags and metadata information. /// </summary> /// <param name="header"></param> public void WriteHeader(ScanFileHeader header) { writer.WriteStartElement("mzXML", "http://sashimi.sourceforge.net/schema_revision/mzXML_3.1"); writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); writer.WriteAttributeString("xsi", "schemaLocation", null, "http://sashimi.sourceforge.net/schema_revision/mzXML_3.1 http://sashimi.sourceforge.net/schema_revision/mzXML_3.1/mzXML_idx_3.1.xsd"); writer.WriteStartElement("msRun"); writer.WriteAttributeString("scanCount", header.ScanCount.ToString()); writer.WriteAttributeString("startTime", MakeRetentionTimeString(header.StartTime)); writer.WriteAttributeString("endTime", MakeRetentionTimeString(header.EndTime)); writer.WriteStartElement("parentFile"); writer.WriteAttributeString("fileName", header.FileName); writer.WriteAttributeString("fileType", "RAWData"); writer.WriteEndElement(); // parentFile writer.WriteStartElement("msInstrument"); writer.WriteStartElement("msManufacturer"); writer.WriteAttributeString("category", "msManufacturer"); writer.WriteAttributeString("value", header.InstrumentManufacturer); writer.WriteEndElement(); // msManufacturer writer.WriteStartElement("msModel"); writer.WriteAttributeString("category", "msModel"); writer.WriteAttributeString("value", header.InstrumentModel); writer.WriteEndElement(); // msModel writer.WriteEndElement(); // msInstrument }
/// <summary> /// Writes the opening tags and metadata information. /// </summary> /// <param name="header"></param> public void WriteHeader(ScanFileHeader header) { writer.WriteStartElement("mzXML", "http://sashimi.sourceforge.net/schema_revision/mzXML_3.1"); writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); writer.WriteAttributeString("xsi", "schemaLocation", null, "http://sashimi.sourceforge.net/schema_revision/mzXML_3.1 http://sashimi.sourceforge.net/schema_revision/mzXML_3.1/mzXML_idx_3.1.xsd"); writer.WriteStartElement("msRun"); writer.WriteAttributeString("scanCount", header.ScanCount.ToString()); writer.WriteAttributeString("startTime", MakeRetentionTimeString(header.StartTime)); writer.WriteAttributeString("endTime", MakeRetentionTimeString(header.EndTime)); writer.WriteStartElement("parentFile"); writer.WriteAttributeString("fileName", header.FileName); writer.WriteAttributeString("fileType", "RAWData"); writer.WriteAttributeString("fileSha1", CalculateFileHash(header.FilePath)); writer.WriteEndElement(); // parentFile writer.WriteStartElement("dataProcessing"); writer.WriteStartElement("software"); writer.WriteAttributeString("type", "conversion"); writer.WriteAttributeString("name", "Monocle"); writer.WriteAttributeString("version", "1"); writer.WriteEndElement(); // software writer.WriteEndElement(); // dataProcessing }
public ScanFileHeader GetHeader() { var header = new ScanFileHeader(); header.StartTime = (float)rawFile.RunHeaderEx.StartTime; header.EndTime = (float)rawFile.RunHeaderEx.EndTime; header.ScanCount = rawFile.RunHeaderEx.SpectraCount; header.InstrumentModel = rawFile.GetInstrumentData().Model; header.InstrumentManufacturer = "ThermoFisher"; return(header); }
/// <summary> /// Writes the header for the file. /// For mzdb, no information from the header is saved. /// </summary> public void WriteHeader(ScanFileHeader header) { string sql = "INSERT INTO metadata (name, value) VALUES ($name, $value)"; var command = new SQLiteCommand(sql, db); command.Parameters.AddWithValue("$name", "version"); command.Parameters.AddWithValue("$value", "1"); command.ExecuteNonQuery(); command.Parameters.AddWithValue("$name", "compression"); command.Parameters.AddWithValue("$value", "none"); command.ExecuteNonQuery(); }
public void testOutput() { var reader = new MzXmlReader(); reader.Open("data/orbixl-mini.mzxml", new ScanReaderOptions()); string dir = Directory.GetCurrentDirectory(); var writer = new MzXmlWriter(); writer.Open("data/mzxml-writer-test.mzxml"); var header = new ScanFileHeader(); header.FileName = "mzxml-writer-test.mzxml"; header.FilePath = "data/mzxml-writer-test.mzxml"; writer.WriteHeader(header); var scans = reader.GetEnumerator(); scans.MoveNext(); Scan scan1 = (Scan)scans.Current; scans.MoveNext(); Scan scan2 = (Scan)scans.Current; writer.WriteScan(scan1); writer.WriteScan(scan2); writer.Close(); reader = new MzXmlReader(); reader.Open("data/mzxml-writer-test.mzxml", new ScanReaderOptions()); scans = reader.GetEnumerator(); scans.MoveNext(); Scan scan3 = (Scan)scans.Current; scans.MoveNext(); Scan scan4 = (Scan)scans.Current; Assert.Equal(scan1.ScanNumber, scan3.ScanNumber); Assert.Equal(scan1.RetentionTime, scan3.RetentionTime); Assert.Equal(scan1.PeakCount, scan3.PeakCount); Assert.Equal(scan1.Centroids[0].Mz, scan3.Centroids[0].Mz); Assert.Equal(scan1.Centroids[11].Intensity, scan3.Centroids[11].Intensity); }
public void WriteHeader(ScanFileHeader header) { writer.WriteStartDocument(); writer.WriteStartElement("indexedmzML", "http://psi.hupo.org/ms/mzml"); writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); writer.WriteAttributeString("xsi", "schemaLocation", null, "http://psi.hupo.org/ms/mzml http://psidev.info/files/ms/mzML/xsd/mzML1.1.0.xsd"); writer.WriteStartElement("mzML", "http://psi.hupo.org/ms/mzml"); writer.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance"); writer.WriteAttributeString("xsi", "schemaLocation", null, "http://psi.hupo.org/ms/mzml http://psidev.info/files/ms/mzML/xsd/mzML1.1.0.xsd"); writer.WriteAttributeString("version", "1.1.0"); writer.WriteAttributeString("id", Path.GetFileNameWithoutExtension(header.FileName)); writer.WriteStartElement("cvList"); writer.WriteAttributeString("count", "2"); writer.WriteStartElement("cv"); writer.WriteAttributeString("id", "MS"); writer.WriteAttributeString("fullName", "Proteomics Standards Initiative Mass Spectrometry Ontology"); writer.WriteAttributeString("version", "1.18.2"); writer.WriteAttributeString("URI", "http://psidev.cvs.sourceforge.net/*checkout*/psidev/psi/psi-ms/mzML/controlledVocabulary/psi-ms.obo"); writer.WriteEndElement(); writer.WriteStartElement("cv"); writer.WriteAttributeString("id", "UO"); writer.WriteAttributeString("fullName", "Unit Ontology"); writer.WriteAttributeString("version", "04:03:2009"); writer.WriteAttributeString("URI", "http://obo.cvs.sourceforge.net/*checkout*/obo/obo/ontology/phenotype/unit.obo"); writer.WriteEndElement(); writer.WriteEndElement();// cvlist writer.WriteStartElement("fileDescription"); writer.WriteStartElement("fileContent"); WriteCVParam("MS:1000579", ""); WriteCVParam("MS:1000580", ""); writer.WriteEndElement(); // fileContent writer.WriteEndElement(); // fileDescription writer.WriteStartElement("softwareList"); writer.WriteAttributeString("count", "1"); writer.WriteStartElement("software"); writer.WriteAttributeString("id", "Monocle"); writer.WriteAttributeString("version", "1"); WriteCVParam("MS:1000799", "custom unreleased software tool"); writer.WriteEndElement(); // software writer.WriteEndElement(); // softwareList writer.WriteStartElement("instrumentConfigurationList"); writer.WriteAttributeString("count", "1"); writer.WriteStartElement("instrumentConfiguration"); writer.WriteAttributeString("id", "IC1"); writer.WriteStartElement("softwareRef"); writer.WriteAttributeString("ref", "Xcalibur"); writer.WriteEndElement(); // softwareRef writer.WriteEndElement(); // instrumentConfiguration writer.WriteEndElement(); // instrumentConfigurationList writer.WriteStartElement("dataProcessingList"); writer.WriteAttributeString("count", "1"); writer.WriteStartElement("dataProcessing"); writer.WriteAttributeString("id", "ThermoRawFileParserProcessing"); writer.WriteStartElement("processingMethod"); writer.WriteAttributeString("order", "0"); writer.WriteAttributeString("softwareRef", "Monocle"); WriteCVParam("MS:1000544", ""); writer.WriteEndElement(); // processingMethod writer.WriteEndElement(); // dataProcessing writer.WriteEndElement(); // dataProcessingList writer.WriteStartElement("run"); writer.WriteAttributeString("id", Path.GetFileNameWithoutExtension(header.FileName)); writer.WriteAttributeString("defaultInstrumentConfigurationRef", "IC1"); writer.WriteAttributeString("defaultSourceFileRef", "sourcefile_1"); writer.WriteStartElement("spectrumList"); writer.WriteAttributeString("count", header.ScanCount.ToString()); writer.WriteAttributeString("defaultDataProcessingRef", "ThermoRawFileParserProcessing"); }
/// <summary> /// Run Monocle on the files indicated in the Processor /// </summary> public async void Run() { tokenSource = new CancellationTokenSource(); CancellationToken token = tokenSource.Token; await Task.Run(() => { token.ThrowIfCancellationRequested(); try { int filesCompleted = 0; foreach (string newFile in files.FileList) { CurrentProgress = CalculateProgress(1, filesCompleted, files.FileList.Count); TrackProcess(newFile, CurrentProgress, RunStatus.Started); token.ThrowIfCancellationRequested(); IScanReader reader = ScanReaderFactory.GetReader(newFile); reader.Open(newFile); ScanFileHeader header = reader.GetHeader(); header.FileName = Path.GetFileName(newFile); var Scans = new List <Monocle.Data.Scan>(); foreach (Scan scan in reader) { token.ThrowIfCancellationRequested(); Scans.Add(scan); } reader.Close(); CurrentProgress = CalculateProgress(2, filesCompleted, files.FileList.Count); TrackProcess(newFile, CurrentProgress, RunStatus.Read); token.ThrowIfCancellationRequested(); if (!ConvertOnly) { // Start Run across Scans Monocle.Monocle.Run(ref Scans, monocleOptions); CurrentProgress = CalculateProgress(3, filesCompleted, files.FileList.Count); TrackProcess(newFile, CurrentProgress, RunStatus.Processed); token.ThrowIfCancellationRequested(); } string outputFilePath = Path.Combine(Path.GetDirectoryName(newFile), Path.GetFileNameWithoutExtension(newFile) + "_monocle." + monocleOptions.OutputFileType.ToString()); ScanWriterFactory.MakeTargetFileName(newFile, monocleOptions.OutputFileType); IScanWriter writer = ScanWriterFactory.GetWriter(monocleOptions.OutputFileType); writer.Open(outputFilePath); writer.WriteHeader(header); foreach (Scan scan in Scans) { token.ThrowIfCancellationRequested(); writer.WriteScan(scan); } writer.Close(); CurrentProgress = CalculateProgress(4, filesCompleted, files.FileList.Count); TrackProcess(outputFilePath, CurrentProgress, RunStatus.Written); token.ThrowIfCancellationRequested(); // Clear data EmptyScans(Scans); filesCompleted++; CurrentProgress = CalculateProgress(4, filesCompleted, files.FileList.Count); TrackProcess(outputFilePath, CurrentProgress, RunStatus.Finished); } AllFilesFinished(true); } catch (Exception ex) { Debug.WriteLine("File processing failed: " + ex); } }); }
/// <summary> /// There is no place to store metadata in the csv file, /// so calling this method does nothing. /// </summary> /// <param name="header"></param> public void WriteHeader(ScanFileHeader header) { // Nothing to do. }