public static void TestPeptideWithFixedModifications()
        {
            var                 prot            = new Protein("M", null);
            DigestionParams     digestionParams = new DigestionParams(maxMissedCleavages: 0, minPeptideLength: 1, maxModsForPeptides: 3); // if you pass Custom Protease7 this test gets really flakey.
            List <Modification> fixedMods       = new List <Modification>();

            ModificationMotif.TryGetMotif("M", out ModificationMotif motif);

            fixedMods.Add(new Modification(_originalId: "ProtNmod", _target: motif, _locationRestriction: "N-terminal.", _chemicalFormula: ChemicalFormula.ParseFormula("H"), _monoisotopicMass: GetElement(1).PrincipalIsotope.AtomicMass));
            fixedMods.Add(new Modification(_originalId: "pepNmod", _target: motif, _locationRestriction: "Peptide N-terminal.", _chemicalFormula: ChemicalFormula.ParseFormula("H"), _monoisotopicMass: GetElement(1).PrincipalIsotope.AtomicMass));
            fixedMods.Add(new Modification(_originalId: "resMod", _target: motif, _locationRestriction: "Anywhere.", _chemicalFormula: ChemicalFormula.ParseFormula("H"), _monoisotopicMass: GetElement(1).PrincipalIsotope.AtomicMass));
            fixedMods.Add(new Modification(_originalId: "PepCmod", _target: motif, _locationRestriction: "Peptide C-terminal.", _chemicalFormula: ChemicalFormula.ParseFormula("H"), _monoisotopicMass: GetElement(1).PrincipalIsotope.AtomicMass));
            fixedMods.Add(new Modification(_originalId: "ProtCmod", _target: motif, _locationRestriction: "C-terminal.", _chemicalFormula: ChemicalFormula.ParseFormula("H"), _monoisotopicMass: GetElement(1).PrincipalIsotope.AtomicMass));

            var ok = prot.Digest(digestionParams, fixedMods, new List <Modification>()).ToList();

            Assert.AreEqual(1, ok.Count);

            Assert.AreEqual("[:pepNmod on M]M[:resMod on M][:ProtCmod on M]", ok.First().FullSequence);

            Assert.AreEqual("[H]M[H][H]", ok.First().SequenceWithChemicalFormulas);
            Assert.AreEqual(5 * GetElement("H").PrincipalIsotope.AtomicMass + Residue.ResidueMonoisotopicMass['M'] + GetElement("O").PrincipalIsotope.AtomicMass, ok.Last().MonoisotopicMass, 1e-9);
        }
示例#2
0
        public static void TestDigestDecoy()
        {
            ModificationMotif.TryGetMotif("N", out ModificationMotif motifN);
            ModificationMotif.TryGetMotif("R", out ModificationMotif motifR);
            Modification modN = new Modification("myMod", null, "myModType", null, motifN, "Anywhere.", null, 10, null, null, null, null, null, null);
            Modification modR = new Modification("myMod", null, "myModType", null, motifR, "Anywhere.", null, 10, null, null, null, null, null, null);
            IDictionary <int, List <Modification> > modDict = new Dictionary <int, List <Modification> >
            {
                { 2, new List <Modification> {
                      modN
                  } },
                { 8, new List <Modification> {
                      modR
                  } }
            };
            var prot = new Protein("MNNNNKRRRRR", null, null, null, modDict, isDecoy: true);

            DigestionParams digestionParams = new DigestionParams(minPeptideLength: 5, initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain);

            var digestedList = prot.Digest(digestionParams, new List <Modification>(), new List <Modification>()).ToList();
            var ok1          = digestedList[1];
            var ok2          = digestedList[3];

            Assert.AreEqual(1, ok1.NumMods);
            Assert.IsTrue(ok1.AllModsOneIsNterminus.ContainsKey(3));
            Assert.AreEqual(1, ok2.NumMods);
            Assert.IsTrue(ok2.AllModsOneIsNterminus.ContainsKey(3));

            prot = new Protein("MNNNNKRRRRR", null, null, null, modDict);
            ok1  = prot.Digest(digestionParams, new List <Modification>(), new List <Modification>()).First();
            ok2  = prot.Digest(digestionParams, new List <Modification>(), new List <Modification>()).Last();

            Assert.AreEqual(0, ok1.NumMods);
            Assert.IsFalse(ok1.AllModsOneIsNterminus.Any());
            Assert.AreEqual(2, ok2.NumMods);
            Assert.IsTrue(ok2.AllModsOneIsNterminus.Any());
        }
示例#3
0
        public static void TestBadPeptide()
        {
            var prot     = new Protein("MNNNKQQXQ", null);
            var protease = new Protease("Custom Protease7", new List <Tuple <string, FragmentationTerminus> > {
                new Tuple <string, FragmentationTerminus>("K", FragmentationTerminus.C)
            }, new List <Tuple <string, FragmentationTerminus> >(), CleavageSpecificity.Full, null, null, null);

            ProteaseDictionary.Dictionary.Add(protease.Name, protease);
            DigestionParams digestionParams = new DigestionParams(
                protease: protease.Name,
                maxMissedCleavages: 0,
                minPeptideLength: 1,
                initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain);
            var ye = prot.Digest(digestionParams, new List <Modification>(), new List <Modification>()).ToList();

            Assert.AreEqual(2, ye.Count);
            var pep1 = ye[0];

            Assert.IsTrue(pep1.MonoisotopicMass > 0);
            foreach (var huh in pep1.Fragment(DissociationType.HCD, FragmentationTerminus.Both))
            {
                Assert.IsTrue(huh.NeutralMass > 0);
            }

            var pep2 = ye[1];

            Assert.IsNaN(pep2.MonoisotopicMass);
            var cool = pep2.Fragment(DissociationType.HCD, FragmentationTerminus.Both).ToArray();

            Assert.IsTrue(cool[0].NeutralMass > 0);
            Assert.IsTrue(cool[1].NeutralMass > 0);
            Assert.IsTrue(cool[3].NeutralMass > 0);
            Assert.IsTrue(double.IsNaN(cool[2].NeutralMass));
            Assert.IsTrue(double.IsNaN(cool[4].NeutralMass));
            Assert.IsTrue(double.IsNaN(cool[5].NeutralMass));
            Assert.IsTrue(cool.Length == 6);
        }
示例#4
0
        public void Test_FragmentationModNeutralLoss()
        {
            // Now we'll check the mass of modified peptide with no neutral losses
            ModificationMotif.TryGetMotif("T", out ModificationMotif motif);
            Modification mod = new Modification(_originalId: "phospho", _modificationType: "testModType", _target: motif, _chemicalFormula: ChemicalFormula.ParseFormula("H1 O3 P1"), _neutralLosses: new Dictionary <DissociationType, List <double> > {
                { DissociationType.HCD, new List <double> {
                      ChemicalFormula.ParseFormula("H3 O4 P1").MonoisotopicMass
                  } }
            }, _locationRestriction: "Anywhere.");
            List <Modification> modlist = new List <Modification> {
                mod
            };
            DigestionParams digestionParams = new DigestionParams(
                protease: "trypsin",
                maxMissedCleavages: 0,
                minPeptideLength: 1,
                initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain);

            var prot = new Protein("PEPTIDE", null, oneBasedModifications: new Dictionary <int, List <Modification> > {
                { 4, modlist }
            });
            var ye = prot.Digest(digestionParams, new List <Modification>(), new List <Modification>()).ToList();

            var peptideWithNeutralMassMod = ye.Where(v => v.AllModsOneIsNterminus.Count > 0).First();

            var myModFragments = new List <Product>();

            peptideWithNeutralMassMod.Fragment(DissociationType.HCD, FragmentationTerminus.Both, myModFragments);
            HashSet <int> neutralMasses  = new HashSet <int>(myModFragments.Select(m => (int)m.NeutralMass.ToMz(1)).ToList());
            HashSet <int> expectedMasses = new HashSet <int> {
                98, 227, 324, 407, 520, 635, 505, 618, 733,  //b-ions with and without neutral loss
                148, 263, 376, 459, 556, 685, 557, 654, 783, //y-ions with and without neutral loss
                782
            };                                               //molecular ion with neutral loss

            CollectionAssert.AreEquivalent(neutralMasses, expectedMasses);
        }
示例#5
0
        public static void TestFragmentNterminalModifiedPeptide()
        {
            ModificationMotif.TryGetMotif("P", out ModificationMotif motif);
            Modification nTermMod = new Modification(_originalId: "acetylation", _modificationType: "testModType", _target: motif, _chemicalFormula: ChemicalFormula.ParseFormula("C2H2O1"), _locationRestriction: "N-terminal.");

            Dictionary <int, List <Modification> > mods = new Dictionary <int, List <Modification> > {
                { 1, new List <Modification> {
                      nTermMod
                  } }
            };

            Protein protein = new Protein("PEPTIDE", "", oneBasedModifications: mods);
            PeptideWithSetModifications peptide = protein.Digest(new DigestionParams(), new List <Modification>(), new List <Modification>()).Where(p => p.AllModsOneIsNterminus.Count == 1).First();

            Assert.That(peptide.FullSequence == "[testModType:acetylation on P]PEPTIDE");

            var fragments = new List <Product>();

            peptide.Fragment(DissociationType.HCD, FragmentationTerminus.Both, fragments);

            var roundedFragments = fragments.Select(f => (int)f.NeutralMass).ToList();

            CollectionAssert.AreEquivalent(roundedFragments, new int[] { 139, 268, 365, 466, 579, 694, 147, 262, 375, 476, 573, 702 });
        }
示例#6
0
        public static void TestFragmentCTerminalModifiedPeptide()
        {
            ModificationMotif.TryGetMotif("E", out ModificationMotif motif);
            Modification cTermMod = new Modification(_originalId: "acetylation", _modificationType: "testModType", _target: motif, _chemicalFormula: ChemicalFormula.ParseFormula("C2H2O1"), _locationRestriction: "C-terminal.");

            Dictionary <int, List <Modification> > mods = new Dictionary <int, List <Modification> > {
                { 7, new List <Modification> {
                      cTermMod
                  } }
            };

            Protein protein = new Protein("PEPTIDE", "", oneBasedModifications: mods);
            PeptideWithSetModifications peptide = protein.Digest(new DigestionParams(), new List <Modification>(), new List <Modification>()).Where(p => p.AllModsOneIsNterminus.Count == 1).First();

            Assert.That(peptide.FullSequence == "PEPTIDE[testModType:acetylation on E]");

            var fragments = new List <Product>();

            peptide.Fragment(DissociationType.HCD, FragmentationTerminus.Both, fragments);

            var roundedFragments = fragments.Select(f => (int)f.NeutralMass).ToList();

            CollectionAssert.AreEquivalent(roundedFragments, new int[] { 97, 226, 323, 424, 537, 652, 189, 304, 417, 518, 615, 744 });
        }
示例#7
0
        public static void TestCompactPeptideMasses_UnmodifiedPeptide()
        {
            Protein         p = new Protein("PET", "accession");
            DigestionParams digestionParams = new DigestionParams(minPeptideLength: 2);
            var             aPeptideWithSetModifications = p.Digest(digestionParams, new List <Modification>(), new List <Modification>()).First();

            var aCompactPeptide = aPeptideWithSetModifications.CompactPeptide(FragmentationTerminus.Both);

            //evaluate N-terminal masses
            var           nTerminalMasses         = aCompactPeptide.TerminalMasses.Where(v => v.Terminus == FragmentationTerminus.N);
            HashSet <int> expectedNTerminalMasses = new HashSet <int> {
                97, 226
            };

            Assert.That(expectedNTerminalMasses.SetEquals(nTerminalMasses.Select(v => (int)Math.Round(v.NeutralMass, 1))));

            //evaluate C-terminal masses
            var           cTerminalMasses         = aCompactPeptide.TerminalMasses.Where(v => v.Terminus == FragmentationTerminus.C);
            HashSet <int> expectedCTerminalMasses = new HashSet <int> {
                101, 230, 327
            };

            Assert.That(expectedCTerminalMasses.SetEquals(cTerminalMasses.Select(v => (int)Math.Round(v.NeutralMass, 1))));
        }
