public static TheoreticalProteoform make_a_theoretical(string a, double mass, int lysine_count)
        {
            ModificationMotif motif;

            ModificationMotif.TryGetMotif("X", out motif);
            Modification       unmodification = new Modification("Unmodified", _target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 0);
            ProteinWithGoTerms p1             = new ProteinWithGoTerms("MSSSSSSSSSSS", "T1", new List <Tuple <string, string> > {
                new Tuple <string, string>("", "")
            }, new Dictionary <int, List <Modification> > {
                { 0, new List <Modification> {
                      unmodification
                  } }
            }, new List <ProteolysisProduct> {
                new ProteolysisProduct(1, 12, "")
            }, "T2", "T3", true, false, new List <DatabaseReference> {
                new DatabaseReference("GO", ":", new List <Tuple <string, string> > {
                    new Tuple <string, string>("term", "P:")
                })
            }, new List <GoTerm> {
                new GoTerm(new DatabaseReference("GO", ":", new List <Tuple <string, string> > {
                    new Tuple <string, string>("term", "P:")
                }))
            });
            PtmSet set = new PtmSet(new List <Ptm> {
                new Ptm()
            });
            var t = new TheoreticalProteoform(a, "", p1.BaseSequence, new List <ProteinWithGoTerms> {
                p1
            }, mass, lysine_count, set, true, false, new Dictionary <InputFile, Protein[]>());

            t.modified_mass = mass;
            return(t);
        }
        public void TestProteoformCommunityRelate_ED()
        {
            SaveState.lollipop = new Lollipop();
            SaveState.lollipop.decoy_databases = 1;
            // In empty comminity, relate ed is empty
            Assert.AreEqual(0, SaveState.lollipop.ed_relations.Count);

            //create a decoy proteoform community
            SaveState.lollipop.decoy_proteoform_communities.Add(SaveState.lollipop.decoy_community_name_prefix + "0", new ProteoformCommunity());
            TheoreticalProteoform pf2 = ConstructorsForTesting.make_a_theoretical("decoyProteoform1", 0, -1);

            SaveState.lollipop.decoy_proteoform_communities[SaveState.lollipop.decoy_community_name_prefix + "0"].theoretical_proteoforms = new TheoreticalProteoform[1] {
                pf2
            };
            SaveState.lollipop.relate_ed();
            // Have a single decoy community --> have single ed_relations
            Assert.AreEqual(1, SaveState.lollipop.ed_relations.Count);
            // But it's empty
            Assert.IsEmpty(SaveState.lollipop.ed_relations[SaveState.lollipop.decoy_community_name_prefix + "0"]);

            // In order to make it not empty, we must have relate_et method output a non-empty List
            // it must take as arguments non-empty pfs1 and pfs2
            // So testProteoformCommunity.experimental_proteoforms must be non-empty
            // And decoy_proteoforms["fake_decoy_proteoform1"] must be non-empty
            ExperimentalProteoform pf1 = ConstructorsForTesting.ExperimentalProteoform("experimentalProteoform1");

            SaveState.lollipop.decoy_proteoform_communities[SaveState.lollipop.decoy_community_name_prefix + "0"].theoretical_proteoforms.First().ExpandedProteinList = new List <ProteinWithGoTerms> {
                p1
            };

            Assert.IsEmpty(SaveState.lollipop.decoy_proteoform_communities[SaveState.lollipop.decoy_community_name_prefix + "0"].experimental_proteoforms);
            SaveState.lollipop.decoy_proteoform_communities[SaveState.lollipop.decoy_community_name_prefix + "0"].experimental_proteoforms = new ExperimentalProteoform[] { pf1 };

            SaveState.lollipop.clear_et();
            prepare_for_et(new List <double> {
                pf1.modified_mass - pf2.modified_mass
            });
            SaveState.lollipop.relate_ed();

            // Make sure there is one relation total, because only a single decoy was provided
            Assert.AreEqual(1, SaveState.lollipop.ed_relations.Count);
            Assert.IsNotEmpty(SaveState.lollipop.ed_relations);
            Assert.AreEqual(1, SaveState.lollipop.ed_relations[SaveState.lollipop.decoy_community_name_prefix + "0"].Count); // Make sure there is one relation for the provided fake_decoy_proteoform1

            ProteoformRelation rel = SaveState.lollipop.ed_relations[SaveState.lollipop.decoy_community_name_prefix + "0"][0];

            Assert.IsFalse(rel.Accepted);
            Assert.AreEqual("decoyProteoform1", rel.connected_proteoforms[1].accession);
            Assert.AreEqual(0, rel.DeltaMass);
            Assert.IsEmpty(((TheoreticalProteoform)rel.connected_proteoforms[1]).fragment);
            Assert.AreEqual(1, rel.nearby_relations_count);  //shows that calculate_unadjusted_group_count works
            //Assert.AreEqual(1, rel.mass_difference_group.Count);  //I don't think we need this test anymore w/ way peaks are made -LVS
            Assert.AreEqual(-1, rel.lysine_count);
            Assert.AreEqual("T2", ((TheoreticalProteoform)rel.connected_proteoforms[1]).name);
            Assert.AreEqual(0, ((ExperimentalProteoform)rel.connected_proteoforms[0]).aggregated_components.Count); //nothing aggregated with the basic constructor
            Assert.IsTrue(rel.outside_no_mans_land);
            Assert.IsNull(rel.peak);
            Assert.True(string.Equals("unmodified", ((TheoreticalProteoform)rel.connected_proteoforms[1]).ptm_description, StringComparison.CurrentCultureIgnoreCase));
            Assert.AreEqual(1, rel.nearby_relations_count);
        }
