Writing mzMLb¶
Using the psims
library, ms_deisotope.output.mzmlb
can write an mzMLb
file with all associated metadata. This uses the same machinery as ms_deisotope.output.mzml
to accomplish this.
This module also contains a specialized version of MzMLbLoader
,
ProcessedMzMLbLoader
, which can directly reconstruct each
deconvoluted peak list and provides fast access to an extended index of
metadata that MzMLbSerializer
writes to an external file.
All behavior available for the ProcessedMzMLLoader
are available for
ProcessedMzMLbLoader
.
import ms_deisotope
from ms_deisotope.test.common import datafile
from ms_deisotope.output.mzmlb import MzMLbSerializer
reader = ms_deisotope.MSFileLoader(datafile("small.mzML"))
with MzMLbSerializer('small.deconvoluted.mzMLb', n_spectra=len(reader)) as writer:
writer.copy_metadata_from(reader)
for bunch in reader:
bunch.precursor.pick_peaks()
bunch.precursor.deconvolute()
for product in bunch.products:
product.pick_peaks()
product.deconvolute()
writer.save(bunch)
- class ms_deisotope.output.mzmlb.MzMLbSerializer(handle, n_spectra=200000, compression=None, deconvoluted=True, sample_name=None, build_extra_index=True, data_encoding=None, include_software_entry=True, close=None)[source]¶
- add_data_processing(data_processing_description: Union[ms_deisotope.data_source.metadata.data_transformation.DataProcessingInformation, ms_deisotope.data_source.metadata.data_transformation.ProcessingMethod])¶
Add a new
DataProcessingInformation
orProcessingMethod
.Creates a new
<dataProcessing>
entry describing one or more<processingMethod>`s for a single referenced :class:`~.Software
instance.- Parameters
data_processing_description (
DataProcessingInformation
orProcessingMethod
) – Data manipulation sequence to add to the document
- add_file_contents(file_contents: Union[str, collections.abc.Mapping, ms_deisotope.data_source.metadata.file_information.FileContent])¶
Add a key to the resulting
<fileDescription>
of the output document.- Parameters
file_contents (
str
orMapping
) – The parameter to add
- add_file_information(file_information: ms_deisotope.data_source.metadata.file_information.FileInformation)¶
Add the information of a
FileInformation
to the output document.- Parameters
file_information (
FileInformation
) – The information to add.
- add_instrument_configuration(configuration: ms_deisotope.data_source.metadata.instrument_components.InstrumentInformation)¶
Add an
InstrumentInformation
object to the output document.- Parameters
configuration (
InstrumentInformation
) – The instrument configuration to add
- add_processing_parameter(name: str, value: Optional[Union[str, int, float]] = None)¶
Add a new processing method to the writer’s own
<dataProcessing>
element.- Parameters
name (str) – The processing technique’s name
value (obj) – The processing technique’s value, if any
- add_software(software_description: ms_deisotope.data_source.metadata.software.Software)¶
Add a
Software
object to the output document.- Parameters
software_description (
Software
) – The software description to add
- add_software(software_description: ms_deisotope.data_source.metadata.software.Software)¶
Add a
Software
object to the output document.- Parameters
software_description (
Software
) – The software description to add
- add_source_file(source_file: ms_deisotope.data_source.metadata.file_information.SourceFile)¶
Add the
SourceFile
to the output document.- Parameters
source_file (
SourceFile
) – The source fil to add
- close()¶
Finish writing scan data, write any pending metadata and close the file stream.
May call
complete()
.
- save(bunch: Union[ms_deisotope.data_source.scan.scan.Scan, ms_deisotope.data_source.scan.base.ScanBunch], **kwargs)¶
Save any scan information in bunch.
This method can handle
ScanBunch
orScanBase
instances, dispatching to the appropriate logic.- Parameters
bunch (
ScanBunch
orScanBase
) – The scan data to save. May be a collection of related scans or a single scan.
See also
- save_scan(scan: ms_deisotope.data_source.scan.base.ScanBase, **kwargs)¶
Write a
Scan
to the output document as a collection of related<spectrum>
tags.Note
If no spectra have been written to the output document yet, this method will call
_add_spectrum_list()
and writes all of the metadata lists out. After this point, no new document-level metadata can be added.- Parameters
scan (
Scan
) – The scan to write.deconvoluted (
bool
) – Whether the scan to write out should include deconvolution information
- save_scan_bunch(bunch: ms_deisotope.data_source.scan.base.ScanBunch, **kwargs)¶
Write a
ScanBunch
to the output document as a collection of related<spectrum>
tags.Note
If no spectra have been written to the output document yet, this method will call
_add_spectrum_list()
and writes all of the metadata lists out. After this point, no new document-level metadata can be added.- Parameters
bunch (
ScanBunch
) – The scan set to write.
- class ms_deisotope.output.mzmlb.ProcessedMzMLbLoader(source_file, use_index=True, use_extended_index=True)[source]¶
- get_index_information_by_scan_id(scan_id: str) dict ¶
Get the scan description from the extended index.
- has_index_file() bool ¶
Checks if an extended index file exists for this reader.
- Returns
- Return type
bool