def setUp(self): # 0. id # 1. quality score (FDR) # 2. retention time (normalized) # 3. intensity m = Multipeptide() m.set_nr_runs(2) # Run 1 r = MockRun("0_1") p = precursor.Precursor("precursor_1", r) pg_tuple = ("someID_1", 0.1, 100, 10000) p.add_peakgroup_tpl(pg_tuple, "precursor_1", -1) prgr = precursor_group.PrecursorGroup(p.get_id(), r) prgr.addPrecursor(p) m.insert("0_1", prgr) # Run 2: # - peakgroup 2 : RT = 105 seconds # - peakgroup 3 : RT = 120 seconds r = MockRun("0_2") p = precursor.Precursor("precursor_1", r) pg_tuple = ("peakgroup2", 0.2, 105, 10000) p.add_peakgroup_tpl(pg_tuple, "precursor_1", -1) pg_tuple = ("peakgroup3", 0.18, 130, 10000) p.add_peakgroup_tpl(pg_tuple, "precursor_1", -1) prgr = precursor_group.PrecursorGroup(p.get_id(), r) prgr.addPrecursor(p) m.insert("0_2", prgr) self.mpep = m self.al = algo.AlignmentAlgorithm() self.al.verbose = True
def test_add_peakgroup_tpl(self): """ 0. id 1. quality score (FDR) 2. retention time (normalized) 3. intensity (4. d_score optional) """ pg_tuple = ("someID", 0.1, 100, 10000, 2) p = precursor.Precursor("precursor_2", []) self.assertRaises(Exception, p.add_peakgroup_tpl, pg_tuple, "notMatchingID", 4) p.add_peakgroup_tpl(pg_tuple, "precursor_2", 4) self.assertEqual(len(list(p.get_all_peakgroups())), 1) firstpg = list(p.get_all_peakgroups())[0] self.assertEqual(firstpg.get_cluster_id(), 4) self.assertAlmostEqual(firstpg.get_fdr_score(), 0.1) self.assertAlmostEqual(firstpg.get_normalized_retentiontime(), 100) self.assertAlmostEqual(firstpg.get_intensity(), 10000) pg_tuple = ("someID", 0.1, 100, 10000) p = precursor.Precursor("precursor_2", []) p.add_peakgroup_tpl(pg_tuple, "precursor_2", 4) self.assertEqual(len(list(p.get_all_peakgroups())), 1)
def test_selection(self): p = precursor.GeneralPrecursor("precursor_2", []) self.assertIsNone(p.get_selected_peakgroup()) self.assertIsNone(p.get_best_peakgroup()) pg = PeakGroupBase() pg.cluster_id_ = 1 pg.id_ = "someID" pg.normalized_retentiontime = 100 p.add_peakgroup(pg) self.assertEqual(len(list(p.get_all_peakgroups())), 1) pg = PeakGroupBase() pg.cluster_id_ = 2 pg.id_ = "someID_" pg.normalized_retentiontime = 105 p.add_peakgroup(pg) self.assertEqual(len(list(p.get_all_peakgroups())), 2) self.assertEqual(p.get_selected_peakgroup().get_feature_id(), "someID") self.assertEqual(p.get_best_peakgroup().get_feature_id(), "someID_") self.assertEqual(p.find_closest_in_iRT(99).get_feature_id(), "someID") self.assertEqual( p.find_closest_in_iRT(110).get_feature_id(), "someID_") self.assertEqual( p.find_closest_in_iRT(102.8).get_feature_id(), "someID_")
def test_append(self): # TODO is this even used anywhere ??? pg = MockPeakGroup(1, "precursor_2") p = precursor.GeneralPrecursor("precursor_2", []) p.append(pg) self.assertEqual(len(list(p.get_all_peakgroups())), 1)
def test_selection(self): p = precursor.Precursor("precursor_2", []) self.assertIsNone(p.get_best_peakgroup()) pg_tuple = ("someID", 0.1, 100, 10000, 2) p.add_peakgroup_tpl(pg_tuple, "precursor_2", 1) pg_tuple = ("someID_", 0.01, 105, 10000, 2) p.add_peakgroup_tpl(pg_tuple, "precursor_2", -1) self.assertEqual(p.get_selected_peakgroup().get_feature_id(), "someID") self.assertEqual(p.get_best_peakgroup().get_feature_id(), "someID_") self.assertEqual(p.find_closest_in_iRT(99).get_feature_id(), "someID") self.assertEqual( p.find_closest_in_iRT(110).get_feature_id(), "someID_") self.assertEqual( p.find_closest_in_iRT(102.8).get_feature_id(), "someID_") self.assertEqual(len(list(p.getClusteredPeakgroups())), 1) self.assertEqual( list(p.getClusteredPeakgroups())[0].get_feature_id(), "someID") # Un-select all pg # Only one pg should be selected at a time p.unselect_all() self.assertIsNone(p.get_selected_peakgroup()) p.select_pg("someID_") self.assertRaises(AssertionError, p.select_pg, "someID")
def test_selectpg(self): pg = PeakGroupBase() pg.cluster_id_ = 4 pg.id_ = "someID" p = precursor.GeneralPrecursor("precursor_2", []) p.add_peakgroup(pg) self.assertEqual(len(list(p.get_all_peakgroups())), 1) firstpg = list(p.get_all_peakgroups())[0] self.assertEqual(firstpg.get_cluster_id(), 4)
def test_setClusterId(self): pg_tuple = ("someID", 0.1, 100, 10000, 2) p = precursor.Precursor("precursor_2", []) p.add_peakgroup_tpl(pg_tuple, "precursor_2", 4) firstpg = list(p.get_all_peakgroups())[0] self.assertEqual(firstpg.get_cluster_id(), 4) p.setClusterID("someID", 5) firstpg = list(p.get_all_peakgroups())[0] self.assertEqual(firstpg.get_cluster_id(), 5)
def test_get_decoy(self): p = precursor.Precursor("precursor_2", []) self.assertFalse(p.get_decoy()) p.set_decoy("TRUE") self.assertTrue(p.get_decoy()) p.set_decoy("FALSE") self.assertFalse(p.get_decoy()) p.set_decoy("1") self.assertTrue(p.get_decoy()) p.set_decoy("0") self.assertFalse(p.get_decoy()) self.assertRaises(Exception, p.set_decoy, "dummy")
def setUp(self): import msproteomicstoolslib.data_structures.Precursor as precursor import msproteomicstoolslib.data_structures.PrecursorGroup as precursor_group import msproteomicstoolslib.format.TransformationCollection as transformations from msproteomicstoolslib.algorithms.alignment.SplineAligner import SplineAligner import msproteomicstoolslib.algorithms.alignment.AlignmentHelper as helper # 0. id # 1. quality score (FDR) # 2. retention time (normalized) # 3. intensity mpeps = [Multipeptide() for i in range(3)] [m.set_nr_runs(5) for m in mpeps] # Parameters self.initial_alignment_cutoff = 0.001 runs = [MockRun("0_%s" % (i + 1)) for i in range(5)] ids = 0 for i in range(5): # Two alignment peptides p = precursor.Precursor("anchorpeptide_1", runs[i]) pg_tuple = ("id_%s" % ids, 0.0001, 100 + i * 10, 10000) p.add_peakgroup_tpl(pg_tuple, "anchorpeptide_1", -1) prgr = precursor_group.PrecursorGroup(p.get_id(), runs[i]) prgr.addPrecursor(p) mpeps[0].insert(runs[i].get_id(), prgr) ids += 1 p = precursor.Precursor("anchorpeptide_2", runs[i]) pg_tuple = ("id_%s" % ids, 0.0001, 1000 + i * 100, 10000) p.add_peakgroup_tpl(pg_tuple, "anchorpeptide_2", -1) prgr = precursor_group.PrecursorGroup(p.get_id(), runs[i]) prgr.addPrecursor(p) mpeps[1].insert(runs[i].get_id(), prgr) ids += 1 # The noise peptide p = precursor.Precursor("anchorpeptide_3", runs[i]) pg_tuple = ("id_%s" % ids, 0.0001, 500 + i * 40, 10000) p.add_peakgroup_tpl(pg_tuple, "anchorpeptide_3", -1) prgr = precursor_group.PrecursorGroup(p.get_id(), runs[i]) prgr.addPrecursor(p) mpeps[2].insert(runs[i].get_id(), prgr) ids += 1 m = Multipeptide() m.set_nr_runs(5) # Run 1 # - peakgroup 1 : RT = 110 seconds [correct] p = precursor.Precursor("precursor_1", runs[0]) pg_tuple = ("peakgroup1", 0.01, 100, 10000) p.add_peakgroup_tpl(pg_tuple, "precursor_1", -1) prgr = precursor_group.PrecursorGroup(p.get_id(), runs[0]) prgr.addPrecursor(p) m.insert(runs[0].get_id(), prgr) # Run 2: # - peakgroup 2 : RT = 115 seconds [correct] # - peakgroup 3 : RT = 130 seconds p = precursor.Precursor("precursor_1", runs[1]) pg_tuple = ("peakgroup2", 0.2, 112, 10000) p.add_peakgroup_tpl(pg_tuple, "precursor_1", -1) pg_tuple = ("peakgroup3", 0.18, 130, 10000) p.add_peakgroup_tpl(pg_tuple, "precursor_1", -1) prgr = precursor_group.PrecursorGroup(p.get_id(), runs[1]) prgr.addPrecursor(p) m.insert(runs[1].get_id(), prgr) # Run 3: # - peakgroup 4 : RT = 120 seconds [correct] # - peakgroup 5 : RT = 130 seconds p = precursor.Precursor("precursor_1", runs[2]) pg_tuple = ("peakgroup4", 0.2, 120, 10000) p.add_peakgroup_tpl(pg_tuple, "precursor_1", -1) pg_tuple = ("peakgroup5", 0.17, 130, 10000) p.add_peakgroup_tpl(pg_tuple, "precursor_1", -1) prgr = precursor_group.PrecursorGroup(p.get_id(), runs[2]) prgr.addPrecursor(p) m.insert(runs[2].get_id(), prgr) # Run 4: # - peakgroup 6 : missing [correct] # - peakgroup 7 : RT = 145 seconds p = precursor.Precursor("precursor_1", runs[3]) pg_tuple = ("peakgroup7", 0.18, 145, 10000) p.add_peakgroup_tpl(pg_tuple, "precursor_1", -1) prgr = precursor_group.PrecursorGroup(p.get_id(), runs[3]) prgr.addPrecursor(p) m.insert(runs[3].get_id(), prgr) # Run 5: # - peakgroup 8 : RT = 140 seconds [correct] # - peakgroup 9 : missing p = precursor.Precursor("precursor_1", runs[4]) pg_tuple = ("peakgroup8", 0.1, 139, 10000) p.add_peakgroup_tpl(pg_tuple, "precursor_1", -1) prgr = precursor_group.PrecursorGroup(p.get_id(), runs[4]) prgr.addPrecursor(p) m.insert(runs[4].get_id(), prgr) self.mpep = m self.exp = Dummy() self.exp.runs = runs mpeps.append(m) self.multipeptides = mpeps # Align all against all self.tr_data = transformations.LightTransformationData() spl_aligner = SplineAligner(self.initial_alignment_cutoff) for run_0 in self.exp.runs: for run_1 in self.exp.runs: helper.addDataToTrafo(self.tr_data, run_0, run_1, spl_aligner, self.multipeptides, "linear", 30)
def test_get_id(self): p = precursor.Precursor("precursor_2", []) self.assertEqual(p.get_id(), "precursor_2")
def test_create_precursor(self): p = precursor.Precursor("precursor_2", []) str(p) self.assertTrue(True)
def test_add_peakgroup(self): pg = PeakGroupBase() p = precursor.GeneralPrecursor("precursor_2", []) p.add_peakgroup(pg) self.assertEqual(len(list(p.get_all_peakgroups())), 1)
def test_create_precursor(self): p = precursor.GeneralPrecursor("precursor_2", []) self.assertTrue(True)
def prepareData(nr_peps=15, nr_targ=None): if nr_targ is None: nr_targ = nr_peps import msproteomicstoolslib.data_structures.Precursor as precursor import msproteomicstoolslib.data_structures.PrecursorGroup as precursor_group import msproteomicstoolslib.format.TransformationCollection as transformations from msproteomicstoolslib.algorithms.alignment.SplineAligner import SplineAligner import msproteomicstoolslib.algorithms.alignment.AlignmentHelper as helper from msproteomicstoolslib.algorithms.alignment.Multipeptide import Multipeptide # 0. id # 1. quality score (FDR) # 2. retention time (normalized) # 3. intensity multipeptides = [] nr_runs = 2 runs = [MockRun("0_%s" % (i + 1)) for i in range(nr_runs)] ids = 0 for j in range(1, nr_peps): mpeps = [Multipeptide() for i in range(2)] [m.set_nr_runs(nr_runs) for m in mpeps] # Iterate over all runs for i in range(nr_runs): # A target peptide label = "target_pep_%s" % j p = precursor.Precursor(label, runs[i]) p.set_decoy("FALSE") pg_tuple = ("id_%s" % ids, 1.0 / j, 100, 10000) p.add_peakgroup_tpl(pg_tuple, "target_pep_%s" % j, -1) prgr = precursor_group.PrecursorGroup(label, runs[i]) prgr.addPrecursor(p) mpeps[0].insert(runs[i].get_id(), prgr) ids += 1 # A decoy peptide label = "decoy_pep_%s" % j p = precursor.Precursor(label, runs[i]) p.set_decoy("TRUE") pg_tuple = ("id_%s" % ids, 1.0 / j, 100, 10000) p.add_peakgroup_tpl(pg_tuple, "decoy_pep_%s" % j, -1) prgr = precursor_group.PrecursorGroup(label, runs[i]) prgr.addPrecursor(p) mpeps[1].insert(runs[i].get_id(), prgr) ids += 1 multipeptides.extend(mpeps) # Add some more target peptides at good FDRs for j in range(1, nr_targ): mpeps = [Multipeptide() for i in range(1)] [m.set_nr_runs(nr_runs) for m in mpeps] # Iterate over all runs for i in range(nr_runs): label = "target_pep_good_%s" % j p = precursor.Precursor(label, runs[i]) p.set_decoy("FALSE") pg_tuple = ("id_%s" % ids, 0.01 / j, 100, 10000) p.add_peakgroup_tpl(pg_tuple, "target_pep_good_%s" % j, -1) prgr = precursor_group.PrecursorGroup(label, runs[i]) prgr.addPrecursor(p) mpeps[0].insert(runs[i].get_id(), prgr) ids += 1 multipeptides.extend(mpeps) return multipeptides