示例#3
0
        public void test_write_families_regular_display()
        {
            TheoreticalProteoform  t  = ConstructorsForTesting.make_a_theoretical();
            ExperimentalProteoform e  = ConstructorsForTesting.ExperimentalProteoform("E1");
            ProteoformRelation     et = new ProteoformRelation(e, t, ProteoformComparison.ExperimentalTheoretical, 0, TestContext.CurrentContext.TestDirectory);

            et.peak = new DeltaMassPeak(et, new HashSet <ProteoformRelation> {
                et
            });
            et.peak.Accepted = true;
            e.relationships.Add(et);
            t.relationships.Add(et);
            e.agg_intensity = 999.99;
            e.quant.TusherValues1.numeratorIntensitySum   = 444.44m;
            e.quant.TusherValues1.denominatorIntensitySum = 333.33m;
            e.quant.intensitySum = 777.77m;
            List <ProteoformFamily> f = new List <ProteoformFamily> {
                new ProteoformFamily(e)
            };

            f.First().construct_family();
            string message = CytoscapeScript.write_cytoscape_script(f, f,
                                                                    TestContext.CurrentContext.TestDirectory, "", "test",
                                                                    null, false, false,
                                                                    CytoscapeScript.color_scheme_names[0], Lollipop.edge_labels[0], Lollipop.node_labels[0], CytoscapeScript.node_label_positions[0], Lollipop.node_positioning[0], 2,
                                                                    false, Lollipop.gene_name_labels[1]);

            Assert.True(File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, CytoscapeScript.script_file_prefix + "test" + CytoscapeScript.script_file_extension)));
            Assert.True(File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, CytoscapeScript.style_file_prefix + "test" + CytoscapeScript.style_file_extension)));
            Assert.True(File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, CytoscapeScript.node_file_prefix + "test" + CytoscapeScript.node_file_extension)));
            Assert.True(File.Exists(Path.Combine(TestContext.CurrentContext.TestDirectory, CytoscapeScript.edge_file_prefix + "test" + CytoscapeScript.edge_file_extension)));

            //Check that the style xml is all there
            List <string> vizProperties = new List <string>();

            using (XmlReader xml = XmlReader.Create(Path.Combine(TestContext.CurrentContext.TestDirectory, CytoscapeScript.style_file_prefix + "test" + CytoscapeScript.style_file_extension)))
            {
                while (xml.Read())
                {
                    switch (xml.NodeType)
                    {
                    case XmlNodeType.Element:
                        if (xml.Name == "visualProperty")
                        {
                            vizProperties.Add(xml.GetAttribute("name"));
                        }
                        break;
                    }
                }
            }
            Assert.AreEqual(CytoscapeScript.default_styles.Keys.Where(s => s.StartsWith("NETWORK")).Count(), vizProperties.Where(s => s.StartsWith("NETWORK")).Count());
            Assert.AreEqual(CytoscapeScript.default_styles.Keys.Where(s => s.StartsWith("NODE")).Count(), vizProperties.Where(s => s.StartsWith("NODE")).Count());
            Assert.AreEqual(CytoscapeScript.default_styles.Keys.Where(s => s.StartsWith("EDGE")).Count(), vizProperties.Where(s => s.StartsWith("EDGE")).Count());
            Assert.AreEqual(CytoscapeScript.default_styles.Keys.Where(s => !s.StartsWith("NETWORK") && !s.StartsWith("NODE") && !s.StartsWith("EDGE")).Count(), vizProperties.Where(s => !s.StartsWith("NETWORK") && !s.StartsWith("NODE") && !s.StartsWith("EDGE")).Count());
            Assert.AreEqual(CytoscapeScript.default_styles.Keys.Count, vizProperties.Count);
            Assert.True(message.StartsWith("Finished"));
        }
        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_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);
        }
        //MAKE THEORETICAL
        public static TheoreticalProteoform make_a_theoretical(string a, ProteinWithGoTerms p, Dictionary <InputFile, Protein[]> dict)
        {
            ModificationMotif motif;

            ModificationMotif.TryGetMotif("X", out motif);
            PtmSet set = new PtmSet(p.OneBasedPossibleLocalizedModifications.SelectMany(m => m.Value.SelectMany(mmm => new List <Ptm> {
                new Ptm(0, mmm)
            })).ToList());
            TheoreticalProteoform t = new TheoreticalProteoform(a, "", p.BaseSequence, new List <ProteinWithGoTerms> {
                p
            }, 100, 0, set, true, true, dict);

            t.begin = 1;
            t.end   = 4;
            return(t);
        }
