Writing MGF¶
ms_deisotope.output.mgf
can write an MGF for centroided or deconvoluted spectra.
from ms_deisotope.output.mgf import MGFSerializer
def to_mgf(reader, outstream, msn_filters=None):
if not msn_filters:
msn_filters = []
reader.make_iterator(grouped=False)
writer = MGFSerializer(outstream, deconvoluted=False)
with writer:
for scan in reader:
if scan.ms_level == 1:
continue
if msn_filters:
scan = scan.transform(msn_filters)
if scan.peak_set is None:
scan.pick_peaks()
writer.save_scan(scan)
Code for writing Mascot Generic Format files and for reading deconvoluted generic format files.
- class ms_deisotope.output.mgf.MGFSerializer(stream, sample_name=None, deconvoluted=True)[source]¶
A MASCOT Generic Format writer which is deconvolution aware.
Implements :class:`~.HeaderedDelimitedWriter, as well as allowing global parameters to be included at the beginning of the file.
- sample_name¶
The name of the sample. This value is currently ignored.
- Type
str
- started¶
Whether scans have been written out yet or not. Once
started
is true, it is no longer possible to add global parameters usingadd_global_parameter()
.- Type
bool
- add_global_parameter(name, value)[source]¶
Add a global parameter at the beginning of the file, before scans are written.
Global parameters follow the same
KEY=value
format as scan-level parameters. New global parameters may not be added once a scan has been written.- Parameters
name (str) – The parameter name. Will be made upper-case.
value (object) – The parameter’s value. Will be converted to a string.
- Raises
ValueError: – If scans have already been written, this method raises a
ValueError
- ms_deisotope.output.mgf.ProcessedMGFDeserializer¶
alias of
ms_deisotope.output.mgf.ProcessedMGFLoader