def test_get_non_UIS_from_transitions4(self): self.transitions = test_shared.transitions_def4 self.collisions = test_shared.collisions_def4 newnon_uis = get_non_UIS_from_transitions(self.transitions, self.collisions, self.par, self.MAX_UIS) newnon_uis = [set(newn.keys()) for newn in newnon_uis] self.assertEqual([len(l) for l in newnon_uis[1:]], test_shared.lennonuis4) self.assertEqual(newnon_uis, test_shared.refnonuis4)
def test_get_non_UIS_from_transitions4(self): self.transitions = test_shared.transitions_def4 self.collisions = test_shared.collisions_def4 newnon_uis = get_non_UIS_from_transitions(self.transitions, self.collisions, self.par, self.MAX_UIS) newnon_uis = [set( newn.keys() ) for newn in newnon_uis] self.assertEqual([len(l) for l in newnon_uis[1:]], test_shared.lennonuis4) self.assertEqual(newnon_uis, test_shared.refnonuis4)
def test_get_non_UIS_from_transitions2_unsorted(self): # here we have the transitions in the wrong order # it should still work self.transitions = test_shared.transitions_def2_unsorted self.collisions = test_shared.collisions_def2 newnon_uis = get_non_UIS_from_transitions(self.transitions, self.collisions, self.par, self.MAX_UIS) newnon_uis = [set(newn.keys()) for newn in newnon_uis] self.assertEqual([len(l) for l in newnon_uis[1:]], test_shared.lennonuis2) self.assertEqual(newnon_uis, test_shared.refnonuis2_unsorted)
def test_get_non_UIS_from_transitions2_unsorted(self): #here we have the transitions in the wrong order #it should still work self.transitions = test_shared.transitions_def2_unsorted self.collisions = test_shared.collisions_def2 newnon_uis = get_non_UIS_from_transitions(self.transitions, self.collisions, self.par, self.MAX_UIS) newnon_uis = [set( newn.keys() ) for newn in newnon_uis] self.assertEqual([len(l) for l in newnon_uis[1:]], test_shared.lennonuis2) self.assertEqual(newnon_uis, test_shared.refnonuis2_unsorted)
def test_two_table_mysql(self): """Compare the two table vs the one table MySQL approach Here we are comparing the old (querying the transitions database as well as the precursor database) and the new way (only query the precursor database and calculate the transitions on the fly) way of calculating the collisions. """ print '\n'*1 print "Comparing one vs two table MySQL solution" par = self.par cursor = self.cursor mycollider = collider.SRMcollider() mypepids = _get_unique_pepids(par, cursor) self.mycollider.pepids = mypepids self.mycollider.calcinner = 0 shuffle( self.mycollider.pepids ) self.mycollider.pepids = self.mycollider.pepids[:self.limit] MAX_UIS = 5 c_newuistime = 0; oldtime = 0; c_fromprecursortime = 0 oldsql = 0; newsql = 0 oldcalctime = 0; localsql = 0 self._cursor = False print "oldtime = get UIS from collisions and transitions (getting all collisions from the transitions db)" print "cuis + oldsql = as oldtime but calculate UIS in C++" print "py+newsql = only get the precursors from the db and calculate collisions in Python" print "ctime + newsql = only get the precursors from the db and calculate collisions in C++" print "new = use fast SQL and C++ code" print "old = use slow SQL and Python code" print "i\toldtime\tcuis+oldsql\tpy+newsql\tctime+newsql\t>>>\toldsql\tnewsql\t...\t...\tspeedup" for kk, pep in enumerate(self.mycollider.pepids): ii = kk + 1 p_id = pep['parent_id'] q1 = pep['q1'] q3_low, q3_high = par.get_q3range_transitions() precursor = Precursor(q1=pep['q1'], transition_group=pep['transition_group'], parent_id = pep['parent_id'], modified_sequence=pep['mod_sequence'], ssrcalc=pep['ssrcalc']) transitions = collider.calculate_transitions_ch( ((q1, pep['mod_sequence'], p_id),), [1], q3_low, q3_high) #fake some srm_id for the transitions transitions = tuple([ (t[0], i) for i,t in enumerate(transitions)]) ##### transitions = self.mycollider._get_all_transitions(par, pep, cursor) nr_transitions = len( transitions ) if nr_transitions == 0: continue #no transitions in this window # mystart = time.time() collisions = list(self.mycollider._get_all_collisions_calculate_new(par, precursor, cursor)) oldcolllen = len(collisions) oldcalctime += time.time() - mystart # mystart = time.time() collisions = _get_all_collisions(mycollider, par, pep, cursor, transitions = transitions) oldcsqllen = len(collisions) oldsql += time.time() - mystart # par.query2_add = ' and isotope_nr = 0 ' # due to the new handling of isotopes mystart = time.time() self.mycollider.mysqlnewtime= 0 precursors = self.mycollider._get_all_precursors(par, precursor, cursor) newsql += time.time() - mystart # mystart = time.time() #precursors = self.mycollider._get_all_precursors(par, pep, cursor_l) localsql += time.time() - mystart par.query2_add = '' # due to the new handling of isotopes # mystart = time.time() non_uis_list = get_non_UIS_from_transitions(transitions, tuple(collisions), par, MAX_UIS) cnewuis = non_uis_list c_newuistime += time.time() - mystart # mystart = time.time() non_uis_list = get_non_UIS_from_transitions_old(transitions, collisions, par, MAX_UIS) oldnonuislist = non_uis_list oldtime += time.time() - mystart # mystart = time.time() q3_low, q3_high = par.get_q3range_transitions() collisions_per_peptide = c_getnonuis.calculate_collisions_per_peptide_other_ion_series( transitions, precursors, par, q3_low, q3_high, par.q3_window, par.ppm, False) non_uis_list = [ {} for i in range(MAX_UIS+1)] for order in range(1,MAX_UIS+1): non_uis_list[order] = c_getnonuis.get_non_uis( collisions_per_peptide, order) c_fromprecursortime += time.time() - mystart newl = [len(n) for n in non_uis_list] self.assertEqual(newl, [len(o) for o in cnewuis]) self.assertEqual(newl, [len(o) for o in oldnonuislist]) non_uis_list = [set(k.keys()) for k in non_uis_list] cnewuis = [set(k.keys()) for k in cnewuis] self.assertEqual(non_uis_list, cnewuis) self.assertEqual(non_uis_list, oldnonuislist) mys = "%s\t%0.fms\t%0.fms\t\t%0.fms\t\t%0.2fms\t\t>>>\t%0.fms\t%0.2fms\t...\t...\t%0.2f" % \ (ii, #i (oldtime + oldsql)*1000/ii, #oldtime (c_newuistime+oldsql)*1000/ii, #cuis + oldsql (oldcalctime + newsql + oldtime)*1000/ii, #newsql (c_fromprecursortime + newsql)*1000/ii, #ctime+newsql #(c_fromprecursortime + localsql)*1000/ii, oldsql*1000/ii, #newsql newsql*1000/ii, #oldsql #localsql*1000/ii, #oldtime / c_newuistime (oldtime + oldsql) / (c_fromprecursortime + newsql) ) self.ESC = chr(27) sys.stdout.write(self.ESC + '[2K') if self._cursor: sys.stdout.write(self.ESC + '[u') self._cursor = True sys.stdout.write(self.ESC + '[s') sys.stdout.write(mys) sys.stdout.flush()
def test_two_table_mysql(self): """Compare the two table vs the one table MySQL approach Here we are comparing the old (querying the transitions database as well as the precursor database) and the new way (only query the precursor database and calculate the transitions on the fly) way of calculating the collisions. """ print '\n' * 1 print "Comparing one vs two table MySQL solution" par = self.par cursor = self.cursor mycollider = collider.SRMcollider() mypepids = _get_unique_pepids(par, cursor) self.mycollider.pepids = mypepids self.mycollider.calcinner = 0 shuffle(self.mycollider.pepids) self.mycollider.pepids = self.mycollider.pepids[:self.limit] MAX_UIS = 5 c_newuistime = 0 oldtime = 0 c_fromprecursortime = 0 oldsql = 0 newsql = 0 oldcalctime = 0 localsql = 0 self._cursor = False print "oldtime = get UIS from collisions and transitions (getting all collisions from the transitions db)" print "cuis + oldsql = as oldtime but calculate UIS in C++" print "py+newsql = only get the precursors from the db and calculate collisions in Python" print "ctime + newsql = only get the precursors from the db and calculate collisions in C++" print "new = use fast SQL and C++ code" print "old = use slow SQL and Python code" print "i\toldtime\tcuis+oldsql\tpy+newsql\tctime+newsql\t>>>\toldsql\tnewsql\t...\t...\tspeedup" for kk, pep in enumerate(self.mycollider.pepids): ii = kk + 1 p_id = pep['parent_id'] q1 = pep['q1'] q3_low, q3_high = par.get_q3range_transitions() precursor = Precursor(q1=pep['q1'], transition_group=pep['transition_group'], parent_id=pep['parent_id'], modified_sequence=pep['mod_sequence'], ssrcalc=pep['ssrcalc']) transitions = collider.calculate_transitions_ch( ((q1, pep['mod_sequence'], p_id), ), [1], q3_low, q3_high) #fake some srm_id for the transitions transitions = tuple([(t[0], i) for i, t in enumerate(transitions)]) ##### transitions = self.mycollider._get_all_transitions(par, pep, cursor) nr_transitions = len(transitions) if nr_transitions == 0: continue #no transitions in this window # mystart = time.time() collisions = list( self.mycollider._get_all_collisions_calculate_new( par, precursor, cursor)) oldcolllen = len(collisions) oldcalctime += time.time() - mystart # mystart = time.time() collisions = _get_all_collisions(mycollider, par, pep, cursor, transitions=transitions) oldcsqllen = len(collisions) oldsql += time.time() - mystart # par.query2_add = ' and isotope_nr = 0 ' # due to the new handling of isotopes mystart = time.time() self.mycollider.mysqlnewtime = 0 precursors = self.mycollider._get_all_precursors( par, precursor, cursor) newsql += time.time() - mystart # mystart = time.time() #precursors = self.mycollider._get_all_precursors(par, pep, cursor_l) localsql += time.time() - mystart par.query2_add = '' # due to the new handling of isotopes # mystart = time.time() non_uis_list = get_non_UIS_from_transitions( transitions, tuple(collisions), par, MAX_UIS) cnewuis = non_uis_list c_newuistime += time.time() - mystart # mystart = time.time() non_uis_list = get_non_UIS_from_transitions_old( transitions, collisions, par, MAX_UIS) oldnonuislist = non_uis_list oldtime += time.time() - mystart # mystart = time.time() q3_low, q3_high = par.get_q3range_transitions() collisions_per_peptide = c_getnonuis.calculate_collisions_per_peptide_other_ion_series( transitions, precursors, par, q3_low, q3_high, par.q3_window, par.ppm, False) non_uis_list = [{} for i in range(MAX_UIS + 1)] for order in range(1, MAX_UIS + 1): non_uis_list[order] = c_getnonuis.get_non_uis( collisions_per_peptide, order) c_fromprecursortime += time.time() - mystart newl = [len(n) for n in non_uis_list] self.assertEqual(newl, [len(o) for o in cnewuis]) self.assertEqual(newl, [len(o) for o in oldnonuislist]) non_uis_list = [set(k.keys()) for k in non_uis_list] cnewuis = [set(k.keys()) for k in cnewuis] self.assertEqual(non_uis_list, cnewuis) self.assertEqual(non_uis_list, oldnonuislist) mys = "%s\t%0.fms\t%0.fms\t\t%0.fms\t\t%0.2fms\t\t>>>\t%0.fms\t%0.2fms\t...\t...\t%0.2f" % \ (ii, #i (oldtime + oldsql)*1000/ii, #oldtime (c_newuistime+oldsql)*1000/ii, #cuis + oldsql (oldcalctime + newsql + oldtime)*1000/ii, #newsql (c_fromprecursortime + newsql)*1000/ii, #ctime+newsql #(c_fromprecursortime + localsql)*1000/ii, oldsql*1000/ii, #newsql newsql*1000/ii, #oldsql #localsql*1000/ii, #oldtime / c_newuistime (oldtime + oldsql) / (c_fromprecursortime + newsql) ) self.ESC = chr(27) sys.stdout.write(self.ESC + '[2K') if self._cursor: sys.stdout.write(self.ESC + '[u') self._cursor = True sys.stdout.write(self.ESC + '[s') sys.stdout.write(mys) sys.stdout.flush()