Ejemplo n.º 1
0
    def setUp(self):
        try:
            import c_getnonuis
            self.transitions = test_shared.transitions_def1
            self.collisions = test_shared.collisions_def1
            self.pep1 = test_shared.peptide1
            self.pep2 = test_shared.peptide2

            self.transitions_12_between300_1500 = test_shared.transitions_12_between300_1500
            self.pep1_yseries = test_shared.pep1_yseries
            self.pep1_bseries = test_shared.pep1_bseries

            tuples = []
            tuples.append(self.pep1)
            tuples.append(self.pep2)
            self.tuples = tuple(tuples)

            self.R = Residues('mono')

            class Minimal:
                pass

            self.par = Minimal()
            self.par.q3_window = 4.0
            self.par.ppm = False
            self.q3_high = 1500
            self.q3_low = 300
            self.MAX_UIS = 5

            self.par.bions = True
            self.par.yions = True
            self.par.aions = False
            self.par.aMinusNH3 = False
            self.par.bMinusH2O = False
            self.par.bMinusNH3 = False
            self.par.bPlusH2O = False
            self.par.yMinusH2O = False
            self.par.yMinusNH3 = False
            self.par.cions = False
            self.par.xions = False
            self.par.zions = False
            self.par.MMinusH2O = False
            self.par.MMinusNH3 = False

        except ImportError:
            pass
Ejemplo n.º 2
0
    def _process(self, line):
        """Parses DOM records.
    
        Records consist of 4 tab deliminated fields;
        sid, pdbid, residues, hierarchy
        """
        #For example ::
        #
        #d1sctg_ 1sct    g:      1.001.001.001.001.001
        #d1scth_ 1sct    h:      1.001.001.001.001.001
        #d1flp__ 1flp    -       1.001.001.001.001.002
        #d1moh__ 1moh    -       1.001.001.001.001.002

        line = line.rstrip()  # no trailing whitespace
        columns = line.split("\t")  # separate the tab-delineated cols
        if len(columns) != 4:
            raise ValueError("I don't understand the format of %s" % line)
        self.sid, pdbid, res, self.hierarchy = columns
        self.residues = Residues(res)
        self.residues.pdbid = pdbid
Ejemplo n.º 3
0
    def getSeqMap(self, residues):
        """Get the sequence map for a collection of residues.

        residues -- A Residues instance, or a string that can be converted into
                    a Residues instance.
        """
        if type(residues) == StringType:
            residues = Residues(residues)

        pdbid = residues.pdbid
        frags = residues.fragments
        if not frags:
            frags = (('_', '', ''), )  # All residues of unnamed chain

        seqMap = None
        for frag in frags:
            chainid = frag[0]
            if chainid == '' or chainid == '-' or chainid == ' ' or chainid == '_':
                chainid = '_'
            id = pdbid + chainid

            sm = self[id]

            #Cut out fragment of interest
            start = 0
            end = len(sm.res)
            if frag[1]: start = int(sm.index(frag[1], chainid))
            if frag[2]: end = int(sm.index(frag[2], chainid) + 1)

            sm = sm[start:end]

            if seqMap == None:
                seqMap = sm
            else:
                seqMap += sm

        return seqMap
 def __init__(self):
     self.peptides = []
     self.R = Residues('mono')
