Post

MzMLWriter

Builds an indexed mzML file from spectra.


Remarks

Builds an indexed mzML file from spectra. Describe the instrument, software and data processing with the Add methods, start a run with AddRun, add spectra with AddSpectrum, then call Write.

Order matters. A run must be started before any spectrum is added, and AddProcessingMethod does nothing unless AddDataProcessing has been called first.


Constructors

SyntaxDescription
MzMLWriter()Creates a writer with the fixed mzML header in place.

Methods

MethodReturnsDescription
AddDataProcessing(string id)voidStarts a data processing entry. Later AddProcessingMethod calls attach to it.
AddFileDescription(string fileName)voidNot yet implemented. Has no effect on the written file.
AddInstrumentConfiguration(string id, string? refID)voidAdds an instrument configuration entry. The refID parameter is unused.
AddProcessingMethod(string softwareRef)voidAdds a processing method to the current data processing entry.
AddRun(string id, string instConf)voidStarts a run. Spectra added afterward belong to it.
AddSoftware(string id, string version)voidAdds a software entry. The ids “Xcalibur” and “pwiz” also get their standard CV terms.
AddSpectrum(Spectrum spec)voidConverts a spectrum object into a spectrum element.
Write(string filename, bool validateSchema = false, string? schemaPath = null)voidWrites the accumulated mzML content to the given path.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using Nova.Data;
using Nova.Io.Read;
using Nova.Io.Write;

MzMLWriter writer = new MzMLWriter();

// Describe how the file was produced. Ids given here are referred to
// by the entries that follow.
writer.AddSoftware("Nova", "1.1.0");
writer.AddInstrumentConfiguration("IC1", null);
writer.AddDataProcessing("DP1");
writer.AddProcessingMethod("Nova");

// A run must be started before any spectrum is added.
writer.AddRun("run1", "IC1");

FileReader reader = new FileReader("DDA.raw", MSFilter.MS1 | MSFilter.MS2);
foreach (Spectrum spectrum in reader)
{
  writer.AddSpectrum(spectrum);
}

writer.Write("converted.mzML");

Validation is off by default, because it needs a local copy of the schema and the output is usable either way.

1
writer.Write("converted.mzML", true, @"C:\schemas\mzML1.1.0.xsd");
This post is licensed under CC BY 4.0 by the author.

Trending Tags