Пример #1
0
def deconvolute(peaklist):
    """Recalculate peaklist to singly charged.
        peaklist (mspy.peaklist) - peak list to deconvolute
    """

    # recalculate peaks
    buff = []
    for peak in copy.deepcopy(peaklist):

        # uncharged peak
        if not peak.charge:
            continue

        # charge is correct
        elif abs(peak.charge) == 1:
            buff.append(peak)

        # recalculate peak
        else:

            # set fwhm
            if peak.fwhm:
                new_fwhm = abs(peak.fwhm * peak.charge)
                peak.setfwhm(new_fwhm)

            # set m/z and charge
            if peak.charge < 0:
                new_mz = masstools.mz(peak.mz, -1, peak.charge)
                peak.set_mz(new_mz)
                peak.setcharge(-1)

            else:
                new_mz = masstools.mz(peak.mz, 1, peak.charge)
                peak.set_mz(new_mz)
                peak.setcharge(1)

            # store peak
            buff.append(peak)

    # remove baseline
    if buff:
        for peak in buff:
            peak.setsn(None)
            peak.setai(peak.intensity)
            peak.setbase(0.)

    # update peaklist
    return type(peaklist)(buff)
Пример #2
0
    def deisotope(self):

        for x, parent in enumerate(self.peaklist):
            if self.isotopes[x] is not None:
                continue

            for charge in self.charges:
                cluster = self._get_cluster(x, parent, charge)

                # no isotope found
                if len(cluster) == 1:
                    continue

                # get theoretical isotopic pattern
                mass = int(masstools.mz(parent.mz, 0, charge))
                mass = min(15000, mass) // 200
                pattern = proteins.MASS_PATTERN_LOOKUP[mass]

                if self._too_few_isotopes(pattern, cluster, charge):
                    continue

                if self.valid_cluster(pattern, cluster, charge):
                    # valid ID, skip other charges
                    parent.setisotope(0)
                    parent.setcharge(charge)
                    break
Пример #3
0
    def deisotope(self):

        for x, parent in enumerate(self.peaklist):
            if self.isotopes[x] is not None:
                continue

            for charge in self.charges:
                cluster = self._get_cluster(x, parent, charge)

                # no isotope found
                if len(cluster) == 1:
                    continue

                # get theoretical isotopic pattern
                mass = int(masstools.mz(parent.mz, 0, charge))
                mass = min(15000, mass) // 200
                pattern = proteins.MASS_PATTERN_LOOKUP[mass]

                if self._too_few_isotopes(pattern, cluster, charge):
                    continue

                if self.valid_cluster(pattern, cluster, charge):
                    # valid ID, skip other charges
                    parent.setisotope(0)
                    parent.setcharge(charge)
                    break
Пример #4
0
    def get_exper_mass(self, index):
        '''Calculates the experimental MS1 mass for a given peptide.'''

        index = index[0]
        mz = self.data['precursor_mz'][index]
        charge = self.data['precursor_z'][index]
        return masstools.mz(mz, 0, charge)
Пример #5
0
    def get_indexes(self):
        '''Extract the match indexes for the given scans'''

        mass = masstools.mz(self.search['mass'], self.query.z, 0)
        exper = self.query.exper[self.index]
        indexes, = np.where(abs(exper - mass) / mass <= self._ppm_thresh)

        return indexes
Пример #6
0
    def set_mass(self, monoisotopic):
        '''Sets the isotopic mass for XICs and then adds self to flattened'''

        mass = monoisotopic + (ISOTOPE_DISTANCE * self.isotope)
        self.setattr('isotope_mass', mass)

        mz = masstools.mz(mass, self.charge, 0)
        self.setattr('isotope_mz', mz)
Пример #7
0
    def set_mass(self, monoisotopic):
        '''Sets the isotopic mass for XICs and then adds self to flattened'''

        mass = monoisotopic + (ISOTOPE_DISTANCE * self.isotope)
        self.setattr('isotope_mass', mass)

        mz = masstools.mz(mass, self.charge, 0)
        self.setattr('isotope_mz', mz)
    def scan(self, attrs):
        '''Initializes the scan data and sets base attributes'''

        num = int(attrs['start_scan'])
        self._scan = matched.Scan(num=num, fraction=self._fraction)
        self._scan['z'] = charge = int(attrs.get('assumed_charge', 1))
        # calculate m/z
        neutral_mass = float(attrs['precursor_neutral_mass'])
        self._scan['mz'] = masstools.mz(neutral_mass, charge, 0)