class SRMColliderController():

    def __init__(self):
        self.peptides = []
        self.R = Residues('mono')

    def initialize(self, db_used, default_org_prefix, db_tables_map):
        self.db_used = db_used
        self.default_org_prefix = default_org_prefix
        self.db_tables_map = db_tables_map

    def get_sample_peptides_html(self):
        sample_peptides = """
        AFGIPVNTFSSEVVTLWYR
        AIPAPHEILTSNVVTR
        VTDISTGIYK
        GYSENPVENSQFLTEYVATR
        ETLVGFMTEYVATR
        IQDPQMTGYVSTR
        ATMVGTPYWMAPEIVNQK
        TNSFVGTEEYLAPEVIR
        TNSFVGTEEYIAPEVIR
        LINSIADTFVGTSTYMSPER
        """
        sample_peptides_html = ''
        for s in sample_peptides.split():
            sample_peptides_html += s + '<br/>'
        return sample_peptides_html 

    def parse_srmcollider_form(self, form, genomes_that_require_N15_data):
        peptides_raw = form.getvalue('peptides')
        q1_w = float(form.getvalue('q1_window') )
        q3_w = float(form.getvalue('q3_window') )
        ssr_w = float(form.getvalue('ssr_window') )
        high = float(form.getvalue('high_mass') )
        low = float(form.getvalue('low_mass') )
        genome = form.getvalue('genome') 
        isotope = int(form.getvalue('isotope') )
        uis = int(form.getvalue('uis') )
        ions = {'aions'    : bool(form.getvalue('aions'      )),
                'aMinusNH3': bool(form.getvalue('aMinusNH3'  )),
                'bions'    : bool(form.getvalue('bions'      )),
                'bMinusH2O': bool(form.getvalue('bMinusH2O'  )),
                'bMinusNH3': bool(form.getvalue('bMinusNH3'  )),
                'bPlusH2O' : bool(form.getvalue('bPlusH2O'   )),
                'cions'    : bool(form.getvalue('cions'      )),
                'xions'    : bool(form.getvalue('xions'      )),
                'yions'    : bool(form.getvalue('yions'      )),
                'yMinusH2O': bool(form.getvalue('yMinusH2O'  )),
                'yMinusNH3': bool(form.getvalue('yMinusNH3'  )),
                'zions'    : bool(form.getvalue('zions'      )),
                'MMinusH2O': bool(form.getvalue('MMinusH2O'  )),
                'MMinusNH3': bool(form.getvalue('MMinusNH3'  )),
               }
        missed = int(form.getvalue('missed') )
        oxMet =  bool(form.getvalue('oxMet') )
        Deamid = bool(form.getvalue('Deamid') )
        chargeCheck = bool(form.getvalue('chargeCheck') )

        try:
          table_used = self.db_tables_map[ genome ]
        except KeyError:
            print "Genome not recognized";
            exit()

        #create the parameter object
        par = collider.SRM_parameters()
        par.dontdo2p2f = False #do not look at 2+ parent / 2+ fragment ions
        par.q1_window = q1_w / 2.0
        par.q3_window = q3_w / 2.0
        par.ssrcalc_window = ssr_w / 2.0 
        par.ppm = False
        par.considerIsotopes = True
        par.isotopes_up_to = isotope
        par.q3_range = [low, high]
        par.peptide_tables = [self.db_used + self.default_org_prefix + table_used]
        par.transition_table = self.db_used + '.srmTransitions_' + table_used
        par.__dict__.update( ions )
        par.max_mods = -1
        par.max_MC = -1
        par.add_sql_select = ""
        par.select_by = "modified_sequence"
        par.eval()
        par.query2_add = ''
        if not oxMet and not Deamid:
            par.query2_add = ' and modifications = 0 '
        elif oxMet and not Deamid:
            par.query2_add = " and modified_sequence not like '%N[115]%' "
        elif not oxMet and Deamid:
            par.query2_add = " and modified_sequence not like '%M[147]%' "

        if missed == 0:
            par.query2_add += ' and missed_cleavages = 0 '
        if missed == 1:
            par.query2_add += ' and missed_cleavages <= 1 '

        par.chargeCheck = chargeCheck
        par.genome = genome
        par.uis = uis

        # check whether we need to recalculate the residues for N15
        if genome in genomes_that_require_N15_data: 
            self.R.recalculate_monisotopic_data_for_N15()

        parser = PeptideParser(self.R)

        # try to parse transition list. If it doesnt work, try to parse the
        # input as single peptide sequences.
        try:
          self.peptides = parser.parse_transition_list(peptides_raw)
          seqs, input_sequences = parser.get_seqs(self.peptides)
        except AssertionError:
          self.peptides = []

        if len(self.peptides) == 0:
            try:
              self.peptides = parser.parse_transition_csv(peptides_raw)
              seqs, input_sequences = parser.get_seqs(self.peptides)
            except AssertionError:
              self.peptides = []

        if len(self.peptides) == 0:
            # sanitize input: all input is already sanitized except myinput and genome
            seqs, input_sequences = parser.sanitize_peptide_input(peptides_raw)
            for s in input_sequences: 
                peptide = DDB.Peptide(); 
                peptide.set_sequence(s)
                peptide.charge = 2
                self.peptides.append(peptide)
            parser.calculate_default_fragmenation(self.peptides, par)

        par.seqs = seqs
        par.input_sequences = input_sequences

        return par

    def getNonuniqueObjects(self, nonunique):

        # Syntax
        ## tmplist.append( python::make_tuple(series[k],
        ## q1_used, 0, peptide_key, curr_ion, snumber, precursor.attr("modified_sequence"), ssrcalc, isotope_nr, ch));

        res = {}
        for key in nonunique:
            nonunique_obj = []
            for n in nonunique[key]:
                o = NonUnique()
                o.q3            = n[0]
                o.q1            = n[1]
                o.dummy         = n[2]
                o.peptide_key   = n[3]
                o.ion_type      = n[4]
                o.ion_number    = n[5]
                o.sequence      = n[6]
                o.ssrcalc       = n[7]
                o.isotope_nr    = n[8]
                o.charge        = n[9]
                nonunique_obj.append(o)
            res[key] = nonunique_obj
        return res

    def parse_skyline(self, data):
        # Parse Skyline reports:
        # 1. Fix unique peptide identifier from skyline (use modified sequence + charge)
        # 2. replace modifications AA[+n] with AA[mass] for parsing
        import csv
        result = ""
        header = True
        mod_mapping = self.R.mod_mapping
        for line in csv.reader( data.split("\n")):
            if len(line) < 8: continue
            if header: header = False; continue
            line[0] = line[1] + "/" + line[2]
            nextline = ",".join(line) + "\n"
            for mmap in mod_mapping:
                nextline = nextline.replace(mmap, mod_mapping[mmap])
            result += nextline
        return result