示例#8
0
        public void TestFragmentationNoMod()
        {
            // First we're checking to see if the fragment masses of an unmodified peptide a calculated correctly
            var             prot            = new Protein("PEPTIDE", null);
            DigestionParams digestionParams = new DigestionParams(

                maxMissedCleavages: 0,
                minPeptideLength: 1,
                initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain);
            List <Modification> variableModifications = new List <Modification>();
            var ye = prot.Digest(digestionParams, new List <Modification>(), variableModifications).ToList();

            // check unmodified
            var unmodPeptide = ye.Where(p => p.AllModsOneIsNterminus.Count == 0).First();
            var fragments    = new List <Product>();

            unmodPeptide.Fragment(DissociationType.HCD, FragmentationTerminus.Both, fragments);
            var           myUnmodFragmentMasses = fragments.Select(v => (int)Math.Round(v.NeutralMass.ToMz(1), 1)).ToList();
            HashSet <int> expectedMzs           = new HashSet <int> {
                98, 227, 324, 425, 538, 653, 703, 574, 477, 376, 263, 148
            };

            Assert.That(expectedMzs.SetEquals(myUnmodFragmentMasses));
        }
        public static void TestIdenticalPeaks()
        {
            IDictionary <int, List <Modification> > mods = new Dictionary <int, List <Modification> >();

            ModificationMotif.TryGetMotif("M", out ModificationMotif motif);
            mods.Add(1, new List <Modification> {
                new Modification(_originalId: "Hehe", _target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 18.010565)
            });
            var             prot            = new Protein("MMMM", null, null, null, mods);
            DigestionParams digestionParams = new DigestionParams(minPeptideLength: 1);
            var             ye = prot.Digest(digestionParams, new List <Modification>(), new List <Modification>()).First();

            var massArray = ye.Fragment(DissociationType.HCD, FragmentationTerminus.Both).Select(p => p.NeutralMass).ToArray();

            Array.Sort(massArray);
            double[]   intensities  = new double[] { 1, 1, 1, 1 };
            double[]   mz           = new double[] { massArray[0].ToMz(1), massArray[2].ToMz(1), massArray[4].ToMz(1), 10000 };
            MzSpectrum massSpectrum = new MzSpectrum(mz, intensities, false);
            MsDataScan scan         = new MsDataScan(massSpectrum, 1, 1, true, Polarity.Positive, 1, new MzRange(300, 2000), "", MZAnalyzerType.Unknown, massSpectrum.SumOfAllY, null, null, "scan=1", 0, null, null, 0, null, DissociationType.Unknown, 1, null);

            PeptideSpectralMatch[]    globalPsms            = new PeptideSpectralMatch[1];
            Ms2ScanWithSpecificMass[] arrayOfSortedMS2Scans = { new Ms2ScanWithSpecificMass(scan, 0, 1, null, new CommonParameters()) };
            CommonParameters          CommonParameters      = new CommonParameters(
                productMassTolerance: new PpmTolerance(5),
                scoreCutoff: 1,
                digestionParams: new DigestionParams(
                    maxMissedCleavages: 0,
                    minPeptideLength: 1,
                    initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain));
            ClassicSearchEngine cse = new ClassicSearchEngine(globalPsms, arrayOfSortedMS2Scans, new List <Modification>(), new List <Modification>(), null, new List <Protein> {
                prot
            }, new OpenSearchMode(), CommonParameters, new List <string>());

            cse.Run();
            Assert.AreEqual(3, globalPsms[0].MatchedFragmentIons.Count);
        }
示例#10
0
        public static void TestBinGeneration()
        {
            SearchTask st = new SearchTask
            {
                CommonParameters = new CommonParameters(scoreCutoff: 1, digestionParams: new DigestionParams(minPeptideLength: 5, initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain)),

                SearchParameters = new SearchParameters
                {
                    DoHistogramAnalysis  = true,
                    MassDiffAcceptorType = MassDiffAcceptorType.Open,
                    DecoyType            = DecoyType.None,
                    DoParsimony          = true,
                    DoQuantification     = true
                },
            };

            string proteinDbFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "BinGenerationTest.xml");
            string mzmlFilePath      = Path.Combine(TestContext.CurrentContext.TestDirectory, "BinGenerationTest.mzML");

            Protein prot1 = new Protein("MEDEEK", "prot1");
            Protein prot2 = new Protein("MENEEK", "prot2");

            ModificationMotif.TryGetMotif("D", out ModificationMotif motif);
            Modification mod = new Modification(_target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 10);

            var pep1_0  = prot1.Digest(st.CommonParameters.DigestionParams, new List <Modification>(), new List <Modification>()).First();
            var pep1_10 = prot1.Digest(st.CommonParameters.DigestionParams, new List <Modification>(), new List <Modification>()).Last();

            Protein prot3 = new Protein("MAAADAAAAAAAAAAAAAAA", "prot3");

            var pep2_0  = prot3.Digest(st.CommonParameters.DigestionParams, new List <Modification>(), new List <Modification>()).First();
            var pep2_10 = prot3.Digest(st.CommonParameters.DigestionParams, new List <Modification>(), new List <Modification> {
                mod
            }).Last();

            Protein prot4   = new Protein("MNNDNNNN", "prot4");
            var     pep3_10 = prot4.Digest(st.CommonParameters.DigestionParams, new List <Modification>(), new List <Modification> {
                mod
            }).Last();

            List <PeptideWithSetModifications> pepsWithSetMods = new List <PeptideWithSetModifications> {
                pep1_0, pep1_10, pep2_0, pep2_10, pep3_10
            };
            MsDataFile myMsDataFile = new TestDataFile(pepsWithSetMods);

            List <Protein> proteinList = new List <Protein> {
                prot1, prot2, prot3, prot4
            };

            IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile, mzmlFilePath, false);
            ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), proteinList, proteinDbFilePath);

            string output_folder = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestBinGeneration");

            Directory.CreateDirectory(output_folder);
            st.RunTask(
                output_folder,
                new List <DbForTask> {
                new DbForTask(proteinDbFilePath, false)
            },
                new List <string> {
                mzmlFilePath
            },
                null);

            Assert.AreEqual(3, File.ReadLines(Path.Combine(output_folder, @"MassDifferenceHistogram.tsv")).Count());
            Directory.Delete(output_folder, true);
            File.Delete(proteinDbFilePath);
            File.Delete(mzmlFilePath);
            Directory.Delete(Path.Combine(TestContext.CurrentContext.TestDirectory, @"Task Settings"), true);
        }
示例#11
0
        public static void OGlycoTest_Localization2()
        {
            //There may have a bug that MM cannot identify Peptide modified with (HexNAc), This is to test and find the bug.
            //Get glycanBox
            var glycanBox = OGlycanBoxes[0];

            //Get unmodified peptide, products, allPossible modPos and all boxes.
            Protein        protein  = new Protein("AATVGSLAGQPLQER", "P16150");
            var            peptide  = protein.Digest(new DigestionParams(), new List <Modification>(), new List <Modification>()).First();
            List <Product> products = new List <Product>();

            peptide.Fragment(DissociationType.ETD, FragmentationTerminus.Both, products);

            int[] modPos = GlycoSpectralMatch.GetPossibleModSites(peptide, new string[] { "S", "T" }).OrderBy(p => p).ToArray();
            var   boxes  = GlycanBox.BuildChildOGlycanBoxes(glycanBox.NumberOfMods, glycanBox.ModIds).ToArray();

            //Load scan.
            CommonParameters commonParameters = new CommonParameters(dissociationType: DissociationType.ETD, trimMsMsPeaks: false);
            string           spectraFile      = Path.Combine(TestContext.CurrentContext.TestDirectory, @"GlycoTestData\181217_Fusion_(LC2)_NewObj_Serum_deSA_Jacalin_HRM_4h_ETD_HCD_DDA_mz(400_1200)_21707.mgf");
            var file  = new MyFileManager(true).LoadFile(spectraFile, commonParameters);
            var scans = MetaMorpheusTask.GetMs2Scans(file, spectraFile, commonParameters).ToArray();

            //Known peptideWithMod match.
            var peptideWithMod = GlycoPeptides.OGlyGetTheoreticalPeptide(new int[1] {
                4
            }, peptide, glycanBox);

            Assert.That(peptideWithMod.FullSequence == "AAT[O-Glycosylation:N1 on X]VGSLAGQPLQER");
            //List<Product> knownProducts = peptideWithMod.Fragment(DissociationType.EThcD, FragmentationTerminus.Both).ToList();
            List <Product> knownProducts            = GlycoPeptides.OGlyGetTheoreticalFragments(DissociationType.ETD, peptide, peptideWithMod);
            var            matchedKnownFragmentIons = MetaMorpheusEngine.MatchFragmentIons(scans.First(), knownProducts, commonParameters);

            //Get hashset int
            int        obsPreviousFragmentCeilingMz = 0;
            List <int> binsToSearch = new List <int>();

            foreach (var envelope in scans.First().ExperimentalFragments)
            {
                // assume charge state 1 to calculate mass tolerance
                double experimentalFragmentMass = envelope.MonoisotopicMass;

                // get theoretical fragment bins within mass tolerance
                int obsFragmentFloorMass   = (int)Math.Floor((commonParameters.ProductMassTolerance.GetMinimumValue(experimentalFragmentMass)) * 1000);
                int obsFragmentCeilingMass = (int)Math.Ceiling((commonParameters.ProductMassTolerance.GetMaximumValue(experimentalFragmentMass)) * 1000);

                // prevents double-counting peaks close in m/z and lower-bound out of range exceptions
                if (obsFragmentFloorMass < obsPreviousFragmentCeilingMz)
                {
                    obsFragmentFloorMass = obsPreviousFragmentCeilingMz;
                }
                obsPreviousFragmentCeilingMz = obsFragmentCeilingMass + 1;

                // search mass bins within a tolerance
                for (int fragmentBin = obsFragmentFloorMass; fragmentBin <= obsFragmentCeilingMass; fragmentBin++)
                {
                    binsToSearch.Add(fragmentBin);
                }
            }
            HashSet <int> allPeaks = new HashSet <int>(binsToSearch);


            //Graph Localization
            LocalizationGraph localizationGraph = new LocalizationGraph(modPos, glycanBox, boxes, -1);

            LocalizationGraph.LocalizeOGlycan(localizationGraph, scans.First(), commonParameters.ProductMassTolerance, products);

            var allPaths = LocalizationGraph.GetAllHighestScorePaths(localizationGraph.array, localizationGraph.ChildModBoxes);

            var knowPath = new int[2] {
                1, 1
            };

            Assert.That(Enumerable.SequenceEqual(knowPath, allPaths[0]));

            var local = LocalizationGraph.GetLocalizedPath(localizationGraph, allPaths.First());

            Assert.That(Enumerable.SequenceEqual(local.Mods.Select(p => p.Item1), new List <int> {
                4
            }));
            Assert.That(Enumerable.SequenceEqual(local.Mods.Select(p => p.Item2), new List <int> {
                0
            }));
        }