示例#7
0
        public void test_contaminant_check()
        {
            InputFile f = new InputFile("fake.txt", Purpose.ProteinDatabase);

            f.ContaminantDB = true;
            InputFile          g  = new InputFile("fake.txt", Purpose.ProteinDatabase);
            InputFile          h  = 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 List <ProteolysisProduct> {
                new ProteolysisProduct(0, 0, "")
            }, "T2", "T3", true, false, new List <DatabaseReference>(), new List <GoTerm>());
            ProteinWithGoTerms p2 = new ProteinWithGoTerms("", "T2", new List <Tuple <string, string> > {
                new Tuple <string, string>("", "")
            }, new Dictionary <int, List <Modification> >(), new List <ProteolysisProduct> {
                new ProteolysisProduct(0, 0, "")
            }, "T2", "T3", true, false, new List <DatabaseReference>(), new List <GoTerm>());
            ProteinWithGoTerms p3 = new ProteinWithGoTerms("", "T3", new List <Tuple <string, string> > {
                new Tuple <string, string>("", "")
            }, new Dictionary <int, List <Modification> >(), new List <ProteolysisProduct> {
                new ProteolysisProduct(0, 0, "")
            }, "T2", "T3", true, false, new List <DatabaseReference>(), new List <GoTerm>());
            Dictionary <InputFile, Protein[]> dict = new Dictionary <InputFile, Protein[]> {
                { f, new Protein[] { p1 } },
                { g, new Protein[] { p2 } },
                { h, new Protein[] { p3 } },
            };
            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);
            TheoreticalProteoform w = new TheoreticalProteoformGroup(new List <TheoreticalProteoform> {
                v, u, t
            }.OrderByDescending(theo => theo.contaminant ? 1 : 0));

            Assert.True(w.contaminant);
            Assert.True(w.accession.Contains(p1.Accession));

            //Not contaminant
            TheoreticalProteoform x = new TheoreticalProteoformGroup(new List <TheoreticalProteoform> {
                v, u
            });

            Assert.False(x.contaminant);

            //PTM mass test
            Assert.AreEqual(0, t.ptm_mass);
        }
