public static void prepare_for_et(List <double> delta_masses) { SaveState.lollipop.theoretical_database.all_mods_with_mass = new List <ModificationWithMass>(); SaveState.lollipop.theoretical_database.all_possible_ptmsets = new List <PtmSet>(); SaveState.lollipop.modification_ranks = new Dictionary <double, int>(); //Prepare for making ET relation foreach (double delta_m in new HashSet <double>(delta_masses)) { ModificationWithMass m = ConstructorsForTesting.get_modWithMass("fake" + delta_m.ToString(), delta_m); SaveState.lollipop.theoretical_database.all_mods_with_mass.Add(m); SaveState.lollipop.theoretical_database.all_possible_ptmsets.Add(new PtmSet(new List <Ptm> { new Ptm(-1, m) })); SaveState.lollipop.modification_ranks.Add(delta_m, 2); } SaveState.lollipop.theoretical_database.possible_ptmset_dictionary = SaveState.lollipop.theoretical_database.make_ptmset_dictionary(); if (!SaveState.lollipop.modification_ranks.TryGetValue(0, out int a)) { SaveState.lollipop.modification_ranks.Add(0, 1); } SaveState.lollipop.mod_rank_sum_threshold = 2; }
public void test_filter() { List <object> asdf = new List <object>(); asdf.Add(ConstructorsForTesting.get_modWithMass("asdf", 0)); asdf.Add(ConstructorsForTesting.get_modWithMass("asd", 0)); asdf.Add(ConstructorsForTesting.get_modWithMass("asdf", 0)); asdf.Add(ConstructorsForTesting.InputFile(@"fake.txt", Labeling.NeuCode, Purpose.CalibrationIdentification, "", "", "1", "1", "1")); asdf.Add(ConstructorsForTesting.InputFile(@"ake.txt", Labeling.NeuCode, Purpose.CalibrationIdentification, "", "", "1", "1", "1")); Assert.AreEqual(5, asdf.Count); Assert.AreEqual(3, ExtensionMethods.filter(asdf, "f").Count()); }
public void test_limit_large_combos() { IDictionary <int, List <Modification> > a1 = new Dictionary <int, List <Modification> > { { 1, new List <Modification> { ConstructorsForTesting.get_modWithMass("ox", 16) } }, { 2, new List <Modification> { ConstructorsForTesting.get_modWithMass("ox", 16) } }, { 3, new List <Modification> { ConstructorsForTesting.get_modWithMass("ox", 16) } }, { 4, new List <Modification> { ConstructorsForTesting.get_modWithMass("ac", 42) } }, }; List <PtmSet> sets1 = PtmCombos.get_combinations(a1, 3, new Dictionary <double, int> { { 16, 1 }, { 42, 2 } }, 1, true); Assert.AreEqual(1, sets1.Count(s => s.ptm_combination.Count == 3)); Assert.True(sets1.Where(s => s.ptm_combination.Count == 3).First().ptm_combination.All(p => p.modification.id == "ox")); IDictionary <int, List <Modification> > a2 = new Dictionary <int, List <Modification> > { { 1, new List <Modification> { ConstructorsForTesting.get_modWithMass("ox", 16), ConstructorsForTesting.get_modWithMass("ox", 16) } }, { 3, new List <Modification> { ConstructorsForTesting.get_modWithMass("ox", 16) } }, { 4, new List <Modification> { ConstructorsForTesting.get_modWithMass("ac", 42) } }, }; List <PtmSet> sets2 = PtmCombos.get_combinations(a2, 3, new Dictionary <double, int> { { 16, 1 }, { 42, 2 } }, 1, true); Assert.AreEqual(0, sets2.Count(s => s.ptm_combination.Count == 3)); }
public void test_same_ptmset() { PtmSet set1 = new PtmSet(new List <Ptm>() { new Ptm(1, ConstructorsForTesting.get_modWithMass("id1", 5)), new Ptm(2, ConstructorsForTesting.get_modWithMass("id2", 6)), new Ptm(2, ConstructorsForTesting.get_modWithMass("id4", 6)) }); PtmSet set2 = new PtmSet(new List <Ptm>() { new Ptm(1, ConstructorsForTesting.get_modWithMass("id1", 5)), new Ptm(2, ConstructorsForTesting.get_modWithMass("id2", 6)), new Ptm(2, ConstructorsForTesting.get_modWithMass("id4", 6)) }); Assert.IsTrue(set1.same_ptmset(set2, true)); Assert.IsTrue(set1.same_ptmset(set2, false)); set2 = new PtmSet(new List <Ptm>() { new Ptm(1, ConstructorsForTesting.get_modWithMass("id1", 5)), new Ptm(2, ConstructorsForTesting.get_modWithMass("id2", 6)), new Ptm(2, ConstructorsForTesting.get_modWithMass("id3", 6)) }); Assert.IsFalse(set1.same_ptmset(set2, true)); Assert.IsFalse(set1.same_ptmset(set2, false)); Assert.IsFalse(set2.same_ptmset(set1, true)); Assert.IsFalse(set2.same_ptmset(set1, false)); set2 = new PtmSet(new List <Ptm>() { new Ptm(1, ConstructorsForTesting.get_modWithMass("id1", 5)), new Ptm(2, ConstructorsForTesting.get_modWithMass("id2", 6)), }); Assert.IsFalse(set1.same_ptmset(set2, true)); Assert.IsFalse(set1.same_ptmset(set2, false)); Assert.IsFalse(set2.same_ptmset(set1, true)); Assert.IsFalse(set2.same_ptmset(set1, false)); }
public void TestAcceptDeltaMassPeaks() { Sweet.lollipop = new Lollipop(); ProteoformCommunity test_community = new ProteoformCommunity(); Sweet.lollipop.target_proteoform_community = test_community; Sweet.lollipop.theoretical_database.uniprotModifications = new Dictionary <string, List <Modification> > { { "unmodified", new List <Modification>() { ConstructorsForTesting.get_modWithMass("unmodified", 0) } } }; //Testing the acceptance of peaks. The FDR is tested above, so I'm not going to work with that here. //Four proteoforms, three relations (linear), middle one isn't accepted; should give 2 families Sweet.lollipop.min_peak_count_ee = 2; ExperimentalProteoform pf3 = ConstructorsForTesting.ExperimentalProteoform("E1"); ExperimentalProteoform pf4 = ConstructorsForTesting.ExperimentalProteoform("E2"); ExperimentalProteoform pf5 = ConstructorsForTesting.ExperimentalProteoform("E3"); ExperimentalProteoform pf6 = ConstructorsForTesting.ExperimentalProteoform("E4"); ProteoformComparison comparison34 = ProteoformComparison.ExperimentalExperimental; ProteoformComparison comparison45 = ProteoformComparison.ExperimentalExperimental; ProteoformComparison comparison56 = ProteoformComparison.ExperimentalExperimental; ProteoformRelation pr2 = new ProteoformRelation(pf3, pf4, comparison34, 0, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr3 = new ProteoformRelation(pf4, pf5, comparison45, 0, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr4 = new ProteoformRelation(pf5, pf6, comparison56, 0, TestContext.CurrentContext.TestDirectory); //Test display strings Assert.AreEqual("E1", pr2.connected_proteoforms[0].accession); Assert.AreEqual("E2", pr2.connected_proteoforms[1].accession); pr2.RelationType = ProteoformComparison.ExperimentalExperimental; pr2.RelationType = ProteoformComparison.ExperimentalTheoretical; pr2.RelationType = ProteoformComparison.ExperimentalDecoy; pr2.RelationType = ProteoformComparison.ExperimentalFalse; pr2.RelationType = comparison34; List <ProteoformRelation> prs2 = new List <ProteoformRelation> { pr2, pr3, pr4 }; foreach (ProteoformRelation pr in prs2) { pr.set_nearby_group(prs2, prs2.Select(r => r.InstanceId).ToList()); } Assert.AreEqual(3, pr2.nearby_relations_count); Assert.AreEqual(3, pr3.nearby_relations_count); Assert.AreEqual(3, pr4.nearby_relations_count); Sweet.lollipop.theoretical_database.all_possible_ptmsets = new List <PtmSet> { new PtmSet(new List <Ptm> { new Ptm(-1, ConstructorsForTesting.get_modWithMass("unmodified", 0)) }) }; Sweet.lollipop.theoretical_database.possible_ptmset_dictionary = Sweet.lollipop.theoretical_database.make_ptmset_dictionary(); //auto accept set to false Sweet.lollipop.ee_accept_peaks_based_on_rank = false; Sweet.lollipop.ee_peaks = test_community.accept_deltaMass_peaks(prs2, new List <ProteoformRelation>()); Assert.AreEqual(1, Sweet.lollipop.ee_peaks.Count); DeltaMassPeak peak = Sweet.lollipop.ee_peaks[0]; Assert.IsTrue(peak.Accepted); Assert.AreEqual(3, peak.grouped_relations.Count); Assert.AreEqual(3, pr2.peak.peak_relation_group_count); Assert.AreEqual(0, pr2.peak.DeltaMass); Assert.AreEqual("[unmodified]", peak.possiblePeakAssignments_string); //Test that the relations in the peak are added to each of the proteoforms referenced in the peak Assert.True(pf3.relationships.Contains(pr2)); Assert.True(pf4.relationships.Contains(pr2) && pf4.relationships.Contains(pr3)); Assert.True(pf5.relationships.Contains(pr3) && pf5.relationships.Contains(pr4)); //autoaccept set to true, must be less than first quartile rank... Sweet.lollipop.clear_ee(); Sweet.lollipop.mod_rank_first_quartile = 0; Sweet.lollipop.ee_accept_peaks_based_on_rank = true; Sweet.lollipop.ee_peaks = test_community.accept_deltaMass_peaks(prs2, new List <ProteoformRelation>()); peak = Sweet.lollipop.ee_peaks[0]; Assert.IsFalse(peak.Accepted); Assert.AreEqual(0, peak.possiblePeakAssignments.Min(p => p.ptm_rank_sum)); Sweet.lollipop.clear_ee(); Sweet.lollipop.mod_rank_first_quartile = 1; Sweet.lollipop.ee_accept_peaks_based_on_rank = true; Sweet.lollipop.ee_peaks = test_community.accept_deltaMass_peaks(prs2, new List <ProteoformRelation>()); peak = Sweet.lollipop.ee_peaks[0]; Assert.IsTrue(peak.Accepted); Assert.AreEqual(0, peak.possiblePeakAssignments.Min(p => p.ptm_rank_sum)); }
public void test_accept_from_presets() { Sweet.lollipop = new Lollipop(); ProteoformCommunity test_community = new ProteoformCommunity(); Sweet.lollipop.target_proteoform_community = test_community; Sweet.lollipop.theoretical_database.uniprotModifications = new Dictionary <string, List <Modification> > { { "unmodified", new List <Modification>() { ConstructorsForTesting.get_modWithMass("unmodified", 0) } } }; //Testing the acceptance of peaks. The FDR is tested above, so I'm not going to work with that here. //Four proteoforms, three relations (linear), middle one isn't accepted; should give 2 families Sweet.lollipop.min_peak_count_ee = 2; ExperimentalProteoform pf3 = ConstructorsForTesting.ExperimentalProteoform("E1"); ExperimentalProteoform pf4 = ConstructorsForTesting.ExperimentalProteoform("E2"); ExperimentalProteoform pf5 = ConstructorsForTesting.ExperimentalProteoform("E3"); ExperimentalProteoform pf6 = ConstructorsForTesting.ExperimentalProteoform("E4"); ProteoformComparison comparison34 = ProteoformComparison.ExperimentalExperimental; ProteoformComparison comparison45 = ProteoformComparison.ExperimentalExperimental; ProteoformComparison comparison56 = ProteoformComparison.ExperimentalExperimental; ProteoformRelation pr2 = new ProteoformRelation(pf3, pf4, comparison34, 0, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr3 = new ProteoformRelation(pf4, pf5, comparison45, 0, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr4 = new ProteoformRelation(pf5, pf6, comparison56, 0, TestContext.CurrentContext.TestDirectory); //Test display strings Assert.AreEqual("E1", pr2.connected_proteoforms[0].accession); Assert.AreEqual("E2", pr2.connected_proteoforms[1].accession); List <ProteoformRelation> prs2 = new List <ProteoformRelation> { pr2, pr3, pr4 }; foreach (ProteoformRelation pr in prs2) { pr.set_nearby_group(prs2, prs2.Select(r => r.InstanceId).ToList()); } Assert.AreEqual(3, pr2.nearby_relations_count); Assert.AreEqual(3, pr3.nearby_relations_count); Assert.AreEqual(3, pr4.nearby_relations_count); Sweet.lollipop.theoretical_database.all_possible_ptmsets = new List <PtmSet> { new PtmSet(new List <Ptm> { new Ptm(-1, ConstructorsForTesting.get_modWithMass("unmodified", 0)) }) }; Sweet.lollipop.theoretical_database.possible_ptmset_dictionary = Sweet.lollipop.theoretical_database.make_ptmset_dictionary(); Sweet.unaccept_peak_action(pr2); using (StreamWriter file = new StreamWriter(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"))) file.WriteLine(Sweet.save_method()); Sweet.open_method(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"), string.Join(Environment.NewLine, File.ReadAllLines(Path.Combine(TestContext.CurrentContext.TestDirectory, "method.xml"))), true, out string warning); Sweet.lollipop.ee_peaks = test_community.accept_deltaMass_peaks(prs2, new List <ProteoformRelation>()); Assert.AreEqual(1, Sweet.lollipop.ee_peaks.Count); DeltaMassPeak peak = Sweet.lollipop.ee_peaks[0]; Assert.IsFalse(peak.Accepted); // <-- even though it's above the threshold Assert.AreEqual(3, peak.grouped_relations.Count); Assert.AreEqual(3, pr2.peak.peak_relation_group_count); Assert.AreEqual(0, pr2.peak.DeltaMass); Assert.AreEqual("[unmodified]", peak.possiblePeakAssignments_string); //Test that the relations in the peak are added to each of the proteoforms referenced in the peak Assert.True(pf3.relationships.Contains(pr2)); Assert.True(pf4.relationships.Contains(pr2) && pf4.relationships.Contains(pr3)); Assert.True(pf5.relationships.Contains(pr3) && pf5.relationships.Contains(pr4)); }
public static ProteoformCommunity construct_two_families_with_potentially_colliding_theoreticals() { //Five experimental proteoforms, four relations (linear), second on not accepted into a peak, one peak; should give 2 families ProteoformCommunity community = new ProteoformCommunity(); SaveState.lollipop = new Lollipop(); SaveState.lollipop.target_proteoform_community = community; SaveState.lollipop.theoretical_database.uniprotModifications = new Dictionary <string, List <Modification> > { { "unmodified", new List <Modification> { ConstructorsForTesting.get_modWithMass("unmodified", 0) } }, { "fake", new List <Modification> { ConstructorsForTesting.get_modWithMass("fake", 19) } }, }; SaveState.lollipop.modification_ranks = new Dictionary <double, int> { { 0, 1 }, { 19, 2 } }; SaveState.lollipop.mod_rank_sum_threshold = 2; SaveState.lollipop.theoretical_database.all_possible_ptmsets = PtmCombos.generate_all_ptmsets(1, SaveState.lollipop.theoretical_database.uniprotModifications.SelectMany(kv => kv.Value).OfType <ModificationWithMass>().ToList(), SaveState.lollipop.modification_ranks, 1); SaveState.lollipop.theoretical_database.all_mods_with_mass = SaveState.lollipop.theoretical_database.uniprotModifications.SelectMany(kv => kv.Value).OfType <ModificationWithMass>().ToList(); SaveState.lollipop.theoretical_database.possible_ptmset_dictionary = SaveState.lollipop.theoretical_database.make_ptmset_dictionary(); SaveState.lollipop.ee_max_mass_difference = 20; SaveState.lollipop.peak_width_base_ee = 0.015; SaveState.lollipop.min_peak_count_ee = 3; //needs to be high so that 0 peak accepted, other peak isn't.... SaveState.lollipop.min_peak_count_et = 2; //needs to be lower so the 2 ET relations are accepted //TheoreticalProteoformGroup InputFile f = new InputFile("fake.txt", Purpose.ProteinDatabase); ProteinWithGoTerms p1 = new ProteinWithGoTerms("", p1_accession, new List <Tuple <string, string> > { new Tuple <string, string>("", "") }, new Dictionary <int, List <Modification> >(), new int?[] { 0 }, new int?[] { 0 }, new string[] { "" }, p1_name, p1_fullName, true, false, new List <DatabaseReference> { p1_dbRef }, new List <GoTerm> { p1_goterm }); Dictionary <InputFile, Protein[]> dict = new Dictionary <InputFile, Protein[]> { { f, new Protein[] { p1 } } }; TheoreticalProteoform t = ConstructorsForTesting.make_a_theoretical("T1_asdf", "T1_asdf", 1234.56, p1, dict); TheoreticalProteoformGroup pf1 = new TheoreticalProteoformGroup(new List <TheoreticalProteoform> { t }); TheoreticalProteoform pf2 = ConstructorsForTesting.make_a_theoretical("T1_asdf_pf2", "T1_asdf_1", 1234.56, dict); //ExperimentalProteoforms ExperimentalProteoform pf3 = ConstructorsForTesting.ExperimentalProteoform("E1", 0, 0, true); ExperimentalProteoform pf4 = ConstructorsForTesting.ExperimentalProteoform("E2", 0, 0, true); ExperimentalProteoform pf5 = ConstructorsForTesting.ExperimentalProteoform("E3", 0, 0, true); ExperimentalProteoform pf6 = ConstructorsForTesting.ExperimentalProteoform("E4", 0, 0, true); ExperimentalProteoform pf7 = ConstructorsForTesting.ExperimentalProteoform("E5", 0, 0, true); ExperimentalProteoform pf8 = ConstructorsForTesting.ExperimentalProteoform("E6", 0, 0, true); TheoreticalProteoform pf9 = ConstructorsForTesting.make_a_theoretical("T1_asdf_pf9", "T1_asdf_1", 1253.56, dict); community.theoretical_proteoforms = new TheoreticalProteoform[] { pf1, pf2, pf9 }; community.experimental_proteoforms = new ExperimentalProteoform[] { pf3, pf4, pf5, pf6, pf7, pf8 }; pf3.agg_mass = 1234.56; pf4.agg_mass = 1234.56; pf5.agg_mass = 1234.56; pf6.agg_mass = 1253.56; pf7.agg_mass = 1253.56; pf8.agg_mass = 1253.56; ProteoformComparison comparison13 = ProteoformComparison.ExperimentalTheoretical; ProteoformComparison comparison23 = ProteoformComparison.ExperimentalTheoretical; ProteoformComparison comparison34 = ProteoformComparison.ExperimentalExperimental; ProteoformComparison comparison45 = ProteoformComparison.ExperimentalExperimental; ProteoformComparison comparison56 = ProteoformComparison.ExperimentalExperimental; ProteoformComparison comparison67 = ProteoformComparison.ExperimentalExperimental; ProteoformComparison comparison78 = ProteoformComparison.ExperimentalExperimental; ProteoformComparison comparison89 = ProteoformComparison.ExperimentalTheoretical; ConstructorsForTesting.make_relation(pf3, pf1, comparison13, 0); ConstructorsForTesting.make_relation(pf3, pf2, comparison23, 0); ConstructorsForTesting.make_relation(pf3, pf4, comparison34, 0); ConstructorsForTesting.make_relation(pf4, pf5, comparison45, 0); ConstructorsForTesting.make_relation(pf5, pf6, comparison56, 19); //not accepted ConstructorsForTesting.make_relation(pf6, pf7, comparison67, 0); ConstructorsForTesting.make_relation(pf7, pf8, comparison78, 0); ConstructorsForTesting.make_relation(pf8, pf9, comparison89, 0); List <ProteoformRelation> prs = new HashSet <ProteoformRelation>(community.experimental_proteoforms.SelectMany(p => p.relationships).Concat(community.theoretical_proteoforms.SelectMany(p => p.relationships))).ToList(); foreach (Proteoform p in prs.SelectMany(r => r.connected_proteoforms)) { Assert.IsNotNull(p); } List <ProteoformRelation> prs_et = prs.Where(r => r.RelationType == ProteoformComparison.ExperimentalTheoretical).OrderBy(r => r.DeltaMass).ToList(); SaveState.lollipop.et_relations = prs_et; List <ProteoformRelation> prs_ee = prs.Where(r => r.RelationType == ProteoformComparison.ExperimentalExperimental).OrderBy(r => r.DeltaMass).ToList(); SaveState.lollipop.ee_relations = prs_ee; foreach (ProteoformRelation pr in prs_et) { pr.set_nearby_group(prs_et, prs_et.Select(r => r.InstanceId).ToList()); } foreach (ProteoformRelation pr in prs_ee) { pr.set_nearby_group(prs_ee, prs_ee.Select(r => r.InstanceId).ToList()); } Assert.AreEqual(3, pf1.relationships.First().nearby_relations_count); // 2 ET relations at 0 delta mass Assert.AreEqual(3, pf2.relationships.First().nearby_relations_count); Assert.AreEqual(4, pf4.relationships.First().nearby_relations_count); // 4 EE relations at 0 delta mass Assert.AreEqual(4, pf5.relationships.First().nearby_relations_count); Assert.AreEqual(1, pf6.relationships.First().nearby_relations_count); // 1 EE relation at 19 delta mass Assert.AreEqual(4, pf7.relationships.First().nearby_relations_count); Assert.AreEqual(4, pf8.relationships.First().nearby_relations_count); community.accept_deltaMass_peaks(prs_et, new List <ProteoformRelation>()); community.accept_deltaMass_peaks(prs_ee, new List <ProteoformRelation>()); Assert.AreEqual(3, SaveState.lollipop.et_peaks.Count + SaveState.lollipop.ee_peaks.Count); Assert.AreEqual(1, SaveState.lollipop.et_peaks.Where(peak => peak.Accepted).Count()); // 1 ET peak Assert.AreEqual(1, SaveState.lollipop.ee_peaks.Where(peak => peak.Accepted).Count()); // 1 EE peak accepted Assert.AreEqual(4, SaveState.lollipop.ee_peaks.Where(peak => peak.Accepted && peak.RelationType == ProteoformComparison.ExperimentalExperimental).First().grouped_relations.Count()); Assert.AreEqual(3, SaveState.lollipop.et_peaks.Where(peak => peak.Accepted && peak.RelationType == ProteoformComparison.ExperimentalTheoretical).First().grouped_relations.Count()); community.construct_families(); //Testing the identification of experimentals //test with a modificationwithmass that's 0 mass, and then see that it crawls around and labels them each with growing ptm sets with that modification //test that the relation.represented_modification gets set Assert.True(SaveState.lollipop.et_relations.All(r => r.peak.DeltaMass != 19 || r.represented_ptmset == null)); Assert.True(SaveState.lollipop.et_relations.All(r => r.peak.DeltaMass != 0 || r.represented_ptmset.ptm_combination.First().modification.id == "unmodified")); Assert.True(pf1 == pf3.linked_proteoform_references.First() || pf2 == pf3.linked_proteoform_references.First()); //test I don't get re-reassignments Assert.AreEqual(pf3, pf4.linked_proteoform_references.Last()); //test that the proteoform.theoretical_reference gets set to each successive PF base Assert.AreEqual((pf3.linked_proteoform_references.First() as TheoreticalProteoform).accession, (pf4.linked_proteoform_references.First() as TheoreticalProteoform).accession); Assert.AreEqual((pf3.linked_proteoform_references.First() as TheoreticalProteoform).fragment, (pf4.linked_proteoform_references.First() as TheoreticalProteoform).fragment); Assert.AreEqual(pf4, pf5.linked_proteoform_references.Last()); Assert.AreEqual((pf3.linked_proteoform_references.First() as TheoreticalProteoform).accession, (pf5.linked_proteoform_references.First() as TheoreticalProteoform).accession); //test that the accession gets carried all the way through the depth of connections Assert.AreEqual((pf3.linked_proteoform_references.First() as TheoreticalProteoform).fragment, (pf5.linked_proteoform_references.First() as TheoreticalProteoform).fragment); Assert.AreEqual(pf9, pf8.linked_proteoform_references.Last()); return(community); }