Exemple #1
0
    def get_crosslinker_replacement(self, crosslink):
        '''Returns the crosslinker reactivity'''

        replaced = {k: 0 for k in crosslink.ends.link}

        crosslinker = self.crosslinkers[crosslink.crosslinker]
        bridge = chemical.Molecule(crosslinker.bridge).mass
        deadends = [chemical.Molecule(i) for i in crosslinker.ends.deadend]
        counts = Counter(crosslinker.ends.aminoacid)

        return Replacement(replaced, crosslinker.ends.aminoacid, counts,
            bridge, deadends, crosslink.ends)
Exemple #2
0
def getmodificationsformula(modifications, engine, **kwds):
    '''
    Calculates formula for all mods within standard library,
    potentially including chemical crosslinker fragments if
    with_crosslinkers is set to True.
    '''

    atom_counts = chemical.Molecule()
    modifications = modifications.byposition()

    for position, names in modifications.items():
        try:
            if frozenset(names) in chemical_defs.MODIFICATION_INTERACTIONS:
                # add the converted modification from id
                id_ = chemical_defs.MODIFICATION_INTERACTIONS[names].converted
                add_modifications(atom_counts, id_, **kwds)
            else:
                # no modification interaction, just add
                #ids = (engine.defaults.modifications.get(i)[0] for i in names)
                ids = [engine.defaults.modifications.get(i)[0] for i in names]
                add_modifications(atom_counts, *ids, **kwds)

        except (TypeError, IndexError):
            # Nonetype from .get(name)[0] or [][0]
            print("Modification not recognized: " + str(names),
                  file=sys.stderr)

    return atom_counts
Exemple #3
0
def molecular_weight(item):
    '''Quick MolecularWeight lookup, returns 0 on an error'''

    try:
        return chemical.Molecule(peptide=item, strict=False).mass
    except KeyError:
        return 0.
Exemple #4
0
    def __init__(self, scan, indexer, index, parent):
        super(PMFChecker, self).__init__()

        # here, need to recalculate the number of possible XL
        # number based on the fragments with 2 peptides
        self.scan = copy.deepcopy(scan)
        self.formula = self.scan.formula
        self.parent = parent
        self.xler = parent.xler
        self.data = parent.data

        self._nterm = parent.engine['nterm']
        self._cterm = parent.engine['cterm']

        self.bridge = chemical.Molecule(self.parent.xler['bridge']).mass()
        self.fragment_masses = self.get_fragment_masses()
        self.site_mass = self.get_sitemass()
        self.index = [indexer.total[index]]

        self.scan_data = self.get_scan_data()
        self.mz = self.scan_data['mz'].value
        self.intensity = self.scan_data['intensity'].value

        self.xlnum = None
        self.theor_charge = None
        self.link_ends_base = self.get_link_ends()
        self.order = sorted(set(self.xler['react_sites']))
Exemple #5
0
    def setdeadendmass(self, ends):
        '''
        Sets the mass for each deadend modificiation on a crosslinker at
        each reactive site, allowing quick lookups.
        '''

        zipped = ZIP(ends.aminoacid, ends.deadend)
        self.deadendmass = {r: chemical.Molecule(d).mass for r, d in zipped}
Exemple #6
0
    def __init__(self, row, crosslinker):
        super(CrosslinkedMass, self).__init__()

        self.crosslinker = crosslinker
        self.engine = row.engines['matched']

        self.setdeadendmass(crosslinker.ends)
        self.bridgemass = chemical.Molecule(crosslinker.bridge).mass
Exemple #7
0
    def get_sitemass(self):
        '''Creates a {res: mass} holder for deadend mods'''

        dead = self.xler['dead_end']
        react = self.xler["react_sites"]
        sitemass = {res: chemical.Molecule(dead[i]).mass for i, res
                    in enumerate(react)}

        return sitemass
Exemple #8
0
def getspecificity(fragment, precision=3):
    '''Returns the fragment rounded mass and reactivity'''

    formula_ = chemical.Molecule(fragment.formula)
    mass = round(formula_, precision)

    positions = fragment.aminoacid.split(',')
    reactivity = [Reactivity(i, fragment.terminus) for i in positions]

    return mass, reactivity