示例#12
0
        public static void OGlycoTest_Localization()
        {
            //Get glycanBox
            var glycanBox = OGlycanBoxes[19];

            //Get unmodified peptide, products, allPossible modPos and all boxes.
            Protein        protein  = new Protein("TTGSLEPSSGASGPQVSSVK", "P16150");
            var            peptide  = protein.Digest(new DigestionParams(), new List <Modification>(), new List <Modification>()).First();
            List <Product> products = new List <Product>();

            peptide.Fragment(DissociationType.ETD, FragmentationTerminus.Both, products);

            int[] modPos = GlycoSpectralMatch.GetPossibleModSites(peptide, new string[] { "S", "T" }).OrderBy(v => v).ToArray();
            var   boxes  = GlycanBox.BuildChildOGlycanBoxes(3, glycanBox.ModIds).ToArray();

            Assert.That(boxes.Count() == 6);

            //Get Unlocal Fragment
            var unlocalCost = GlycoPeptides.GetUnlocalFragment(products, modPos, glycanBox);

            Assert.That(unlocalCost.Count == 4); //Basicly, the unlocal are c/z ions that don't localize glycosylation.

            //Get scan
            CommonParameters commonParameters = new CommonParameters(dissociationType: DissociationType.EThcD, trimMsMsPeaks: false);
            string           spectraFile      = Path.Combine(TestContext.CurrentContext.TestDirectory, @"GlycoTestData\2019_09_16_StcEmix_35trig_EThcD25_rep1_4565.mgf");
            var file  = new MyFileManager(true).LoadFile(spectraFile, commonParameters);
            var scans = MetaMorpheusTask.GetMs2Scans(file, spectraFile, commonParameters).ToArray();

            //Known peptideWithMod match.
            var peptideWithMod = GlycoPeptides.OGlyGetTheoreticalPeptide(new int[3] {
                10, 2, 3
            }, peptide, glycanBox);

            Assert.That(peptideWithMod.FullSequence == "T[O-Glycosylation:H1N1 on X]T[O-Glycosylation:H1N1 on X]GSLEPSS[O-Glycosylation:N1 on X]GASGPQVSSVK");
            List <Product> knownProducts            = GlycoPeptides.OGlyGetTheoreticalFragments(DissociationType.EThcD, peptide, peptideWithMod);
            var            matchedKnownFragmentIons = MetaMorpheusEngine.MatchFragmentIons(scans.First(), knownProducts, commonParameters);

            //Graph Localization
            LocalizationGraph localizationGraph = new LocalizationGraph(modPos, glycanBox, boxes, -1);

            LocalizationGraph.LocalizeOGlycan(localizationGraph, scans.First(), commonParameters.ProductMassTolerance, products);
            var allPaths = LocalizationGraph.GetAllHighestScorePaths(localizationGraph.array, localizationGraph.ChildModBoxes);
            var knowPath = new int[8] {
                2, 4, 4, 4, 5, 5, 5, 5
            };

            Assert.That(Enumerable.SequenceEqual(knowPath, allPaths[0]));

            //Get localized Route
            var local = LocalizationGraph.GetLocalizedPath(localizationGraph, allPaths.First());

            Assert.That(Enumerable.SequenceEqual(local.Mods.Select(v => v.Item1), new List <int> {
                2, 3, 10
            }));
            Assert.That(Enumerable.SequenceEqual(local.Mods.Select(v => v.Item2), new List <int> {
                1, 1, 0
            }));


            //Get all paths, calculate PScore and calculate position probability.
            var p = scans.First().TheScan.MassSpectrum.Size *commonParameters.ProductMassTolerance.GetRange(1000).Width / scans.First().TheScan.MassSpectrum.Range.Width;
            var n = knownProducts.Where(v => v.ProductType == ProductType.c || v.ProductType == ProductType.zDot).Count();
            var allPathWithWeights = LocalizationGraph.GetAllPaths_CalP(localizationGraph, p, n);

            Assert.That(allPathWithWeights.Count == 168);

            //Calculate Site Specific Localization Probability
            var y = LocalizationGraph.CalSiteSpecificLocalizationProbability(allPathWithWeights, localizationGraph.ModPos);

            Assert.That(y.Count == 8);
            Assert.That(y.First().Value[1].Item2 > 0.99);
        }
        public static void SearchWithPeptidesAddedInParsimonyTest()
        {
            // Make sure can run the complete search task when multiple compact peptides may correspond to a single PWSM
            SearchTask st = new SearchTask
            {
                SearchParameters = new SearchParameters
                {
                    DoParsimony             = true,
                    DecoyType               = DecoyType.None,
                    ModPeptidesAreDifferent = false
                },
                CommonParameters = new CommonParameters(scoreCutoff: 1, digestionParams: new DigestionParams(minPeptideLength: 2)),
            };

            string xmlName = "andguiaheow.xml";

            CommonParameters CommonParameters = new CommonParameters(
                scoreCutoff: 1,
                digestionParams: new DigestionParams(
                    maxMissedCleavages: 0,
                    minPeptideLength: 1,
                    maxModificationIsoforms: 2,
                    initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain,
                    maxModsForPeptides: 1));

            ModificationMotif.TryGetMotif("A", out ModificationMotif motifA);
            Modification alanineMod = new Modification(_originalId: "111", _modificationType: "mt", _target: motifA, _locationRestriction: "Anywhere.", _monoisotopicMass: 111);

            var variableModifications = new List <Modification>();
            IDictionary <int, List <Modification> > oneBasedModifications1 = new Dictionary <int, List <Modification> >
            {
                { 2, new List <Modification> {
                      alanineMod
                  } }
            };
            Protein protein1 = new Protein("MA", "protein1", oneBasedModifications: oneBasedModifications1);

            // Alanine = Glycine + CH2

            ModificationMotif.TryGetMotif("G", out ModificationMotif motif1);

            Modification glycineMod = new Modification(_originalId: "CH2 on Glycine", _modificationType: "mt", _target: motif1, _locationRestriction: "Anywhere.", _monoisotopicMass: Chemistry.ChemicalFormula.ParseFormula("CH2").MonoisotopicMass);

            IDictionary <int, List <Modification> > oneBasedModifications2 = new Dictionary <int, List <Modification> >
            {
                { 2, new List <Modification> {
                      glycineMod
                  } }
            };
            Protein protein2 = new Protein("MG", "protein3", oneBasedModifications: oneBasedModifications2);

            PeptideWithSetModifications pepMA    = protein1.Digest(CommonParameters.DigestionParams, new List <Modification>(), variableModifications).First();
            PeptideWithSetModifications pepMA111 = protein1.Digest(CommonParameters.DigestionParams, new List <Modification>(), variableModifications).Last();

            var pepMG = protein2.Digest(CommonParameters.DigestionParams, new List <Modification>(), variableModifications).First();

            ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), new List <Protein> {
                protein1, protein2
            }, xmlName);

            string mzmlName = @"ajgdiu.mzML";

            MsDataFile myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> {
                pepMA, pepMG, pepMA111
            });

            IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile, mzmlName, false);
            string outputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestSearchWithPeptidesAddedInParsimony");

            Directory.CreateDirectory(outputFolder);

            st.RunTask(outputFolder,
                       new List <DbForTask> {
                new DbForTask(xmlName, false)
            },
                       new List <string> {
                mzmlName
            }, "");
            Directory.Delete(outputFolder, true);
            File.Delete(mzmlName);
            File.Delete(xmlName);
            Directory.Delete(Path.Combine(TestContext.CurrentContext.TestDirectory, @"Task Settings"), true);
        }
示例#14
0
        public static void TestProteinPrunedWithModSelection()
        {
            var modToWrite    = GlobalVariables.AllModsKnown.Where(p => p.ModificationType == "UniProt" && p.Target.ToString() == "T").First();
            var modToNotWrite = GlobalVariables.AllModsKnown.Where(p => p.ModificationType == "Common Artifact" && p.Target.ToString() == "X").First();

            var protein1 = new Protein("PEPTIDEKPEPT", "1", oneBasedModifications: new Dictionary <int, List <Modification> > {
                { 1, new List <Modification> {
                      modToNotWrite
                  } }, { 12, new List <Modification> {
                             modToWrite
                         } }
            });
            var protein2 = new Protein("PEPTIDPEPT", "2", oneBasedModifications: new Dictionary <int, List <Modification> > {
                { 1, new List <Modification> {
                      modToNotWrite
                  } }, { 10, new List <Modification> {
                             modToWrite
                         } }
            });

            string path = @"temp";

            ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), new List <Protein> {
                protein1, protein2
            }, path);

            Directory.CreateDirectory(Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest"));

            Dictionary <string, HashSet <Tuple <int, Modification> > > modList = new Dictionary <string, HashSet <Tuple <int, Modification> > >();
            var Hash = new HashSet <Tuple <int, Modification> >
            {
                new Tuple <int, Modification>(1, modToWrite),
                new Tuple <int, Modification>(2, modToNotWrite),
            };

            var db = ProteinDbWriter.WriteXmlDatabase(modList, new List <Protein> {
                protein1, protein2
            }, Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest/fakeDb.xml"));

            var peptideObserved = protein1.Digest(new DigestionParams(minPeptideLength: 1), new List <Modification>(), new List <Modification>())
                                  .Where(p => p.BaseSequence == "PEPT" && p.AllModsOneIsNterminus.Count > 0).First();
            PostSearchAnalysisParameters testPostTaskParameters = new PostSearchAnalysisParameters();
            CommonParameters             commonParam            = new CommonParameters(useDeltaScore: false);

            double[,] noiseData = new double[10000, 10000];
            noiseData[0, 0]     = 1.0;
            List <Proteomics.Fragmentation.MatchedFragmentIon> matchedFragmentIons = new List <Proteomics.Fragmentation.MatchedFragmentIon>()
            {
            };
            MzSpectrum spectrum = new MzSpectrum(noiseData);
            MsDataScan scan     = new MsDataScan(spectrum, 1, 1, true, Polarity.Unknown, 2, new MzLibUtil.MzRange(10, 1000), "", MZAnalyzerType.Orbitrap, 10000, null, noiseData, "");

            testPostTaskParameters.ProteinList = new List <Protein>()
            {
                protein1, protein2
            };
            testPostTaskParameters.AllPsms = new List <PeptideSpectralMatch> {
                new PeptideSpectralMatch(peptideObserved, 0, 20, 1, new Ms2ScanWithSpecificMass(scan, 100, 1, @"", commonParam), commonParam, matchedFragmentIons)
            };
            testPostTaskParameters.SearchParameters = new SearchParameters();
            testPostTaskParameters.SearchParameters.WritePrunedDatabase = true;
            testPostTaskParameters.SearchParameters.DoQuantification    = false;
            testPostTaskParameters.SearchParameters.WriteMzId           = false;
            testPostTaskParameters.DatabaseFilenameList = new List <DbForTask>()
            {
                new DbForTask(Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest/fakeDb.xml"), false)
            };
            testPostTaskParameters.OutputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest");
            Directory.CreateDirectory(Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest/individual"));
            testPostTaskParameters.IndividualResultsOutputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest/individual");
            int[] stuffForSpectraFile = new int[2];
            stuffForSpectraFile[0] = 10;
            stuffForSpectraFile[1] = 10;
            Dictionary <string, int[]> numSpectraPerFile = new Dictionary <string, int[]>();

            numSpectraPerFile.Add("", stuffForSpectraFile);
            testPostTaskParameters.NumMs2SpectraPerFile = numSpectraPerFile;

            MsDataFile myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications>
            {
                peptideObserved
            });
            string mzmlName = @"newMzml.mzML";

            IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile, mzmlName, false);

            modList.Add("test", Hash);

            testPostTaskParameters.CurrentRawFileList = new List <string>()
            {
                mzmlName
            };

            SearchTask task5 = new SearchTask
            {
                SearchParameters = new SearchParameters
                {
                    WritePrunedDatabase  = true,
                    SearchTarget         = true,
                    MassDiffAcceptorType = MassDiffAcceptorType.Exact,
                },
                CommonParameters = new CommonParameters()
            };

            var test = task5.RunTask(Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest"), new List <DbForTask>()
            {
                new DbForTask(Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest/fakeDb.xml"), false)
            }, new List <string>()
            {
                mzmlName
            }, "name");

            testPostTaskParameters.SearchTaskResults = test;

            PostSearchAnalysisTask testPostTask = new PostSearchAnalysisTask();

            testPostTask.Parameters             = testPostTaskParameters;
            testPostTask.CommonParameters       = commonParam;
            testPostTask.FileSpecificParameters = new List <(string FileName, CommonParameters Parameters)> {
                ("newMzMl.mzml", commonParam)
            };
            testPostTask.Run();

            var proteinsLoaded = ProteinDbLoader.LoadProteinXML(path, true, DecoyType.None, GlobalVariables.AllModsKnown, false, new List <string>(), out var unknownMods);

            // assert that mods on proteins are the same before/after task is run
            Assert.That(protein1.Equals(proteinsLoaded.First(p => p.Accession == "1")));
            Assert.That(protein2.Equals(proteinsLoaded.First(p => p.Accession == "2")));

            // assert that protein pruned DB has correct proteins mods
            var proteinPruned = ProteinDbLoader.LoadProteinXML(Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest/fakeDbproteinPruned.xml"), true, DecoyType.None, GlobalVariables.AllModsKnown, false, new List <string>(), out var unknownMods1);

            Assert.That(proteinPruned.Count().Equals(1));
            Assert.That(proteinPruned.FirstOrDefault().OneBasedPossibleLocalizedModifications.Count().Equals(1));
            // assert that mod-pruned DB has correct proteins and mods
            var modPruned = ProteinDbLoader.LoadProteinXML(Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest/fakeDbpruned.xml"), true, DecoyType.None, GlobalVariables.AllModsKnown, false, new List <string>(), out var unknownMods2);

            Assert.That(modPruned.Count().Equals(2));
            Assert.That(modPruned.ElementAt(0).OneBasedPossibleLocalizedModifications.Count().Equals(1));
            Assert.That(modPruned.ElementAt(1).OneBasedPossibleLocalizedModifications.Count().Equals(1));
        }
示例#15
0
        public static void TestBinGeneration()
        {
            SearchTask st = new SearchTask
            {
                CommonParameters = new CommonParameters
                {
                    ScoreCutoff     = 1,
                    DigestionParams = new DigestionParams
                    {
                        InitiatorMethionineBehavior = InitiatorMethionineBehavior.Retain,
                    },
                    ConserveMemory = false,
                },
                SearchParameters = new SearchParameters
                {
                    DoHistogramAnalysis  = true,
                    MassDiffAcceptorType = MassDiffAcceptorType.Open,
                    DecoyType            = DecoyType.None,
                    DoParsimony          = true,
                    DoQuantification     = true
                },
            };

            string proteinDbFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "BinGenerationTest.xml");
            string mzmlFilePath      = Path.Combine(TestContext.CurrentContext.TestDirectory, "BinGenerationTest.mzml");

            Protein prot1 = new Protein("MEDEEK", "prot1");
            Protein prot2 = new Protein("MENEEK", "prot2");

            ModificationMotif.TryGetMotif("D", out ModificationMotif motif);
            ModificationWithMass mod = new ModificationWithMass(null, null, motif, TerminusLocalization.Any, 10);

            var pep1_0  = prot1.Digest(st.CommonParameters.DigestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).First();
            var pep1_10 = prot1.Digest(st.CommonParameters.DigestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).Last();

            Protein prot3 = new Protein("MAAADAAAAAAAAAAAAAAA", "prot3");

            var pep2_0  = prot3.Digest(st.CommonParameters.DigestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).First();
            var pep2_10 = prot3.Digest(st.CommonParameters.DigestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass> {
                mod
            }).Last();

            Protein prot4   = new Protein("MNNDNNNN", "prot4");
            var     pep3_10 = prot4.Digest(st.CommonParameters.DigestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass> {
                mod
            }).Last();

            List <PeptideWithSetModifications> pepsWithSetMods = new List <PeptideWithSetModifications> {
                pep1_0, pep1_10, pep2_0, pep2_10, pep3_10
            };
            IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile = new TestDataFile(pepsWithSetMods);

            List <Protein> proteinList = new List <Protein> {
                prot1, prot2, prot3, prot4
            };

            IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile, mzmlFilePath, false);
            ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), proteinList, proteinDbFilePath);

            string output_folder = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestBinGeneration");

            Directory.CreateDirectory(output_folder);
            st.RunTask(
                output_folder,
                new List <DbForTask> {
                new DbForTask(proteinDbFilePath, false)
            },
                new List <string> {
                mzmlFilePath
            },
                null);

            Assert.AreEqual(3, File.ReadLines(Path.Combine(output_folder, @"aggregate.mytsv")).Count());
        }