Пример #9
0
    def scan(self, attrs):
        '''Initializes the scan data and sets base attributes'''

        num = int(attrs['start_scan'])
        self._scan = matched.Scan(num=num, fraction=self._fraction)
        self._scan['z'] = charge = int(attrs.get('assumed_charge', 1))
        # calculate m/z
        neutral_mass = float(attrs['precursor_neutral_mass'])
        self._scan['mz'] = masstools.mz(neutral_mass, charge, 0)
Пример #10
0
    def scan(self, attrs):
        '''Initializes the scan data and sets base attributes'''

        title = attrs['spectrum']
        match = self.titleformatter(title)

        num = int(match.group('num'))
        self._scan = matched.Scan(num=num, fraction=self._fraction)
        self._scan['z'] = charge = int(attrs.get('assumed_charge', 1))
        # calculate m/z
        neutral_mass = float(attrs['precursor_neutral_mass'])
        self._scan['mz'] = masstools.mz(neutral_mass, charge, 0)
Пример #11
0
    def scan(self, attrs):
        '''Initializes the scan data and sets base attributes'''

        self._scan = {}
        self._scan['num'] = int(attrs['start_scan'])
        self._scan['z'] = charge = int(attrs.get('assumed_charge', 1))
        self._scan['fraction'] = self._fraction

        # the neutral mass is actually MH+ in the specification
        mh_plus_mass = float(attrs['precursor_neutral_mass'])
        neutral_mass = mh_plus_mass - params.PROTON_MASS
        self._scan['m/z'] = masstools.mz(neutral_mass, charge, 0)
Пример #12
0
    def scan(self, attrs):
        '''Initializes the scan data and sets base attributes'''

        title = attrs['spectrum']
        match = self.titleformatter(title)

        num = int(match.group('num'))
        self._scan = matched.Scan(num=num, fraction=self._fraction)
        self._scan['z'] = charge = int(attrs.get('assumed_charge', 1))
        # calculate m/z
        neutral_mass = float(attrs['precursor_neutral_mass'])
        self._scan['mz'] = masstools.mz(neutral_mass, charge, 0)
Пример #13
0
    def calculate_ppm(self, atom_counts, mods, exper, charge):
        '''Calculates the theroetical PPM from the exper mass'''

        atom_counts = copy.deepcopy(atom_counts)
        mods = unpack_mods(mods)

        for name, pos in mods.items():
            if name in self.fragments:
                formula = self.fragments[name]
                count = len(pos)
                atom_counts.update_formula(formula, count=count)

        theor = masstools.mz(atom_counts.mass, charge, 0)
        return (theor - exper) / exper * 1e6
Пример #14
0
    def calculate_ppm(self, atom_counts, mods, exper, charge):
        '''Calculates the theroetical PPM from the exper mass'''

        atom_counts = copy.deepcopy(atom_counts)
        mods = unpack_mods(mods)

        for name, pos in mods.items():
            if name in self.fragments:
                formula = self.fragments[name]
                count = len(pos)
                atom_counts.update_formula(formula, count=count)

        theor = masstools.mz(atom_counts.mass, charge, 0)
        return (theor - exper) / exper * 1e6
Пример #15
0
    def _b_series(self):
        '''
        Calculates the b-ion series, which is characterized by the following
        formula: [N]+[M]-H, starting from the N-terminus.
        For example, the b3 ion for KPIDWGAASPAVQSFR is the mass of
        KPI + # proton(s) * charge.
        '''

        for position in range(2, self.length):
            for charge in self._charges:
                seq = self.peptide[:position]
                mass = (chemical.Molecule(self._aminoacids[i]) for i in seq)
                mass = (i.mass for i in mass)
                mz = masstools.mz(mass, charge, 0)

                self.mzs.append(mz)
                self.charges.append(charge)
                self.position.append(position)

        self._toarray()