Exemple #9
0
    def check_threshold(self):
        '''
        Calculates mass of group of peptides, taking into considering
        their sequence, posttranslation modificaitons, and their neutral
        losses.
        '''

        formulas = self.unpack_data('formula')
        theor = sum(chemical.Molecule(i).mass for i in formulas)
        exper = self.get_exper_mass_(self.index)

        return exper - theor < self._threshold
    def get_fragment_masses(self):
        '''Returns a dictionary with crosslink fragment {name: mass}'''

        fragments = self.xler['fragments']
        names = fragments['name']
        formula = fragments['formula']
        react = fragments['reactivity']
        masses = mapping.OrderedDefaultdict(list)

        for index, name in enumerate(names):
            mass = round(chemical.Molecule(formula[index]), self.precision)
            masses[(mass, react[index])].append(name)

        return masses
Exemple #11
0
    def get_formula(self, mod_perm, index):
        '''
        Calculates the theoretical formula from the mod permutations
        and the current XL fragments and peptide.
        '''

        sequence = self._peptides[index].decode('utf-8')
        formula = chemical.Molecule(peptide=sequence)
        formulas = Counter(i[1] for item in mod_perm for i in item)

        for mod_formula, count in formulas.items():
            formula.update_formula(mod_formula, count=count)

        return formula
Exemple #12
0
    def calculate_formula(self, peptide, mods):
        '''
        Calculates the exact formula for the peptide without XLer
        modification
        '''

        atom_counts = chemical.Molecule(peptide=peptide)
        mods = unpack_mods(mods)
        for name, pos in mods.items():
            if name not in self.fragments and name in self.engine['mods']:
                formula = self.engine['mods'][name][0]
                count = len(pos)
                atom_counts.update_formula(formula, count=count)

        return atom_counts
Exemple #13
0
    def __call__(self, name, delimiter='+'):
        '''Returns the skyline formatted name for the modification'''

        atom_counts = chemical.Molecule()

        names = name.split(delimiter)
        modifications = self.getmodifications(names)
        crosslinkernumber = 0

        for modification in modifications:
            if not modification.fragment:
                atom_counts.update_formula(modification.formula)
            else:
                crosslinkernumber += 1

        return self.getskylinemass(atom_counts, crosslinkernumber)
Exemple #14
0
    def _add_search_data(self, match_idx):
        '''
        Adds data specific to the matched peptide, such as sequence,
        peptide start and uniprot ID
        '''

        id_ = self.search['id'][match_idx].decode('utf-8')
        self.data['id'].append(id_)

        self.data['name'].append(self.protein_names.get(id_, 'decoy'))

        peptide = self.search['peptide'][match_idx].decode('utf-8')
        self.data['peptide'].append(peptide)

        self.data['start'].append(self.search['start'][match_idx])

        formula = self.search['formula'][match_idx].decode('utf-8')
        self.data['formula'].append(chemical.Molecule(formula))
Exemple #15
0
    def _get_formula(self, string_formula, modname, leaving_group):
        '''
        Produces the net mod formula, with the addition or overall formula
        defined by string_formula and the loss by the leaving_group.
        If no formula is defined or is a monomer formula (not chemical),
        an AssertionError or AttributeError is defined and the formula
        is attempted to be solved via .mods.MONOMERS.
        '''

        try:
            assert string_formula
            string_formula = self.formula.sub('', string_formula)
            formula = chemical.Molecule(string_formula)
            formula.update_formula(leaving_group, count=-1)
            formula = formula.tostr()

        except (AssertionError, AttributeError):
            formula = MONOMERS.get(modname)
            if formula is None:
                print(exception.CODES['024'].format(modname), file=sys.stderr)
        return formula
Exemple #16
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)
Exemple #17
0
 def mw(self):
     return chemical.Molecule(peptide=self.sequence, strict=False).mass
Exemple #18
0
    :copyright: (c) 2015 The Regents of the University of California.
    :license: GNU GPL, see licenses/GNU GPLv3.txt for more details.
'''

# load modules
import itertools as it

from xldlib import chemical
from xldlib.chemical import building_blocks
from xldlib.resources.parameters import defaults
from xldlib.utils import masstools

# CONSTANTS
# ---------
RESIDUE_MASSES = {
    i: chemical.Molecule(peptide=i).mass
    for i in building_blocks.ONE_LETTER
}

SUBSTITUES = {
    'B': {'D', 'N'},
    'J': {'I', 'L'},
    'X': set(building_blocks.ONE_LETTER),
    'Z': {'E', 'Q'}
}

# HELPERS
# -------


def get_substitution_events(peptide):