示例#16
0
        public static void TestDeltaValues()
        {
            CommonParameters CommonParameters = new CommonParameters(scoreCutoff: 1, useDeltaScore: true, digestionParams: new DigestionParams(minPeptideLength: 5));

            SearchParameters SearchParameters = new SearchParameters
            {
                MassDiffAcceptorType = MassDiffAcceptorType.Exact,
            };
            List <Modification> variableModifications = GlobalVariables.AllModsKnown.OfType <Modification>().Where(b => CommonParameters.ListOfModsVariable.Contains((b.ModificationType, b.IdWithMotif))).ToList();
            List <Modification> fixedModifications    = GlobalVariables.AllModsKnown.OfType <Modification>().Where(b => CommonParameters.ListOfModsFixed.Contains((b.ModificationType, b.IdWithMotif))).ToList();

            // Generate data for files
            Protein TargetProtein1    = new Protein("TIDEANTHE", "accession1");
            Protein TargetProtein2    = new Protein("TIDELVE", "accession2");
            Protein TargetProtein3    = new Protein("TIDENIE", "accession3");
            Protein TargetProteinLost = new Protein("PEPTIDEANTHE", "accession4");
            Protein DecoyProteinFound = new Protein("PETPLEDQGTHE", "accessiond", isDecoy: true);

            MsDataFile myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications>
            {
                TargetProtein1.Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[0],
                TargetProtein2.Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[0],
                TargetProtein3.Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[0],
                DecoyProteinFound.Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[0]
            });

            var proteinList = new List <Protein> {
                TargetProtein1, TargetProtein2, TargetProtein3, TargetProteinLost, DecoyProteinFound
            };

            var searchModes = new SinglePpmAroundZeroSearchMode(5);

            Tolerance DeconvolutionMassTolerance = new PpmTolerance(5);

            var listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray();

            //check better when using delta
            PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, proteinList, searchModes, CommonParameters, new List <string>()).Run();

            var indexEngine  = new IndexingEngine(proteinList, variableModifications, fixedModifications, null, 1, DecoyType.None, CommonParameters, 30000, false, new List <FileInfo>(), new List <string>());
            var indexResults = (IndexingResults)indexEngine.Run();
            MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac);

            PeptideSpectralMatch[] allPsmsArrayModern = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ModernSearchEngine(allPsmsArrayModern, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, massDiffAcceptor, 0, new List <string>()).Run();

            FdrAnalysisResults fdrResultsClassicDelta = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArray.ToList(), 1, CommonParameters, new List <string>()).Run());
            FdrAnalysisResults fdrResultsModernDelta  = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArrayModern.ToList(), 1, CommonParameters, new List <string>()).Run());

            Assert.IsTrue(fdrResultsClassicDelta.PsmsWithin1PercentFdr == 3);
            Assert.IsTrue(fdrResultsModernDelta.PsmsWithin1PercentFdr == 3);

            CommonParameters = new CommonParameters(digestionParams: new DigestionParams(minPeptideLength: 5));

            //check worse when using score
            FdrAnalysisResults fdrResultsClassic = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArray.ToList(), 1, CommonParameters, new List <string>()).Run());
            FdrAnalysisResults fdrResultsModern  = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArray.ToList(), 1, CommonParameters, new List <string>()).Run());

            Assert.IsTrue(fdrResultsClassic.PsmsWithin1PercentFdr == 0);
            Assert.IsTrue(fdrResultsModern.PsmsWithin1PercentFdr == 0);

            //check that when delta is bad, we used the score
            // Generate data for files
            Protein DecoyProtein1     = new Protein("TLEDAGGTHE", "accession1d", isDecoy: true);
            Protein DecoyProtein2     = new Protein("TLEDLVE", "accession2d", isDecoy: true);
            Protein DecoyProtein3     = new Protein("TLEDNIE", "accession3d", isDecoy: true);
            Protein DecoyProteinShiny = new Protein("GGGGGG", "accessionShinyd", isDecoy: true);

            myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications>
            {
                TargetProtein1.Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[0],
                TargetProtein2.Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[0],
                TargetProtein3.Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[0],
                DecoyProteinShiny.Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[0],
            });

            proteinList = new List <Protein>
            {
                TargetProtein1, DecoyProtein1,
                TargetProtein2, DecoyProtein2,
                TargetProtein3, DecoyProtein3,
                DecoyProteinShiny,
            };

            listOfSortedms2Scans = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, new CommonParameters()).OrderBy(b => b.PrecursorMass).ToArray();

            //check no change when using delta
            allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, proteinList, searchModes, CommonParameters, new List <string>()).Run();

            CommonParameters = new CommonParameters(useDeltaScore: true, digestionParams: new DigestionParams(minPeptideLength: 5));

            indexEngine        = new IndexingEngine(proteinList, variableModifications, fixedModifications, null, 1, DecoyType.None, CommonParameters, 30000, false, new List <FileInfo>(), new List <string>());
            indexResults       = (IndexingResults)indexEngine.Run();
            massDiffAcceptor   = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac);
            allPsmsArrayModern = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ModernSearchEngine(allPsmsArrayModern, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, massDiffAcceptor, 0, new List <string>()).Run();

            fdrResultsClassicDelta = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArray.ToList(), 1, CommonParameters, new List <string>()).Run());
            fdrResultsModernDelta  = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArrayModern.ToList(), 1, CommonParameters, new List <string>()).Run());
            Assert.IsTrue(fdrResultsClassicDelta.PsmsWithin1PercentFdr == 3);
            Assert.IsTrue(fdrResultsModernDelta.PsmsWithin1PercentFdr == 3);

            CommonParameters = new CommonParameters(digestionParams: new DigestionParams(minPeptideLength: 5));

            //check no change when using score
            fdrResultsClassic = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArray.ToList(), 1, CommonParameters, new List <string>()).Run());
            fdrResultsModern  = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArrayModern.ToList(), 1, CommonParameters, new List <string>()).Run());
            Assert.IsTrue(fdrResultsClassic.PsmsWithin1PercentFdr == 3);
            Assert.IsTrue(fdrResultsModern.PsmsWithin1PercentFdr == 3);
        }
示例#17
0
        public void Test_FragmentationTwoModNeutralLossTwoFragTypes()
        {
            // Now we'll check the mass of modified peptide with no neutral losses
            ModificationMotif.TryGetMotif("T", out ModificationMotif motif);

            Dictionary <DissociationType, List <double> > myNeutralLosses = new Dictionary <DissociationType, List <double> >()
            {
                { DissociationType.HCD, new List <double> {
                      ChemicalFormula.ParseFormula("H3 O4 P1").MonoisotopicMass
                  } },
                { DissociationType.ETD, new List <double>()
                  {
                      ChemicalFormula.ParseFormula("H3 N1").MonoisotopicMass
                  } }                                                                                                   // this makes no sense in real life, it's just for a unit test
            };

            Modification        mod     = new Modification(_originalId: "phospho", _modificationType: "testModType", _target: motif, _chemicalFormula: ChemicalFormula.ParseFormula("H1 O3 P1"), _neutralLosses: myNeutralLosses, _locationRestriction: "Anywhere.");
            List <Modification> modlist = new List <Modification> {
                mod
            };
            DigestionParams digestionParams = new DigestionParams(
                protease: "trypsin",
                maxMissedCleavages: 0,
                minPeptideLength: 1,
                initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain);

            var prot = new Protein("PEPTIDE", null, oneBasedModifications: new Dictionary <int, List <Modification> > {
                { 4, modlist }
            });
            var ye = prot.Digest(digestionParams, new List <Modification>(), new List <Modification>()).ToList();

            var peptideWithNeutralMassMod = ye.Where(v => v.AllModsOneIsNterminus.Count == 1).First();

            var myModFragmentsHCD = new List <Product>();

            peptideWithNeutralMassMod.Fragment(DissociationType.HCD, FragmentationTerminus.Both, myModFragmentsHCD);

            var neutralMassesHCD  = myModFragmentsHCD.Select(m => (int)m.NeutralMass.ToMz(1));
            var expectedMassesHCD = new HashSet <int> {
                98, 227, 324, 407, 520, 635, 505, 618, 733,  // b-ions with and without neutral loss
                148, 263, 376, 459, 556, 685, 557, 654, 783, //y-ions with and without neutral loss
                782
            };                                               // molecular ion with neutral loss

            CollectionAssert.AreEquivalent(expectedMassesHCD, neutralMassesHCD);

            //Now try the other half
            var myModFragmentsETD = new List <Product>();

            peptideWithNeutralMassMod.Fragment(DissociationType.ETD, FragmentationTerminus.Both, myModFragmentsETD);

            var neutralMassesETD  = myModFragmentsETD.Select(m => (int)m.NeutralMass.ToMz(1));
            var expectedMassesETD = new HashSet <int> {
                115, 244, 341, 505, 618, 733, 522, 635, 750, // c-ions and c-17 ions
                148, 263, 376, 540, 637, 766, 557, 654, 783, // y and y-17 ions
                133, 248, 361, 525, 622, 751, 542, 639, 768, // z+1 and z+1-17 ions
                863
            };                                               //Molecular ions minus ammonia

            CollectionAssert.AreEquivalent(expectedMassesHCD, neutralMassesHCD);
        }