示例#8
0
        public void TestUnabeledProteoformCommunityRelateLargePeakBase_ET()
        {
            Sweet.lollipop.neucode_labeled    = false;
            Sweet.lollipop.et_use_notch       = false;
            Sweet.lollipop.peak_width_base_et = 1;

            // 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 - .9
            });
            prList = community.relate(paE, paT, ProteoformComparison.ExperimentalTheoretical, true,
                                      TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(1, prList.Count);

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

            prepare_for_et(new List <double> {
                pf1.modified_mass - pf2.modified_mass + 1
            });
            prList = community.relate(paE, paT, ProteoformComparison.ExperimentalTheoretical, true,
                                      TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(0, prList.Count);
        }
示例#9
0
        public void cytoscape_improper_build_folder()
        {
            TheoreticalProteoform  t  = ConstructorsForTesting.make_a_theoretical();
            ExperimentalProteoform e  = ConstructorsForTesting.ExperimentalProteoform("E1");
            ProteoformRelation     et = new ProteoformRelation(e, t, ProteoformComparison.ExperimentalTheoretical, 0, TestContext.CurrentContext.TestDirectory);

            e.agg_intensity = 999.99;
            e.quant.TusherValues1.numeratorIntensitySum   = 444.44m;
            e.quant.TusherValues1.denominatorIntensitySum = 333.33m;
            e.quant.intensitySum = 777.77m;
            List <ProteoformFamily> f = new List <ProteoformFamily> {
                new ProteoformFamily(e)
            };

            f.First().construct_family();
            string message = CytoscapeScript.write_cytoscape_script(f, f,
                                                                    "", "", "test",
                                                                    null, false, false,
                                                                    CytoscapeScript.color_scheme_names[0], Lollipop.edge_labels[0], Lollipop.node_labels[0], CytoscapeScript.node_label_positions[0], Lollipop.node_positioning[0], 2,
                                                                    false, Lollipop.gene_name_labels[1]);

            Assert.False(message.StartsWith("Finished"));
        }
示例#10
0
 public DisplayTheoreticalProteoform(TheoreticalProteoform t)
     : base(t)
 {
     this.t = t;
 }
示例#11
0
        public void get_interesting_goterm_families()
        {
            Sweet.lollipop = new Lollipop();
            Sweet.lollipop.theoretical_database.aaIsotopeMassList = new AminoAcidMasses(Sweet.lollipop.carbamidomethylation, Sweet.lollipop.neucode_labeled).AA_Masses;
            Sweet.lollipop.significance_by_permutation            = true;
            Sweet.lollipop.significance_by_log2FC = false;
            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("ASDF", "T1", new List <Tuple <string, string> > {
                new Tuple <string, string>("", "")
            }, new Dictionary <int, List <Modification> >(), new List <ProteolysisProduct> {
                new ProteolysisProduct(0, 0, "")
            }, "T2", "T3", true, false, new List <DatabaseReference> {
                d1
            }, new List <GoTerm> {
                g1
            });
            ProteinWithGoTerms p2 = new ProteinWithGoTerms("ASDF", "T2", new List <Tuple <string, string> > {
                new Tuple <string, string>("", "")
            }, new Dictionary <int, List <Modification> >(), new List <ProteolysisProduct> {
                new ProteolysisProduct(0, 0, "")
            }, "T2", "T3", true, false, new List <DatabaseReference> {
                d2
            }, new List <GoTerm> {
                g2
            });
            ProteinWithGoTerms p3 = new ProteinWithGoTerms("ASDF", "T3", new List <Tuple <string, string> > {
                new Tuple <string, string>("", "")
            }, new Dictionary <int, List <Modification> >(), new List <ProteolysisProduct> {
                new ProteolysisProduct(0, 0, "")
            }, "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.TusherValues1.significant = true;
            e1.quant.tusherlogFoldChange       = 1;
            e2.quant.intensitySum = 1;
            e2.quant.TusherValues1.significant = true;
            e2.quant.tusherlogFoldChange       = 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
            };
            t.begin = 1;
            t.end   = 1;
            u.begin = 1;
            u.end   = 1;
            v.begin = 1;
            v.end   = 1;
            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 = Sweet.lollipop.getInducedOrRepressedProteins(fake_significant, Sweet.lollipop.TusherAnalysis1.GoAnalysis);
            List <GoTermNumber>       gtn = Sweet.lollipop.TusherAnalysis1.GoAnalysis.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 = Sweet.lollipop.getInterestingFamilies(gtn, families);

            Assert.AreEqual(1, fams.Count);
            Assert.AreEqual(1, fams[0].theoretical_proteoforms.Count);
        }
示例#12
0
        public void test_goterm_analysis_with_custom_list()
        {
            Sweet.lollipop = new Lollipop();
            Sweet.lollipop.theoretical_database.aaIsotopeMassList = new AminoAcidMasses(Sweet.lollipop.carbamidomethylation, Sweet.lollipop.neucode_labeled).AA_Masses;
            Sweet.lollipop.significance_by_permutation            = true;
            Sweet.lollipop.significance_by_log2FC = false;
            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("ASDF", "T1", new List <Tuple <string, string> > {
                new Tuple <string, string>("", "")
            }, new Dictionary <int, List <Modification> >(), new List <ProteolysisProduct> {
                new ProteolysisProduct(0, 0, "")
            }, "T2", "T3", true, false, new List <DatabaseReference> {
                d1
            }, new List <GoTerm> {
                g1
            });
            ProteinWithGoTerms p2 = new ProteinWithGoTerms("ASDF", "T2", new List <Tuple <string, string> > {
                new Tuple <string, string>("", "")
            }, new Dictionary <int, List <Modification> >(), new List <ProteolysisProduct> {
                new ProteolysisProduct(0, 0, "")
            }, "T2", "T3", true, false, new List <DatabaseReference> {
                d2
            }, new List <GoTerm> {
                g2
            });
            ProteinWithGoTerms p3 = new ProteinWithGoTerms("ASDF", "T3", new List <Tuple <string, string> > {
                new Tuple <string, string>("", "")
            }, new Dictionary <int, List <Modification> >(), new List <ProteolysisProduct> {
                new ProteolysisProduct(0, 0, "")
            }, "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.TusherValues1.significant = true;
            e1.quant.tusherlogFoldChange       = 1;
            e2.quant.intensitySum = 1;
            e2.quant.TusherValues1.significant = true;
            e2.quant.tusherlogFoldChange       = 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;
            Sweet.lollipop.TusherAnalysis1.inducedOrRepressedProteins = Sweet.lollipop.getInducedOrRepressedProteins(new List <ExperimentalProteoform> {
                e1
            }, Sweet.lollipop.TusherAnalysis1.GoAnalysis);
            Sweet.lollipop.TusherAnalysis1.GoAnalysis.allTheoreticalProteins = true;
            Sweet.lollipop.theoretical_database.expanded_proteins            = new ProteinWithGoTerms[] { p1, p2, p3 };
            Sweet.lollipop.TusherAnalysis1.GoAnalysis.backgroundProteinsList = Path.Combine(TestContext.CurrentContext.TestDirectory, "test_protein_list.txt");
            Sweet.lollipop.TusherAnalysis1.GoAnalysis.GO_analysis(Sweet.lollipop.TusherAnalysis1.inducedOrRepressedProteins);
            Assert.AreEqual(1, Sweet.lollipop.TusherAnalysis1.inducedOrRepressedProteins.Count);  // only taking one ET connection by definition in forming ET relations; only one is used in identify theoreticals
            Assert.AreEqual(1, Sweet.lollipop.TusherAnalysis1.GoAnalysis.goTermNumbers.Count);
            Assert.AreEqual("1", Sweet.lollipop.TusherAnalysis1.GoAnalysis.goTermNumbers.First().Id);
            Assert.AreEqual(0 - (decimal)Math.Log(2d / 3d, 2), Sweet.lollipop.TusherAnalysis1.GoAnalysis.goTermNumbers.First().log_odds_ratio);

            List <ProteoformFamily> fams = Sweet.lollipop.getInterestingFamilies(Sweet.lollipop.TusherAnalysis1.GoAnalysis.goTermNumbers, families);

            Assert.AreEqual(1, fams.Count);
            Assert.AreEqual(2, fams[0].theoretical_proteoforms.Count);
        }
示例#13
0
 private void btn_compare_with_td_Click(object sender, RoutedEventArgs e)
 {
     MessageBox.Show("Please select a top-down results file.");
     System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
     openFileDialog.Title       = "Top-Down Results";
     openFileDialog.Filter      = "Excel Files (*.xlsx) | *.xlsx";
     openFileDialog.Multiselect = false;
     System.Windows.Forms.DialogResult dr = openFileDialog.ShowDialog();
     if (dr == System.Windows.Forms.DialogResult.OK)
     {
         MessageBox.Show("Save comparison results file.");
         System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();
         saveFileDialog.Title  = "Top-Down Comparison Results";
         saveFileDialog.Filter = "Text Files (*.tsv) | *.tsv";
         System.Windows.Forms.DialogResult sdr = saveFileDialog.ShowDialog();
         if (sdr == System.Windows.Forms.DialogResult.OK)
         {
             InputFile                     file           = new InputFile(openFileDialog.FileName, Purpose.TopDown);
             TopDownReader                 reader         = new TopDownReader();
             List <TopDownHit>             hits           = reader.ReadTDFile(file);
             List <TopDownProteoform>      td_proteoforms = Sweet.lollipop.aggregate_td_hits(hits, 0, true, true);
             List <ExperimentalProteoform> experimentals  = Sweet.lollipop.target_proteoform_community.experimental_proteoforms.Where(p => p.linked_proteoform_references != null && (Sweet.lollipop.count_adducts_as_identifications || !p.adduct) && !p.topdown_id).ToList();
             experimentals = Sweet.lollipop.add_topdown_proteoforms(experimentals, td_proteoforms);
             using (var writer = new System.IO.StreamWriter(saveFileDialog.FileName))
             {
                 writer.WriteLine("Experimental Accession\tExperimental Mass\tExperimental Retention Time\tTheoretical Accession\tTheoretical Description\tTheoretical Begin\tTheoretical End\tTheoretical PTM Description\tTop-Down Accession\tTop-Down Begin\tTop-Down End\tTop-Down PTM Description\tTop-Down Observed Mass\tTop-Down Retention Time\tTop Top-Down C-Score");
                 foreach (ExperimentalProteoform ep in experimentals)
                 {
                     if (ep.topdown_id)
                     {
                         TopDownProteoform tdp = ep as TopDownProteoform;
                         if (tdp.matching_experimental != null)
                         {
                             ExperimentalProteoform exp = tdp.matching_experimental;
                             string exp_ptm             = exp.ptm_set.ptm_combination.Count == 0 ? "Unmodified" : String.Join(", ", exp.ptm_set.ptm_combination.Select(ptm => Sweet.lollipop.theoretical_database.unlocalized_lookup.TryGetValue(ptm.modification, out UnlocalizedModification x) ? x.id : ptm.modification.OriginalId).OrderBy(p => p));
                             string td_ptm = tdp.topdown_ptm_set.ptm_combination.Count == 0 ? "Unmodified" : String.Join(", ", tdp.topdown_ptm_set.ptm_combination.Select(ptm => Sweet.lollipop.theoretical_database.unlocalized_lookup.TryGetValue(ptm.modification, out UnlocalizedModification x) ? x.id : ptm.modification.OriginalId).OrderBy(p => p));
                             writer.WriteLine(exp.accession + "\t" + exp.agg_mass + "\t" + exp.agg_rt + "\t" + exp.linked_proteoform_references.First().accession.Split('_')[0] + "\t" + (exp.linked_proteoform_references.First() as TheoreticalProteoform).description + "\t" + exp.begin + "\t" + exp.end + "\t" + exp_ptm
                                              + "\t" + tdp.accession.Split('_')[0] + "\t" + tdp.topdown_begin + "\t" + tdp.topdown_end + "\t" + td_ptm + "\t" + tdp.modified_mass + "\t" + tdp.agg_rt + "\t" + tdp.topdown_hits.Max(h => h.score));
                         }
                     }
                     else
                     {
                         string exp_ptm          = ep.ptm_set.ptm_combination.Count == 0 ? "Unmodified" : String.Join(", ", ep.ptm_set.ptm_combination.Select(ptm => Sweet.lollipop.theoretical_database.unlocalized_lookup.TryGetValue(ptm.modification, out UnlocalizedModification x) ? x.id : ptm.modification.OriginalId).OrderBy(p => p));
                         TheoreticalProteoform t = ep.linked_proteoform_references.First() as TheoreticalProteoform;
                         writer.WriteLine(ep.accession + "\t" + ep.agg_mass + "\t" + ep.agg_rt + "\t" + t.accession.Split('_')[0] + "\t" + t.description + "\t" + t.begin + "\t" + t.end + "\t" + exp_ptm
                                          + "\t" + "N\\A" + "\t" + "N\\A" + "\t" + "N\\A" + "\t" + "N\\A" + "\t" + "N\\A" + "\t" + "N\\A" + "\t" + "N\\A");
                     }
                 }
             }
             MessageBox.Show("Successfully saved top-down comparison results.");
         }
         else
         {
             return;
         }
     }
     else
     {
         return;
     }
 }
        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 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 TestUnabeledProteoformCommunityRelate_ET()
        {
            SaveState.lollipop.neucode_labeled = false;

            // 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, true, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(1, 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, true, 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, true, 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, true, 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, true, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(0, prList.Count);
        }
示例#18
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);
        }
示例#19
0
        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);
            }
        }
示例#20
0
        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 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());
        }
示例#22
0
        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);
            }
        }
示例#23
0
        public void TestUnabeledProteoformCommunityRelateWithNotches_ET()
        {
            Sweet.lollipop.neucode_labeled = false;
            Sweet.lollipop.et_use_notch    = true;

            // 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, true, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(1, 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, true, 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, true, 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, true, 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, true, 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, true, TestContext.CurrentContext.TestDirectory, true);
            Assert.AreEqual(1, prList.Count);
        }
示例#24
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
        }
示例#25
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);
        }