Ejemplo n.º 6
0
#!/usr/bin/python
# -*- coding: utf-8  -*-
"""
 *
 * Program       : SRMCollider
 * Author        : Hannes Roest <*****@*****.**>
 * Date          : 13.11.2012
"""
import srmcollider_website_helper
import DDB, collider, sys

from Residues import Residues
R = Residues('mono')
peptideparser = srmcollider_website_helper.PeptideParser(R)

###########################################################################
# Parse options
from optparse import OptionParser, OptionGroup
usage = "usage: %prog [options]"
parser = OptionParser(usage=usage)
group = OptionGroup(parser, "Run options")
group.add_option("--in",
                 dest="inputfile",
                 type="str",
                 help="Input file with one peptide sequence per line")
group.add_option("--out",
                 dest="outputfile",
                 type="str",
                 help="Output file in mProphet format")
parser.add_option_group(group)
 def __init__(self):
     self.peptides = []
     self.R = Residues('mono')
class SRMColliderController():
    """
    Main controller for the website

    Parses the main form using parse_srmcollider_form or Skyline input using parse_skyline.
    """

    def __init__(self):
        self.peptides = []
        self.R = Residues('mono')

    def initialize(self, db_used, default_org_prefix, db_tables_map):
        self.db_used = db_used
        self.default_org_prefix = default_org_prefix
        self.db_tables_map = db_tables_map

    def get_sample_peptides_html(self):
        sample_peptides = """
        AFGIPVNTFSSEVVTLWYR
        AIPAPHEILTSNVVTR
        VTDISTGIYK
        GYSENPVENSQFLTEYVATR
        ETLVGFMTEYVATR
        IQDPQMTGYVSTR
        ATMVGTPYWMAPEIVNQK
        TNSFVGTEEYLAPEVIR
        TNSFVGTEEYIAPEVIR
        LINSIADTFVGTSTYMSPER
        """
        sample_peptides_html = ''
        for s in sample_peptides.split():
            sample_peptides_html += s + '<br/>'
        return sample_peptides_html 

    def parse_srmcollider_form(self, form, genomes_that_require_N15_data):
        peptides_raw = form.getvalue('peptides')
        q1_w = float(form.getvalue('q1_window') )
        q3_w = float(form.getvalue('q3_window') )
        ssr_w = float(form.getvalue('ssr_window') )
        high = float(form.getvalue('high_mass') )
        low = float(form.getvalue('low_mass') )
        genome = form.getvalue('genome') 
        isotope = int(form.getvalue('isotope') )
        uis = int(form.getvalue('uis') )
        ions = {'aions'    : bool(form.getvalue('aions'      )),
                'aMinusNH3': bool(form.getvalue('aMinusNH3'  )),
                'bions'    : bool(form.getvalue('bions'      )),
                'bMinusH2O': bool(form.getvalue('bMinusH2O'  )),
                'bMinusNH3': bool(form.getvalue('bMinusNH3'  )),
                'bPlusH2O' : bool(form.getvalue('bPlusH2O'   )),
                'cions'    : bool(form.getvalue('cions'      )),
                'xions'    : bool(form.getvalue('xions'      )),
                'yions'    : bool(form.getvalue('yions'      )),
                'yMinusH2O': bool(form.getvalue('yMinusH2O'  )),
                'yMinusNH3': bool(form.getvalue('yMinusNH3'  )),
                'zions'    : bool(form.getvalue('zions'      )),
                'MMinusH2O': bool(form.getvalue('MMinusH2O'  )),
                'MMinusNH3': bool(form.getvalue('MMinusNH3'  )),
               }
        missed = int(form.getvalue('missed') )
        oxMet =  bool(form.getvalue('oxMet') )
        Deamid = bool(form.getvalue('Deamid') )
        chargeCheck = bool(form.getvalue('chargeCheck') )

        try:
          table_used = self.db_tables_map[ genome ]
        except KeyError:
            print "Genome not recognized";
            exit()

        #create the parameter object
        par = collider.SRM_parameters()
        par.dontdo2p2f = False #do not look at 2+ parent / 2+ fragment ions
        par.q1_window = q1_w / 2.0
        par.q3_window = q3_w / 2.0
        par.ssrcalc_window = ssr_w / 2.0 
        par.ppm = False
        par.considerIsotopes = True
        par.isotopes_up_to = isotope
        par.q3_range = [low, high]
        par.peptide_tables = [self.db_used + self.default_org_prefix + table_used]
        par.transition_table = self.db_used + '.srmTransitions_' + table_used
        par.__dict__.update( ions )
        par.max_mods = -1
        par.max_MC = -1
        par.add_sql_select = ""
        par.select_by = "modified_sequence"
        par.eval()
        par.query2_add = ''
        if not oxMet and not Deamid:
            par.query2_add = ' and modifications = 0 '
        elif oxMet and not Deamid:
            par.query2_add = " and modified_sequence not like '%N[115]%' "
        elif not oxMet and Deamid:
            par.query2_add = " and modified_sequence not like '%M[147]%' "

        if missed == 0:
            par.query2_add += ' and missed_cleavages = 0 '
        if missed == 1:
            par.query2_add += ' and missed_cleavages <= 1 '

        par.chargeCheck = chargeCheck
        par.genome = genome
        par.uis = uis

        # check whether we need to recalculate the residues for N15
        if genome in genomes_that_require_N15_data: 
            self.R.recalculate_monisotopic_data_for_N15()

        parser = PeptideParser(self.R)

        # try to parse transition list. If it doesnt work, try to parse the
        # input as single peptide sequences.
        try:
          self.peptides = parser.parse_transition_list(peptides_raw)
          seqs, input_sequences = parser.get_seqs(self.peptides)
        except AssertionError:
          self.peptides = []

        if len(self.peptides) == 0:
            try:
              self.peptides = parser.parse_transition_csv(peptides_raw)
              seqs, input_sequences = parser.get_seqs(self.peptides)
            except AssertionError:
              self.peptides = []

        if len(self.peptides) == 0:
            # sanitize input: all input is already sanitized except myinput and genome
            seqs, input_sequences = parser.sanitize_peptide_input(peptides_raw)
            for s in input_sequences: 
                peptide = DDB.Peptide(); 
                peptide.set_sequence(s)
                peptide.charge = 2
                self.peptides.append(peptide)
            parser.calculate_default_fragmenation(self.peptides, par)

        par.seqs = seqs
        par.input_sequences = input_sequences

        return par

    def getNonuniqueObjects(self, nonunique):

        # Syntax
        ## tmplist.append( python::make_tuple(series[k],
        ## q1_used, 0, peptide_key, curr_ion, snumber, precursor.attr("modified_sequence"), ssrcalc, isotope_nr, ch));

        res = {}
        for key in nonunique:
            nonunique_obj = []
            for n in nonunique[key]:
                o = NonUnique()
                o.q3            = n[0]
                o.q1            = n[1]
                o.dummy         = n[2]
                o.peptide_key   = n[3]
                o.ion_type      = n[4]
                o.ion_number    = n[5]
                o.sequence      = n[6]
                o.ssrcalc       = n[7]
                o.isotope_nr    = n[8]
                o.charge        = n[9]
                nonunique_obj.append(o)
            res[key] = nonunique_obj
        return res

    def parse_skyline(self, data):
        # Parse Skyline reports:
        # 1. Fix unique peptide identifier from skyline (use modified sequence + charge)
        # 2. replace modifications AA[+n] with AA[mass] for parsing
        import csv
        result = ""
        header = True
        mod_mapping = self.R.mod_mapping
        for line in csv.reader( data.split("\n")):
            if len(line) < 8: continue
            if header: header = False; continue
            line[0] = line[1] + "/" + line[2]
            nextline = ",".join(line) + "\n"
            for mmap in mod_mapping:
                nextline = nextline.replace(mmap, mod_mapping[mmap])
            result += nextline
        return result
