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());
        }
Ejemplo n.º 2
0
        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
        }
Ejemplo n.º 3
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);
        }