示例#18
0
        private static Tuple <List <PeptideSpectralMatch>, Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >, MassDiffAcceptor, bool, CompactPeptideBase, CompactPeptideBase> GetInfo(bool localizeable)
        {
            CommonParameters CommonParameters = new CommonParameters(digestionParams: new DigestionParams(maxMissedCleavages: 0, minPeptideLength: 1, maxModificationIsoforms: 2, initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain, maxModsForPeptides: 1), scoreCutoff: 1);


            // Alanine = Glycine + CH2
            Protein protein1 = new Protein("MA", "protein1");
            Protein protein2 = new Protein("MG", "protein2");
            Protein protein3;
            double  monoisotopicMass = Chemistry.ChemicalFormula.ParseFormula("CH2").MonoisotopicMass;

            ModificationMotif.TryGetMotif("G", out ModificationMotif motif1);
            ModificationMotif.TryGetMotif("A", out ModificationMotif motif2);
            TerminusLocalization        modificationSites          = TerminusLocalization.Any;
            List <ModificationWithMass> allKnownFixedModifications = new List <ModificationWithMass>
            {
                new ModificationWithMass("CH2 on Glycine", null, motif1, modificationSites, monoisotopicMass)
            };
            List <ModificationWithMass> variableModifications;

            ModificationWithMass alanineMod = new ModificationWithMass("CH2 on Alanine", null, motif2, modificationSites, monoisotopicMass);

            if (localizeable)
            {
                variableModifications = new List <ModificationWithMass>();
                IDictionary <int, List <Modification> > oneBasedModifications = new Dictionary <int, List <Modification> >
                {
                    { 2, new List <Modification> {
                          alanineMod
                      } }
                };
                protein3 = new Protein("MA", "protein3", oneBasedModifications: oneBasedModifications);
            }
            else
            {
                variableModifications = new List <ModificationWithMass>();
                variableModifications = new List <ModificationWithMass> {
                    alanineMod
                };
                protein3 = new Protein("MA", "protein3");
            }

            var pepWithSetModifications1 = protein1.Digest(CommonParameters.DigestionParams, allKnownFixedModifications, variableModifications).First();

            var pepWithSetModifications2 = protein2.Digest(CommonParameters.DigestionParams, allKnownFixedModifications, variableModifications).First();

            var pepWithSetModifications3 = protein3.Digest(CommonParameters.DigestionParams, allKnownFixedModifications, variableModifications).Last();

            CompactPeptide compactPeptide1         = new CompactPeptide(pepWithSetModifications1, TerminusType.None);
            CompactPeptide compactPeptideDuplicate = new CompactPeptide(pepWithSetModifications2, TerminusType.None);

            Assert.AreEqual(compactPeptide1, compactPeptideDuplicate);
            CompactPeptide compactPeptide2 = new CompactPeptide(pepWithSetModifications3, TerminusType.None);

            string                  fullFilePath    = null;
            int                     precursorCharge = 0;
            TestDataFile            testDataFile    = new TestDataFile();
            MsDataScan              mzLibScan       = testDataFile.GetOneBasedScan(2);
            Ms2ScanWithSpecificMass scan            = new Ms2ScanWithSpecificMass(mzLibScan, 0, precursorCharge, fullFilePath);
            int                     scanIndex       = 0;
            double                  score           = 0;
            int                     notch           = 0;
            PeptideSpectralMatch    psm1            = new PeptideSpectralMatch(compactPeptide1, notch, score, scanIndex, scan, CommonParameters.DigestionParams);

            psm1.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0, 0, false);
            PeptideSpectralMatch psm2 = new PeptideSpectralMatch(compactPeptide1, notch, score, scanIndex, scan, CommonParameters.DigestionParams);

            psm2.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0, 0, false);
            PeptideSpectralMatch psm3 = new PeptideSpectralMatch(compactPeptide2, notch, score, scanIndex, scan, CommonParameters.DigestionParams);

            psm3.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0, 0, false);
            var newPsms = new List <PeptideSpectralMatch>
            {
                psm1,
                psm2,
                psm3
            };

            MassDiffAcceptor massDiffAcceptors            = new SinglePpmAroundZeroSearchMode(5);
            SequencesToActualProteinPeptidesEngine stappe = new SequencesToActualProteinPeptidesEngine(newPsms, new List <Protein> {
                protein1, protein2, protein3
            },
                                                                                                       allKnownFixedModifications, variableModifications, new List <ProductType> {
                ProductType.B, ProductType.Y
            }, new List <DigestionParams> {
                CommonParameters.DigestionParams
            }, CommonParameters.ReportAllAmbiguity, CommonParameters, new List <string>());

            var haha = (SequencesToActualProteinPeptidesEngineResults)stappe.Run();
            var compactPeptideToProteinPeptideMatching = haha.CompactPeptideToProteinPeptideMatching;

            Assert.AreEqual(2, compactPeptideToProteinPeptideMatching.Count);

            psm1.MatchToProteinLinkedPeptides(compactPeptideToProteinPeptideMatching);

            bool noOneHitWonders = false;

            return(new Tuple <List <PeptideSpectralMatch>, Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >, MassDiffAcceptor, bool, CompactPeptideBase, CompactPeptideBase>
                   (
                       newPsms, compactPeptideToProteinPeptideMatching, massDiffAcceptors, noOneHitWonders, compactPeptide1, compactPeptide2
                   ));
        }
        public static void ParsimonyDontTreatModifiedFormsAsUnique()
        {
            bool modPeptidesAreUnique = false;

            // set up mods
            var modDictionary = new Dictionary <int, List <Modification> >();

            ModificationMotif.TryGetMotif("M", out ModificationMotif motif1);
            var mod = new Modification(_originalId: "Oxidation of M", _modificationType: "Common Variable", _target: motif1, _locationRestriction: "Anywhere.", _monoisotopicMass: 15.99491461957);

            // modified version of protein
            var protein1 = new Protein("PEPTIDEM", "accession1");

            // unmodified version of protein
            var protein2 = new Protein("YYYKPEPTIDEM", "accession2");

            List <PeptideWithSetModifications> pwsmsFromProtein1 = protein1.Digest(new DigestionParams(protease: "trypsin", minPeptideLength: 1), new List <Modification> {
                mod
            }, new List <Modification>()).ToList();                                                                                                                                                                   //this is a fixed mod
            List <PeptideWithSetModifications> pwsmsFromProtein2 = protein2.Digest(new DigestionParams(protease: "trypsin", minPeptideLength: 1), new List <Modification>(), new List <Modification>()).ToList();

            // check to make sure mod is present
            PeptideWithSetModifications modifiedPeptide   = pwsmsFromProtein1[0];
            PeptideWithSetModifications unmodifiedPeptide = pwsmsFromProtein2[1];

            Assert.That(!modifiedPeptide.FullSequence.Equals(unmodifiedPeptide.FullSequence)); // sequences should not be equal (one has a mod)
            Assert.That(modifiedPeptide.BaseSequence.Equals(unmodifiedPeptide.BaseSequence));  // base sequences should be equal
            Assert.That(modifiedPeptide.NumMods == 1);                                         // methionine was oxidized on this protein
            Assert.That(unmodifiedPeptide.NumMods == 0);                                       // there was no modification on this protein

            // build PSMs for parsimony
            List <PeptideSpectralMatch> psmsForParsimony = new List <PeptideSpectralMatch>();

            MsDataScan fakeScan = new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false),
                                                 0, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null,
                                                 null, "scan=1", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 0, null);

            Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(fakeScan, 2, 0, "File", new CommonParameters());

            PeptideSpectralMatch psm1 = new PeptideSpectralMatch(modifiedPeptide, 0, 10, 1, scan, new DigestionParams(), new List <MatchedFragmentIon>());

            psm1.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0);
            psm1.ResolveAllAmbiguities();

            PeptideSpectralMatch psm2 = new PeptideSpectralMatch(unmodifiedPeptide, 0, 10, 2, scan, new DigestionParams(), new List <MatchedFragmentIon>());

            psm2.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0);
            psm2.ResolveAllAmbiguities();

            psmsForParsimony.Add(psm1);
            psmsForParsimony.Add(psm2);

            // apply parsimony
            ProteinParsimonyEngine pae = new ProteinParsimonyEngine(psmsForParsimony, modPeptidesAreUnique, new CommonParameters(), new List <string>());

            // because the two chosen peptides are the same, we should end up with both protein accessions still in the list
            var proteinParsimonyResult = (ProteinParsimonyResults)pae.Run();

            // score protein groups and merge indistinguishable ones
            ProteinScoringAndFdrEngine proteinScoringEngine = new ProteinScoringAndFdrEngine(proteinParsimonyResult.ProteinGroups, psmsForParsimony, false, true, true, new CommonParameters(), new List <string>());
            var results = (ProteinScoringAndFdrResults)proteinScoringEngine.Run();

            int countOfProteinGroups = results.SortedAndScoredProteinGroups.Count;

            // because modified peptides were NOT considered as unique,
            // then there should be one ambiguous protein group after parsimony,
            // and two protein accessions for each peptide
            Assert.AreEqual(1, countOfProteinGroups);
            Assert.AreEqual(2, results.SortedAndScoredProteinGroups.First().Proteins.Count);
            Assert.IsNull(psm1.ProteinAccession);
            Assert.IsNull(psm2.ProteinAccession);
        }
示例#20
0
        public static void TestSerializationPeptideFromProteinWithMod()
        {
            // purpose of this test is to serialize/deserialize a PeptideWithSetModifications and make sure the deserialized peptide
            // has the same properties as before it was serialized. This peptide is modified with a phosphorylation

            ModificationMotif.TryGetMotif("T", out ModificationMotif motif);

            Dictionary <DissociationType, List <double> > myNeutralLosses = new Dictionary <DissociationType, List <double> >()
            {
                { DissociationType.HCD, new List <double> {
                      ChemicalFormula.ParseFormula("H3 O4 P1").MonoisotopicMass
                  } },
                { DissociationType.ETD, new List <double>()
                  {
                      ChemicalFormula.ParseFormula("H3 N1").MonoisotopicMass
                  } }                                                                                                   // this makes no sense in real life, it's just for a unit test
            };

            Modification mod = new Modification(_originalId: "phospho", _modificationType: "testModType", _target: motif, _chemicalFormula: ChemicalFormula.ParseFormula("H1 O3 P1"), _neutralLosses: myNeutralLosses, _locationRestriction: "Anywhere.");

            Dictionary <int, List <Modification> > mods = new Dictionary <int, List <Modification> > {
                { 4, new List <Modification> {
                      mod
                  } }
            };

            Protein protein = new Protein("PEPTIDE", "Accession1", name: "MyProtein", oneBasedModifications: mods);

            PeptideWithSetModifications peptide             = protein.Digest(new DigestionParams(), new List <Modification>(), new List <Modification>()).Where(v => v.AllModsOneIsNterminus.Count == 1).First();
            PeptideWithSetModifications deserializedPeptide = null;

            string dir = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, "TestSerializationPeptideFromProteinWithMod");

            System.IO.Directory.CreateDirectory(dir);
            string path = System.IO.Path.Combine(dir, "myPeptideIndex.ind");

            var messageTypes = typeof(PeptideWithSetModifications);
            var ser          = new NetSerializer.Serializer(new List <Type> {
                messageTypes
            });

            using (var file = System.IO.File.Create(path))
            {
                ser.Serialize(file, peptide);
            }

            using (var file = System.IO.File.OpenRead(path))
            {
                deserializedPeptide = (PeptideWithSetModifications)ser.Deserialize(file);
            }

            Dictionary <string, Modification> stringToMod = new Dictionary <string, Modification> {
                { mods.Values.First().First().IdWithMotif, mods.Values.First().First() }
            };

            deserializedPeptide.SetNonSerializedPeptideInfo(stringToMod, new Dictionary <string, Protein> {
                { protein.Accession, protein }
            }, peptide.DigestionParams);

            Assert.That(peptide.Equals(deserializedPeptide));
            Assert.That(deserializedPeptide.Protein.Name == peptide.Protein.Name);
            Assert.That(deserializedPeptide.MonoisotopicMass == peptide.MonoisotopicMass);
            Assert.That(deserializedPeptide.SequenceWithChemicalFormulas == peptide.SequenceWithChemicalFormulas);

            var products = new List <Product>();

            deserializedPeptide.Fragment(DissociationType.HCD, FragmentationTerminus.Both, products);
            List <double> deserializedPeptideFragments = products.Select(v => v.NeutralMass).ToList();

            peptide.Fragment(DissociationType.HCD, FragmentationTerminus.Both, products);
            List <double> peptideFragments = products.Select(v => v.NeutralMass).ToList();

            Assert.That(deserializedPeptideFragments.SequenceEqual(peptideFragments));
        }
