public static void update_peaks_from_presets(ProteoformComparison comparison_to_update) { Regex findacceptrelationtype = new Regex(@"(accept )(\S+)"); foreach (string peak_change in loaded_actions.Where(x => x.StartsWith("accept ") || x.StartsWith("unaccept "))) { string relationshiptype = findacceptrelationtype.Match(peak_change).Groups[2].ToString(); ProteoformComparison?comparison = ExtensionMethods.EnumUntil.GetValues <ProteoformComparison>().FirstOrDefault(x => relationshiptype == x.ToString()); bool converted = Double.TryParse(findmass.Match(peak_change).Groups[2].ToString(), out double mass); if (comparison == null || comparison != comparison_to_update || !converted) { continue; } DeltaMassPeak peak = null; if (comparison == ProteoformComparison.ExperimentalTheoretical) { peak = lollipop.et_peaks.FirstOrDefault(p => Math.Round(p.DeltaMass, 2) == Math.Round(mass, 2)); } else if (comparison == ProteoformComparison.ExperimentalExperimental) { peak = lollipop.ee_peaks.FirstOrDefault(p => Math.Round(p.DeltaMass, 2) == Math.Round(mass, 2)); } if (peak != null) { lollipop.change_peak_acceptance(peak, peak_change.StartsWith("accept "), true); } } }
public bool allowed_relation(Proteoform pf1, Proteoform pf2, ProteoformComparison relation_type) { switch (relation_type) { case (ProteoformComparison.ExperimentalTheoretical): case (ProteoformComparison.ExperimentalDecoy): return((!SaveState.lollipop.neucode_labeled || pf2.lysine_count == pf1.lysine_count) && (pf1.modified_mass - pf2.modified_mass) >= SaveState.lollipop.et_low_mass_difference && (pf1.modified_mass - pf2.modified_mass) <= SaveState.lollipop.et_high_mass_difference && (pf2.ptm_set.ptm_combination.Count < 3 || pf2.ptm_set.ptm_combination.Select(ptm => ptm.modification.monoisotopicMass).All(x => x == pf2.ptm_set.ptm_combination.First().modification.monoisotopicMass))); case (ProteoformComparison.ExperimentalExperimental): return(pf1.modified_mass >= pf2.modified_mass && pf1 != pf2 && (!SaveState.lollipop.neucode_labeled || pf1.lysine_count == pf2.lysine_count) && pf1.modified_mass - pf2.modified_mass <= SaveState.lollipop.ee_max_mass_difference && Math.Abs(((ExperimentalProteoform)pf1).agg_rt - ((ExperimentalProteoform)pf2).agg_rt) <= SaveState.lollipop.ee_max_RetentionTime_difference); case (ProteoformComparison.ExperimentalFalse): return(pf1.modified_mass >= pf2.modified_mass && pf1 != pf2 && (pf1.modified_mass - pf2.modified_mass <= SaveState.lollipop.ee_max_mass_difference) && (!SaveState.lollipop.neucode_labeled || Math.Abs(pf1.lysine_count - pf2.lysine_count) > SaveState.lollipop.missed_lysines) && (SaveState.lollipop.neucode_labeled || Math.Abs(((ExperimentalProteoform)pf1).agg_rt - ((ExperimentalProteoform)pf2).agg_rt) > SaveState.lollipop.ee_max_RetentionTime_difference * 2) && (!SaveState.lollipop.neucode_labeled || Math.Abs(((ExperimentalProteoform)pf1).agg_rt - ((ExperimentalProteoform)pf2).agg_rt) < SaveState.lollipop.ee_max_RetentionTime_difference)); default: return(false); } }
public DisplayProteoformRelation(ProteoformRelation r) : base(r) { peak = r.peak; relation_type = r.RelationType; connected_proteoforms = r.connected_proteoforms; }
public static ProteoformRelation make_relation(Proteoform p1, Proteoform p2, ProteoformComparison c, double delta_mass) { ProteoformRelation pp = new ProteoformRelation(p1, p2, c, delta_mass, TestContext.CurrentContext.TestDirectory); p1.relationships.Add(pp); p2.relationships.Add(pp); return(pp); }
public void test_construct_one_proteform_family_from_ET_with_theoretical_pf_group() { ProteoformCommunity test_community = new ProteoformCommunity(); SaveState.lollipop.theoretical_database.uniprotModifications = new Dictionary <string, List <Modification> > { { "unmodified", new List <Modification> { new Modification("unmodified", "unknown") } } }; InputFile f = new InputFile("fake.txt", Purpose.ProteinDatabase); ProteinWithGoTerms p1 = new ProteinWithGoTerms("", "T1", new List <Tuple <string, string> > { new Tuple <string, string>("", "") }, new Dictionary <int, List <Modification> >(), new int?[] { 0 }, new int?[] { 0 }, new string[] { "" }, "name", "full_name", true, false, new List <DatabaseReference>(), new List <GoTerm>()); Dictionary <InputFile, Protein[]> dict = new Dictionary <InputFile, Protein[]> { { f, new Protein[] { p1 } } }; TheoreticalProteoform t = ConstructorsForTesting.make_a_theoretical("T1_T1_asdf", p1, dict); //One accepted ET relation; should give one ProteoformFamily SaveState.lollipop.min_peak_count_et = 1; ExperimentalProteoform pf1 = ConstructorsForTesting.ExperimentalProteoform("E1"); TheoreticalProteoformGroup pf2 = new TheoreticalProteoformGroup(new List <TheoreticalProteoform> { t }); ProteoformComparison comparison = ProteoformComparison.ExperimentalTheoretical; ProteoformRelation pr1 = new ProteoformRelation(pf1, pf2, comparison, 0, TestContext.CurrentContext.TestDirectory); pr1.Accepted = true; List <ProteoformRelation> prs = new List <ProteoformRelation> { pr1 }; foreach (ProteoformRelation pr in prs) { pr.set_nearby_group(prs, prs.Select(r => r.InstanceId).ToList()); } DeltaMassPeak peak = new DeltaMassPeak(prs[0], prs); SaveState.lollipop.et_peaks = new List <DeltaMassPeak> { peak }; test_community.experimental_proteoforms = new ExperimentalProteoform[] { pf1 }; test_community.theoretical_proteoforms = new TheoreticalProteoform[] { pf2 }; test_community.construct_families(); Assert.AreEqual(1, test_community.families.Count); Assert.AreEqual(2, test_community.families[0].proteoforms.Count); Assert.AreEqual(1, test_community.families.First().experimental_proteoforms.Count); Assert.AreEqual(1, test_community.families.First().theoretical_proteoforms.Count); Assert.AreEqual("E1", test_community.families.First().experimentals_list); Assert.AreEqual(p1.Name, test_community.families.First().name_list); Assert.AreEqual(pf2.accession, test_community.families.First().accession_list); }
public void test_construct_multi_member_family() { //Four experimental proteoforms, three relations (linear), all accepted; should give 1 bundled family SaveState.lollipop = new Lollipop(); ProteoformCommunity test_community = new ProteoformCommunity(); SaveState.lollipop.target_proteoform_community = test_community; SaveState.lollipop.theoretical_database.uniprotModifications = new Dictionary <string, List <Modification> > { { "unmodified", new List <Modification> { new Modification("unmodified", "unknown") } } }; SaveState.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"); test_community.experimental_proteoforms = new ExperimentalProteoform[] { pf3, pf4, pf5, pf6 }; ProteoformComparison comparison34 = ProteoformComparison.ExperimentalExperimental; ProteoformComparison comparison45 = ProteoformComparison.ExperimentalExperimental; ProteoformComparison comparison56 = ProteoformComparison.ExperimentalExperimental; ConstructorsForTesting.make_relation(pf3, pf4, comparison34, 0); ConstructorsForTesting.make_relation(pf4, pf5, comparison45, 0); ConstructorsForTesting.make_relation(pf5, pf6, comparison56, 0); List <ProteoformRelation> prs2 = new HashSet <ProteoformRelation>(test_community.experimental_proteoforms.SelectMany(p => p.relationships).Concat(test_community.theoretical_proteoforms.SelectMany(p => p.relationships))).OrderBy(r => r.DeltaMass).ToList(); foreach (ProteoformRelation pr in prs2) { pr.set_nearby_group(prs2, prs2.Select(r => r.InstanceId).ToList()); } Assert.AreEqual(3, pf3.relationships.First().nearby_relations_count); Assert.AreEqual(3, pf5.relationships.First().nearby_relations_count); Assert.AreEqual(3, pf6.relationships.First().nearby_relations_count); test_community.accept_deltaMass_peaks(prs2, new List <ProteoformRelation>()); Assert.AreEqual(1, SaveState.lollipop.ee_peaks.Count); Assert.AreEqual(3, SaveState.lollipop.ee_peaks[0].grouped_relations.Count); test_community.experimental_proteoforms = new ExperimentalProteoform[] { pf3, pf4, pf5, pf6 }; test_community.construct_families(); Assert.AreEqual(1, test_community.families.Count); Assert.AreEqual("", test_community.families.First().accession_list); Assert.AreEqual(4, test_community.families.First().proteoforms.Count); Assert.AreEqual(4, test_community.families.First().experimental_proteoforms.Count); Assert.AreEqual(0, test_community.families.First().theoretical_proteoforms.Count); }
public void artificial_deltaMPeak() { Sweet.lollipop.theoretical_database.all_possible_ptmsets = new List <PtmSet>(); ExperimentalProteoform pf3 = ConstructorsForTesting.ExperimentalProteoform("E1"); ExperimentalProteoform pf4 = ConstructorsForTesting.ExperimentalProteoform("E2"); ProteoformComparison comparison = ProteoformComparison.ExperimentalExperimental; ProteoformRelation pr2 = new ProteoformRelation(pf3, pf4, comparison, 0, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr3 = new ProteoformRelation(pf3, pf4, comparison, 0, TestContext.CurrentContext.TestDirectory); HashSet <ProteoformRelation> prs = new HashSet <ProteoformRelation> { pr2, pr3 }; Assert.AreEqual(prs, new DeltaMassPeak(pr2, prs).grouped_relations); }
public void test_construct_one_proteform_family_from_ET() { SaveState.lollipop = new Lollipop(); ProteoformCommunity test_community = new ProteoformCommunity(); SaveState.lollipop.target_proteoform_community = test_community; SaveState.lollipop.theoretical_database.uniprotModifications = new Dictionary <string, List <Modification> > { { "unmodified", new List <Modification> { new Modification("unmodified", "unknown") } } }; //One accepted ET relation; should give one ProteoformFamily SaveState.lollipop.min_peak_count_et = 1; ExperimentalProteoform pf1 = ConstructorsForTesting.ExperimentalProteoform("E1"); pf1.accepted = true; TheoreticalProteoform pf2 = ConstructorsForTesting.make_a_theoretical(); pf2.name = "T1"; ProteoformComparison comparison = ProteoformComparison.ExperimentalTheoretical; ProteoformRelation pr1 = new ProteoformRelation(pf1, pf2, comparison, 0, TestContext.CurrentContext.TestDirectory); pr1.Accepted = true; List <ProteoformRelation> prs = new List <ProteoformRelation> { pr1 }; foreach (ProteoformRelation pr in prs) { pr.set_nearby_group(prs, prs.Select(r => r.InstanceId).ToList()); } DeltaMassPeak peak = new DeltaMassPeak(prs[0], prs); SaveState.lollipop.et_peaks = new List <DeltaMassPeak> { peak }; test_community.experimental_proteoforms = new ExperimentalProteoform[] { pf1 }; test_community.theoretical_proteoforms = new TheoreticalProteoform[] { pf2 }; test_community.construct_families(); Assert.AreEqual("T1", test_community.families.First().name_list); Assert.AreEqual("T1", test_community.families.First().accession_list); Assert.AreEqual("E1", test_community.families.First().experimentals_list); Assert.AreEqual(1, test_community.families.Count); Assert.AreEqual(2, test_community.families[0].proteoforms.Count); Assert.AreEqual(1, test_community.families.First().experimental_proteoforms.Count); Assert.AreEqual(1, test_community.families.First().theoretical_proteoforms.Count); }
public ProteoformRelation(Proteoform pf1, Proteoform pf2, ProteoformComparison relation_type, double delta_mass, string current_directory) { connected_proteoforms[0] = pf1; connected_proteoforms[1] = pf2; RelationType = relation_type; DeltaMass = delta_mass; InstanceId = instanceCounter; lock (SaveState.lollipop) instanceCounter += 1; //Not thread safe if (CH2 == null || HPO3 == null) { Loaders.LoadElements(Path.Combine(current_directory, "elements.dat")); CH2 = ChemicalFormula.ParseFormula("C1 H2"); HPO3 = ChemicalFormula.ParseFormula("H1 O3 P1"); } if (SaveState.lollipop.neucode_labeled) { lysine_count = pf1.lysine_count; } if ((relation_type == ProteoformComparison.ExperimentalTheoretical || relation_type == ProteoformComparison.ExperimentalDecoy) && SaveState.lollipop.theoretical_database.possible_ptmset_dictionary.TryGetValue(Math.Round(delta_mass, 1), out List <PtmSet> candidate_sets) && pf2 as TheoreticalProteoform != null) { TheoreticalProteoform t = pf2 as TheoreticalProteoform; double mass_tolerance = t.modified_mass / 1000000 * (double)SaveState.lollipop.mass_tolerance; List <PtmSet> narrower_range_of_candidates = candidate_sets.Where(s => Math.Abs(s.mass - delta_mass) < 0.05).ToList(); candidate_ptmset = t.generate_possible_added_ptmsets(narrower_range_of_candidates, delta_mass, mass_tolerance, SaveState.lollipop.theoretical_database.all_mods_with_mass, t, t.sequence, SaveState.lollipop.mod_rank_first_quartile) .OrderBy(x => x.ptm_rank_sum + Math.Abs(Math.Abs(x.mass) - Math.Abs(delta_mass)) * 10E-6) // major score: delta rank; tie breaker: deltaM, where it's always less than 1 .FirstOrDefault(); } // Start the model (0 Da) at the mass defect of CH2 or HPO3 itself, allowing the peak width tolerance on either side double half_peak_width = RelationType == ProteoformComparison.ExperimentalTheoretical || RelationType == ProteoformComparison.ExperimentalDecoy ? SaveState.lollipop.peak_width_base_et / 2 : SaveState.lollipop.peak_width_base_ee / 2; double low_decimal_bound = half_peak_width + ((CH2.MonoisotopicMass - Math.Truncate(CH2.MonoisotopicMass)) / CH2.MonoisotopicMass) * (Math.Abs(delta_mass) <= CH2.MonoisotopicMass ? CH2.MonoisotopicMass : Math.Abs(delta_mass)); double high_decimal_bound = 1 - half_peak_width + ((HPO3.MonoisotopicMass - Math.Ceiling(HPO3.MonoisotopicMass)) / HPO3.MonoisotopicMass) * (Math.Abs(delta_mass) <= HPO3.MonoisotopicMass ? HPO3.MonoisotopicMass : Math.Abs(delta_mass)); double delta_mass_decimal = Math.Abs(delta_mass - Math.Truncate(delta_mass)); outside_no_mans_land = delta_mass_decimal <= low_decimal_bound || delta_mass_decimal >= high_decimal_bound || high_decimal_bound <= low_decimal_bound; }
public void wrong_relation_shifting() { ProteoformCommunity test_community = new ProteoformCommunity(); SaveState.lollipop.target_proteoform_community = test_community; ExperimentalProteoform pf3 = ConstructorsForTesting.ExperimentalProteoform("E1"); ExperimentalProteoform pf4 = ConstructorsForTesting.ExperimentalProteoform("E2"); ProteoformComparison wrong_comparison = ProteoformComparison.ExperimentalExperimental; ProteoformRelation pr2 = new ProteoformRelation(pf3, pf4, wrong_comparison, 0, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr3 = new ProteoformRelation(pf3, pf4, wrong_comparison, 0, TestContext.CurrentContext.TestDirectory); List <ProteoformRelation> prs = new List <ProteoformRelation> { pr2, pr3 }; foreach (ProteoformRelation pr in prs) { pr.set_nearby_group(prs, prs.Select(r => r.InstanceId).ToList()); } test_community.accept_deltaMass_peaks(prs, new List <ProteoformRelation>()); Assert.False(SaveState.lollipop.et_peaks[0].shift_experimental_masses(1, true)); }
public void test_construct_two_families() { //Five experimental proteoforms, four relations (linear), second on not accepted into a peak, one peak; should give 2 families SaveState.lollipop = new Lollipop(); ProteoformCommunity test_community = new ProteoformCommunity(); SaveState.lollipop.target_proteoform_community = test_community; SaveState.lollipop.theoretical_database.uniprotModifications = new Dictionary <string, List <Modification> > { { "unmodified", new List <Modification> { new Modification("unmodified", "unknown") } } }; 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.... ExperimentalProteoform pf3 = ConstructorsForTesting.ExperimentalProteoform("E1"); ExperimentalProteoform pf4 = ConstructorsForTesting.ExperimentalProteoform("E2"); ExperimentalProteoform pf5 = ConstructorsForTesting.ExperimentalProteoform("E3"); ExperimentalProteoform pf6 = ConstructorsForTesting.ExperimentalProteoform("E4"); ExperimentalProteoform pf7 = ConstructorsForTesting.ExperimentalProteoform("E5"); ProteoformComparison comparison34 = ProteoformComparison.ExperimentalExperimental; ProteoformComparison comparison45 = ProteoformComparison.ExperimentalExperimental; ProteoformComparison comparison56 = ProteoformComparison.ExperimentalExperimental; ProteoformComparison comparison67 = ProteoformComparison.ExperimentalExperimental; ProteoformRelation pr2 = new ProteoformRelation(pf3, pf4, comparison34, 0, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr3 = new ProteoformRelation(pf4, pf5, comparison45, 19, TestContext.CurrentContext.TestDirectory); //not accepted ProteoformRelation pr4 = new ProteoformRelation(pf5, pf6, comparison56, 0, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr5 = new ProteoformRelation(pf6, pf7, comparison67, 0, TestContext.CurrentContext.TestDirectory); List <ProteoformRelation> prs2 = new List <ProteoformRelation> { pr2, pr3, pr4, pr5 }.OrderBy(r => r.DeltaMass).ToList(); 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(1, pr3.nearby_relations_count); Assert.AreEqual(3, pr4.nearby_relations_count); Assert.AreEqual(3, pr5.nearby_relations_count); test_community.accept_deltaMass_peaks(prs2, new List <ProteoformRelation>()); Assert.AreEqual(2, SaveState.lollipop.ee_peaks.Count); Assert.AreEqual(1, SaveState.lollipop.ee_peaks.Where(peak => peak.Accepted).Count()); Assert.AreEqual(3, SaveState.lollipop.ee_peaks.Where(peak => peak.Accepted).First().grouped_relations.Count()); test_community.experimental_proteoforms = new ExperimentalProteoform[] { pf3, pf4, pf5, pf6, pf7 }; test_community.construct_families(); Assert.AreEqual(2, test_community.families.Count); Assert.AreEqual("", test_community.families.FirstOrDefault(f => f.proteoforms.Contains(pf3)).accession_list); Assert.AreEqual(2, test_community.families.FirstOrDefault(f => f.proteoforms.Contains(pf3)).proteoforms.Count); Assert.AreEqual(2, test_community.families.FirstOrDefault(f => f.proteoforms.Contains(pf3)).experimental_proteoforms.Count); Assert.AreEqual(0, test_community.families.FirstOrDefault(f => f.proteoforms.Contains(pf3)).theoretical_proteoforms.Count); Assert.AreEqual("", test_community.families.FirstOrDefault(f => f.proteoforms.Contains(pf5)).accession_list); Assert.AreEqual(3, test_community.families.FirstOrDefault(f => f.proteoforms.Contains(pf5)).proteoforms.Count); Assert.AreEqual(3, test_community.families.FirstOrDefault(f => f.proteoforms.Contains(pf5)).experimental_proteoforms.Count); Assert.AreEqual(0, test_community.families.FirstOrDefault(f => f.proteoforms.Contains(pf5)).theoretical_proteoforms.Count); }
public void TestDeltaMassPeakConstructorWithNotches() { Sweet.lollipop = new Lollipop(); Sweet.lollipop.et_use_notch = true; Sweet.lollipop.enter_input_files(new string[] { Path.Combine(TestContext.CurrentContext.TestDirectory, "ptmlist.txt") }, Lollipop.acceptable_extensions[2], Lollipop.file_types[2], Sweet.lollipop.input_files, false); ConstructorsForTesting.read_mods(); Sweet.lollipop.et_high_mass_difference = 250; Sweet.lollipop.et_low_mass_difference = -250; ExperimentalProteoform pf1 = ConstructorsForTesting.ExperimentalProteoform("acession1"); TheoreticalProteoform pf2 = ConstructorsForTesting.make_a_theoretical(); pf1.modified_mass = 1000; ProteoformComparison relation_type = ProteoformComparison.ExperimentalTheoretical; double delta_mass = 1 - 1e-7; ExperimentalProteoform pf3 = ConstructorsForTesting.ExperimentalProteoform("acession3"); TheoreticalProteoform pf4 = ConstructorsForTesting.make_a_theoretical(); pf3.modified_mass = 1000; ProteoformComparison relation_type2 = ProteoformComparison.ExperimentalTheoretical; double delta_mass2 = 1; ExperimentalProteoform pf5 = ConstructorsForTesting.ExperimentalProteoform("acession5"); TheoreticalProteoform pf6 = ConstructorsForTesting.make_a_theoretical(); pf5.modified_mass = 1000; ProteoformComparison relation_type3 = ProteoformComparison.ExperimentalTheoretical; double delta_mass3 = 1 + 1e-7; ExperimentalProteoform pf55 = ConstructorsForTesting.ExperimentalProteoform("acession5"); TheoreticalProteoform pf65 = ConstructorsForTesting.make_a_theoretical(); pf55.modified_mass = 1000; ProteoformComparison relation_type35 = ProteoformComparison.ExperimentalTheoretical; double delta_mass35 = 1 + 2e-7; TestProteoformCommunityRelate.prepare_for_et(new List <double>() { 1 }); List <ProteoformRelation> theList = new List <ProteoformRelation>(); theList.Add(new ProteoformRelation(pf1, pf2, relation_type, delta_mass, TestContext.CurrentContext.TestDirectory)); theList.Add(new ProteoformRelation(pf3, pf4, relation_type2, delta_mass2, TestContext.CurrentContext.TestDirectory)); theList.Add(new ProteoformRelation(pf5, pf6, relation_type3, delta_mass3, TestContext.CurrentContext.TestDirectory)); theList.Add(new ProteoformRelation(pf55, pf65, relation_type35, delta_mass35, TestContext.CurrentContext.TestDirectory)); ProteoformRelation base_relation = new ProteoformRelation(pf3, pf4, relation_type2, delta_mass2, TestContext.CurrentContext.TestDirectory); //base_relation.nearby_relations = base_relation.set_nearby_group(theList, theList.Select(r => r.InstanceId).ToList()); Console.WriteLine("Creating deltaMassPeak"); DeltaMassPeak deltaMassPeak = new DeltaMassPeak(base_relation, new HashSet <ProteoformRelation>(theList)); Console.WriteLine("Created deltaMassPeak"); Assert.AreEqual(0, deltaMassPeak.peak_group_fdr); Assert.AreEqual(4, deltaMassPeak.grouped_relations.Count); Assert.AreEqual("[fake1]", deltaMassPeak.possiblePeakAssignments_string); Assert.AreEqual(1.0, deltaMassPeak.DeltaMass); Dictionary <string, List <ProteoformRelation> > decoy_relations = new Dictionary <string, List <ProteoformRelation> >(); decoy_relations["decoyDatabase1"] = new List <ProteoformRelation>(); ExperimentalProteoform pf7 = ConstructorsForTesting.ExperimentalProteoform("experimental1"); TheoreticalProteoform pf8 = ConstructorsForTesting.make_a_theoretical(); pf7.modified_mass = 1000; ProteoformComparison relation_type4 = ProteoformComparison.ExperimentalDecoy; double delta_mass4 = 1; ProteoformRelation decoy_relation = new ProteoformRelation(pf7, pf8, relation_type4, delta_mass4, TestContext.CurrentContext.TestDirectory); decoy_relations["decoyDatabase1"].Add(decoy_relation); deltaMassPeak.calculate_fdr(decoy_relations); Assert.AreEqual(0.25, deltaMassPeak.peak_group_fdr); // 1 decoy database, (1 decoy relation, median=1), 4 target relations decoy_relations["decoyDatabase2"] = new List <ProteoformRelation>(); decoy_relations["decoyDatabase2"].Add(decoy_relation); decoy_relations["decoyDatabase2"].Add(decoy_relation); deltaMassPeak.calculate_fdr(decoy_relations); Assert.AreEqual(0.375, deltaMassPeak.peak_group_fdr); // 2 decoy databases (1 & 2 decoy relations, median=1.5), 4 target relations }
public List <ProteoformRelation> relate(ExperimentalProteoform[] pfs1, Proteoform[] pfs2, ProteoformComparison relation_type, bool accepted_only, string current_directory, bool limit_et_relations) { if (accepted_only) { pfs1 = pfs1.Where(pf1 => pf1.accepted).ToArray(); } if (accepted_only && (relation_type == ProteoformComparison.ExperimentalExperimental || relation_type == ProteoformComparison.ExperimentalFalse)) { pfs2 = pfs2.OfType <ExperimentalProteoform>().Where(pf2 => pf2.accepted).ToArray(); } Parallel.ForEach(pfs1, pf1 => { lock (pf1) { pf1.candidate_relatives = pfs2.Where(pf2 => allowed_relation(pf1, pf2, relation_type)).ToList(); if (relation_type == ProteoformComparison.ExperimentalExperimental) { pf1.ptm_set = null; pf1.linked_proteoform_references = null; pf1.gene_name = null; } if (limit_et_relations && (relation_type == ProteoformComparison.ExperimentalTheoretical || relation_type == ProteoformComparison.ExperimentalDecoy)) { ProteoformRelation best_relation = pf1.candidate_relatives .Select(pf2 => new ProteoformRelation(pf1, pf2, relation_type, pf1.modified_mass - pf2.modified_mass, current_directory)) .Where(r => r.candidate_ptmset != null) // don't consider unassignable relations for ET .OrderBy(r => r.candidate_ptmset.ptm_rank_sum + Math.Abs(Math.Abs(r.candidate_ptmset.mass) - Math.Abs(r.DeltaMass)) * 10E-6) // get the best explanation for the experimental observation .FirstOrDefault(); pf1.candidate_relatives = best_relation != null ? new List <Proteoform> { best_relation.connected_proteoforms[1] } : new List <Proteoform>(); } } }); List <ProteoformRelation> relations = (from pf1 in pfs1 from pf2 in pf1.candidate_relatives select new ProteoformRelation(pf1, pf2, relation_type, pf1.modified_mass - pf2.modified_mass, Environment.CurrentDirectory)).ToList(); return(count_nearby_relations(relations)); //putative counts include no-mans land }
public void shift_et_peak_neucode_from_actions() { Sweet.lollipop = new Lollipop(); ProteoformCommunity test_community = new ProteoformCommunity(); Sweet.lollipop.target_proteoform_community = test_community; //Make a few experimental proteoforms List <IAggregatable> n1 = TestExperimentalProteoform.generate_neucode_components(100); List <IAggregatable> n2 = TestExperimentalProteoform.generate_neucode_components(100); List <IAggregatable> n3 = TestExperimentalProteoform.generate_neucode_components(200); List <IAggregatable> n4 = TestExperimentalProteoform.generate_neucode_components(200); ExperimentalProteoform pf1 = ConstructorsForTesting.ExperimentalProteoform("E1"); pf1.aggregated = n1; ExperimentalProteoform pf2 = ConstructorsForTesting.ExperimentalProteoform("E2"); pf2.aggregated = n2; ExperimentalProteoform pf3 = ConstructorsForTesting.ExperimentalProteoform("E3"); pf3.aggregated = n3; ExperimentalProteoform pf4 = ConstructorsForTesting.ExperimentalProteoform("E4"); pf4.aggregated = n4; Sweet.lollipop.target_proteoform_community.experimental_proteoforms = new List <ExperimentalProteoform> { pf1, pf2, pf3, pf4 }.ToArray(); //Connect them to theoreticals to form two peaks ProteoformComparison comparison14 = ProteoformComparison.ExperimentalTheoretical; ProteoformComparison comparison25 = ProteoformComparison.ExperimentalTheoretical; ProteoformComparison comparison36 = ProteoformComparison.ExperimentalTheoretical; ProteoformComparison comparison47 = ProteoformComparison.ExperimentalTheoretical; TheoreticalProteoform pf5 = ConstructorsForTesting.make_a_theoretical(); TheoreticalProteoform pf6 = ConstructorsForTesting.make_a_theoretical(); TheoreticalProteoform pf7 = ConstructorsForTesting.make_a_theoretical(); TheoreticalProteoform pf8 = ConstructorsForTesting.make_a_theoretical(); ProteoformRelation pr1 = new ProteoformRelation(pf1, pf5, comparison14, 0, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr2 = new ProteoformRelation(pf2, pf6, comparison25, 0, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr3 = new ProteoformRelation(pf3, pf7, comparison36, 1, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr4 = new ProteoformRelation(pf4, pf8, comparison47, 1, TestContext.CurrentContext.TestDirectory); List <ProteoformRelation> prs = new List <ProteoformRelation> { pr1, pr2, pr3, pr4 }; foreach (ProteoformRelation pr in prs) { pr.set_nearby_group(prs, prs.Select(r => r.InstanceId).ToList()); } test_community.accept_deltaMass_peaks(prs, new List <ProteoformRelation>()); Assert.AreEqual(2, Sweet.lollipop.et_peaks.Count); //Shift the peaks, which shifts all of the proteoforms DeltaMassPeak d2 = Sweet.lollipop.et_peaks[1]; d2.mass_shifter = "-1"; Sweet.shift_peak_action(d2); d2.mass_shifter = null; 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.mass_shifts_from_presets(); d2.shift_experimental_masses(Convert.ToInt32(d2.mass_shifter), true); foreach (Component c in n3.OfType <NeuCodePair>().Select(n => n.neuCodeLight). Concat(n4.OfType <NeuCodePair>().Select(n => n.neuCodeLight))) { Assert.AreEqual(-1.0 * Lollipop.MONOISOTOPIC_UNIT_MASS, c.manual_mass_shift); Assert.AreEqual(200 - 1.0 * Lollipop.MONOISOTOPIC_UNIT_MASS, c.weighted_monoisotopic_mass); } foreach (Component c in n3.OfType <NeuCodePair>().Select(n => n.neuCodeHeavy). Concat(n4.OfType <NeuCodePair>().Select(n => n.neuCodeHeavy))) { Assert.AreEqual(-1.0 * Lollipop.MONOISOTOPIC_UNIT_MASS, c.manual_mass_shift); Assert.AreEqual(200 + TestExperimentalProteoform.starter_lysine_count * Lollipop.NEUCODE_LYSINE_MASS_SHIFT - 1.0 * Lollipop.MONOISOTOPIC_UNIT_MASS, c.weighted_monoisotopic_mass); } }
public void shift_et_peak_unlabeled() { Sweet.lollipop = new Lollipop(); ProteoformCommunity test_community = new ProteoformCommunity(); Sweet.lollipop.target_proteoform_community = test_community; Sweet.lollipop.neucode_labeled = false; //Make a few experimental proteoforms List <IAggregatable> n1 = TestExperimentalProteoform.generate_neucode_components(100); List <IAggregatable> n2 = TestExperimentalProteoform.generate_neucode_components(200); List <IAggregatable> n3 = TestExperimentalProteoform.generate_neucode_components(200); List <IAggregatable> n4 = TestExperimentalProteoform.generate_neucode_components(200); ExperimentalProteoform pf1 = ConstructorsForTesting.ExperimentalProteoform("E1"); pf1.aggregated = n1.Select(n => (n as NeuCodePair).neuCodeLight).ToList <IAggregatable>(); ExperimentalProteoform pf2 = ConstructorsForTesting.ExperimentalProteoform("E2"); pf2.aggregated = n2.Select(n => (n as NeuCodePair).neuCodeLight).ToList <IAggregatable>(); ExperimentalProteoform pf3 = ConstructorsForTesting.ExperimentalProteoform("E3"); pf3.aggregated = n3.Select(n => (n as NeuCodePair).neuCodeLight).ToList <IAggregatable>(); ExperimentalProteoform pf4 = ConstructorsForTesting.ExperimentalProteoform("E4"); pf4.aggregated = n4.Select(n => (n as NeuCodePair).neuCodeLight).ToList <IAggregatable>(); Sweet.lollipop.target_proteoform_community.experimental_proteoforms = new List <ExperimentalProteoform> { pf1, pf2, pf3, pf4 }.ToArray(); //Connect them to theoreticals to form two peaks ProteoformComparison comparison14 = ProteoformComparison.ExperimentalTheoretical; ProteoformComparison comparison25 = ProteoformComparison.ExperimentalTheoretical; ProteoformComparison comparison36 = ProteoformComparison.ExperimentalTheoretical; ProteoformComparison comparison47 = ProteoformComparison.ExperimentalTheoretical; TheoreticalProteoform pf5 = ConstructorsForTesting.make_a_theoretical(); TheoreticalProteoform pf6 = ConstructorsForTesting.make_a_theoretical(); TheoreticalProteoform pf7 = ConstructorsForTesting.make_a_theoretical(); TheoreticalProteoform pf8 = ConstructorsForTesting.make_a_theoretical(); ProteoformRelation pr1 = new ProteoformRelation(pf1, pf5, comparison14, 0, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr2 = new ProteoformRelation(pf2, pf6, comparison25, 0, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr3 = new ProteoformRelation(pf3, pf7, comparison36, 1, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr4 = new ProteoformRelation(pf4, pf8, comparison47, 1, TestContext.CurrentContext.TestDirectory); List <ProteoformRelation> prs = new List <ProteoformRelation> { pr1, pr2, pr3, pr4 }; foreach (ProteoformRelation pr in prs) { pr.set_nearby_group(prs, prs.Select(r => r.InstanceId).ToList()); } test_community.accept_deltaMass_peaks(prs, new List <ProteoformRelation>()); Assert.AreEqual(2, Sweet.lollipop.et_peaks.Count); //Shift the peaks, which shifts all of the proteoforms DeltaMassPeak d2 = Sweet.lollipop.et_peaks[1]; d2.shift_experimental_masses(-1, false); foreach (Component c in pf3.aggregated.Concat(pf4.aggregated).OfType <Component>()) { Assert.AreEqual(-1.0 * Lollipop.MONOISOTOPIC_UNIT_MASS, c.manual_mass_shift); Assert.AreEqual(200 - 1.0 * Lollipop.MONOISOTOPIC_UNIT_MASS, c.weighted_monoisotopic_mass); } Sweet.lollipop.clear_et(); Assert.AreEqual(0, Sweet.lollipop.et_peaks.Count); //don't double shift E if it's in two peaks... pr1 = new ProteoformRelation(pf1, pf5, comparison14, 1, TestContext.CurrentContext.TestDirectory); pr2 = new ProteoformRelation(pf1, pf6, comparison14, 1, TestContext.CurrentContext.TestDirectory); prs = new List <ProteoformRelation> { pr1, pr2 }; foreach (ProteoformRelation pr in prs) { pr.set_nearby_group(prs, prs.Select(r => r.InstanceId).ToList()); } test_community.accept_deltaMass_peaks(prs, new List <ProteoformRelation>()); Assert.AreEqual(1, Sweet.lollipop.et_peaks.Count); //Shift the peaks, which shifts all of the proteoforms d2 = Sweet.lollipop.et_peaks[0]; d2.shift_experimental_masses(-1, false); foreach (Component c in pf3.aggregated.Concat(pf4.aggregated).OfType <Component>()) { Assert.AreEqual(-1.0 * Lollipop.MONOISOTOPIC_UNIT_MASS, c.manual_mass_shift); Assert.AreEqual(200 - 1.0 * Lollipop.MONOISOTOPIC_UNIT_MASS, c.weighted_monoisotopic_mass); } }
public void TestDeltaMassPeakConstructor() { Sweet.lollipop = new Lollipop(); ConstructorsForTesting.read_mods(); Sweet.lollipop.et_high_mass_difference = 250; Sweet.lollipop.et_low_mass_difference = -250; Sweet.lollipop.peak_width_base_ee = 0.015; Sweet.lollipop.peak_width_base_et = 0.015; ExperimentalProteoform pf1 = ConstructorsForTesting.ExperimentalProteoform("acession1"); TheoreticalProteoform pf2 = ConstructorsForTesting.make_a_theoretical(); ProteoformComparison relation_type = ProteoformComparison.ExperimentalTheoretical; double delta_mass = 1 - 1e-7; ExperimentalProteoform pf3 = ConstructorsForTesting.ExperimentalProteoform("acession3"); TheoreticalProteoform pf4 = ConstructorsForTesting.make_a_theoretical(); ProteoformComparison relation_type2 = ProteoformComparison.ExperimentalTheoretical; double delta_mass2 = 1; ExperimentalProteoform pf5 = ConstructorsForTesting.ExperimentalProteoform("acession5"); TheoreticalProteoform pf6 = ConstructorsForTesting.make_a_theoretical(); ProteoformComparison relation_type3 = ProteoformComparison.ExperimentalTheoretical; double delta_mass3 = 1 + 1e-7; ExperimentalProteoform pf55 = ConstructorsForTesting.ExperimentalProteoform("acession5"); TheoreticalProteoform pf65 = ConstructorsForTesting.make_a_theoretical(); ProteoformComparison relation_type35 = ProteoformComparison.ExperimentalTheoretical; double delta_mass35 = 1 + 2e-7; List <ProteoformRelation> theList = new List <ProteoformRelation>(); theList.Add(new ProteoformRelation(pf1, pf2, relation_type, delta_mass, TestContext.CurrentContext.TestDirectory)); theList.Add(new ProteoformRelation(pf3, pf4, relation_type2, delta_mass2, TestContext.CurrentContext.TestDirectory)); theList.Add(new ProteoformRelation(pf5, pf6, relation_type3, delta_mass3, TestContext.CurrentContext.TestDirectory)); theList.Add(new ProteoformRelation(pf55, pf65, relation_type35, delta_mass35, TestContext.CurrentContext.TestDirectory)); ProteoformRelation base_relation = new ProteoformRelation(pf3, pf4, relation_type2, delta_mass2, TestContext.CurrentContext.TestDirectory); //base_relation.nearby_relations = base_relation.set_nearby_group(theList, theList.Select(r => r.InstanceId).ToList()); Console.WriteLine("Creating deltaMassPeak"); DeltaMassPeak deltaMassPeak = new DeltaMassPeak(base_relation, new HashSet <ProteoformRelation>(theList)); Console.WriteLine("Created deltaMassPeak"); Assert.AreEqual(0, deltaMassPeak.peak_group_fdr); Dictionary <string, List <ProteoformRelation> > decoy_relations = new Dictionary <string, List <ProteoformRelation> >(); decoy_relations["decoyDatabase1"] = new List <ProteoformRelation>(); ExperimentalProteoform pf7 = ConstructorsForTesting.ExperimentalProteoform("experimental1"); TheoreticalProteoform pf8 = ConstructorsForTesting.make_a_theoretical(); ProteoformComparison relation_type4 = ProteoformComparison.ExperimentalDecoy; double delta_mass4 = 1; ProteoformRelation decoy_relation = new ProteoformRelation(pf7, pf8, relation_type4, delta_mass4, TestContext.CurrentContext.TestDirectory); decoy_relations["decoyDatabase1"].Add(decoy_relation); deltaMassPeak.calculate_fdr(decoy_relations); Assert.AreEqual(0.25, deltaMassPeak.peak_group_fdr); // 1 decoy database, (1 decoy relation, median=1), 4 target relations decoy_relations["decoyDatabase2"] = new List <ProteoformRelation>(); decoy_relations["decoyDatabase2"].Add(decoy_relation); decoy_relations["decoyDatabase2"].Add(decoy_relation); deltaMassPeak.calculate_fdr(decoy_relations); Assert.AreEqual(0.375, deltaMassPeak.peak_group_fdr); // 2 decoy databases (1 & 2 decoy relations, median=1.5), 4 target relations }
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); }
public List <ProteoformRelation> relate(ExperimentalProteoform[] pfs1, Proteoform[] pfs2, ProteoformComparison relation_type, string current_directory, bool limit_et_relations) { if (relation_type == ProteoformComparison.ExperimentalExperimental || relation_type == ProteoformComparison.ExperimentalFalse) { pfs2 = pfs2.OfType <ExperimentalProteoform>().ToArray(); } Dictionary <int, List <Proteoform> > pfs2_lysine_lookup = new Dictionary <int, List <Proteoform> >(); if (Sweet.lollipop.neucode_labeled) { foreach (Proteoform pf2 in pfs2) { if (!pfs2_lysine_lookup.TryGetValue(pf2.lysine_count, out List <Proteoform> same_lysine_ct)) { pfs2_lysine_lookup.Add(pf2.lysine_count, new List <Proteoform> { pf2 }); } else { same_lysine_ct.Add(pf2); } } } Parallel.ForEach(pfs1, pf1 => { lock (pf1) { if (Sweet.lollipop.neucode_labeled && (relation_type == ProteoformComparison.ExperimentalTheoretical || relation_type == ProteoformComparison.ExperimentalDecoy || relation_type == ProteoformComparison.ExperimentalExperimental)) { pfs2_lysine_lookup.TryGetValue(pf1.lysine_count, out List <Proteoform> pfs2_same_lysine_count); pf1.candidate_relatives = pfs2_same_lysine_count != null ? pfs2_same_lysine_count.Where(pf2 => allowed_relation(pf1, pf2, relation_type)).ToList() : new List <Proteoform>(); } else if (Sweet.lollipop.neucode_labeled && relation_type == ProteoformComparison.ExperimentalFalse) { List <Proteoform> pfs2_lysines_outside_tolerance = pfs2_lysine_lookup .Where(kv => Math.Abs(pf1.lysine_count - kv.Key) > Sweet.lollipop.maximum_missed_lysines) .SelectMany(kv => kv.Value).ToList(); pf1.candidate_relatives = pfs2_lysines_outside_tolerance .Where(pf2 => allowed_relation(pf1, pf2, relation_type)).ToList(); } else if (!Sweet.lollipop.neucode_labeled) { pf1.candidate_relatives = pfs2.Where(pf2 => allowed_relation(pf1, pf2, relation_type)).ToList(); } if (relation_type == ProteoformComparison.ExperimentalExperimental) { pf1.ptm_set = null; pf1.linked_proteoform_references = null; pf1.ambiguous_identifications.Clear(); pf1.gene_name = null; // pf1.relation_to_id = null; } if (relation_type == ProteoformComparison.ExperimentalTheoretical || relation_type == ProteoformComparison.ExperimentalDecoy) { if (limit_et_relations) { ProteoformRelation best_relation = pf1.candidate_relatives .Select(pf2 => new ProteoformRelation(pf1, pf2, relation_type, pf1.modified_mass - pf2.modified_mass, current_directory)) .Where(r => r.candidate_ptmset != null && topdown_bottomup_comparison(pf1, r.connected_proteoforms[1] as TheoreticalProteoform) ) // don't consider unassignable relations for ET .OrderBy(r => r.candidate_ptmset.ptm_rank_sum + Math.Abs(Math.Abs(r.candidate_ptmset.mass) - Math.Abs(r.DeltaMass)) * 10E-6) // get the best explanation for the experimental observation .FirstOrDefault(); pf1.candidate_relatives = best_relation != null ? new List <Proteoform> { best_relation.connected_proteoforms[1] } : new List <Proteoform>(); } else //candidate relatives will be best T from each gene (won't get -42, etc) { List <ProteoformRelation> best_relatives_for_each_gene_name = new List <ProteoformRelation>(); var gene_names = pf1.candidate_relatives.Select(r => (r as TheoreticalProteoform).gene_name.get_prefered_name(Lollipop .preferred_gene_label)) .Distinct(); foreach (var gene_name in gene_names) { best_relatives_for_each_gene_name.Add(pf1.candidate_relatives .Where(p => (p as TheoreticalProteoform).gene_name.get_prefered_name( Lollipop.preferred_gene_label) == gene_name) .Select(pf2 => new ProteoformRelation(pf1, pf2, relation_type, pf1.modified_mass - pf2.modified_mass, current_directory)) .Where(r => r.candidate_ptmset != null) // don't consider unassignable relations for ET .OrderBy(r => r.candidate_ptmset.ptm_rank_sum + Math.Abs(Math.Abs(r.candidate_ptmset.mass) - Math.Abs(r.DeltaMass)) * 10E-6) // get the best explanation for the experimental observation .FirstOrDefault()); } pf1.candidate_relatives = best_relatives_for_each_gene_name != null ? best_relatives_for_each_gene_name.Where(r => r != null && topdown_bottomup_comparison(pf1, r.connected_proteoforms[1] as TheoreticalProteoform)).Select(r => r.connected_proteoforms[1]).ToList() : new List <Proteoform>(); } } } }); List <ProteoformRelation> relations = (from pf1 in pfs1 from pf2 in pf1.candidate_relatives select new ProteoformRelation(pf1, pf2, relation_type, pf1.modified_mass - pf2.modified_mass, current_directory)).ToList(); if (relation_type == ProteoformComparison.ExperimentalExperimental || relation_type == ProteoformComparison.ExperimentalFalse) { if (Sweet.lollipop.ee_use_notch) { relations = relations.Where(r => r.candidate_ptmset != null).ToList(); } } return(count_nearby_relations(relations)); //putative counts include no-mans land }
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 bool allowed_relation(Proteoform pf1, Proteoform pf2_with_allowed_lysines, ProteoformComparison relation_type) { if (relation_type == ProteoformComparison.ExperimentalTheoretical || relation_type == ProteoformComparison.ExperimentalDecoy) { return ((pf1.modified_mass - pf2_with_allowed_lysines.modified_mass) >= Sweet.lollipop.et_low_mass_difference && (pf1.modified_mass - pf2_with_allowed_lysines.modified_mass) <= Sweet.lollipop.et_high_mass_difference && (Sweet.lollipop.add_td_theoreticals || !(pf2_with_allowed_lysines as TheoreticalProteoform).new_topdown_proteoform)); } else if (relation_type == ProteoformComparison.ExperimentalExperimental) { return (pf1 != pf2_with_allowed_lysines && pf1.modified_mass >= pf2_with_allowed_lysines.modified_mass && pf1 != pf2_with_allowed_lysines && pf1.modified_mass - pf2_with_allowed_lysines.modified_mass <= Sweet.lollipop.ee_max_mass_difference && Math.Abs((pf1 as ExperimentalProteoform).agg_rt - (pf2_with_allowed_lysines as ExperimentalProteoform).agg_rt) <= Sweet.lollipop.ee_max_RetentionTime_difference); } else if (relation_type == ProteoformComparison.ExperimentalFalse) { //going to hard code in 10 minutes as min RT for 2 to not be related. return (pf1.modified_mass >= pf2_with_allowed_lysines.modified_mass && pf1 != pf2_with_allowed_lysines && (pf1.modified_mass - pf2_with_allowed_lysines.modified_mass <= Sweet.lollipop.ee_max_mass_difference) && (Sweet.lollipop.neucode_labeled || Math.Abs((pf1 as ExperimentalProteoform).agg_rt - (pf2_with_allowed_lysines as ExperimentalProteoform).agg_rt) > 10) && (!Sweet.lollipop.neucode_labeled || Math.Abs((pf1 as ExperimentalProteoform).agg_rt - (pf2_with_allowed_lysines as ExperimentalProteoform).agg_rt) < Sweet.lollipop.ee_max_RetentionTime_difference)); } else { return(false); } }
public ProteoformRelation(Proteoform pf1, Proteoform pf2, ProteoformComparison relation_type, double delta_mass, string current_directory) { connected_proteoforms[0] = pf1; connected_proteoforms[1] = pf2; RelationType = relation_type; DeltaMass = delta_mass; InstanceId = instanceCounter; lock (Sweet.lollipop) instanceCounter += 1; //Not thread safe if (CH2 == null || HPO3 == null) { CH2 = ChemicalFormula.ParseFormula("C1 H2"); HPO3 = ChemicalFormula.ParseFormula("H1 O3 P1"); } if (Sweet.lollipop.neucode_labeled) { lysine_count = pf1.lysine_count; } List <PtmSet> candidate_sets = new List <PtmSet>(); if (Sweet.lollipop.et_use_notch && (relation_type == ProteoformComparison.ExperimentalTheoretical || relation_type == ProteoformComparison.ExperimentalDecoy)) { if (Sweet.lollipop.et_use_notch && !Sweet.lollipop.et_notch_ppm) { double mass = delta_mass - Sweet.lollipop.notch_tolerance_et; while (mass <= delta_mass + Sweet.lollipop.notch_tolerance_et) { Sweet.lollipop.theoretical_database.possible_ptmset_dictionary_notches.TryGetValue( Math.Round(mass, 1), out List <PtmSet> candidates); if (candidates != null) { candidate_sets.AddRange(candidates); } mass += 0.1; } candidate_sets = candidate_sets.Distinct().ToList(); } else { Sweet.lollipop.theoretical_database.possible_ptmset_dictionary_notches.TryGetValue(Math.Round(delta_mass, 1), out candidate_sets); } if (candidate_sets != null) { candidate_sets = candidate_sets.Where(s => Sweet.lollipop.et_notch_ppm ? Math.Abs(s.mass - delta_mass) * 1e6 / pf1.modified_mass < Sweet.lollipop.notch_tolerance_et : Math.Abs(s.mass - delta_mass) < Sweet.lollipop.notch_tolerance_et).ToList(); candidate_ptmset = candidate_sets.OrderBy(s => s.ptm_rank_sum).FirstOrDefault(); } } else if (Sweet.lollipop.ee_use_notch && (relation_type == ProteoformComparison.ExperimentalExperimental || relation_type == ProteoformComparison.ExperimentalFalse)) { if (Sweet.lollipop.ee_use_notch && !Sweet.lollipop.ee_notch_ppm) { double mass = delta_mass - Sweet.lollipop.notch_tolerance_ee; while (mass <= delta_mass + Sweet.lollipop.notch_tolerance_ee) { Sweet.lollipop.theoretical_database.possible_ptmset_dictionary_notches.TryGetValue( Math.Round(mass, 1), out List <PtmSet> candidates); if (candidates != null) { candidate_sets.AddRange(candidates); } mass += 0.1; } candidate_sets = candidate_sets.Distinct().ToList(); } else { Sweet.lollipop.theoretical_database.possible_ptmset_dictionary_notches.TryGetValue(Math.Round(delta_mass, 1), out candidate_sets); } if (candidate_sets != null) { candidate_sets = candidate_sets.Where(s => Sweet.lollipop.ee_notch_ppm ? Math.Abs(s.mass - delta_mass) * 1e6 / pf1.modified_mass < Sweet.lollipop.notch_tolerance_ee : Math.Abs(s.mass - delta_mass) < Sweet.lollipop.notch_tolerance_ee).ToList(); candidate_ptmset = candidate_sets.OrderBy(s => s.ptm_rank_sum).FirstOrDefault(); } } else if (relation_type == ProteoformComparison.ExperimentalTheoretical || relation_type == ProteoformComparison.ExperimentalDecoy) { if (Sweet.lollipop.peak_width_base_et > 0.09) { double mass = delta_mass - Sweet.lollipop.peak_width_base_et; while (mass <= delta_mass + Sweet.lollipop.peak_width_base_et) { Sweet.lollipop.theoretical_database.possible_ptmset_dictionary.TryGetValue( Math.Round(mass, 1), out List <PtmSet> candidates); if (candidates != null) { candidate_sets.AddRange(candidates); } mass += 0.1; } candidate_sets = candidate_sets.Distinct().ToList(); } else { Sweet.lollipop.theoretical_database.possible_ptmset_dictionary.TryGetValue( Math.Round(delta_mass, 1), out candidate_sets); } if (pf2 as TheoreticalProteoform != null && candidate_sets != null && candidate_sets.Count > 0) { List <PtmSet> narrower_range_of_candidates = new List <PtmSet>(); if (Sweet.lollipop.et_use_notch) { narrower_range_of_candidates = candidate_sets; } else { narrower_range_of_candidates = candidate_sets .Where(s => Math.Abs(s.mass - delta_mass) < Sweet.lollipop.peak_width_base_et).ToList(); } TheoreticalProteoform t = pf2 as TheoreticalProteoform; candidate_ptmset = Proteoform.generate_possible_added_ptmsets(narrower_range_of_candidates, Sweet.lollipop.theoretical_database.all_mods_with_mass, t, pf2.begin, pf2.end, pf2.ptm_set, Sweet.lollipop.mod_rank_first_quartile, false).OrderBy(x => x.ptm_rank_sum + Math.Abs(Math.Abs(x.mass) - Math.Abs(delta_mass)) * 10E-6) // major score: delta rank; tie breaker: deltaM, where it's always less than 1 .FirstOrDefault(); } } // Start the model (0 Da) at the mass defect of CH2 or HPO3 itself, allowing the peak width tolerance on either side double half_peak_width = RelationType == ProteoformComparison.ExperimentalTheoretical || RelationType == ProteoformComparison.ExperimentalDecoy ? Sweet.lollipop.peak_width_base_et / 2 : Sweet.lollipop.peak_width_base_ee / 2; double low_decimal_bound = half_peak_width + ((CH2.MonoisotopicMass - Math.Truncate(CH2.MonoisotopicMass)) / CH2.MonoisotopicMass) * (Math.Abs(delta_mass) <= CH2.MonoisotopicMass ? CH2.MonoisotopicMass : Math.Abs(delta_mass)); double high_decimal_bound = 1 - half_peak_width + ((HPO3.MonoisotopicMass - Math.Ceiling(HPO3.MonoisotopicMass)) / HPO3.MonoisotopicMass) * (Math.Abs(delta_mass) <= HPO3.MonoisotopicMass ? HPO3.MonoisotopicMass : Math.Abs(delta_mass)); double delta_mass_decimal = Math.Abs(delta_mass - Math.Truncate(delta_mass)); outside_no_mans_land = delta_mass_decimal <= low_decimal_bound || delta_mass_decimal >= high_decimal_bound || high_decimal_bound <= low_decimal_bound; if (Sweet.lollipop.et_use_notch && (relation_type == ProteoformComparison.ExperimentalTheoretical || relation_type == ProteoformComparison.ExperimentalDecoy)) { outside_no_mans_land = true; } if (Sweet.lollipop.ee_use_notch && (relation_type == ProteoformComparison.ExperimentalExperimental || relation_type == ProteoformComparison.ExperimentalFalse)) { outside_no_mans_land = true; } }
public void shift_et_peak_neucode() { SaveState.lollipop = new Lollipop(); ProteoformCommunity test_community = new ProteoformCommunity(); SaveState.lollipop.target_proteoform_community = test_community; //Make a few experimental proteoforms List <Component> n1 = TestExperimentalProteoform.generate_neucode_components(100); List <Component> n2 = TestExperimentalProteoform.generate_neucode_components(100); List <Component> n3 = TestExperimentalProteoform.generate_neucode_components(200); List <Component> n4 = TestExperimentalProteoform.generate_neucode_components(200); ExperimentalProteoform pf1 = ConstructorsForTesting.ExperimentalProteoform("E1"); pf1.aggregated_components = n1; ExperimentalProteoform pf2 = ConstructorsForTesting.ExperimentalProteoform("E2"); pf2.aggregated_components = n2; ExperimentalProteoform pf3 = ConstructorsForTesting.ExperimentalProteoform("E3"); pf3.aggregated_components = n3; ExperimentalProteoform pf4 = ConstructorsForTesting.ExperimentalProteoform("E4"); pf4.aggregated_components = n4; SaveState.lollipop.target_proteoform_community.experimental_proteoforms = new List <ExperimentalProteoform> { pf1, pf2, pf3, pf4 }.ToArray(); //Connect them to theoreticals to form two peaks ProteoformComparison comparison14 = ProteoformComparison.ExperimentalTheoretical; ProteoformComparison comparison25 = ProteoformComparison.ExperimentalTheoretical; ProteoformComparison comparison36 = ProteoformComparison.ExperimentalTheoretical; ProteoformComparison comparison47 = ProteoformComparison.ExperimentalTheoretical; TheoreticalProteoform pf5 = ConstructorsForTesting.make_a_theoretical(); TheoreticalProteoform pf6 = ConstructorsForTesting.make_a_theoretical(); TheoreticalProteoform pf7 = ConstructorsForTesting.make_a_theoretical(); TheoreticalProteoform pf8 = ConstructorsForTesting.make_a_theoretical(); ProteoformRelation pr1 = new ProteoformRelation(pf1, pf5, comparison14, 0, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr2 = new ProteoformRelation(pf2, pf6, comparison25, 0, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr3 = new ProteoformRelation(pf3, pf7, comparison36, 1, TestContext.CurrentContext.TestDirectory); ProteoformRelation pr4 = new ProteoformRelation(pf4, pf8, comparison47, 1, TestContext.CurrentContext.TestDirectory); List <ProteoformRelation> prs = new List <ProteoformRelation> { pr1, pr2, pr3, pr4 }; foreach (ProteoformRelation pr in prs) { pr.set_nearby_group(prs, prs.Select(r => r.InstanceId).ToList()); } test_community.accept_deltaMass_peaks(prs, new List <ProteoformRelation>()); Assert.AreEqual(2, SaveState.lollipop.et_peaks.Count); //Shift the peaks, which shifts all of the proteoforms DeltaMassPeak d2 = SaveState.lollipop.et_peaks[1]; d2.shift_experimental_masses(-1, true); Assert.IsTrue(pf3.mass_shifted); Assert.IsTrue(pf4.mass_shifted); foreach (Component c in n3. Concat(n4). Concat(n3.Select(n => ((NeuCodePair)n).neuCodeLight)). Concat(n4.Select(n => ((NeuCodePair)n).neuCodeLight))) { Assert.AreEqual(-1.0 * Lollipop.MONOISOTOPIC_UNIT_MASS, c.manual_mass_shift); Assert.AreEqual(200 - 1.0 * Lollipop.MONOISOTOPIC_UNIT_MASS, c.weighted_monoisotopic_mass); } foreach (Component c in n3.Select(n => ((NeuCodePair)n).neuCodeHeavy). Concat(n4.Select(n => ((NeuCodePair)n).neuCodeHeavy))) { Assert.AreEqual(-1.0 * Lollipop.MONOISOTOPIC_UNIT_MASS, c.manual_mass_shift); Assert.AreEqual(200 + TestExperimentalProteoform.starter_lysine_count * Lollipop.NEUCODE_LYSINE_MASS_SHIFT - 1.0 * Lollipop.MONOISOTOPIC_UNIT_MASS, c.weighted_monoisotopic_mass); } }
public bool allowed_relation(Proteoform pf1, Proteoform pf2_with_allowed_lysines, ProteoformComparison relation_type) { if (relation_type == ProteoformComparison.ExperimentalTheoretical || relation_type == ProteoformComparison.ExperimentalDecoy) { return ((pf1.modified_mass - pf2_with_allowed_lysines.modified_mass) >= Sweet.lollipop.et_low_mass_difference && (pf1.modified_mass - pf2_with_allowed_lysines.modified_mass) <= Sweet.lollipop.et_high_mass_difference); } else if (relation_type == ProteoformComparison.ExperimentalExperimental) { return (pf1 != pf2_with_allowed_lysines && pf1.modified_mass >= pf2_with_allowed_lysines.modified_mass && pf1 != pf2_with_allowed_lysines && pf1.modified_mass - pf2_with_allowed_lysines.modified_mass <= Sweet.lollipop.ee_max_mass_difference && Math.Abs((pf1 as ExperimentalProteoform).agg_rt - (pf2_with_allowed_lysines as ExperimentalProteoform).agg_rt) <= Sweet.lollipop.ee_max_RetentionTime_difference); } else if (relation_type == ProteoformComparison.ExperimentalFalse) { return (pf1.modified_mass >= pf2_with_allowed_lysines.modified_mass && pf1 != pf2_with_allowed_lysines && (pf1.modified_mass - pf2_with_allowed_lysines.modified_mass <= Sweet.lollipop.ee_max_mass_difference) && (Sweet.lollipop.neucode_labeled || Math.Abs((pf1 as ExperimentalProteoform).agg_rt - (pf2_with_allowed_lysines as ExperimentalProteoform).agg_rt) > Sweet.lollipop.ee_max_RetentionTime_difference * 2) && (!Sweet.lollipop.neucode_labeled || Math.Abs((pf1 as ExperimentalProteoform).agg_rt - (pf2_with_allowed_lysines as ExperimentalProteoform).agg_rt) < Sweet.lollipop.ee_max_RetentionTime_difference)); } else { return(false); } }
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)); }