Ejemplo n.º 9
0
    def setUp(self):
        self.limit = 100
        self.limit_large = 100
        self.limit = 300
        self.limit_large = 600
        try:
            import MySQLdb
            #db_l = MySQLdb.connect(read_default_file="~/.my.cnf.local")
            db = MySQLdb.connect(read_default_file="~/.srm.cnf")
            cursor = db.cursor()
            self.cursor = cursor

            par = test_shared.get_default_setup_parameters()
            par.use_sqlite = True
            par.q1_window = 1.2 / 2.0
            par.q3_window = 2.0 / 2.0
            par.ssrcalc_window = 4 / 2.0
            par.ssrcalc_window = 9999 / 2.0
            par.peptide_tables = ['hroest.srmPeptides_yeast']
            par.transition_table = 'hroest.srmTransitions_yeast'
            par.isotopes_up_to = 3
            self.mycollider = collider.SRMcollider()
            par.select_by = "id"

            self.par = par
            self.min_q1 = 440
            self.max_q1 = 450

            ## For debugging
            ##self.max_q1 = 440.18
            ##par.q1_window = 0.009 / 2.0
            ##par.q3_window = 2.0 / 2.0
            ##par.isotopes_up_to = 1

            import Residues
            R = Residues.Residues('mono')
            isotope_correction = par.isotopes_up_to * R.mass_diffC13 / min(
                par.parent_charges)

            start = time.time()
            query = """
            select modified_sequence, transition_group, parent_id, q1_charge, q1, ssrcalc, isotope_nr, 0, 0
            from %s where q1 between %s and %s
            #and isotope_nr = 0
                           """ % (par.peptide_tables[0], self.min_q1 -
                                  par.q1_window, self.max_q1 + par.q1_window)
            cursor.execute(query)
            self.alltuples = list(cursor.fetchall())
            #print "len alltuples", len(self.alltuples)

            query = """
            select modified_sequence, transition_group, parent_id, q1_charge, q1, ssrcalc, isotope_nr, 0, 0
            from %s where q1 between %s - %s and %s
            and isotope_nr = 0
                           """ % (par.peptide_tables[0], self.min_q1 -
                                  par.q1_window, isotope_correction,
                                  self.max_q1 + par.q1_window)
            cursor.execute(query)
            self.alltuples_isotope_correction = list(cursor.fetchall())
            #print "len alltuples zero", len(self.alltuples_isotope_correction)

            self.myprecursors = Precursors()

            # myprecursors.getFromDB(par, db.cursor(), self.min_q1 - par.q1_window, self.max_q1 + par.q1_window)
            ##### LEGACY getFromDB -- have isotope_nr = 0 in there!

            # Get all precursors from the DB within a window of Q1
            lower_q1 = self.min_q1 - par.q1_window
            upper_q1 = self.max_q1 + par.q1_window
            self.myprecursors.precursors = []
            isotope_correction = par.isotopes_up_to * R.mass_diffC13 / min(
                par.parent_charges)
            q = """
            select modified_sequence, transition_group, parent_id, q1_charge, q1, ssrcalc, modifications, missed_cleavages, isotopically_modified
            from %(peptide_table)s where q1 between %(lowq1)s - %(isotope_correction)s and %(highq1)s
            and isotope_nr = 0
            """ % {
                'peptide_table': par.peptide_tables[0],
                'lowq1': lower_q1,  # min_q1 - par.q1_window
                'highq1': upper_q1,  # max_q1 + par.q1_window,
                'isotope_correction': isotope_correction
            }
            cursor.execute(q)
            for res in cursor.fetchall():
                p = Precursor()
                p.initialize(*res)
                # Only include those precursors that are actually have isotopes in the specified range
                if (p.included_in_isotopic_range(lower_q1, upper_q1, par)):
                    self.myprecursors.precursors.append(p)

            ##### END LEGACY getFromDB

            self.precursors_to_evaluate = self.myprecursors.getPrecursorsToEvaluate(
                self.min_q1, self.max_q1)

        except Exception as inst:
            print "something went wrong"
            print inst