示例#21
0
        public static void FdrTestMethod()
        {
            MassDiffAcceptor searchModes = new DotMassDiffAcceptor(null, new List <double> {
                0, 1.0029
            }, new PpmTolerance(5));
            List <string> nestedIds = new List <string>();

            Protein         p = new Protein("MNKNNKNNNKNNNNK", null);
            DigestionParams digestionParams = new DigestionParams();
            var             digested        = p.Digest(digestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).ToList();

            PeptideWithSetModifications pep1 = digested[0];
            PeptideWithSetModifications pep2 = digested[1];
            PeptideWithSetModifications pep3 = digested[2];
            PeptideWithSetModifications pep4 = digested[3];

            TestDataFile t = new TestDataFile(new List <PeptideWithSetModifications> {
                pep1, pep2, pep3
            });

            CompactPeptide peptide1 = new CompactPeptide(pep1, TerminusType.None);
            IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> > mzLibScan1 = t.GetOneBasedScan(2) as IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >;
            Ms2ScanWithSpecificMass scan1 = new Ms2ScanWithSpecificMass(mzLibScan1, peptide1.MonoisotopicMassIncludingFixedMods.ToMz(1), 1, null);
            PeptideSpectralMatch    psm1  = new PeptideSpectralMatch(peptide1, 0, 3, 0, scan1);

            CompactPeptide peptide2 = new CompactPeptide(pep2, TerminusType.None);
            IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> > mzLibScan2 = t.GetOneBasedScan(4) as IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >;
            Ms2ScanWithSpecificMass scan2 = new Ms2ScanWithSpecificMass(mzLibScan2, peptide2.MonoisotopicMassIncludingFixedMods.ToMz(1), 1, null);
            PeptideSpectralMatch    psm2  = new PeptideSpectralMatch(peptide2, 1, 2, 1, scan2);

            CompactPeptide peptide3 = new CompactPeptide(pep3, TerminusType.None);
            IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> > mzLibScan3 = t.GetOneBasedScan(6) as IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >;
            Ms2ScanWithSpecificMass scan3 = new Ms2ScanWithSpecificMass(mzLibScan3, peptide3.MonoisotopicMassIncludingFixedMods.ToMz(1), 1, null);
            PeptideSpectralMatch    psm3  = new PeptideSpectralMatch(peptide3, 0, 1, 2, scan3);

            CompactPeptide peptide4 = new CompactPeptide(pep4, TerminusType.None);

            psm3.AddOrReplace(peptide4, 1, 1, true);

            Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > matching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >
            {
                {
                    peptide1, new HashSet <PeptideWithSetModifications> {
                        pep1
                    }
                },
                {
                    peptide2, new HashSet <PeptideWithSetModifications> {
                        pep2
                    }
                },
                {
                    peptide3, new HashSet <PeptideWithSetModifications> {
                        pep3
                    }
                },
                {
                    peptide4, new HashSet <PeptideWithSetModifications> {
                        pep4
                    }
                },
            };

            psm1.MatchToProteinLinkedPeptides(matching);
            psm2.MatchToProteinLinkedPeptides(matching);
            psm3.MatchToProteinLinkedPeptides(matching);

            var newPsms = new List <PeptideSpectralMatch> {
                psm1, psm2, psm3
            };
            FdrAnalysisEngine fdr = new FdrAnalysisEngine(newPsms, searchModes.NumNotches, true, nestedIds);

            fdr.Run();

            Assert.AreEqual(2, searchModes.NumNotches);
            Assert.AreEqual(0, newPsms[0].FdrInfo.CumulativeDecoyNotch);
            Assert.AreEqual(1, newPsms[0].FdrInfo.CumulativeTargetNotch);
            Assert.AreEqual(0, newPsms[1].FdrInfo.CumulativeDecoyNotch);
            Assert.AreEqual(1, newPsms[1].FdrInfo.CumulativeTargetNotch);
            Assert.AreEqual(0, newPsms[2].FdrInfo.CumulativeDecoyNotch);
            Assert.AreEqual(1, newPsms[2].FdrInfo.CumulativeTargetNotch);

            Assert.AreEqual(0, newPsms[0].FdrInfo.CumulativeDecoy);
            Assert.AreEqual(1, newPsms[0].FdrInfo.CumulativeTarget);
            Assert.AreEqual(0, newPsms[1].FdrInfo.CumulativeDecoy);
            Assert.AreEqual(2, newPsms[1].FdrInfo.CumulativeTarget);
            Assert.AreEqual(0, newPsms[2].FdrInfo.CumulativeDecoy);
            Assert.AreEqual(3, newPsms[2].FdrInfo.CumulativeTarget);
        }
示例#22
0
        public static void TestProteinSplitAcrossFiles()
        {
            SearchTask st = new SearchTask()
            {
                CommonParameters = new CommonParameters
                {
                    ScoreCutoff     = 1,
                    DigestionParams = new DigestionParams
                    {
                        InitiatorMethionineBehavior = InitiatorMethionineBehavior.Retain,
                        MaxMissedCleavages          = 0
                    },
                    ConserveMemory = false,
                },
                SearchParameters = new SearchParameters
                {
                    DoHistogramAnalysis  = true,
                    MassDiffAcceptorType = MassDiffAcceptorType.Open,
                    MatchBetweenRuns     = true,
                    DoQuantification     = true
                },
            };

            string proteinDbFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestProteinSplitAcrossFiles.xml");
            string mzmlFilePath1     = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestProteinSplitAcrossFiles1.mzml");
            string mzmlFilePath2     = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestProteinSplitAcrossFiles2.mzml");

            ModificationMotif.TryGetMotif("D", out ModificationMotif motif);
            ModificationWithMass mod = new ModificationWithMass("mod1", "mt", motif, TerminusLocalization.Any, 10);

            IDictionary <int, List <Modification> > oneBasedModification = new Dictionary <int, List <Modification> >
            {
                { 3, new List <Modification> {
                      mod
                  } }
            };

            Protein prot1 = new Protein("MEDEEK", "prot1", oneBasedModifications: oneBasedModification);

            var pep1 = prot1.Digest(st.CommonParameters.DigestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).First();
            var pep2 = prot1.Digest(st.CommonParameters.DigestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).Last();

            List <PeptideWithSetModifications> listForFile1 = new List <PeptideWithSetModifications> {
                pep1, pep2
            };
            List <PeptideWithSetModifications> listForFile2 = new List <PeptideWithSetModifications> {
                pep2
            };
            IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile1 = new TestDataFile(listForFile1);
            IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile2 = new TestDataFile(listForFile2);

            List <Protein> proteinList = new List <Protein> {
                prot1
            };

            IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile1, mzmlFilePath1, false);
            IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile2, mzmlFilePath2, false);
            ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), proteinList, proteinDbFilePath);

            string output_folder = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestProteinSplitAcrossFiles");

            Directory.CreateDirectory(output_folder);

            st.RunTask(
                output_folder,
                new List <DbForTask> {
                new DbForTask(proteinDbFilePath, false)
            },
                new List <string> {
                mzmlFilePath1, mzmlFilePath2,
            },
                null);
        }
示例#23
0
        public static void TestProteinSplitAcrossFiles()
        {
            SearchTask st = new SearchTask()
            {
                CommonParameters = new CommonParameters(
                    scoreCutoff: 1,
                    digestionParams: new DigestionParams(
                        maxMissedCleavages: 0,
                        minPeptideLength: 5,
                        initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain)),

                SearchParameters = new SearchParameters
                {
                    DoHistogramAnalysis  = true,
                    MassDiffAcceptorType = MassDiffAcceptorType.Open,
                    MatchBetweenRuns     = true,
                    DoQuantification     = true
                },
            };

            string proteinDbFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestProteinSplitAcrossFiles.xml");
            string mzmlFilePath1     = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestProteinSplitAcrossFiles1.mzML");
            string mzmlFilePath2     = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestProteinSplitAcrossFiles2.mzML");

            ModificationMotif.TryGetMotif("D", out ModificationMotif motif);
            Modification mod = new Modification(_originalId: "mod1 on D", _modificationType: "mt", _target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 10);

            IDictionary <int, List <Modification> > oneBasedModification = new Dictionary <int, List <Modification> >
            {
                { 3, new List <Modification> {
                      mod
                  } }
            };

            Protein prot1 = new Protein("MEDEEK", "prot1", oneBasedModifications: oneBasedModification);

            var pep1 = prot1.Digest(st.CommonParameters.DigestionParams, new List <Modification>(), new List <Modification>()).First();
            var pep2 = prot1.Digest(st.CommonParameters.DigestionParams, new List <Modification>(), new List <Modification>()).Last();

            List <PeptideWithSetModifications> listForFile1 = new List <PeptideWithSetModifications> {
                pep1, pep2
            };
            List <PeptideWithSetModifications> listForFile2 = new List <PeptideWithSetModifications> {
                pep2
            };
            MsDataFile myMsDataFile1 = new TestDataFile(listForFile1);
            MsDataFile myMsDataFile2 = new TestDataFile(listForFile2);

            List <Protein> proteinList = new List <Protein> {
                prot1
            };

            IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile1, mzmlFilePath1, false);
            IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile2, mzmlFilePath2, false);
            ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), proteinList, proteinDbFilePath);

            string output_folder = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestProteinSplitAcrossFiles");

            Directory.CreateDirectory(output_folder);

            st.RunTask(
                output_folder,
                new List <DbForTask> {
                new DbForTask(proteinDbFilePath, false)
            },
                new List <string> {
                mzmlFilePath1, mzmlFilePath2,
            },
                null);
            Directory.Delete(output_folder, true);
            File.Delete(proteinDbFilePath);
            File.Delete(mzmlFilePath1);
            File.Delete(mzmlFilePath2);
            Directory.Delete(Path.Combine(TestContext.CurrentContext.TestDirectory, @"Task Settings"), true);
        }
