MGF¶
MGF is a simple human-readable format for MS/MS data. It allows storing MS/MS peak lists and exprimental parameters.
This module provides MGFLoader
, a RandomAccessScanSource
implementation.
The parser is based on pyteomics.mgf
.
- class ms_deisotope.data_source.mgf.MGFLoader(source_file, encoding='utf-8', use_index=True, **kwargs)[source]¶
Reads scans from MASCOT Generic File (MGF) Format files. Provides both iterative and random access.
Note
If the file is not sorted by retention time,
get_scan_by_time()
and any other time-based accessors will fail.- source_file¶
Path to file to read from.
- Type
str
- source¶
Underlying scan data source
- Type
pyteomics.mgf.MGFBase
- header¶
Any top-of-the-file parameters
- Type
dict
- data_processing()¶
Describe any preprocessing steps applied to the data described by this instance.
- Returns
- Return type
list
ofDataProcessingInformation
- file_description()¶
Describe the file and its components, as well as any content types it has.
- Returns
- Return type
- find_next_ms1(start_index: int) Optional[ms_deisotope.data_source.scan.loader.ScanType] ¶
Locate the MS1 scan following
start_index
, iterating forwards through scans until either the last scan is reached or an MS1 scan is found.- Returns
- Return type
ScanBase
orNone
if not found
- find_previous_ms1(start_index: int) Optional[ms_deisotope.data_source.scan.loader.ScanType] ¶
Locate the MS1 scan preceding
start_index
, iterating backwards through scans until either the first scan is reached or an MS1 scan is found.- Returns
- Return type
ScanBase
orNone
if not found
- get_scan_by_id(scan_id)[source]¶
Retrieve the scan object for the specified scan id.
If the scan object is still bound and in memory somewhere, a reference to that same object will be returned. Otherwise, a new object will be created.
- Parameters
scan_id (str) – The unique scan id value to be retrieved
- Returns
- Return type
- get_scan_by_index(index)[source]¶
Retrieve the scan object for the specified scan index.
This internally calls
get_scan_by_id()
which will use its cache.- Parameters
index (int) – The index to get the scan for
- Returns
- Return type
- get_scan_by_time(time)[source]¶
Retrieve the scan object for the specified scan time.
This internally calls
get_scan_by_id()
which will use its cache.- Parameters
time (float) – The time to get the nearest scan from
- Returns
- Return type
- property has_fast_random_access¶
Check whether the underlying data stream supports fast random access or not.
Even if the file format supports random access, it may be impractical due to overhead in parsing the underlying data stream, e.g. calling
gzip.GzipFile.seek()
can force the file to be decompressed from the beginning of the file on each call. This property can be used to signal to the caller whether or not it should use a different strategy.- Returns
One of
DefinitelyNotFastRandomAccess
,MaybeFastRandomAccess
, orDefinitelyFastRandomAccess
. The first is a False-y value, the latter two will evaluate toTrue
- Return type
Constant
- has_ms1_scans()[source]¶
Checks if this
ScanDataSource
contains MS1 spectra.- Returns
Returns a boolean value if the presence of MS1 scans is known for certain, or
None
if it cannot be determined in the case of missing metadata.- Return type
bool
orNone
- has_msn_scans()[source]¶
Checks if this
ScanDataSource
contains MSn spectra.- Returns
Returns a boolean value if the presence of MSn scans is known for certain, or
None
if it cannot be determined in the case of missing metadata.- Return type
bool
orNone
- property header¶
Any top-of-the-file parameters
- Returns
- Return type
dict
- property index¶
The byte offset index used to achieve fast random access.
Maps
ScanBase
IDs to the byte offsets, implying the order the scans reside in the file.- Returns
- Return type
pyteomics.xml.ByteEncodingOrderedDict
- initialize_scan_cache()¶
Initialize a cache which keeps track of which
Scan
objects are still in memory using aweakref.WeakValueDictionary
.When a scan is requested, if the scan object is found in the cache, the existing object is returned rather than re-read from disk.
- instrument_configuration()¶
Describe the different instrument components and configurations used to acquire scans in this run.
- Returns
- Return type
list
ofInstrumentInformation
- next()[source]¶
Advance the iterator, fetching the next
ScanBunch
orScanBase
depending upon iteration strategy.- Returns
- Return type
ScanBunch
orScanBase
- reset()[source]¶
Reset the object, clearing out any existing state.
This resets the underlying file iterator, then calls
make_iterator()
, and clears the scan cache.
- property scan_cache¶
A
weakref.WeakValueDictionary
mapping used to retrieve scans from memory if available before re-reading them from disk.
- software_list() List[ms_deisotope.data_source.metadata.software.Software] ¶
Describe any software used on the data described by this instance.
- Returns
- Return type
list
ofSoftware
- property source¶
The file parser that this reader consumes.
- property source_file_name: Optional[str]¶
Return the name of the file that backs this data source, if available.
- Returns
- Return type
str
orNone
- start_from_scan(scan_id=None, rt=None, index=None, require_ms1=True, grouped=True)[source]¶
Reconstruct an iterator which will start from the scan matching one of
scan_id
,rt
, orindex
. Only one may be provided.After invoking this method, the iterator this object wraps will be changed to begin yielding scan bunchs (or single scans if
grouped
isFalse
).This method will trigger several random-access operations, making it prohibitively expensive for normally compressed files.
- Parameters
scan_id (str, optional) – Start from the scan with the specified id.
rt (float, optional) – Start from the scan nearest to specified time (in minutes) in the run. If no exact match is found, the nearest scan time will be found, rounded up.
index (int, optional) – Start from the scan with the specified index.
require_ms1 (bool, optional) – Whether the iterator must start from an MS1 scan. True by default.
grouped (bool, optional) – whether the iterator should yield scan bunches or single scans. True by default.
- property time¶
A indexer facade that lets you index and slice by scan time.
- Returns
- Return type
TimeIndex