Ejemplo n.º 10
0
    def setUp(self):

        try:
            import MySQLdb
            self.database_available = True
        except ImportError:
            print """Module MySQLdb not available.
            
            Please install it if you want to use it.
            Use the following command (on Ubuntu systems):
                sudo apt-get install python-mysqldb
            """
            self.database_available = False

        try:
            self.db = MySQLdb.connect(read_default_file=mysql_conf_file)
            self.database_available = True
        except MySQLdb.OperationalError as e:
            print "Could not connect to database: Please check the configuration in test/test_db.py!\n", e
            self.database_available = False

        class Minimal:
            def get_q3_window_transitions(self, q3):
                if self.ppm:
                    return [
                        q3 - self.q3_window * 10**(-6) * q3,
                        q3 + self.q3_window * 10**(-6) * q3
                    ]
                else:
                    return [q3 - self.q3_window, q3 + self.q3_window]

        self.par = Minimal()
        self.par.q3_window = 4.0
        self.par.ppm = False
        self.MAX_UIS = 5
        self.q3_high = 1500
        self.q3_low = 300

        self.par.q1_window = 1.2 / 2.0
        self.par.ssrcalc_window = 9999
        self.par.query2_add = ' and isotope_nr = 0 '
        self.par.peptide_tables = [test_database + '.srmPeptides_human']
        self.par.transition_table = test_database + '.srmTransitions_human'
        self.par.print_query = False
        self.par.select_floor = False
        self.par.isotopes_up_to = 3
        self.par.select_by = "id"

        self.par.parent_charges = [2, 3]

        self.par.bions = True
        self.par.yions = True
        self.par.aions = False
        self.par.aMinusNH3 = False
        self.par.bMinusH2O = False
        self.par.bMinusNH3 = False
        self.par.bPlusH2O = False
        self.par.yMinusH2O = False
        self.par.yMinusNH3 = False
        self.par.cions = False
        self.par.xions = False
        self.par.zions = False
        self.par.MMinusH2O = False
        self.par.MMinusNH3 = False

        def returntrue():
            return True

        self.par.do_b_y_only = returntrue

        def returnrange():
            return self.q3_low, self.q3_high

        self.par.get_q3range_collisions = returnrange
        #self.par.get_q3_window_transitions = get_q3_window_transitions
        #self.par.get_q3_window_transitions = collider.SRM_parameters.get_q3_window_transitions

        import sys
        self.R = Residues('mono')

        self.acollider = collider.SRMcollider()
        self.aparamset = collider.testcase(testdatabase=test_database)