示例#24
0
        public static void ParsimonyLocalizeableDontTreatAsUnique()
        {
            bool modPeptidesAreUnique = false;

            // set up mods
            var modDictionary = new Dictionary <int, List <Modification> >();

            ModificationMotif.TryGetMotif("M", out ModificationMotif motif1);
            var mod = new ModificationWithMass("Oxidation of M", "Common Variable", motif1, TerminusLocalization.Any, 15.99491461957);

            TerminusType terminusType = ProductTypeMethod.IdentifyTerminusType(new List <ProductType> {
                ProductType.B, ProductType.Y
            });

            var protease = new Protease("kprotease", new List <string> {
                "K"
            }, new List <string>(), TerminusType.C, CleavageSpecificity.Full, null, null, null);

            // modified version of protein
            var protein1 = new Protein("PEPTIDEM", "accession1");
            // unmodified version of protein
            var protein2 = new Protein("YYYKPEPTIDEM", "accession2");

            var pep1 = protein1.Digest(new DigestionParams {
                MinPeptideLength = null, Protease = protease
            }, new List <ModificationWithMass> {
                mod
            }, new List <ModificationWithMass>()).First();
            var pep2 = protein2.Digest(new DigestionParams {
                MinPeptideLength = null, Protease = protease
            }, new List <ModificationWithMass>(), new List <ModificationWithMass>()).ToList()[1];

            // check to make sure mod is present
            Assert.That(pep1.Sequence != pep2.Sequence);
            Assert.That(pep1.NumMods == 1);
            Assert.That(pep2.NumMods == 0);

            // build the dictionary for input to parsimony
            var compactPeptideToProteinPeptideMatching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >();

            compactPeptideToProteinPeptideMatching.Add(pep1.CompactPeptide(terminusType), new HashSet <PeptideWithSetModifications> {
                pep1
            });
            compactPeptideToProteinPeptideMatching.Add(pep2.CompactPeptide(terminusType), new HashSet <PeptideWithSetModifications> {
                pep2
            });

            // apply parsimony
            ProteinParsimonyEngine pae = new ProteinParsimonyEngine(compactPeptideToProteinPeptideMatching, modPeptidesAreUnique, new List <string>());

            pae.Run();

            // check to make sure both peptides are associated with both proteins
            Assert.That(compactPeptideToProteinPeptideMatching.Count == 2);
            foreach (var kvp in compactPeptideToProteinPeptideMatching)
            {
                Assert.That(kvp.Value.Count == 2);
                var seq = kvp.Value.First().Sequence;

                foreach (var peptide in kvp.Value)
                {
                    Assert.That(peptide.Sequence.Equals(seq));
                }
            }
            var test1 = compactPeptideToProteinPeptideMatching.First().Value.ToList();

            Assert.That(test1[0].OneBasedStartResidueInProtein != test1[1].OneBasedStartResidueInProtein);
            Assert.That(test1[0].OneBasedEndResidueInProtein != test1[1].OneBasedEndResidueInProtein);
        }
示例#25
0
        public static void FdrTestMethod()
        {
            MassDiffAcceptor searchModes = new DotMassDiffAcceptor(null, new List <double> {
                0, 1.0029
            }, new PpmTolerance(5));
            List <string> nestedIds = new List <string>();

            Protein         p = new Protein("MNKNNKNNNKNNNNK", null);
            DigestionParams digestionParams = new DigestionParams();
            var             digested        = p.Digest(digestionParams, new List <Modification>(), new List <Modification>()).ToList();

            PeptideWithSetModifications pep1 = digested[0];
            PeptideWithSetModifications pep2 = digested[1];
            PeptideWithSetModifications pep3 = digested[2];
            PeptideWithSetModifications pep4 = digested[3];

            TestDataFile t = new TestDataFile(new List <PeptideWithSetModifications> {
                pep1, pep2, pep3
            });

            MsDataScan mzLibScan1         = t.GetOneBasedScan(2);
            Ms2ScanWithSpecificMass scan1 = new Ms2ScanWithSpecificMass(mzLibScan1, pep1.MonoisotopicMass.ToMz(1), 1, null, new CommonParameters());
            PeptideSpectralMatch    psm1  = new PeptideSpectralMatch(pep1, 0, 3, 0, scan1, digestionParams, new List <MatchedFragmentIon>());

            MsDataScan mzLibScan2         = t.GetOneBasedScan(4);
            Ms2ScanWithSpecificMass scan2 = new Ms2ScanWithSpecificMass(mzLibScan2, pep2.MonoisotopicMass.ToMz(1), 1, null, new CommonParameters());
            PeptideSpectralMatch    psm2  = new PeptideSpectralMatch(pep2, 1, 2, 1, scan2, digestionParams, new List <MatchedFragmentIon>());

            MsDataScan mzLibScan3         = t.GetOneBasedScan(6);
            Ms2ScanWithSpecificMass scan3 = new Ms2ScanWithSpecificMass(mzLibScan3, pep3.MonoisotopicMass.ToMz(1), 1, null, new CommonParameters());
            PeptideSpectralMatch    psm3  = new PeptideSpectralMatch(pep3, 0, 1, 2, scan3, digestionParams, new List <MatchedFragmentIon>());

            psm3.AddOrReplace(pep4, 1, 1, true, new List <MatchedFragmentIon>(), 0);

            var newPsms = new List <PeptideSpectralMatch> {
                psm1, psm2, psm3
            };

            foreach (PeptideSpectralMatch psm in newPsms)
            {
                psm.ResolveAllAmbiguities();
            }

            FdrAnalysisEngine fdr = new FdrAnalysisEngine(newPsms, searchModes.NumNotches, new CommonParameters(), nestedIds);

            fdr.Run();

            Assert.AreEqual(2, searchModes.NumNotches);
            Assert.AreEqual(0, newPsms[0].FdrInfo.CumulativeDecoyNotch);
            Assert.AreEqual(1, newPsms[0].FdrInfo.CumulativeTargetNotch);
            Assert.AreEqual(0, newPsms[1].FdrInfo.CumulativeDecoyNotch);
            Assert.AreEqual(1, newPsms[1].FdrInfo.CumulativeTargetNotch);
            Assert.AreEqual(0, newPsms[2].FdrInfo.CumulativeDecoyNotch);
            Assert.AreEqual(1, newPsms[2].FdrInfo.CumulativeTargetNotch);

            Assert.AreEqual(0, newPsms[0].FdrInfo.CumulativeDecoy);
            Assert.AreEqual(1, newPsms[0].FdrInfo.CumulativeTarget);
            Assert.AreEqual(0, newPsms[1].FdrInfo.CumulativeDecoy);
            Assert.AreEqual(2, newPsms[1].FdrInfo.CumulativeTarget);
            Assert.AreEqual(0, newPsms[2].FdrInfo.CumulativeDecoy);
            Assert.AreEqual(3, newPsms[2].FdrInfo.CumulativeTarget);
        }
示例#26
0
        public static void TestEverythingRunner()
        {
            foreach (var modFile in Directory.GetFiles(@"Mods"))
            {
                GlobalVariables.AddMods(PtmListLoader.ReadModsFromFile(modFile));
            }

            CalibrationTask task1 = new CalibrationTask
            {
                CommonParameters = new CommonParameters(digestionParams: new DigestionParams(maxMissedCleavages: 0, minPeptideLength: 1, initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain)),

                CalibrationParameters = new CalibrationParameters
                {
                    WriteIntermediateFiles = true,
                    NumFragmentsNeededForEveryIdentification = 6,
                }
            };
            GptmdTask task2 = new GptmdTask
            {
                CommonParameters = new CommonParameters()
            };

            SearchTask task3 = new SearchTask
            {
                CommonParameters = new CommonParameters(),

                SearchParameters = new SearchParameters
                {
                    DoParsimony  = true,
                    SearchTarget = true,
                    SearchType   = SearchType.Modern
                }
            };

            SearchTask task4 = new SearchTask
            {
                CommonParameters = new CommonParameters(),

                SearchParameters = new SearchParameters
                {
                    SearchType = SearchType.Modern,
                }
            };
            List <(string, MetaMorpheusTask)> taskList = new List <(string, MetaMorpheusTask)> {
                ("task1", task1),
                ("task2", task2),
                ("task3", task3),
                ("task4", task4),
            };

            List <ModificationWithMass> variableModifications = GlobalVariables.AllModsKnown.OfType <ModificationWithMass>().Where(b => task1.CommonParameters.ListOfModsVariable.Contains((b.modificationType, b.id))).ToList();
            List <ModificationWithMass> fixedModifications    = GlobalVariables.AllModsKnown.OfType <ModificationWithMass>().Where(b => task1.CommonParameters.ListOfModsFixed.Contains((b.modificationType, b.id))).ToList();

            // Generate data for files
            Protein ParentProtein = new Protein("MPEPTIDEKANTHE", "accession1");

            var digestedList = ParentProtein.Digest(task1.CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList();

            Assert.AreEqual(3, digestedList.Count);

            PeptideWithSetModifications pepWithSetMods1 = digestedList[0];

            PeptideWithSetModifications pepWithSetMods2 = digestedList[2];

            var dictHere = new Dictionary <int, List <Modification> >();

            ModificationMotif.TryGetMotif("E", out ModificationMotif motif);
            dictHere.Add(3, new List <Modification> {
                new ModificationWithMass("21", null, motif, TerminusLocalization.Any, 21.981943)
            });
            Protein ParentProteinToNotInclude = new Protein("MPEPTIDEK", "accession2", "organism", new List <Tuple <string, string> >(), dictHere);

            digestedList = ParentProteinToNotInclude.Digest(task1.CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList();

            MsDataFile myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> {
                pepWithSetMods1, pepWithSetMods2, digestedList[1]
            });

            Protein proteinWithChain = new Protein("MAACNNNCAA", "accession3", "organism", new List <Tuple <string, string> >(), new Dictionary <int, List <Modification> >(), new List <ProteolysisProduct> {
                new ProteolysisProduct(4, 8, "chain")
            }, "name2", "fullname2");

            string mzmlName = @"ok.mzML";

            IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile, mzmlName, false);
            string xmlName = "okk.xml";

            ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), new List <Protein> {
                ParentProtein, proteinWithChain
            }, xmlName);

            // RUN!
            var engine = new EverythingRunnerEngine(taskList, new List <string> {
                mzmlName
            }, new List <DbForTask> {
                new DbForTask(xmlName, false)
            }, Environment.CurrentDirectory);

            engine.Run();
        }
        public static void SearchWithPeptidesAddedInParsimonyTest()
        {
            // Make sure can run the complete search task when multiple compact peptides may correspond to a single PWSM
            SearchTask st = new SearchTask
            {
                SearchParameters = new SearchParameters
                {
                    DoParsimony             = true,
                    DecoyType               = DecoyType.None,
                    ModPeptidesAreDifferent = false
                },
                CommonParameters = new CommonParameters
                {
                    ScoreCutoff     = 1,
                    DigestionParams = new DigestionParams
                    {
                        MinPeptideLength = 2
                    }
                }
            };

            string xmlName = "andguiaheow.xml";

            #region Generate protein and write to file

            CommonParameters CommonParameters = new CommonParameters
            {
                DigestionParams = new DigestionParams
                {
                    MaxMissedCleavages          = 0,
                    MinPeptideLength            = null,
                    InitiatorMethionineBehavior = InitiatorMethionineBehavior.Retain,
                    MaxModsForPeptide           = 1,
                    MaxModificationIsoforms     = 2
                },
                ScoreCutoff = 1
            };
            ModificationMotif.TryGetMotif("A", out ModificationMotif motifA);
            ModificationWithMass alanineMod = new ModificationWithMass("111", "mt", motifA, TerminusLocalization.Any, 111);

            var variableModifications = new List <ModificationWithMass>();
            IDictionary <int, List <Modification> > oneBasedModifications1 = new Dictionary <int, List <Modification> >
            {
                { 2, new List <Modification> {
                      alanineMod
                  } }
            };
            Protein protein1 = new Protein("MA", "protein1", oneBasedModifications: oneBasedModifications1);
            // Alanine = Glycine + CH2

            ModificationMotif.TryGetMotif("G", out ModificationMotif motif1);

            ModificationWithMass glycineMod = new ModificationWithMass("CH2 on Glycine", "mt", motif1, TerminusLocalization.Any, Chemistry.ChemicalFormula.ParseFormula("CH2").MonoisotopicMass);

            IDictionary <int, List <Modification> > oneBasedModifications2 = new Dictionary <int, List <Modification> >
            {
                { 2, new List <Modification> {
                      glycineMod
                  } }
            };
            Protein protein2 = new Protein("MG", "protein3", oneBasedModifications: oneBasedModifications2);

            PeptideWithSetModifications pepMA    = protein1.Digest(CommonParameters.DigestionParams, new List <ModificationWithMass>(), variableModifications).First();
            PeptideWithSetModifications pepMA111 = protein1.Digest(CommonParameters.DigestionParams, new List <ModificationWithMass>(), variableModifications).Last();

            var pepMG = protein2.Digest(CommonParameters.DigestionParams, new List <ModificationWithMass>(), variableModifications).First();

            ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), new List <Protein> {
                protein1, protein2
            }, xmlName);

            #endregion Generate protein and write to file

            string mzmlName = @"ajgdiu.mzML";

            #region Generate and write the mzml

            {
                IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> {
                    pepMA, pepMG, pepMA111
                }, true);

                IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile, mzmlName, false);
            }

            #endregion Generate and write the mzml

            st.RunTask("",
                       new List <DbForTask> {
                new DbForTask(xmlName, false)
            },
                       new List <string> {
                mzmlName
            }, "");
        }
        public static void Test_UnmodifiedPeptide_AllProductType_fragmentMasses()
        {
            Protein p = new Protein("PET", "accession");

            DigestionParams digestionParams = new DigestionParams(minPeptideLength: 2);

            var aPeptideWithSetModifications = p.Digest(digestionParams, new List <Modification>(), new List <Modification>()).First();
            var fragments = new List <Product>();

            aPeptideWithSetModifications.Fragment(DissociationType.Unknown, FragmentationTerminus.Both, fragments);

            var allFragmentIonMzs = new HashSet <int>(fragments.Select(i => (int)Math.Round(i.NeutralMass.ToMz(1))));

            Assert.IsTrue(allFragmentIonMzs.SetEquals(new HashSet <int> {
            }));

            aPeptideWithSetModifications.Fragment(DissociationType.CID, FragmentationTerminus.Both, fragments);
            allFragmentIonMzs = new HashSet <int>(fragments.Select(i => (int)Math.Round(i.NeutralMass.ToMz(1))));
            Assert.IsTrue(allFragmentIonMzs.SetEquals(new HashSet <int> {
                227, 120, 249
            }));

            aPeptideWithSetModifications.Fragment(DissociationType.IRMPD, FragmentationTerminus.Both, fragments);
            allFragmentIonMzs = new HashSet <int>(fragments.Select(i => (int)Math.Round(i.NeutralMass.ToMz(1))));
            Assert.IsTrue(allFragmentIonMzs.SetEquals(new HashSet <int> {
                98, 227, 120, 249
            }));

            aPeptideWithSetModifications.Fragment(DissociationType.ECD, FragmentationTerminus.Both, fragments);
            allFragmentIonMzs = new HashSet <int>(fragments.Select(i => (int)Math.Round(i.NeutralMass.ToMz(1))));
            Assert.IsTrue(allFragmentIonMzs.SetEquals(new HashSet <int> {
                115, 244, 120, 249, 104, 233
            }));

            aPeptideWithSetModifications.Fragment(DissociationType.PQD, FragmentationTerminus.Both, fragments);
            allFragmentIonMzs = new HashSet <int>(fragments.Select(i => (int)Math.Round(i.NeutralMass.ToMz(1))));
            Assert.IsTrue(allFragmentIonMzs.SetEquals(new HashSet <int> {
            }));

            aPeptideWithSetModifications.Fragment(DissociationType.ETD, FragmentationTerminus.Both, fragments);
            allFragmentIonMzs = new HashSet <int>(fragments.Select(i => (int)Math.Round(i.NeutralMass.ToMz(1))));
            Assert.IsTrue(allFragmentIonMzs.SetEquals(new HashSet <int> {
                115, 244, 120, 249, 104, 233
            }));

            aPeptideWithSetModifications.Fragment(DissociationType.HCD, FragmentationTerminus.Both, fragments);
            allFragmentIonMzs = new HashSet <int>(fragments.Select(i => (int)Math.Round(i.NeutralMass.ToMz(1))));
            Assert.IsTrue(allFragmentIonMzs.SetEquals(new HashSet <int> {
                98, 227, 120, 249
            }));

            aPeptideWithSetModifications.Fragment(DissociationType.AnyActivationType, FragmentationTerminus.Both, fragments);
            allFragmentIonMzs = new HashSet <int>(fragments.Select(i => (int)Math.Round(i.NeutralMass.ToMz(1))));
            Assert.IsTrue(allFragmentIonMzs.SetEquals(new HashSet <int> {
                98, 227, 120, 249
            }));

            aPeptideWithSetModifications.Fragment(DissociationType.EThcD, FragmentationTerminus.Both, fragments);
            allFragmentIonMzs = new HashSet <int>(fragments.Select(i => (int)Math.Round(i.NeutralMass.ToMz(1))));
            Assert.IsTrue(allFragmentIonMzs.SetEquals(new HashSet <int> {
                98, 227, 115, 244, 120, 249, 104, 233
            }));

            DissociationTypeCollection.ProductsFromDissociationType[DissociationType.Custom] = new List <ProductType> {
            };
            aPeptideWithSetModifications.Fragment(DissociationType.Custom, FragmentationTerminus.Both, fragments);
            allFragmentIonMzs = new HashSet <int>(fragments.Select(i => (int)Math.Round(i.NeutralMass.ToMz(1))));
            Assert.IsTrue(allFragmentIonMzs.SetEquals(new HashSet <int> {
            }));

            aPeptideWithSetModifications.Fragment(DissociationType.ISCID, FragmentationTerminus.Both, fragments);
            allFragmentIonMzs = new HashSet <int>(fragments.Select(i => (int)Math.Round(i.NeutralMass.ToMz(1))));
            Assert.IsTrue(allFragmentIonMzs.SetEquals(new HashSet <int> {
            }));
        }