Пример #16
0
    def _y_series(self):
        '''
        Calculates the y-ion series, which is characterized by the following
        formula: [C]+[M]+H, starting from the C-terminus.
        For example, the y3 ion for KPIDWGAASPAVQSFR is the mass of
        SFR + water + # proton(s) * charge.
        '''

        for position in range(1, self.length):
            for charge in self._charges:
                seq = self.peptide[-position:]
                mass = sum(chemical.Molecule(self._aminoacids[i]) for i in seq)
                mass = (i.mass for i in mass)
                mass += WATER_MASS
                mz = masstools.mz(mass, charge, 0)

                self.mzs.append(mz)
                self.charges.append(charge)
                self.position.append(position)

        self._toarray()
Пример #17
0
    def process_hit(self, query, peptide_info, rank):
        '''Initializes the hit with all the default peptide parameters'''

        hit = {'rank': int(rank)}

        variable_modification_string = peptide_info[6]
        hit['peptide'] = peptide = peptide_info[4]
        hit['modifications'] = self.modifications.process(
            peptide, variable_modification_string)

        # score for  Mascot is defined as -log(p), where p is chance of ion
        # match by chance
        hit['score'] = score = float(peptide_info[7])
        hit['ev'] = 10**(-score / 10)

        mass = float(peptide_info[1])
        charge = self.queries[query]['z']
        mz_theor = masstools.mz(mass, charge, 0)
        mz_exper = self.queries[query]['mz']
        hit['ppm'] = (mz_theor - mz_exper) * 1e6 / mz_exper

        return hit
Пример #18
0
    def process_hit(self, query, peptide_info, rank):
        '''Initializes the hit with all the default peptide parameters'''

        hit = {'rank': int(rank)}

        variable_modification_string = peptide_info[6]
        hit['peptide'] = peptide = peptide_info[4]
        hit['modifications'] = self.modifications.process(
            peptide, variable_modification_string)

        # score for  Mascot is defined as -log(p), where p is chance of ion
        # match by chance
        hit['score'] = score = float(peptide_info[7])
        hit['ev'] = 10 ** (-score/10)

        mass = float(peptide_info[1])
        charge = self.queries[query]['z']
        mz_theor = masstools.mz(mass, charge, 0)
        mz_exper = self.queries[query]['mz']
        hit['ppm'] = (mz_theor - mz_exper) * 1e6 / mz_exper

        return hit
Пример #19
0
    def get_missing_mass(self, link_ends, fragments):
        '''
        Grabs the missing basemass and initiates a named tuple for
        the mass lists form the link and deadends.
        '''

        max_links = self.max_link_ends()
        dead_ends = self.get_dead_ends(link_ends, max_links)
        ends = Ends(link_ends, dead_ends, self.xlnum)

        # now need to calculate the base mass and mass permutations
        basemass = self.missing_ms1_mass(dead_ends)
        assert basemass > self._threshold
        mass_perm = list(self.get_fragment_combinations(sum(fragments), False))

        mzs = []
        for mass in mass_perm:
            mz_ = masstools.mz(basemass + sum(mass), self.missing_z(), 0)
            mzs.append(mz_)
        mzs = np.array(mzs).reshape((-1, 1))
        ms1 = self.ms1(ends, basemass, mass_perm, mzs)

        return ms1
Пример #20
0
    def getmz(self, label, spreadsheet):
        '''Returns the m/z value for the given label'''

        charge = spreadsheet['MS2 z'][0]
        return masstools.mz(label.mass, charge, 0)
Пример #21
0
    def fromfragment(cls, fragment):
        '''Initializes a reporter ion from a Fragment instance'''

        mass = chemical.Molecule(fragment.formula).mass
        mz = masstools.mz(mass, fragment.charge)
        return cls(fragment.name, mz)
Пример #22
0
    def fromfragment(cls, fragment):
        '''Initializes a reporter ion from a Fragment instance'''

        mass = chemical.Molecule(fragment.formula).mass
        mz = masstools.mz(mass, fragment.charge)
        return cls(fragment.name, mz)
Пример #23
0
 def getmz(self, currentcharge=0):
     return masstools.mz(self.precursor_mz, currentcharge, self.precursor_z)