How to use the pyteomics.mgf function in pyteomics

To help you get started, we’ve selected a few pyteomics examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mobiusklein / ms_deisotope / ms_deisotope / data_source / mgf.py View on Github external
import numpy as np

from six import string_types as basestring

from .scan import (
    ScanFileMetadataBase, RandomAccessScanSource, ScanDataSource,
    PrecursorInformation, _FakeGroupedScanIteratorImpl,
    ChargeNotProvided)

from .metadata.file_information import (
    FileInformation, MS_MSn_Spectrum)

from ._compression import test_if_file_has_fast_random_access


class _MGFParser(mgf.IndexedMGF):

    def parse_charge(self, charge_text, list_only=False):
        '''Pyteomics _parse_charge is very general-purpose, and
        can't be sped up, so we specialize it here.'''
        try:
            if not list_only:
                return int(charge_text.replace('+', ''))
            return list(map(self.parse_charge, charge_text.split(" ")))
        except Exception:
            if '-' in charge_text:
                return int(charge_text.replace("-", '')) * -1
            raise


class _MGFMetadata(ScanFileMetadataBase):
    """Objects implementing this interface can describe the original source
github mobiusklein / ms_deisotope / ms_deisotope / data_source / mgf.py View on Github external
def _create_parser(self):
        if self._use_index:
            return _MGFParser(self.source_file, read_charges=False,
                              convert_arrays=1, encoding=self.encoding)
        simple_reader = mgf.MGF(
            self.source_file, read_charges=False,
            convert_arrays=1, encoding=self.encoding)
        simple_reader.index = OffsetIndex()
        return simple_reader