示例#29
0
        public static void ParsimonyVariableDontTreatAsUnique()
        {
            bool modPeptidesAreUnique = false;

            // set up mods
            var modDictionary = new Dictionary <int, List <Modification> >();

            ModificationMotif.TryGetMotif("M", out ModificationMotif motif1);
            var      mod      = new ModificationWithMass("Oxidation of M", "Common Variable", motif1, TerminusLocalization.Any, 15.99491461957);
            Protease protease = new Protease("k Protease", new List <Tuple <string, TerminusType> > {
                new Tuple <string, TerminusType>("K", TerminusType.C)
            }, new List <Tuple <string, TerminusType> >(), CleavageSpecificity.Full, null, null, null);

            ProteaseDictionary.Dictionary.Add(protease.Name, protease);
            TerminusType terminusType = ProductTypeMethods.IdentifyTerminusType(new List <ProductType> {
                ProductType.B, ProductType.Y
            });

            // modified version of protein
            var protein1 = new Protein("PEPTIDEM", "accession1");
            // unmodified version of protein
            var protein2 = new Protein("YYYKPEPTIDEM", "accession2");

            var pep1 = protein1.Digest(new DigestionParams(protease: "k Protease", minPeptideLength: 1), new List <ModificationWithMass> {
                mod
            }, new List <ModificationWithMass>()).First();
            var pep2 = protein2.Digest(new DigestionParams(protease: "k Protease", minPeptideLength: 1), new List <ModificationWithMass> {
                mod
            }, new List <ModificationWithMass>()).ToList()[1];

            // check to make sure mod is present
            Assert.That(pep1.Sequence.Equals(pep2.Sequence));
            Assert.That(pep1.NumMods == 1);
            Assert.That(pep2.NumMods == 1);

            // build the dictionary for input to parsimony
            var compactPeptideToProteinPeptideMatching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >();
            var cp1 = pep1.CompactPeptide(terminusType);
            var cp2 = pep2.CompactPeptide(terminusType);

            Assert.That(cp1.Equals(cp2));

            compactPeptideToProteinPeptideMatching.Add(pep1.CompactPeptide(terminusType), new HashSet <PeptideWithSetModifications> {
                pep1
            });
            Assert.That(compactPeptideToProteinPeptideMatching.ContainsKey(cp2));
            compactPeptideToProteinPeptideMatching[cp2].Add(pep2);

            // apply parsimony
            ProteinParsimonyEngine pae = new ProteinParsimonyEngine(compactPeptideToProteinPeptideMatching, modPeptidesAreUnique, new CommonParameters(), new List <string>());

            pae.Run();


            // check to make sure both peptides are associated with both proteins
            Assert.That(compactPeptideToProteinPeptideMatching.Count == 1);
            Assert.That(compactPeptideToProteinPeptideMatching.First().Value.Count == 2);
            var seq = compactPeptideToProteinPeptideMatching.First().Value.First().Sequence;

            foreach (var sequence in compactPeptideToProteinPeptideMatching.First().Value)
            {
                Assert.That(sequence.Sequence.Equals(seq));
            }
        }
示例#30
0
        public static void CNBrProteinDigestion()
        {
            var    proteaseMods = PtmListLoader.ReadModsFromFile(Path.Combine(TestContext.CurrentContext.TestDirectory, "ModificationTests", "ProteaseMods.txt"), out var errors).ToList();
            var    prot         = new Protein("PEPTIDEMPEPTIDEM", null);
            var    prot2        = new Protein("MPEPTIDEMPEPTIDE", null);
            string path         = Path.Combine(TestContext.CurrentContext.TestDirectory, "DoubleProtease.tsv");

            Assert.That(File.Exists(path));

            var proteaseDict = ProteaseDictionary.LoadProteaseDictionary(path, proteaseMods);

            ProteaseDictionary.Dictionary = ProteaseDictionary.LoadProteaseDictionary(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ProteolyticDigestion", "proteases.tsv"), proteaseMods);
            var             protease1        = proteaseDict["CNBr"];
            DigestionParams digestionParams1 = new DigestionParams(
                protease: protease1.Name,
                maxMissedCleavages: 0,
                minPeptideLength: 1,
                initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain);
            List <Modification> variableModifications1 = new List <Modification>();

            var             protease2        = proteaseDict["CNBr_old"];
            DigestionParams digestionParams2 = new DigestionParams(
                protease: protease2.Name,
                maxMissedCleavages: 0,
                minPeptideLength: 1,
                initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain);
            List <Modification> variableModifications2 = new List <Modification>();

            var             protease3        = proteaseDict["CNBr_N"];
            DigestionParams digestionParams3 = new DigestionParams(
                protease: protease3.Name,
                maxMissedCleavages: 0,
                minPeptideLength: 1,
                initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain);
            List <Modification> variableModifications3 = new List <Modification>();

            var peps1 = prot.Digest(digestionParams1, new List <Modification>(), variableModifications1).ToList();
            var peps2 = prot.Digest(digestionParams2, new List <Modification>(), variableModifications2).ToList();
            var peps3 = prot2.Digest(digestionParams3, new List <Modification>(), variableModifications1).ToList();

            Assert.AreNotEqual(null, protease3.CleavageMod);
            Assert.AreEqual("M", protease3.CleavageMod.Target.ToString());


            Assert.AreNotEqual(peps3[0].MonoisotopicMass, peps3[1].MonoisotopicMass);

            Assert.AreEqual(882.39707781799996, peps3[1].MonoisotopicMass);
            Assert.AreEqual(930.400449121, peps3[0].MonoisotopicMass);


            Assert.AreEqual(null, protease2.CleavageMod);
            Assert.AreNotEqual(null, protease1.CleavageMod);
            Assert.AreEqual("M", protease1.CleavageMod.Target.ToString());

            Assert.AreEqual(peps1[1].MonoisotopicMass, peps2[1].MonoisotopicMass);
            Assert.AreEqual(peps1[1].MonoisotopicMass, peps2[0].MonoisotopicMass);
            Assert.AreEqual(peps2[0].MonoisotopicMass, peps2[1].MonoisotopicMass);
            Assert.AreNotEqual(peps1[0].MonoisotopicMass, peps1[1].MonoisotopicMass);
            Assert.AreNotEqual(peps1[0].MonoisotopicMass, peps2[0].MonoisotopicMass);
            Assert.AreNotEqual(peps1[0].MonoisotopicMass, peps2[1].MonoisotopicMass);

            Assert.AreEqual(882.39707781799996, peps1[0].MonoisotopicMass);
            Assert.AreEqual(930.400449121, peps1[1].MonoisotopicMass);
        }