示例#1
0
        public void TestUnabeledProteoformCommunityRelateWithNotches_ET()
        {
            Sweet.lollipop = new Lollipop();
            Sweet.lollipop.neucode_labeled         = false;
            Sweet.lollipop.et_use_notch            = true;
            Sweet.lollipop.et_low_mass_difference  = -200;
            Sweet.lollipop.et_high_mass_difference = 200;

            // One experimental one theoretical protoeform; mass difference < 500 -- return 1
            ExperimentalProteoform pf1 = ConstructorsForTesting.ExperimentalProteoform("A1", 1000.0, -1, true);
            TheoreticalProteoform  pf2 = ConstructorsForTesting.make_a_theoretical();

            pf2.modified_mass       = 1010.0;
            pf2.lysine_count        = 1;
            pf2.is_target           = true;
            pf2.ExpandedProteinList = new List <ProteinWithGoTerms> {
                p1
            };
            ExperimentalProteoform[] paE = new ExperimentalProteoform[1];
            TheoreticalProteoform[]  paT = new TheoreticalProteoform[1];
            paE[0] = pf1;
            paT[0] = pf2;
            List <ProteoformRelation> prList = new List <ProteoformRelation>();

            prepare_for_et(new List <double> {
                pf1.modified_mass - pf2.modified_mass
            });
            prList = community.relate(paE, paT, ProteoformComparison.ExperimentalTheoretical, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(1, prList.Count);

            //Da instead of ppm -- return 1
            Sweet.lollipop.et_notch_ppm = false;
            prList = community.relate(paE, paT, ProteoformComparison.ExperimentalTheoretical, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(1, prList.Count);

            //outside ppm tolerance - return 0
            pf1.modified_mass                 = 1000;
            pf2.modified_mass                 = 1010.5;
            Sweet.lollipop.et_notch_ppm       = true;
            Sweet.lollipop.notch_tolerance_et = 1;
            paE[0] = pf1;
            paT[0] = pf2;
            prepare_for_et(new List <double> {
                -10
            });
            prList = community.relate(paE, paT, ProteoformComparison.ExperimentalTheoretical, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(0, prList.Count);


            //outside Da toelrance - return 0.
            pf1.modified_mass                 = 1000;
            pf2.modified_mass                 = 1010.5;
            Sweet.lollipop.et_notch_ppm       = false;
            Sweet.lollipop.notch_tolerance_et = .5;
            paE[0] = pf1;
            paT[0] = pf2;
            prepare_for_et(new List <double> {
                -10
            });
            prList = community.relate(paE, paT, ProteoformComparison.ExperimentalTheoretical, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(0, prList.Count);

            // One experimental one theoretical protoeform; mass difference > 500 -- return 0
            pf1.modified_mass = 1000;
            pf2.modified_mass = 2000;
            paE[0]            = pf1;
            paT[0]            = pf2;
            prepare_for_et(new List <double> {
                pf1.modified_mass - pf2.modified_mass
            });
            prList = community.relate(paE, paT, ProteoformComparison.ExperimentalTheoretical, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(0, prList.Count);

            //Two experimental one theoretical proteoforms; mass difference < 500 Da -- return 2
            ExperimentalProteoform pf3 = ConstructorsForTesting.ExperimentalProteoform("A1", 1000.0, -1, true);
            ExperimentalProteoform pf4 = ConstructorsForTesting.ExperimentalProteoform("A2", 1010.0, -1, true);
            TheoreticalProteoform  pf5 = ConstructorsForTesting.make_a_theoretical();

            pf5.modified_mass       = 1020.0;
            pf5.lysine_count        = 1;
            pf5.is_target           = true;
            pf5.ExpandedProteinList = new List <ProteinWithGoTerms> {
                p1
            };
            ExperimentalProteoform[] paE2 = new ExperimentalProteoform[2];
            paE2[0] = pf3;
            paE2[1] = pf4;
            paT[0]  = pf5;
            prepare_for_et(new List <double> {
                pf3.modified_mass - pf5.modified_mass,
                pf4.modified_mass - pf5.modified_mass,
            });
            prList = community.relate(paE2, paT, ProteoformComparison.ExperimentalTheoretical, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(2, prList.Count);

            //Two experimental one theoretical proteoforms; one mass difference >500 Da -- return 0
            pf3.modified_mass = 1000;
            pf4.modified_mass = 1010;
            pf5.modified_mass = 2000;
            paE2[0]           = pf3;
            paE2[1]           = pf4;
            paT[0]            = pf5;
            prepare_for_et(new List <double> {
                pf3.modified_mass - pf5.modified_mass,
                pf4.modified_mass - pf5.modified_mass,
            });
            prList = community.relate(paE2, paT, ProteoformComparison.ExperimentalTheoretical, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(0, prList.Count);

            //Two experimental one theoretical proteoforms; mass difference > 500 Da -- return 0
            pf3.modified_mass = 1000;
            pf4.modified_mass = 2000;
            pf5.modified_mass = 3000;
            paE2[0]           = pf3;
            paE2[1]           = pf4;
            paT[0]            = pf5;
            prepare_for_et(new List <double> {
                pf3.modified_mass - pf5.modified_mass,
                pf4.modified_mass - pf5.modified_mass,
            });
            prList = community.relate(paE2, paT, ProteoformComparison.ExperimentalTheoretical, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(0, prList.Count);

            //test methionine retention
            pf1.modified_mass = 2131.04;
            pf1.lysine_count  = 1;
            pf2.modified_mass = 2000;
            pf2.lysine_count  = 1;
            pf2.begin         = 2;

            ModificationMotif motif;

            ModificationMotif.TryGetMotif("M", out motif);
            Modification m = new Modification("Met retention", _modificationType: "AminoAcid", _target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 131.04);

            Sweet.lollipop.theoretical_database.all_mods_with_mass.Add(m);
            Sweet.lollipop.theoretical_database.all_possible_ptmsets.Add(new PtmSet(new List <Ptm> {
                new Ptm(-1, m)
            }));
            Sweet.lollipop.modification_ranks.Add(131.04, 2);
            Sweet.lollipop.theoretical_database.possible_ptmset_dictionary = Sweet.lollipop.theoretical_database.make_ptmset_dictionary();

            paE[0] = pf1;
            paT[0] = pf2;
            prList = community.relate(paE, paT, ProteoformComparison.ExperimentalTheoretical, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(1, prList.Count);
        }
        public void test_construct_target_and_decoy_families()
        {
            SaveState.lollipop = new Lollipop();
            SaveState.lollipop.neucode_labeled = true;
            ExperimentalProteoform pf1    = ConstructorsForTesting.ExperimentalProteoform("E1", 1000, 5, true);
            ExperimentalProteoform pf2    = ConstructorsForTesting.ExperimentalProteoform("E2", 1020, 5, true);
            ExperimentalProteoform pf3    = ConstructorsForTesting.ExperimentalProteoform("E3", 1040, 8, true);
            ExperimentalProteoform pf4    = ConstructorsForTesting.ExperimentalProteoform("E4", 1050, 5, true);
            TheoreticalProteoform  t1     = ConstructorsForTesting.make_a_theoretical("t1", 1000, 5);
            TheoreticalProteoform  decoy1 = ConstructorsForTesting.make_a_theoretical("Decoy1", 1020, 5);

            TestProteoformCommunityRelate.prepare_for_et(new List <double>()
            {
                0
            });

            SaveState.lollipop.target_proteoform_community = new ProteoformCommunity();
            SaveState.lollipop.target_proteoform_community.experimental_proteoforms = new ExperimentalProteoform[4] {
                pf1, pf2, pf3, pf4
            };
            SaveState.lollipop.target_proteoform_community.theoretical_proteoforms = new TheoreticalProteoform[1] {
                t1
            };
            SaveState.lollipop.decoy_proteoform_communities.Add(SaveState.lollipop.decoy_community_name_prefix + "0", new ProteoformCommunity());
            SaveState.lollipop.decoy_proteoform_communities[SaveState.lollipop.decoy_community_name_prefix + "0"].experimental_proteoforms = SaveState.lollipop.target_proteoform_community.experimental_proteoforms.Select(e => new ExperimentalProteoform(e)).ToArray();
            SaveState.lollipop.decoy_proteoform_communities[SaveState.lollipop.decoy_community_name_prefix + "0"].theoretical_proteoforms  = new TheoreticalProteoform[1] {
                decoy1
            };

            SaveState.lollipop.et_relations = SaveState.lollipop.target_proteoform_community.relate(SaveState.lollipop.target_proteoform_community.experimental_proteoforms, SaveState.lollipop.target_proteoform_community.theoretical_proteoforms, ProteoformComparison.ExperimentalTheoretical, true, TestContext.CurrentContext.TestDirectory, true);
            SaveState.lollipop.ee_relations = SaveState.lollipop.target_proteoform_community.relate(SaveState.lollipop.target_proteoform_community.experimental_proteoforms, SaveState.lollipop.target_proteoform_community.experimental_proteoforms, ProteoformComparison.ExperimentalExperimental, true, TestContext.CurrentContext.TestDirectory, true);
            SaveState.lollipop.relate_ed();
            SaveState.lollipop.relate_ef();
            foreach (ProteoformRelation pr in SaveState.lollipop.et_relations)
            {
                pr.set_nearby_group(SaveState.lollipop.et_relations, SaveState.lollipop.et_relations.Select(r => r.InstanceId).ToList());
            }
            foreach (ProteoformRelation pr in SaveState.lollipop.ee_relations)
            {
                pr.set_nearby_group(SaveState.lollipop.ee_relations, SaveState.lollipop.ee_relations.Select(r => r.InstanceId).ToList());
            }

            SaveState.lollipop.et_peaks = SaveState.lollipop.target_proteoform_community.accept_deltaMass_peaks(SaveState.lollipop.et_relations, SaveState.lollipop.ed_relations);
            SaveState.lollipop.ee_peaks = SaveState.lollipop.target_proteoform_community.accept_deltaMass_peaks(SaveState.lollipop.ee_relations, SaveState.lollipop.ef_relations);

            //one ED relation
            Assert.AreEqual(1, SaveState.lollipop.ed_relations.Values.SelectMany(v => v).Count());
            Assert.AreEqual(1, SaveState.lollipop.decoy_proteoform_communities[SaveState.lollipop.decoy_community_name_prefix + "0"].theoretical_proteoforms.SelectMany(t => t.relationships).Count());

            //peak is unaccepted --> relation should be unaccepted, peak added to relation
            Assert.IsFalse(SaveState.lollipop.ed_relations.First().Value.FirstOrDefault().Accepted); //should be false if peak unaccepted
            Assert.AreEqual(1, SaveState.lollipop.et_peaks.Count);
            Assert.IsNotNull(SaveState.lollipop.ed_relations.Values.SelectMany(v => v).First().peak);


            //peak is accepted --> relation should be accepted, peak added to relation
            SaveState.lollipop.clear_et();
            SaveState.lollipop.min_peak_count_et = 1;
            SaveState.lollipop.et_relations      = SaveState.lollipop.target_proteoform_community.relate(SaveState.lollipop.target_proteoform_community.experimental_proteoforms, SaveState.lollipop.target_proteoform_community.theoretical_proteoforms, ProteoformComparison.ExperimentalTheoretical, true, TestContext.CurrentContext.TestDirectory, true);
            SaveState.lollipop.relate_ed();
            foreach (ProteoformRelation pr in SaveState.lollipop.et_relations)
            {
                pr.set_nearby_group(SaveState.lollipop.et_relations, SaveState.lollipop.et_relations.Select(r => r.InstanceId).ToList());
            }
            foreach (ProteoformRelation pr in SaveState.lollipop.ee_relations)
            {
                pr.set_nearby_group(SaveState.lollipop.ee_relations, SaveState.lollipop.ee_relations.Select(r => r.InstanceId).ToList());
            }
            SaveState.lollipop.et_peaks = SaveState.lollipop.target_proteoform_community.accept_deltaMass_peaks(SaveState.lollipop.et_relations, SaveState.lollipop.ed_relations);

            SaveState.lollipop.et_peaks = SaveState.lollipop.target_proteoform_community.accept_deltaMass_peaks(SaveState.lollipop.et_relations, SaveState.lollipop.ed_relations);
            Assert.IsTrue(SaveState.lollipop.ed_relations.First().Value.FirstOrDefault().Accepted);               //should be true if peak accepted
            Assert.IsNotNull(SaveState.lollipop.ed_relations.Values.SelectMany(v => v).First().peak);
            Assert.AreEqual(1, SaveState.lollipop.ed_relations.Values.SelectMany(v => v).Count(r => r.Accepted)); //only 1 relation is in delta mass range of accepted peak - only 1 accepted

            //2 ef relations, unaccepted because peak unaccepted
            Assert.AreEqual(3, SaveState.lollipop.ef_relations.Values.SelectMany(v => v).Count());                //2 ef relations
            Assert.AreEqual(0, SaveState.lollipop.ef_relations.Values.SelectMany(v => v).Count(r => r.Accepted)); //all peaks accepted are false, so relation accepted should be false

            //one peak accepted --> one of the EF relations falls into range of peak and should be accepted
            SaveState.lollipop.clear_ee();
            SaveState.lollipop.min_peak_count_ee = 1;
            SaveState.lollipop.ee_relations      = SaveState.lollipop.target_proteoform_community.relate(SaveState.lollipop.target_proteoform_community.experimental_proteoforms, SaveState.lollipop.target_proteoform_community.experimental_proteoforms, ProteoformComparison.ExperimentalExperimental, true, TestContext.CurrentContext.TestDirectory, true);
            SaveState.lollipop.relate_ef();
            SaveState.lollipop.ee_peaks = SaveState.lollipop.target_proteoform_community.accept_deltaMass_peaks(SaveState.lollipop.ee_relations, SaveState.lollipop.ef_relations);
            Assert.AreEqual(3, SaveState.lollipop.ee_peaks.Count(p => p.Accepted));
            Assert.AreEqual(3, SaveState.lollipop.ee_relations.Count);
            Assert.AreEqual(1, SaveState.lollipop.ef_relations.Values.SelectMany(v => v).Count(r => r.Accepted)); //only 1 relation is in delta mass range of accepted peak - only 1 accepted
            SaveState.lollipop.construct_target_and_decoy_families();

            //should be 2 target families and 3 decoy families
            //only make decoy relations out of accepted relations --> 1 family with accepted relations
            Assert.AreEqual(2, SaveState.lollipop.target_proteoform_community.families.Count);
            Assert.AreEqual(3, SaveState.lollipop.decoy_proteoform_communities[SaveState.lollipop.decoy_community_name_prefix + "0"].families.Count);
            Assert.AreEqual(1, SaveState.lollipop.decoy_proteoform_communities[SaveState.lollipop.decoy_community_name_prefix + "0"].families.Count(f => f.relations.Count > 0));
            Assert.AreEqual(2, SaveState.lollipop.decoy_proteoform_communities[SaveState.lollipop.decoy_community_name_prefix + "0"].families.SelectMany(f => f.relations).Count());
        }
示例#3
0
        public void TestNeuCodeLabeledProteoformCommunityRelate_ET()
        {
            Sweet.lollipop = new Lollipop();
            Sweet.lollipop.neucode_labeled = true;

            // One experimental one theoretical proteoforms; lysine count equal; mass difference < 500 -- return 1
            ExperimentalProteoform pf1 = ConstructorsForTesting.ExperimentalProteoform("A1", 1000.0, 1, true);
            TheoreticalProteoform  pf2 = ConstructorsForTesting.make_a_theoretical();

            pf2.modified_mass       = 1010.0;
            pf2.lysine_count        = 1;
            pf2.is_target           = true;
            pf2.ExpandedProteinList = new List <ProteinWithGoTerms> {
                p1
            };
            prepare_for_et(new List <double> {
                pf1.modified_mass - pf2.modified_mass
            });

            ExperimentalProteoform[] paE = new ExperimentalProteoform[1];
            TheoreticalProteoform[]  paT = new TheoreticalProteoform[1];
            paE[0] = pf1;
            paT[0] = pf2;
            List <ProteoformRelation> prList = new List <ProteoformRelation>();

            prList = community.relate(paE, paT, ProteoformComparison.ExperimentalTheoretical, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(1, prList.Count);

            // One experimental one theoretical proteoforms; lysine count equal; mass difference > 500 -- return 0
            pf1.modified_mass = 1000;
            pf1.lysine_count  = 1;
            pf2.modified_mass = 2000;
            pf2.lysine_count  = 1;
            prepare_for_et(new List <double> {
                pf1.modified_mass - pf2.modified_mass
            });

            paE[0] = pf1;
            paT[0] = pf2;
            prList = community.relate(paE, paT, ProteoformComparison.ExperimentalTheoretical, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(0, prList.Count);

            // One experimental one theoretical proteoforms; lysine count NOT equal; mass difference < 500 -- return 0
            pf1.modified_mass = 1000;
            pf1.lysine_count  = 1;
            pf2.modified_mass = 1100;
            pf2.lysine_count  = 2;
            prepare_for_et(new List <double> {
                pf1.modified_mass - pf2.modified_mass
            });

            paE[0] = pf1;
            paT[0] = pf2;
            prList = community.relate(paE, paT, ProteoformComparison.ExperimentalTheoretical, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(0, prList.Count);

            //Two experimental one theoretical proteoforms; lysine count equal; mass difference < 500 Da -- return 2
            ExperimentalProteoform pf3 = ConstructorsForTesting.ExperimentalProteoform("A1", 1000.0, 1, true);
            ExperimentalProteoform pf4 = ConstructorsForTesting.ExperimentalProteoform("A2", 1010.0, 1, true);
            TheoreticalProteoform  pf5 = ConstructorsForTesting.make_a_theoretical();

            pf5.modified_mass       = 1020.0;
            pf5.lysine_count        = 1;
            pf5.is_target           = true;
            pf5.ExpandedProteinList = new List <ProteinWithGoTerms> {
                p1
            };
            ExperimentalProteoform[] paE2 = new ExperimentalProteoform[2];
            paE2[0] = pf3;
            paE2[1] = pf4;
            paT[0]  = pf5;
            prepare_for_et(new List <double> {
                pf3.modified_mass - pf5.modified_mass,
                pf4.modified_mass - pf5.modified_mass,
            });
            prList = community.relate(paE2, paT, ProteoformComparison.ExperimentalTheoretical, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(2, prList.Count);

            //Two experimental one theoretical proteoforms; lysine count equal; one mass difference < 500 Da; one mass difference > 500 -- return 1
            pf3.modified_mass = 1000;
            pf3.lysine_count  = 1;
            pf4.modified_mass = 1500;
            pf4.lysine_count  = 1;
            pf5.modified_mass = 1510;
            pf5.lysine_count  = 1;
            paE2[0]           = pf3;
            paE2[1]           = pf4;
            paT[0]            = pf5;
            prepare_for_et(new List <double> {
                pf3.modified_mass - pf5.modified_mass,
                pf4.modified_mass - pf5.modified_mass,
            });
            prList = community.relate(paE2, paT, ProteoformComparison.ExperimentalTheoretical, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(1, prList.Count);

            //Two experimental one theoretical proteoforms; lysine count NOT equal; mass difference < 500 Da -- return 0
            pf3.modified_mass = 1000;
            pf3.lysine_count  = 1;
            pf4.modified_mass = 1010;
            pf4.lysine_count  = 2;
            pf5.modified_mass = 1020;
            pf5.lysine_count  = 3;
            paE2[0]           = pf3;
            paE2[1]           = pf4;
            paT[0]            = pf5;
            prepare_for_et(new List <double> {
                pf3.modified_mass - pf5.modified_mass,
                pf4.modified_mass - pf5.modified_mass,
            });
            prList = community.relate(paE2, paT, ProteoformComparison.ExperimentalTheoretical, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(0, prList.Count);

            //Two experimental one theoretical proteoforms; lysine count equal; mass difference > 500 Da -- return 0
            pf3.lysine_count  = 1;
            pf3.modified_mass = 1000;
            pf4.lysine_count  = 1;
            pf4.modified_mass = 1600;
            pf5.lysine_count  = 1;
            pf5.modified_mass = 2500;
            paE2[0]           = pf3;
            paE2[1]           = pf4;
            paT[0]            = pf5;
            prepare_for_et(new List <double> {
                pf3.modified_mass - pf5.modified_mass,
                pf4.modified_mass - pf5.modified_mass,
            });
            prList = community.relate(paE2, paT, ProteoformComparison.ExperimentalTheoretical, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(0, prList.Count);
        }
        public void get_interesting_goterm_families()
        {
            SaveState.lollipop = new Lollipop();
            DatabaseReference d1 = new DatabaseReference("GO", "GO:1", new List <Tuple <string, string> > {
                new Tuple <string, string>("term", "P:1")
            });
            DatabaseReference d2 = new DatabaseReference("GO", "GO:2", new List <Tuple <string, string> > {
                new Tuple <string, string>("term", "P:2")
            });
            DatabaseReference d3 = new DatabaseReference("GO", "GO:1", new List <Tuple <string, string> > {
                new Tuple <string, string>("term", "P:1")
            });
            GoTerm             g1 = new GoTerm(d1);
            GoTerm             g2 = new GoTerm(d2);
            GoTerm             g3 = new GoTerm(d3);
            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[] { "" }, "T2", "T3", true, false, new List <DatabaseReference> {
                d1
            }, new List <GoTerm> {
                g1
            });
            ProteinWithGoTerms p2 = new ProteinWithGoTerms("", "T2", new List <Tuple <string, string> > {
                new Tuple <string, string>("", "")
            }, new Dictionary <int, List <Modification> >(), new int?[] { 0 }, new int?[] { 0 }, new string[] { "" }, "T2", "T3", true, false, new List <DatabaseReference> {
                d2
            }, new List <GoTerm> {
                g2
            });
            ProteinWithGoTerms p3 = new ProteinWithGoTerms("", "T3", new List <Tuple <string, string> > {
                new Tuple <string, string>("", "")
            }, new Dictionary <int, List <Modification> >(), new int?[] { 0 }, new int?[] { 0 }, new string[] { "" }, "T2", "T3", true, false, new List <DatabaseReference> {
                d3
            }, new List <GoTerm> {
                g3
            });
            Dictionary <InputFile, Protein[]> dict = new Dictionary <InputFile, Protein[]>
            {
                { new InputFile("fake.txt", Purpose.ProteinDatabase), new Protein[] { p1 } },
                { new InputFile("fake.txt", Purpose.ProteinDatabase), new Protein[] { p2 } },
                { new InputFile("fake.txt", Purpose.ProteinDatabase), new Protein[] { p3 } },
            };
            ExperimentalProteoform e1 = ConstructorsForTesting.ExperimentalProteoform("E");
            ExperimentalProteoform e2 = ConstructorsForTesting.ExperimentalProteoform("E");

            e1.quant.intensitySum  = 1;
            e1.quant.FDR           = 0;
            e1.quant.logFoldChange = 1;
            e2.quant.intensitySum  = 1;
            e2.quant.FDR           = 0;
            e2.quant.logFoldChange = 1;
            TheoreticalProteoform t = ConstructorsForTesting.make_a_theoretical("T1_T1_asdf", p1, dict);
            TheoreticalProteoform u = ConstructorsForTesting.make_a_theoretical("T2_T1_asdf_asdf", p2, dict);
            TheoreticalProteoform v = ConstructorsForTesting.make_a_theoretical("T3_T1_asdf_Asdf_Asdf", p3, dict);

            t.ExpandedProteinList = new List <ProteinWithGoTerms> {
                p1
            };
            u.ExpandedProteinList = new List <ProteinWithGoTerms> {
                p2
            };
            v.ExpandedProteinList = new List <ProteinWithGoTerms> {
                p3
            };
            make_relation(e1, t);
            //make_relation(e1, v); // we don't allow this to happen anymore... we only allow one ET conntection per E
            make_relation(e2, u);
            ProteoformFamily f = new ProteoformFamily(e1); // two theoreticals with the same GoTerms... expecting one GoTerm number but two theoretical proteins (now only one)
            ProteoformFamily h = new ProteoformFamily(e2);

            f.construct_family();
            f.identify_experimentals();
            h.construct_family();
            h.identify_experimentals();
            List <ProteoformFamily> families = new List <ProteoformFamily> {
                f, h
            };

            t.family  = f;
            v.family  = f;
            e1.family = f;
            u.family  = h;
            e2.family = h;
            List <ExperimentalProteoform> fake_significant = new List <ExperimentalProteoform> {
                e1
            };
            List <ProteinWithGoTerms> significant_proteins = SaveState.lollipop.getInducedOrRepressedProteins(fake_significant, 0, 1, 0);
            List <GoTermNumber>       gtn = SaveState.lollipop.getGoTermNumbers(significant_proteins, new List <ProteinWithGoTerms> {
                p1, p2, p3
            });

            Assert.AreEqual(1, significant_proteins.Count);
            Assert.AreEqual(1, gtn.Count);
            Assert.AreEqual("1", gtn.First().Id);
            Assert.AreEqual(0 - (decimal)Math.Log(2d / 3d, 2), gtn.First().log_odds_ratio);

            List <ProteoformFamily> fams = SaveState.lollipop.getInterestingFamilies(gtn, families);

            Assert.AreEqual(1, fams.Count);
            Assert.AreEqual(1, fams[0].theoretical_proteoforms.Count);
        }
        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 void test_goterm_analysis_with_custom_list()
        {
            SaveState.lollipop = new Lollipop();
            DatabaseReference d1 = new DatabaseReference("GO", "GO:1", new List <Tuple <string, string> > {
                new Tuple <string, string>("term", "P:1")
            });
            DatabaseReference d2 = new DatabaseReference("GO", "GO:2", new List <Tuple <string, string> > {
                new Tuple <string, string>("term", "P:2")
            });
            DatabaseReference d3 = new DatabaseReference("GO", "GO:1", new List <Tuple <string, string> > {
                new Tuple <string, string>("term", "P:1")
            });
            GoTerm             g1 = new GoTerm(d1);
            GoTerm             g2 = new GoTerm(d2);
            GoTerm             g3 = new GoTerm(d3);
            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[] { "" }, "T2", "T3", true, false, new List <DatabaseReference> {
                d1
            }, new List <GoTerm> {
                g1
            });
            ProteinWithGoTerms p2 = new ProteinWithGoTerms("", "T2", new List <Tuple <string, string> > {
                new Tuple <string, string>("", "")
            }, new Dictionary <int, List <Modification> >(), new int?[] { 0 }, new int?[] { 0 }, new string[] { "" }, "T2", "T3", true, false, new List <DatabaseReference> {
                d2
            }, new List <GoTerm> {
                g2
            });
            ProteinWithGoTerms p3 = new ProteinWithGoTerms("", "T3", new List <Tuple <string, string> > {
                new Tuple <string, string>("", "")
            }, new Dictionary <int, List <Modification> >(), new int?[] { 0 }, new int?[] { 0 }, new string[] { "" }, "T2", "T3", true, false, new List <DatabaseReference> {
                d3
            }, new List <GoTerm> {
                g3
            });
            Dictionary <InputFile, Protein[]> dict = new Dictionary <InputFile, Protein[]> {
                { new InputFile("fake.txt", Purpose.ProteinDatabase), new Protein[] { p1 } },
                { new InputFile("fake.txt", Purpose.ProteinDatabase), new Protein[] { p2 } },
                { new InputFile("fake.txt", Purpose.ProteinDatabase), new Protein[] { p3 } },
            };
            ExperimentalProteoform e1 = ConstructorsForTesting.ExperimentalProteoform("E");
            ExperimentalProteoform e2 = ConstructorsForTesting.ExperimentalProteoform("E");

            e1.quant.intensitySum  = 1;
            e1.quant.FDR           = 0;
            e1.quant.logFoldChange = 1;
            e2.quant.intensitySum  = 1;
            e2.quant.FDR           = 0;
            e2.quant.logFoldChange = 1;
            TheoreticalProteoform t = ConstructorsForTesting.make_a_theoretical("T1_T1_asdf", p1, dict);
            TheoreticalProteoform u = ConstructorsForTesting.make_a_theoretical("T2_T1_asdf_asdf", p2, dict);
            TheoreticalProteoform v = ConstructorsForTesting.make_a_theoretical("T3_T1_asdf_Asdf_Asdf", p3, dict);

            t.ExpandedProteinList = new List <ProteinWithGoTerms> {
                p1
            };
            u.ExpandedProteinList = new List <ProteinWithGoTerms> {
                p2
            };
            v.ExpandedProteinList = new List <ProteinWithGoTerms> {
                p3
            };
            make_relation(e1, t);
            make_relation(e1, v);
            make_relation(e2, u);
            ProteoformFamily f = new ProteoformFamily(e1); // two theoreticals with the same GoTerms... expecting one GoTerm number but two theoretical proteins
            ProteoformFamily h = new ProteoformFamily(e2);

            f.construct_family();
            f.identify_experimentals();
            h.construct_family();
            h.identify_experimentals();
            List <ProteoformFamily> families = new List <ProteoformFamily> {
                f, h
            };

            t.family  = f;
            v.family  = f;
            e1.family = f;
            u.family  = h;
            e2.family = h;
            SaveState.lollipop.inducedOrRepressedProteins = SaveState.lollipop.getInducedOrRepressedProteins(new List <ExperimentalProteoform> {
                e1
            }, 0, 1, 0);
            SaveState.lollipop.allTheoreticalProteins = true;
            SaveState.lollipop.theoretical_database.expanded_proteins = new ProteinWithGoTerms[] { p1, p2, p3 };
            SaveState.lollipop.backgroundProteinsList = Path.Combine(TestContext.CurrentContext.TestDirectory, "test_protein_list.txt");
            SaveState.lollipop.GO_analysis();
            Assert.AreEqual(1, SaveState.lollipop.inducedOrRepressedProteins.Count);  // only taking one ET connection by definition in forming ET relations; only one is used in identify theoreticals
            Assert.AreEqual(1, SaveState.lollipop.goTermNumbers.Count);
            Assert.AreEqual("1", SaveState.lollipop.goTermNumbers.First().Id);
            Assert.AreEqual(0 - (decimal)Math.Log(2d / 3d, 2), SaveState.lollipop.goTermNumbers.First().log_odds_ratio);

            List <ProteoformFamily> fams = SaveState.lollipop.getInterestingFamilies(SaveState.lollipop.goTermNumbers, families);

            Assert.AreEqual(1, fams.Count);
            Assert.AreEqual(2, fams[0].theoretical_proteoforms.Count);
        }
        public void shift_et_peak_unlabeled()
        {
            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(200);
            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, false);

            Assert.IsTrue(pf3.mass_shifted);
            Assert.IsTrue(pf4.mass_shifted);
            foreach (Component c in n3.Concat(n4))
            {
                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()
        {
            SaveState.lollipop.enter_input_files(new string[] { Path.Combine(TestContext.CurrentContext.TestDirectory, "ptmlist.txt") }, Lollipop.acceptable_extensions[2], Lollipop.file_types[2], SaveState.lollipop.input_files);
            ConstructorsForTesting.read_mods();
            SaveState.lollipop.et_high_mass_difference = 250;
            SaveState.lollipop.et_low_mass_difference  = -250;
            SaveState.lollipop.peak_width_base_ee      = 0.015;
            SaveState.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, 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
        }
示例#9
0
        public void TestCorrectTopDownID()
        {
            TopDownProteoform td = ConstructorsForTesting.TopDownProteoform("TD1", 1000, 40);

            //linked reference null - should be false
            td.set_correct_id();
            Assert.IsFalse(td.correct_id);
            TheoreticalProteoform t = ConstructorsForTesting.make_a_theoretical();

            t.ExpandedProteinList.First().AccessionList.Add("TD1");
            td.linked_proteoform_references = new List <Proteoform>()
            {
                t
            };
            //no PTMs diff begin fail
            td.begin           = 10;
            td.topdown_begin   = 10;
            td.end             = 20;
            td.topdown_end     = 30;
            td.ptm_set         = new PtmSet(new List <Ptm>());
            td.topdown_ptm_set = new PtmSet(new List <Ptm>());
            td.set_correct_id();
            Assert.IsFalse(td.correct_id);
            //no PTMs diff end fail
            td.begin         = 10;
            td.topdown_begin = 20;
            td.end           = 30;
            td.topdown_end   = 30;
            td.set_correct_id();
            Assert.IsFalse(td.correct_id);
            //no PTMs same pass
            td.begin         = 10;
            td.topdown_begin = 10;
            td.end           = 30;
            td.topdown_end   = 30;
            td.set_correct_id();
            Assert.IsTrue(td.correct_id);
            //same begin and end, T has more PTMs
            ModificationMotif motif;

            ModificationMotif.TryGetMotif("K", out motif);
            td.ptm_set = new PtmSet(new List <Ptm>()
            {
                new Ptm(15, new Modification("Acetylation", _modificationType: "type", _target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 42.02))
            });
            td.set_correct_id();
            Assert.IsFalse(td.correct_id);
            //same begin and end TD has more of a PTM type
            td.ptm_set         = new PtmSet(new List <Ptm>());
            td.topdown_ptm_set = new PtmSet(new List <Ptm>()
            {
                new Ptm(15, new Modification("Acetylation", _modificationType: "type", _target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 42.02))
            });
            td.set_correct_id();
            Assert.IsFalse(td.correct_id);
            //same begin and end and PTMs
            td.ptm_set = new PtmSet(new List <Ptm>()
            {
                new Ptm(15, new Modification("Acetylation", _modificationType: "type", _target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 42.02))
            });
            td.topdown_ptm_set = new PtmSet(new List <Ptm>()
            {
                new Ptm(15, new Modification("Acetylation", _modificationType: "type", _target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 42.02))
            });
            td.set_correct_id();
            Assert.IsTrue(td.correct_id);
        }
示例#10
0
        public void TestRelateTD()
        {
            Sweet.lollipop = new Lollipop();
            Sweet.lollipop.neucode_labeled                = false;
            Sweet.lollipop.maximum_missed_monos           = 1;
            Sweet.lollipop.agg_minBiorepsWithObservations = 0;
            InputFile f = new InputFile("path", Purpose.Identification);

            Sweet.lollipop.input_files.Add(f);
            // Two proteoforms; lysine count equal; mass difference < 250 -- return 1
            Component c1 = new Component();

            c1.weighted_monoisotopic_mass = 1000.0;
            c1.rt_apex       = 45;
            c1.accepted      = true;
            c1.id            = 1.ToString();
            c1.intensity_sum = 1e6;
            c1.input_file    = f;
            c1.charge_states = new List <ChargeState>()
            {
                new ChargeState(1, c1.intensity_sum, c1.weighted_monoisotopic_mass)
            };
            Component c2 = new Component();

            c2.weighted_monoisotopic_mass = 1000.0;
            c2.rt_apex       = 85;
            c2.accepted      = true;
            c2.input_file    = f;
            c2.intensity_sum = 1e6;
            c2.charge_states = new List <ChargeState>()
            {
                new ChargeState(1, c2.intensity_sum, c2.weighted_monoisotopic_mass)
            };
            c2.id = 2.ToString();
            Component c3 = new Component();

            c3.weighted_monoisotopic_mass = 1131.04;
            c3.rt_apex       = 45;
            c3.accepted      = true;
            c3.input_file    = f;
            c3.intensity_sum = 1e6;
            c3.charge_states = new List <ChargeState>()
            {
                new ChargeState(1, c3.intensity_sum, c3.weighted_monoisotopic_mass)
            };
            c3.id = 3.ToString();
            Component c4 = new Component();

            c4.weighted_monoisotopic_mass = 2000.00;
            c4.rt_apex       = 45;
            c4.accepted      = true;
            c4.input_file    = new InputFile("path", Purpose.Identification);
            c4.intensity_sum = 1e6;
            c4.charge_states = new List <ChargeState>()
            {
                new ChargeState(1, c4.intensity_sum, c4.weighted_monoisotopic_mass)
            };
            c4.id = 4.ToString();
            Component c5 = new Component();

            c5.weighted_monoisotopic_mass = 1001.0;
            c5.rt_apex       = 45;
            c5.accepted      = true;
            c5.input_file    = f;
            c5.intensity_sum = 1e6;
            c5.charge_states = new List <ChargeState>()
            {
                new ChargeState(1, c5.intensity_sum, c5.weighted_monoisotopic_mass)
            };
            c5.id = 2.ToString();
            List <IAggregatable> components = new List <IAggregatable>()
            {
                c1, c2, c3, c4, c5
            };

            Sweet.lollipop.raw_experimental_components = components.OfType <Component>().ToList();

            TopDownProteoform td1 = ConstructorsForTesting.TopDownProteoform("ACCESSION_1", 1000.0, 45);
            TopDownProteoform td2 = ConstructorsForTesting.TopDownProteoform("ACCESSION_2", 1001.0, 85);
            TopDownProteoform td3 = ConstructorsForTesting.TopDownProteoform("ACCESSION_3", 1131.04, 45);

            TheoreticalProteoform t1 = ConstructorsForTesting.make_a_theoretical("ACCESSION", 1000.0, 1);

            //need to make theoretical accession database
            TestProteoformCommunityRelate.prepare_for_et(new List <double>()
            {
                0
            });
            Sweet.lollipop.target_proteoform_community.community_number   = -100;
            Sweet.lollipop.theoretical_database.theoreticals_by_accession = new Dictionary <int, Dictionary <string, List <TheoreticalProteoform> > >();
            Sweet.lollipop.theoretical_database.theoreticals_by_accession.Add(-100, new Dictionary <string, List <TheoreticalProteoform> >());
            Sweet.lollipop.theoretical_database.theoreticals_by_accession[-100].Add(t1.accession, new List <TheoreticalProteoform>()
            {
                t1
            });

            //need to make decon error top "deconvolution error"
            ModificationMotif motif;

            ModificationMotif.TryGetMotif("S", out motif);
            Modification m = new Modification("id", _modificationType: "modtype", _target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 1);

            Sweet.lollipop.theoretical_database.all_mods_with_mass.Add(m);
            PtmSet set = new PtmSet(new List <Ptm> {
                new Ptm(-1, m)
            });

            Sweet.lollipop.theoretical_database.all_possible_ptmsets.Add(set);
            Sweet.lollipop.modification_ranks.Add(-1.0023, 2);
            Sweet.lollipop.theoretical_database.possible_ptmset_dictionary.Add(-1.0, new List <PtmSet>()
            {
                set
            });

            //need missing error
            Modification m2 = new Modification("id", _modificationType: "modtype", _target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 1);

            Sweet.lollipop.theoretical_database.all_mods_with_mass.Add(m2);
            PtmSet set2 = new PtmSet(new List <Ptm> {
                new Ptm(-1, m2)
            });

            Sweet.lollipop.theoretical_database.all_possible_ptmsets.Add(set2);
            Sweet.lollipop.modification_ranks.Add(-87.03, 2);
            Sweet.lollipop.theoretical_database.possible_ptmset_dictionary.Add(-87.0, new List <PtmSet>()
            {
                set2
            });

            Sweet.lollipop.target_proteoform_community.theoretical_proteoforms = new List <TheoreticalProteoform>()
            {
                t1
            }.ToArray();
            Sweet.lollipop.topdown_proteoforms = new List <TopDownProteoform> {
                td1, td2, td3
            };
            Sweet.lollipop.add_td_proteoforms = true;
            Sweet.lollipop.aggregate_proteoforms(Sweet.lollipop.validate_proteoforms, Sweet.lollipop.raw_neucode_pairs, Sweet.lollipop.raw_experimental_components, Sweet.lollipop.raw_quantification_components, 0);
            List <ProteoformRelation> relations = Sweet.lollipop.target_proteoform_community.relate(Sweet.lollipop.target_proteoform_community.experimental_proteoforms, Sweet.lollipop.target_proteoform_community.theoretical_proteoforms, ProteoformComparison.ExperimentalTheoretical, true, Environment.CurrentDirectory, true);
            List <DeltaMassPeak>      peaks     = Sweet.lollipop.target_proteoform_community.accept_deltaMass_peaks(relations, new Dictionary <string, List <ProteoformRelation> >());

            //should have 4 experimental proteoforms -- 3 topdown, 1 not topdown experimental
            Assert.AreEqual(3, Sweet.lollipop.target_proteoform_community.experimental_proteoforms.Count(e => e.topdown_id));
            Assert.AreEqual(4, Sweet.lollipop.target_proteoform_community.experimental_proteoforms.Count());
            Assert.AreEqual(1, relations.Count);
            Assert.AreEqual(1, relations.Count(r => r.RelationType == ProteoformComparison.ExperimentalTheoretical && (r.connected_proteoforms[0] as ExperimentalProteoform).topdown_id));
            Assert.AreEqual(1, td1.relationships.Count(r => r.RelationType == ProteoformComparison.ExperimentalTheoretical && (r.connected_proteoforms[0] as ExperimentalProteoform).topdown_id));
            Assert.AreEqual(0, td2.relationships.Count());
            Assert.AreEqual(0, td3.relationships.Count());

            //accession 3 has higher score... gets td
            Sweet.lollipop.clear_td();
            td3 = ConstructorsForTesting.TopDownProteoform("ACCESSION_3", 1000.0, 45);
            TopDownHit h3 = new TopDownHit();

            h3.score         = 100;
            td3.topdown_hits = new List <TopDownHit>()
            {
                h3
            };
            TopDownHit h4 = new TopDownHit();

            h4.score = 1;
            TopDownProteoform td4 = ConstructorsForTesting.TopDownProteoform("ACCESSION_4", 1001.0, 45);

            td4.topdown_hits = new List <TopDownHit>()
            {
                h4
            };
            Sweet.lollipop.topdown_proteoforms = new List <TopDownProteoform> {
                td4, td3
            };
            Sweet.lollipop.topdown_proteoforms.OrderBy(p => p.modified_mass);
            Sweet.lollipop.aggregate_proteoforms(Sweet.lollipop.validate_proteoforms, Sweet.lollipop.raw_neucode_pairs, Sweet.lollipop.raw_experimental_components, Sweet.lollipop.raw_quantification_components, 0);
            Assert.AreEqual(0, Math.Round(td3.modified_mass - td3.matching_experimental.modified_mass, 0));
            Assert.IsNull(td4.matching_experimental);
        }