def test_getMinNeededTransitions_2(self): pep = test_shared.runpep2 transitions = test_shared.runtransitions2 precursors = test_shared.runprecursors2 transitions = tuple([(t[0], i) for i, t in enumerate(transitions)]) par = self.par q3_high = self.q3_high q3_low = self.q3_low R = self.R par.max_uis = len(transitions) + 1 collisions = list( collider.SRMcollider._get_all_collisions_calculate_sub( collider.SRMcollider(), precursors, par, R, q3_low, q3_high)) m = self.acollider._getMinNeededTransitions(par, transitions, collisions) self.assertEqual(m, -1) #now also test with lower q3 window par.q3_window = 1.0 collisions = list( collider.SRMcollider._get_all_collisions_calculate_sub( collider.SRMcollider(), precursors, par, R, q3_low, q3_high)) m = self.acollider._getMinNeededTransitions(par, transitions, collisions) self.assertEqual(m, 6)
def test_complete_with_isotopes(self): if not self.database_available: return #now test with isotopes enabled par = collider.testcase(testdatabase=test_database) par.quiet = True par.isotopes_up_to = 3 par.eval() par.query2_add = ' and isotope_nr = 0 ' # need to do this because we also have other isotopes in there! mycollider = collider.SRMcollider() cursor = self.db.cursor() #for historic reasons, we only select a subset of peptides exclude_pepids = [ 183, 203, 319, 345, 355, 365, 367, 385, 393, 425, 1227, 1233, 1297, 1299, 1303, 1305, 1307, 1309, 1311, 1509, 1681, 1683 ] mycollider = collider.SRMcollider() pepids = _get_unique_pepids(par, cursor, ignore_genomeoccurence=True) pepids = [p for p in pepids if p['parent_id'] not in exclude_pepids] find_clashes_small(self, mycollider, cursor, par, pepids) assert abs(mycollider.allpeps[111] - 0.888888888889) < 1e-5 assert abs(mycollider.allpeps[191] - 0.7) < 1e-5 assert abs(mycollider.allpeps[375] - 0.941176470588) < 1e-5 assert abs(mycollider.allpeps[585] - 0.875) < 1e-5 assert abs(mycollider.allpeps[609] - 0.6666666) < 1e-5 assert abs(mycollider.allpeps[929] - 0.857142857143) < 1e-5 assert abs(mycollider.allpeps[1089] - 0.7) < 1e-5 assert abs(mycollider.allpeps[1101] - 0.916666666667) < 1e-5 assert abs(mycollider.allpeps[1177] - 0.928571428571) < 1e-5 assert abs(mycollider.allpeps[1493] - 0.928571428571) < 1e-5 assert abs(mycollider.allpeps[1537] - 0.857142857143) < 1e-5 assert abs(mycollider.allpeps[1585] - 0.933333333333) < 1e-5 assert abs(mycollider.allpeps[1663] - 0.928571428571) < 1e-5 assert abs(mycollider.allpeps[1763] - 0.8125) < 1e-5 assert abs(mycollider.allpeps[1925] - 0.928571428571) < 1e-5 assert abs(mycollider.allpeps[1957] - 0.833333333333) < 1e-5 assert abs(mycollider.allpeps[1967] - 0.857142857143) < 1e-5 assert abs(mycollider.allpeps[1991] - 0.857142857143) < 1e-5 self.assertTrue( abs(sum(mycollider.allpeps.values()) - 971.215436) < 10**(-3)) self.assertEqual( len([v for v in mycollider.allpeps.values() if v == 1.0]), 922) self.assertEqual(mycollider.non_unique_count, 71) self.assertEqual(mycollider.total_count, 12502)
def test_calculate_collisions_2(self): pep = test_shared.runpep2 transitions = test_shared.runtransitions2 precursors = test_shared.runprecursors2 transitions = tuple([(t[0], i) for i, t in enumerate(transitions)]) par = self.par q3_high = self.q3_high q3_low = self.q3_low R = self.R collisions = list( collider.SRMcollider._get_all_collisions_calculate_sub( collider.SRMcollider(), precursors, par, R, q3_low, q3_high)) collisions_per_peptide = {} q3_window_used = par.q3_window for t in transitions: if par.ppm: q3_window_used = par.q3_window * 10**(-6) * t[0] for c in collisions: if abs(t[0] - c[0]) <= q3_window_used: #gets all collisions if collisions_per_peptide.has_key(c[3]): if not t[1] in collisions_per_peptide[c[3]]: collisions_per_peptide[c[3]].append(t[1]) else: collisions_per_peptide[c[3]] = [t[1]] self.assertEqual(collisions_per_peptide, test_shared.collpepresult2)
def setUp(self): import sys self.R = Residues('mono') self.acollider = collider.SRMcollider() self.aparamset = collider.testcase() self.real_parameters = test_shared.get_default_setup_parameters() self.precursor = test_shared.ThreePeptideExample.precursor self.interfering_precursors = test_shared.ThreePeptideExample.interfering_precursors
def test_complete_without_isotopes(self): if not self.database_available: return par = collider.testcase(testdatabase=test_database) par.query2_add = ' and isotope_nr = 0 ' # still necessary, old style tables par.quiet = True mycollider = collider.SRMcollider() cursor = self.db.cursor() #for historic reasons, we only select a subset of peptides exclude_pepids = [ 183, 203, 319, 345, 355, 365, 367, 385, 393, 425, 1227, 1233, 1297, 1299, 1303, 1305, 1307, 1309, 1311, 1509, 1681, 1683 ] mycollider = collider.SRMcollider() pepids = _get_unique_pepids(par, cursor, ignore_genomeoccurence=True) pepids = [p for p in pepids if p['parent_id'] not in exclude_pepids] find_clashes_small(self, mycollider, cursor, par, pepids) do_check_complete(self, mycollider)
def test_getMinNeededTransitions_2(self): pep = test_shared.runpep2 transitions = test_shared.runtransitions2 precursors = test_shared.runprecursors2 transitions = tuple([(t[0], i) for i, t in enumerate(transitions)]) par = self.par q3_high = self.q3_high q3_low = self.q3_low R = self.R par.max_uis = len(transitions) + 1 collisions = list( collider.SRMcollider._get_all_collisions_calculate_sub( collider.SRMcollider(), precursors, par, R, q3_low, q3_high)) m = self.acollider._getMinNeededTransitions(par, transitions, collisions) #negative result, the transitions are not sufficient self.assertEqual(m, -1) m = c_integrated.getMinNeededTransitions(transitions, tuple(precursors), par.max_uis, par.q3_window, par.ppm, par) # TODO fix this # self.assertEqual(m, 16) #now also test with lower q3 window par.q3_window = 1.0 collisions = list( collider.SRMcollider._get_all_collisions_calculate_sub( collider.SRMcollider(), precursors, par, R, q3_low, q3_high)) m = self.acollider._getMinNeededTransitions(par, transitions, collisions) self.assertEqual(m, 6) m = c_integrated.getMinNeededTransitions(transitions, tuple(precursors), par.max_uis, par.q3_window, par.ppm, par) self.assertEqual(m, 6)
def test_getMinNeededTransitions_1(self): pep = test_shared.runpep1 transitions = test_shared.runtransitions1 precursors = test_shared.runprecursors1 transitions = tuple([(t[0], i) for i, t in enumerate(transitions)]) par = self.par q3_high = self.q3_high q3_low = self.q3_low R = self.R par.max_uis = 15 collisions = list( collider.SRMcollider._get_all_collisions_calculate_sub( collider.SRMcollider(), precursors, par, R, q3_low, q3_high)) m = self.acollider._getMinNeededTransitions(par, transitions, collisions) self.assertEqual(m, 8) m = c_integrated.getMinNeededTransitions(transitions, tuple(precursors), par.max_uis, par.q3_window, par.ppm, par) self.assertEqual(m, 8) #now also test with lower q3 window par.q3_window = 1.0 collisions = list( collider.SRMcollider._get_all_collisions_calculate_sub( collider.SRMcollider(), precursors, par, R, q3_low, q3_high)) m = self.acollider._getMinNeededTransitions(par, transitions, collisions) self.assertEqual(m, 4) m = c_integrated.getMinNeededTransitions(transitions, tuple(precursors), par.max_uis, par.q3_window, par.ppm, par) self.assertEqual(m, 4)
def setUp(self): self.transitions = transitions_def1 self.collisions = collisions_def1 self.MAX_UIS = 5 self.q3_high = 1500 self.q3_low = 300 self.R = Residues('mono') self.acollider = collider.SRMcollider() self.aparamset = collider.testcase() self.par = test_shared.get_default_setup_parameters() self.par.q3_window = 4.0
def setUp(self): import sys self.acollider = collider.SRMcollider() self.aparamset = collider.testcase() self.EPSILON = 10**-5 par = collider.SRM_parameters() par.q1_window = 25 / 2.0 par.q3_window = 1 / 2.0 par.ppm = False par.q3_low = 400 par.q3_high = 1400 par.q3_range = [par.q3_low, par.q3_high] par.set_default_vars() par.eval() self.real_parameters = par self.precursor = test_shared.ThreePeptideExample.precursor self.interfering_precursors = test_shared.ThreePeptideExample.interfering_precursors self.oldstyle_precursors = tuple([(p.q1, p.modified_sequence, p.transition_group, p.q1_charge, p.isotopically_modified) for p in self.interfering_precursors])
def setUp(self): self.transitions = transitions_def1 self.collisions = collisions_def1 class Minimal: pass 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.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 returnrange(): return self.q3_high, self.q3_low self.par.get_q3range_collisions = returnrange import sys self.R = Residues('mono') self.acollider = collider.SRMcollider() self.aparamset = collider.testcase()
if use_experimental_height: infile = options.exp_resultfile threshold = float(options.threshold) parse_mprophet_resultfile(library, infile, threshold) # }}} ########################################################################### # Start program ########################################################################### ## ## First create the mapping of the SSRcalc values to the peptide sequences ## {{{ mycollider = collider.SRMcollider() pepmap = {} seqs = '' seqdic = {} for icount, spectrum in enumerate(library): seqs += "'%s'," % spectrum.sequence seqdic[spectrum.sequence] = 0 # try to find SSRCalc values try: ssr_query = """ select sequence, ssrcalc from %(ssrcalc_table)s where sequence in (%(seqs)s) """ % { 'seqs': seqs[:-1],
def setUp(self): self.transitions = transitions_def1 self.collisions = collisions_def1 self.EPSILON = 10**-5 self.min_q1 = 400 self.max_q1 = 1500 par = collider.SRM_parameters() par.q1_window = 1 / 2.0 par.q3_window = 1 / 2.0 par.ssrcalc_window = 10 / 2.0 par.ppm = False par.isotopes_up_to = 3 par.q3_low = 400 par.q3_high = 1400 par.max_uis = 5 par.peptide_tables = [PEPTIDE_TABLE_NAME] par.mysql_config = '~/.my.cnf' par.sqlite_database = test_shared.SQLITE_DATABASE_LOCATION print par.sqlite_database par.use_sqlite = USE_SQLITE par.quiet = False par.bions = True par.yions = True par.aions = False par.aMinusNH3 = False par.bMinusH2O = False par.bMinusNH3 = False par.bPlusH2O = False par.yMinusH2O = False par.yMinusNH3 = False par.cions = False par.xions = False par.zions = False par.MMinusH2O = False par.MMinusNH3 = False par.q3_range = [par.q3_low, par.q3_high] par.set_default_vars() par.eval() self.par = par self.R = Residues('mono') self.acollider = collider.SRMcollider() self.aparamset = collider.testcase() self.db = par.get_db() # Get the precursors ########################################################################### myprecursors = Precursors() cursor = self.db.cursor() myprecursors.getFromDB(par, cursor, self.min_q1 - par.q1_window, self.max_q1 + par.q1_window) testrange = myprecursors.build_rangetree() self.precursors_to_evaluate = myprecursors.getPrecursorsToEvaluate( self.min_q1, self.max_q1) myprecursors.build_parent_id_lookup() myprecursors.build_transition_group_lookup() self.myprecursors = myprecursors cursor.close()
def do_analysis(input_sequences, seqs, par, wuis, local_cursor, controller): """ ########################################################################### # Do analysis # 1. Find SSRCalc values for all peptides # 2. Iterate through all sequences and calculate the b / y series # 3. Find all (potentially) interfering precursors # 4. For each precursors, find the list of transitions that interfers # 5. For each transition, find the precursors that interfere # 6. Print information ########################################################################### """ q3_low, q3_high = par.q3_range uis = par.uis pepmap = get_ssrcalc_values(seqs, input_sequences, default_ssrcalc, local_cursor, ssrcalc_path) toggle_all_str = '<script language="javascript"> function toggleAll(){ ' mycollider = collider.SRMcollider() for seq_id, peptide in enumerate(controller.peptides): # # Step 2 : find the SSRCalc values for this sequence # try: ssrcalc = pepmap[filter(str.isalpha, peptide.sequence)] except KeyError: ssrcalc = 25 transitions = [(f.q3, f.fragment_count) for f in peptide.fragments] if len(transitions) == 0: continue # no transitions in this window # # Step 3 : find all potentially interfering precursors using a MySQL query # Create precursor and use db to find all interfering precursors # precursor = Precursor( modified_sequence=peptide.get_modified_sequence(), parent_id=-1, q1=peptide.charged_mass, q1_charge=2, ssrcalc=ssrcalc, transition_group=-1) precursor.seq_id = seq_id precursors_obj = mycollider._get_all_precursors( par, precursor, local_cursor) # # Step 4 and 5: Find interferences per precursor, then find # interferences per transition (see the two readouts in the html) # collisions_per_peptide = \ c_getnonuis.calculate_collisions_per_peptide_other_ion_series( tuple(transitions), precursors_obj, par, q3_low, q3_high, par.q3_window, par.ppm, par.chargeCheck) nonunique = c_getnonuis._find_clashes_forall_other_series( tuple(transitions), precursors_obj, par, q3_low, q3_high, par.q3_window, par.ppm, peptide.charged_mass - par.q1_window, par.chargeCheck) # also add those that have no interference for fragment in peptide.fragments: if not fragment.fragment_count in nonunique: nonunique[fragment.fragment_count] = [] nonunique_obj = controller.getNonuniqueObjects(nonunique) # # Step 6: printing # do_all_print(peptide, collisions_per_peptide, wuis, precursor, par, precursors_obj, nonunique_obj) toggle_all_str += "toggleDisplay('col_peptides_%s'); toggleDisplay('col_transitions_%s');\n" % ( seq_id, seq_id) toggle_all_str += "};</script>" print toggle_all_str print """
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)