Ejemplo n.º 1
0
        //Calculate if crosslink amino acid exist and return its position based on compactPeptide
        public static List <int> XlPosCal(CompactPeptide compactPeptide, string crosslinkerModSites)
        {
            Tolerance  tolerance = new PpmTolerance(1);
            List <int> xlpos     = new List <int>();

            foreach (char item in crosslinkerModSites)
            {
                if (tolerance.Within(compactPeptide.NTerminalMasses[0], Residue.GetResidue(item).MonoisotopicMass))
                {
                    xlpos.Add(0);
                }
                for (int i = 1; i < compactPeptide.NTerminalMasses.Length; i++)
                {
                    if (tolerance.Within(compactPeptide.NTerminalMasses[i] - compactPeptide.NTerminalMasses[i - 1], Residue.GetResidue(item).MonoisotopicMass))
                    {
                        xlpos.Add(i);
                    }
                }
                if (tolerance.Within(compactPeptide.CTerminalMasses[0], Residue.GetResidue(item).MonoisotopicMass))
                {
                    xlpos.Add(compactPeptide.NTerminalMasses.Length);
                }
            }
            xlpos.Sort();
            return(xlpos);
        }
Ejemplo n.º 2
0
        public static void TestCompactPeptideSerialization()
        {
            // purpose of this test is to serialize/deserialize a CompactPeptide and make sure the deserialized peptide
            // has the same properties as before it was serialized. This peptide is unmodified
            string sequence = "PEPTIDE";
            PeptideWithSetModifications p = new PeptideWithSetModifications(sequence, new Dictionary <string, Modification>(), 0, null, null, 0, 7, 0, null);
            CompactPeptide cp             = p.CompactPeptide(FragmentationTerminus.Both);
            CompactPeptide deserializedCp = null;

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

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

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

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

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

            Assert.That(cp.Equals(deserializedCp));
        }
        private Tuple <int, double> Accepts(double scanPrecursorMass, CompactPeptide peptide, TerminusType terminusType, MassDiffAcceptor searchMode)
        {
            //all masses in N and CTerminalMasses are b-ion masses, which are one water away from a full peptide
            int localminPeptideLength = CommonParameters.DigestionParams.MinPeptideLength ?? 0;

            if (terminusType == TerminusType.N)
            {
                for (int i = localminPeptideLength; i < peptide.NTerminalMasses.Count(); i++)
                {
                    double theoMass = peptide.NTerminalMasses[i] + waterMonoisotopicMass;
                    int    notch    = searchMode.Accepts(scanPrecursorMass, theoMass);
                    if (notch >= 0)
                    {
                        return(new Tuple <int, double>(notch, theoMass));
                    }
                    else if (theoMass > scanPrecursorMass)
                    {
                        break;
                    }
                }
                //if the theoretical and experimental have the same mass
                if (peptide.NTerminalMasses.Count() > localminPeptideLength)
                {
                    double totalMass = peptide.MonoisotopicMassIncludingFixedMods;// + Constants.protonMass;
                    int    notch     = searchMode.Accepts(scanPrecursorMass, totalMass);
                    if (notch >= 0)
                    {
                        return(new Tuple <int, double>(notch, totalMass));
                    }
                }
            }
            else//if (terminusType==TerminusType.C)
            {
                for (int i = localminPeptideLength; i < peptide.CTerminalMasses.Count(); i++)
                {
                    double theoMass = peptide.CTerminalMasses[i] + waterMonoisotopicMass;
                    int    notch    = searchMode.Accepts(scanPrecursorMass, theoMass);
                    if (notch >= 0)
                    {
                        return(new Tuple <int, double>(notch, theoMass));
                    }
                    else if (theoMass > scanPrecursorMass)
                    {
                        break;
                    }
                }
                //if the theoretical and experimental have the same mass
                if (peptide.CTerminalMasses.Count() > localminPeptideLength)
                {
                    double totalMass = peptide.MonoisotopicMassIncludingFixedMods;// + Constants.protonMass;
                    int    notch     = searchMode.Accepts(scanPrecursorMass, totalMass);
                    if (notch >= 0)
                    {
                        return(new Tuple <int, double>(notch, totalMass));
                    }
                }
            }
            return(new Tuple <int, double>(-1, -1));
        }
Ejemplo n.º 4
0
        public void TestMods()
        {
            PsmCross PSM = new PsmCross();

            PSM.BaseSequence           = "DMHGDSEYNIMFGPDICGPGTK";
            PSM.FullSequence           = "DM[Common Variable:Oxidation of M]HGDSEYNIM[Common Variable:Oxidation of M]FGPDIC[Common Fixed:Carbamidomethyl of C]GPGTK";
            PSM.PeptideMonisotopicMass = 2472.0032;

            var mods = TsvResultReader.GetMods(PSM);

            Dictionary <int, ModificationWithMass> allModsOneIsNterminus = new Dictionary <int, ModificationWithMass>();

            foreach (var item in mods)
            {
                ModificationMotif.TryGetMotif(item.Value, out ModificationMotif modificationMotif);

                ModificationWithMass mod = new ModificationWithMass("mod", null, modificationMotif, TerminusLocalization.Any, 10);

                allModsOneIsNterminus.Add(item.Key, mod);
            }

            PepWithSetModForCompactPep pepWithSetModForCompactPep = new PepWithSetModForCompactPep();

            pepWithSetModForCompactPep.allModsOneIsNterminus = allModsOneIsNterminus;
            pepWithSetModForCompactPep.BaseSequence          = PSM.BaseSequence;
            pepWithSetModForCompactPep.Length           = PSM.BaseSequence.Length;
            pepWithSetModForCompactPep.MonoisotopicMass = (double)PSM.PeptideMonisotopicMass;

            var compactPeptide = new CompactPeptide(pepWithSetModForCompactPep, TerminusType.None);

            PSM.CompactPeptide = compactPeptide;

            var lp = new List <ProductType> {
                ProductType.BnoB1ions, ProductType.Y
            };
            Tolerance productMassTolerance = new PpmTolerance(10);

            var pmm = PsmCross.XlCalculateTotalProductMassesForSingle(PSM, lp, false);

            var matchedIonMassesListPositiveIsMatch = new MatchedIonInfo(pmm.ProductMz.Length);
            //double pmmScore = PsmCross.XlMatchIons(theScan.TheScan, productMassTolerance, pmm.ProductMz, pmm.ProductName, matchedIonMassesListPositiveIsMatch);
        }
Ejemplo n.º 5
0
        //Calculate if crosslink amino acid exist and return its position based on compactPeptide
        public static List <int> XlPosCal(CompactPeptide compactPeptide, CrosslinkerTypeClass crosslinker)
        {
            Tolerance  tolerance = new PpmTolerance(1);
            List <int> xlpos     = new List <int>();

            if (tolerance.Within(compactPeptide.NTerminalMasses[0], Residue.GetResidue(crosslinker.CrosslinkerModSite).MonoisotopicMass))
            {
                xlpos.Add(0);
            }
            for (int i = 1; i < compactPeptide.NTerminalMasses.Length; i++)
            {
                if (tolerance.Within(compactPeptide.NTerminalMasses[i] - compactPeptide.NTerminalMasses[i - 1], Residue.GetResidue(crosslinker.CrosslinkerModSite).MonoisotopicMass))
                {
                    xlpos.Add(i);
                }
            }
            if (tolerance.Within(compactPeptide.CTerminalMasses[0], Residue.GetResidue(crosslinker.CrosslinkerModSite).MonoisotopicMass))
            {
                xlpos.Add(compactPeptide.NTerminalMasses.Length);
            }
            return(xlpos);
        }
Ejemplo n.º 6
0
        public static void ParsimonyWeirdCatch()
        {
            Protein protein1 = new Protein("MATSIK", "protein1", isDecoy: true);
            Protein protein2 = new Protein("MATSLK", "protein2");
            Protein protein3 = new Protein("MTASIK", "protein3");

            IEnumerable <ModificationWithMass> allKnownFixedModifications = new List <ModificationWithMass>();
            DigestionParams             digestionParams       = new DigestionParams(minPeptideLength: 5);
            List <ModificationWithMass> variableModifications = new List <ModificationWithMass>();
            var pep1 = protein1.Digest(digestionParams, allKnownFixedModifications, variableModifications).First();
            var pep2 = protein2.Digest(digestionParams, allKnownFixedModifications, variableModifications).First();
            var pep3 = protein3.Digest(digestionParams, allKnownFixedModifications, variableModifications).First();

            CompactPeptide compactPeptide1 = pep1.CompactPeptide(TerminusType.None);
            CompactPeptide compactPeptide2 = pep2.CompactPeptide(TerminusType.None);
            CompactPeptide compactPeptide3 = pep3.CompactPeptide(TerminusType.None);

            Assert.AreEqual(compactPeptide1, compactPeptide2);

            Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > compactPeptideToProteinPeptideMatching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >
            {
                { compactPeptide1, new HashSet <PeptideWithSetModifications> {
                      pep1, pep2
                  } },
                { compactPeptide3, new HashSet <PeptideWithSetModifications> {
                      pep3
                  } }
            };

            var cool = (ProteinParsimonyResults) new ProteinParsimonyEngine(compactPeptideToProteinPeptideMatching, false, new CommonParameters(), new List <string>()).Run();

            Assert.AreEqual(2, compactPeptideToProteinPeptideMatching.Count);

            // Only 1 because the target is removed!!!
            Assert.AreEqual(1, compactPeptideToProteinPeptideMatching[compactPeptide1].Count);
            Assert.AreEqual(1, compactPeptideToProteinPeptideMatching[compactPeptide2].Count);

            Assert.AreEqual(1, compactPeptideToProteinPeptideMatching[compactPeptide3].Count);
        }
Ejemplo n.º 7
0
 public PsmCross(CompactPeptide theBestPeptide, int notch, double score, int scanIndex, Ms2ScanWithSpecificMass scan) : base(theBestPeptide, notch, score, scanIndex, scan)
 {
     compactPeptide = theBestPeptide;
 }
Ejemplo n.º 8
0
        protected override MetaMorpheusEngineResults RunSpecific()
        {
            double       progress           = 0;
            int          oldPercentProgress = 0;
            TerminusType terminusType       = ProductTypeMethods.IdentifyTerminusType(ProductTypes);

            // digest database
            HashSet <CompactPeptide> peptideToId = new HashSet <CompactPeptide>();

            Parallel.ForEach(Partitioner.Create(0, ProteinList.Count), new ParallelOptions {
                MaxDegreeOfParallelism = commonParameters.MaxThreadsToUsePerFile
            }, (range, loopState) =>
            {
                for (int i = range.Item1; i < range.Item2; i++)
                {
                    // Stop loop if canceled
                    if (GlobalVariables.StopLoops)
                    {
                        loopState.Stop();
                        return;
                    }

                    foreach (var digestionParams in CollectionOfDigestionParams)
                    {
                        foreach (var pepWithSetMods in ProteinList[i].Digest(digestionParams, FixedModifications, VariableModifications))
                        {
                            CompactPeptide compactPeptide = pepWithSetMods.CompactPeptide(terminusType);

                            var observed = peptideToId.Contains(compactPeptide);
                            if (observed)
                            {
                                continue;
                            }
                            lock (peptideToId)
                            {
                                observed = peptideToId.Contains(compactPeptide);
                                if (observed)
                                {
                                    continue;
                                }
                                peptideToId.Add(compactPeptide);
                            }
                        }
                    }

                    progress++;
                    var percentProgress = (int)((progress / ProteinList.Count) * 100);

                    if (percentProgress > oldPercentProgress)
                    {
                        oldPercentProgress = percentProgress;
                        ReportProgress(new ProgressEventArgs(percentProgress, "Digesting proteins...", nestedIds));
                    }
                }
            });

            // sort peptides by mass
            var peptidesSortedByMass = peptideToId.AsParallel().WithDegreeOfParallelism(commonParameters.MaxThreadsToUsePerFile).OrderBy(p => p.MonoisotopicMassIncludingFixedMods).ToList();

            peptideToId = null;

            // create fragment index
            List <int>[] fragmentIndex;

            try
            {
                fragmentIndex = new List <int> [(int)Math.Ceiling(MaxFragmentSize) * FragmentBinsPerDalton + 1];
            }
            catch (OutOfMemoryException)
            {
                throw new MetaMorpheusException("Max fragment mass too large for indexing engine; try \"Classic Search\" mode, or make the maximum fragment mass smaller");
            }

            // populate fragment index
            progress           = 0;
            oldPercentProgress = 0;
            for (int peptideId = 0; peptideId < peptidesSortedByMass.Count; peptideId++)
            {
                var validFragments = peptidesSortedByMass[peptideId].ProductMassesMightHaveDuplicatesAndNaNs(ProductTypes).Distinct().Where(p => !Double.IsNaN(p));

                foreach (var theoreticalFragmentMass in validFragments)
                {
                    if (theoreticalFragmentMass < MaxFragmentSize && theoreticalFragmentMass > 0)
                    {
                        int fragmentBin = (int)Math.Round(theoreticalFragmentMass * FragmentBinsPerDalton);

                        if (fragmentIndex[fragmentBin] == null)
                        {
                            fragmentIndex[fragmentBin] = new List <int> {
                                peptideId
                            }
                        }
                        ;
                        else
                        {
                            fragmentIndex[fragmentBin].Add(peptideId);
                        }
                    }
                }

                progress++;
                var percentProgress = (int)((progress / peptidesSortedByMass.Count) * 100);

                if (percentProgress > oldPercentProgress)
                {
                    oldPercentProgress = percentProgress;
                    ReportProgress(new ProgressEventArgs(percentProgress, "Creating fragment index...", nestedIds));
                }
            }

            return(new IndexingResults(peptidesSortedByMass, fragmentIndex, this));
        }
        public static void TestModificationAnalysis()
        {
            IScan scan = new ThisTestScan();

            ModificationMotif.TryGetMotif("N", out ModificationMotif motif1);
            ModificationWithMass mod1 = new ModificationWithMass("mod1", null, motif1, TerminusLocalization.Any, 10);

            ModificationMotif.TryGetMotif("L", out ModificationMotif motif2);
            ModificationWithMass mod2 = new ModificationWithMass("mod2", null, motif2, TerminusLocalization.Any, 10);

            IDictionary <int, List <Modification> > oneBasedModifications = new Dictionary <int, List <Modification> >
            {
                { 2, new List <Modification> {
                      mod1
                  } },
                { 5, new List <Modification> {
                      mod2
                  } },
                { 7, new List <Modification> {
                      mod1
                  } },
            };
            Protein protein1 = new Protein("MNLDLDNDL", "prot1", oneBasedModifications: oneBasedModifications);

            Dictionary <int, ModificationWithMass> allModsOneIsNterminus1 = new Dictionary <int, ModificationWithMass>
            {
                { 2, mod1 },
            };
            PeptideWithSetModifications pwsm1 = new PeptideWithSetModifications(0, protein1, 2, 9, allModsOneIsNterminus1);
            CompactPeptideBase          pep1  = new CompactPeptide(pwsm1, TerminusType.None);

            Dictionary <int, ModificationWithMass> allModsOneIsNterminus2 = new Dictionary <int, ModificationWithMass>
            {
                { 2, mod1 },
                { 7, mod1 },
            };
            PeptideWithSetModifications pwsm2 = new PeptideWithSetModifications(0, protein1, 2, 9, allModsOneIsNterminus2);
            CompactPeptideBase          pep2  = new CompactPeptide(pwsm2, TerminusType.None);

            Dictionary <int, ModificationWithMass> allModsOneIsNterminus3 = new Dictionary <int, ModificationWithMass>
            {
                { 7, mod1 },
            };
            PeptideWithSetModifications pwsm3 = new PeptideWithSetModifications(0, protein1, 2, 9, allModsOneIsNterminus3);
            CompactPeptideBase          pep3  = new CompactPeptide(pwsm3, TerminusType.None);

            Dictionary <int, ModificationWithMass> allModsOneIsNterminus4 = new Dictionary <int, ModificationWithMass>
            {
                { 8, mod1 },
            };
            PeptideWithSetModifications pwsm4 = new PeptideWithSetModifications(0, protein1, 1, 9, allModsOneIsNterminus4);
            CompactPeptideBase          pep4  = new CompactPeptide(pwsm4, TerminusType.None);

            CommonParameters CommonParameters = new CommonParameters(
                digestionParams: new DigestionParams(
                    maxMissedCleavages: 0,
                    minPeptideLength: 1,
                    maxModificationIsoforms: int.MaxValue),
                scoreCutoff: 1);

            var newPsms = new List <PeptideSpectralMatch>
            {
                new PeptideSpectralMatch(pep1, 0, 10, 0, scan, CommonParameters.DigestionParams),
                new PeptideSpectralMatch(pep1, 0, 10, 0, scan, CommonParameters.DigestionParams),
                new PeptideSpectralMatch(pep2, 0, 10, 0, scan, CommonParameters.DigestionParams),
                new PeptideSpectralMatch(pep3, 0, 10, 0, scan, CommonParameters.DigestionParams),
                new PeptideSpectralMatch(pep4, 0, 10, 0, scan, CommonParameters.DigestionParams),
            };

            MassDiffAcceptor searchMode  = new SinglePpmAroundZeroSearchMode(5);
            List <Protein>   proteinList = new List <Protein> {
                protein1
            };

            SequencesToActualProteinPeptidesEngine sequencesToActualProteinPeptidesEngine = new SequencesToActualProteinPeptidesEngine
                                                                                                (newPsms, proteinList, new List <ModificationWithMass>(), new List <ModificationWithMass>(), new List <ProductType>
            {
                ProductType.B, ProductType.Y
            }, new List <DigestionParams> {
                CommonParameters.DigestionParams
            }, CommonParameters.ReportAllAmbiguity, CommonParameters, new List <string>());
            var nice = (SequencesToActualProteinPeptidesEngineResults)sequencesToActualProteinPeptidesEngine.Run();

            foreach (var psm in newPsms)
            {
                psm.MatchToProteinLinkedPeptides(nice.CompactPeptideToProteinPeptideMatching);
            }
            FdrAnalysisEngine fdrAnalysisEngine = new FdrAnalysisEngine(newPsms, searchMode.NumNotches, CommonParameters, new List <string>());

            fdrAnalysisEngine.Run();
            ModificationAnalysisEngine modificationAnalysisEngine = new ModificationAnalysisEngine(newPsms, new CommonParameters(), new List <string>());
            var res = (ModificationAnalysisResults)modificationAnalysisEngine.Run();

            Assert.AreEqual(2, res.AllModsOnProteins.Count());
            Assert.AreEqual(2, res.AllModsOnProteins[mod1.id]);
            Assert.AreEqual(1, res.AllModsOnProteins[mod2.id]);

            Assert.AreEqual(1, res.ModsSeenAndLocalized.Count());
            Assert.AreEqual(2, res.ModsSeenAndLocalized[mod1.id]);

            Assert.AreEqual(0, res.AmbiguousButLocalizedModsSeen.Count());

            Assert.AreEqual(0, res.UnlocalizedMods.Count());

            Assert.AreEqual(0, res.UnlocalizedFormulas.Count());
        }
        public static void MultiProteaseIndistiguishableTest()
        {
            string[] sequences =
            {
                "ABCEFG",
                "EFGABC",
            };

            List <Tuple <string, TerminusType> > sequencesInducingCleavage = new List <Tuple <string, TerminusType> > {
                new Tuple <string, TerminusType>("C", TerminusType.C)
            };
            List <Tuple <string, TerminusType> > sequencesInducingCleavage2 = new List <Tuple <string, TerminusType> > {
                new Tuple <string, TerminusType>("G", TerminusType.C)
            };

            var protease = new Protease("testA", sequencesInducingCleavage, new List <Tuple <string, TerminusType> >(), CleavageSpecificity.Full, null, null, null);

            ProteaseDictionary.Dictionary.Add(protease.Name, protease);
            var protease2 = new Protease("testB", sequencesInducingCleavage2, new List <Tuple <string, TerminusType> >(), CleavageSpecificity.Full, null, null, null);

            ProteaseDictionary.Dictionary.Add(protease2.Name, protease2);
            var peptideList = new HashSet <PeptideWithSetModifications>();

            var p = new List <Protein>();
            List <Tuple <string, string> > gn = new List <Tuple <string, string> >();

            for (int i = 0; i < sequences.Length; i++)
            {
                p.Add(new Protein(sequences[i], (i + 1).ToString(), null, gn, new Dictionary <int, List <Modification> >()));
            }

            DigestionParams digestionParams  = new DigestionParams(protease: protease.Name, minPeptideLength: 1);
            DigestionParams digestionParams2 = new DigestionParams(protease: protease2.Name, minPeptideLength: 1);

            foreach (var protein in p)
            {
                foreach (var peptide in protein.Digest(digestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()))
                {
                    switch (peptide.BaseSequence)
                    {
                    case "ABC": peptideList.Add(peptide); break;

                    case "EFG": peptideList.Add(peptide); break;
                    }
                }
                foreach (var peptide in protein.Digest(digestionParams2, new List <ModificationWithMass>(), new List <ModificationWithMass>()))
                {
                    switch (peptide.BaseSequence)
                    {
                    case "ABC": peptideList.Add(peptide); break;

                    case "EFG": peptideList.Add(peptide); break;
                    }
                }
            }

            // creates the initial dictionary of "peptide" and "virtual peptide" matches
            var dictionary = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >();

            CompactPeptide[] peptides = new CompactPeptide[peptideList.Count];

            PeptideWithSetModifications[] PWSM = new PeptideWithSetModifications[peptideList.Count];

            // creates peptide list
            for (int i = 0; i < peptideList.Count; i++)
            {
                peptides[i] = new CompactPeptide(peptideList.ElementAt(i), TerminusType.None);
                PWSM[i]     = peptideList.ElementAt(i);
            }

            dictionary.Add(peptides[0], new HashSet <PeptideWithSetModifications> {
                PWSM[0], PWSM[3]
            });
            dictionary.Add(peptides[1], new HashSet <PeptideWithSetModifications> {
                PWSM[1], PWSM[2]
            });

            // builds psm list to match to peptides
            List <PeptideSpectralMatch> psms = new List <PeptideSpectralMatch>();

            MsDataScan dfb = 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(dfb, 2, 0, "File");

            foreach (var kvp in dictionary)
            {
                foreach (var peptide in kvp.Value)
                {
                    switch (peptide.BaseSequence)
                    {
                    case "ABC":
                        if (peptide.DigestionParams == digestionParams)
                        {
                            psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 10, 0, scan, digestionParams));
                            break;
                        }
                        if (peptide.DigestionParams == digestionParams2)
                        {
                            psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 10, 0, scan, digestionParams2));
                            break;
                        }
                        else
                        {
                            break;
                        }

                    case "EFG":
                        if (peptide.DigestionParams == digestionParams)
                        {
                            psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 10, 0, scan, digestionParams));
                            break;
                        }
                        if (peptide.DigestionParams == digestionParams2)
                        {
                            psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 10, 0, scan, digestionParams2));
                            break;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }

            List <ProductType> IonTypes  = new List <ProductType>();
            ProductType        BnoB1ions = ProductType.BnoB1ions;
            ProductType        Yions     = ProductType.Y;

            IonTypes.Add(BnoB1ions);
            IonTypes.Add(Yions);

            HashSet <DigestionParams> digestionParamsList = new HashSet <DigestionParams>();

            digestionParamsList.Add(digestionParams);
            digestionParamsList.Add(digestionParams2);
            ModificationMotif.TryGetMotif("M", out ModificationMotif motif1);
            ModificationWithMass        mod        = new ModificationWithMass("Oxidation of M", "Common Variable", motif1, TerminusLocalization.Any, 15.99491461957);
            List <ModificationWithMass> modVarList = new List <ModificationWithMass> {
                mod
            };

            ModificationMotif.TryGetMotif("M", out ModificationMotif motif2);
            List <ModificationWithMass> modFixedList = new List <ModificationWithMass> {
                mod
            };
            SequencesToActualProteinPeptidesEngine sequencesToActualProteinPeptidesEngine =
                new SequencesToActualProteinPeptidesEngine(psms, p, modFixedList, modVarList, IonTypes, digestionParamsList, true, new CommonParameters(), null);
            var results = (SequencesToActualProteinPeptidesEngineResults)sequencesToActualProteinPeptidesEngine.Run();
            var CompactPeptidesToProteinPeptidesMatching = results.CompactPeptideToProteinPeptideMatching;

            Assert.AreEqual(2, CompactPeptidesToProteinPeptidesMatching.Count);

            Assert.AreEqual(2, CompactPeptidesToProteinPeptidesMatching.ElementAt(0).Value.Count);
            Assert.AreEqual("ABC", CompactPeptidesToProteinPeptidesMatching.ElementAt(0).Value.ElementAt(0).BaseSequence);
            Assert.AreEqual("ABC", CompactPeptidesToProteinPeptidesMatching.ElementAt(0).Value.ElementAt(1).BaseSequence);

            Assert.AreEqual(2, CompactPeptidesToProteinPeptidesMatching.ElementAt(1).Value.Count);
            Assert.AreEqual("EFG", CompactPeptidesToProteinPeptidesMatching.ElementAt(1).Value.ElementAt(0).BaseSequence);
            Assert.AreEqual("EFG", CompactPeptidesToProteinPeptidesMatching.ElementAt(1).Value.ElementAt(1).BaseSequence);

            ProteinParsimonyEngine ppe = new ProteinParsimonyEngine(CompactPeptidesToProteinPeptidesMatching, false, new CommonParameters(), null);
            var proteinAnalysisResults = (ProteinParsimonyResults)ppe.Run();

            List <ProteinGroup> proteinGroups = proteinAnalysisResults.ProteinGroups;

            Assert.AreEqual(2, proteinGroups.Count);

            Assert.AreEqual(2, proteinGroups.ElementAt(0).AllPeptides.Count);
            Assert.AreEqual(2, proteinGroups.ElementAt(0).UniquePeptides.Count);
            Assert.AreEqual("ABC", proteinGroups.ElementAt(0).AllPeptides.ElementAt(0).BaseSequence);
            Assert.AreEqual("testA", proteinGroups.ElementAt(0).AllPeptides.ElementAt(0).DigestionParams.Protease.Name);
            Assert.AreEqual("EFG", proteinGroups.ElementAt(0).AllPeptides.ElementAt(1).BaseSequence);
            Assert.AreEqual("testA", proteinGroups.ElementAt(0).AllPeptides.ElementAt(1).DigestionParams.Protease.Name);
            Assert.AreEqual("ABC", proteinGroups.ElementAt(0).UniquePeptides.ElementAt(0).BaseSequence);
            Assert.AreEqual("EFG", proteinGroups.ElementAt(0).UniquePeptides.ElementAt(1).BaseSequence);

            Assert.AreEqual(2, proteinGroups.ElementAt(1).AllPeptides.Count);
            Assert.AreEqual(2, proteinGroups.ElementAt(1).UniquePeptides.Count);
            Assert.AreEqual("ABC", proteinGroups.ElementAt(1).AllPeptides.ElementAt(0).BaseSequence);
            Assert.AreEqual("testB", proteinGroups.ElementAt(1).AllPeptides.ElementAt(0).DigestionParams.Protease.Name);
            Assert.AreEqual("EFG", proteinGroups.ElementAt(1).AllPeptides.ElementAt(1).BaseSequence);
            Assert.AreEqual("testB", proteinGroups.ElementAt(1).AllPeptides.ElementAt(1).DigestionParams.Protease.Name);
            Assert.AreEqual("ABC", proteinGroups.ElementAt(1).UniquePeptides.ElementAt(0).BaseSequence);
            Assert.AreEqual("EFG", proteinGroups.ElementAt(1).UniquePeptides.ElementAt(1).BaseSequence);
        }
Ejemplo n.º 11
0
        public static void TestParsimony()
        {
            // creates some test proteins and digests them (simulating a protein database)
            string[] sequences = { "AB--------",   // 1: contains unique
                                   "--C-------",   // 2: one hit wonder
                                   "---D---HHH--", // 3: subset
                                   "-B-D---HHH--", // 4: D should go to 4, not 3 (3 is subset)
                                   "-B--E-----",   // 5: subsumable
                                   "----EFG---",   // 6: indistinguishable from 8 (J will not be a "detected" PSM)
                                   "-----F----",   // 7: lone pep shared w/ decoy
                                   "--------I-",   // 8: I should go to 9, not 8
                                   "-B------I-",   // 9: I should go to 9, not 8
                                   "----EFG--J"    // 10: indistinguishable from 6 (J will not be a "detected" PSM)
            };

            IEnumerable <Tuple <string, TerminusType> > sequencesInducingCleavage = new List <Tuple <string, TerminusType> > {
                new Tuple <string, TerminusType>("A", TerminusType.C), new Tuple <string, TerminusType>("B", TerminusType.C), new Tuple <string, TerminusType>("C", TerminusType.C), new Tuple <string, TerminusType>("D", TerminusType.C), new Tuple <string, TerminusType>("E", TerminusType.C), new Tuple <string, TerminusType>("F", TerminusType.C), new Tuple <string, TerminusType>("G", TerminusType.C), new Tuple <string, TerminusType>("H", TerminusType.C), new Tuple <string, TerminusType>("I", TerminusType.C), new Tuple <string, TerminusType>("J", TerminusType.C), new Tuple <string, TerminusType>("-", TerminusType.C)
            };
            var protease    = new Protease("test", sequencesInducingCleavage, new List <Tuple <string, TerminusType> >(), CleavageSpecificity.Full, null, null, null);
            var peptideList = new HashSet <PeptideWithSetModifications>();

            ProteaseDictionary.Dictionary.Add(protease.Name, protease);

            var p = new List <Protein>();
            List <Tuple <string, string> > gn = new List <Tuple <string, string> >();

            for (int i = 0; i < sequences.Length; i++)
            {
                p.Add(new Protein(sequences[i], (i + 1).ToString(), null, gn, new Dictionary <int, List <Modification> >()));
            }
            p.Add(new Protein("-----F----*", "D1", null, gn, new Dictionary <int, List <Modification> >(), isDecoy: true));
            p.Add(new Protein("-----F----**", "C1", null, gn, new Dictionary <int, List <Modification> >(), isContaminant: true));
            p.Add(new Protein("----E----**", "C2", null, gn, new Dictionary <int, List <Modification> >(), isContaminant: true));

            DigestionParams digestionParams = new DigestionParams(protease: protease.Name, minPeptideLength: 1);

            foreach (var protein in p)
            {
                foreach (var peptide in protein.Digest(digestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()))
                {
                    switch (peptide.BaseSequence)
                    {
                    case "A": peptideList.Add(peptide); break;

                    case "B": peptideList.Add(peptide); break;

                    case "C": peptideList.Add(peptide); break;

                    case "D": peptideList.Add(peptide); break;

                    case "E": peptideList.Add(peptide); break;

                    case "F": peptideList.Add(peptide); break;

                    case "G": peptideList.Add(peptide); break;

                    case "H": peptideList.Add(peptide); break;

                    case "I": peptideList.Add(peptide); break;
                    }
                }
            }

            // creates the initial dictionary of "peptide" and "virtual peptide" matches
            var dictionary = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >();

            CompactPeptide[] peptides = new CompactPeptide[peptideList.Count];
            HashSet <PeptideWithSetModifications>[] virtualPeptideSets = new HashSet <PeptideWithSetModifications> [peptideList.Count];

            Dictionary <ModificationWithMass, ushort> modsDictionary = new Dictionary <ModificationWithMass, ushort>();

            // creates peptide list
            for (int i = 0; i < peptideList.Count; i++)
            {
                peptides[i] = new CompactPeptide(peptideList.ElementAt(i), TerminusType.None);
            }

            // creates protein list
            for (int i = 0; i < virtualPeptideSets.Length; i++)
            {
                virtualPeptideSets[i] = new HashSet <PeptideWithSetModifications>();

                foreach (var virtualPeptide in peptideList)
                {
                    string peptideBaseSequence = string.Join("", peptideList.ElementAt(i).BaseSequence.Select(b => char.ConvertFromUtf32(b)));

                    if (virtualPeptide.BaseSequence.Contains(peptideBaseSequence))
                    {
                        virtualPeptideSets[i].Add(virtualPeptide);
                    }
                }
            }

            // populates initial peptide-virtualpeptide dictionary
            for (int i = 0; i < peptides.Length; i++)
            {
                if (!dictionary.ContainsKey(peptides[i]))
                {
                    dictionary.Add(peptides[i], virtualPeptideSets[i]);
                }
            }

            // copy for comparison later
            Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > initialDictionary = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >();

            foreach (var kvp in dictionary)
            {
                CompactPeptideBase cp = kvp.Key;
                HashSet <PeptideWithSetModifications> peps = new HashSet <PeptideWithSetModifications>();
                foreach (var pep in kvp.Value)
                {
                    peps.Add(pep);
                }

                initialDictionary.Add(cp, peps);
            }

            // apply parsimony to dictionary
            ProteinParsimonyEngine ae = new ProteinParsimonyEngine(dictionary, false, new CommonParameters(), new List <string>());
            var hah           = (ProteinParsimonyResults)ae.Run();
            var proteinGroups = hah.ProteinGroups;

            var parsimonyProteinList   = new List <Protein>();
            var parsimonyBaseSequences = new List <string>();

            foreach (var kvp in dictionary)
            {
                foreach (var virtualPeptide in kvp.Value)
                {
                    if (!parsimonyProteinList.Contains(virtualPeptide.Protein))
                    {
                        parsimonyProteinList.Add(virtualPeptide.Protein);
                        parsimonyBaseSequences.Add(virtualPeptide.Protein.BaseSequence);
                    }
                }
            }

            // builds psm list to match to peptides
            List <PeptideSpectralMatch> psms = new List <PeptideSpectralMatch>();

            MsDataScan dfb = 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(dfb, 2, 0, "File");

            foreach (var kvp in dictionary)
            {
                foreach (var peptide in kvp.Value)
                {
                    switch (peptide.BaseSequence)
                    {
                    case "A": psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 10, 0, scan, digestionParams)); break;

                    case "B": psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 9, 0, scan, digestionParams)); break;

                    case "C": psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 8, 0, scan, digestionParams)); break;

                    case "D": psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 7, 0, scan, digestionParams)); break;

                    case "E": psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 6, 0, scan, digestionParams)); break;

                    case "F": psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 5, 0, scan, digestionParams)); break;

                    case "G": psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 4, 0, scan, digestionParams)); break;

                    case "H": psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 3, 0, scan, digestionParams)); break;

                    case "I": psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 2, 0, scan, digestionParams)); break;
                    }
                }
            }

            List <ProductType> lp = new List <ProductType> {
                ProductType.B, ProductType.Y
            };
            Tolerance fragmentTolerance = new AbsoluteTolerance(0.01);

            foreach (var hm in psms)
            {
                hm.MatchToProteinLinkedPeptides(initialDictionary);
                hm.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0, 0, false);
            }

            ProteinScoringAndFdrEngine f = new ProteinScoringAndFdrEngine(proteinGroups, psms, true, false, true, new CommonParameters(), new List <string>());
            var ok = (ProteinScoringAndFdrResults)f.Run();

            proteinGroups = ok.SortedAndScoredProteinGroups;

            //prints initial dictionary
            List <Protein> proteinList = new List <Protein>();

            foreach (var kvp in initialDictionary)
            {
                proteinList = new List <Protein>();
                foreach (var peptide in kvp.Value)
                {
                    if (!proteinList.Contains(peptide.Protein))
                    {
                        proteinList.Add(peptide.Protein);
                    }
                }
            }

            //prints parsimonious dictionary
            foreach (var kvp in dictionary)
            {
                proteinList = new List <Protein>();
                foreach (var peptide in kvp.Value)
                {
                    if (!proteinList.Contains(peptide.Protein))
                    {
                        proteinList.Add(peptide.Protein);
                    }
                }
            }

            // check that correct proteins are in parsimony list
            Assert.Contains("AB--------", parsimonyBaseSequences);
            Assert.Contains("--C-------", parsimonyBaseSequences);
            Assert.Contains("-B-D---HHH--", parsimonyBaseSequences);
            Assert.Contains("-----F----*", parsimonyBaseSequences);
            Assert.Contains("----E----**", parsimonyBaseSequences);
            Assert.Contains("-B------I-", parsimonyBaseSequences);
            Assert.Contains("----EFG---", parsimonyBaseSequences);
            Assert.Contains("----EFG--J", parsimonyBaseSequences);
            Assert.AreEqual(8, parsimonyProteinList.Count);

            // sequence coverage test
            foreach (var proteinGroup in proteinGroups)
            {
                foreach (var coverage in proteinGroup.SequenceCoveragePercent)
                {
                    Assert.That(coverage <= 1.0);
                }
            }

            // protein group tests
            Assert.AreEqual(4, proteinGroups.Count);
            Assert.AreEqual(1, proteinGroups.First().Proteins.Count);
            Assert.AreEqual("AB--------", proteinGroups.First().Proteins.First().BaseSequence);
            Assert.AreEqual(4, proteinGroups.First().AllPsmsBelowOnePercentFDR.Count);
            Assert.AreEqual(19, proteinGroups.First().ProteinGroupScore);
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
 public BestPeptideScoreNotch(CompactPeptide bestPeptide, double bestScore, int bestNotch)
 {
     BestPeptide = bestPeptide;
     BestScore   = bestScore;
     BestNotch   = bestNotch;
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Generates theoretical fragments for given dissociation type for this peptide
        /// </summary>
        public IEnumerable <Product> Fragment(DissociationType dissociationType, FragmentationTerminus fragmentationTerminus)
        {
            // molecular ion
            //yield return new Product(ProductType.M, new NeutralTerminusFragment(FragmentationTerminus.None, this.MonoisotopicMass, Length, Length), 0);

            var productCollection = TerminusSpecificProductTypes.ProductIonTypesFromSpecifiedTerminus[fragmentationTerminus].Intersect(DissociationTypeCollection.ProductsFromDissociationType[dissociationType]);

            List <(ProductType, int)> skippers = new List <(ProductType, int)>();

            foreach (var product in productCollection.Where(f => f != ProductType.zDot))
            {
                skippers.Add((product, BaseSequence.Length));
            }

            switch (dissociationType)
            {
            case DissociationType.CID:
                skippers.Add((ProductType.b, 1));
                break;

            //for LowCID I assume we don't have the first ion on the b-side from any ion type
            case DissociationType.LowCID:
                skippers.Add((ProductType.b, 1));
                skippers.Add((ProductType.aDegree, 1));
                skippers.Add((ProductType.bDegree, 1));
                skippers.Add((ProductType.aStar, 1));
                skippers.Add((ProductType.bStar, 1));
                break;

            case DissociationType.ETD:
            case DissociationType.ECD:
            case DissociationType.EThcD:
                skippers.AddRange(GetProlineZIonIndicies());
                break;
            }

            foreach (var productType in productCollection)
            {
                // we're separating the N and C terminal masses and computing a separate compact peptide for each one
                // this speeds calculations up without producing unnecessary terminus fragment info
                FragmentationTerminus     temporaryFragmentationTerminus = TerminusSpecificProductTypes.ProductTypeToFragmentationTerminus[productType];
                NeutralTerminusFragment[] terminalMasses = new CompactPeptide(this, temporaryFragmentationTerminus).TerminalMasses;

                int  firstUsableIndex            = FullSequence.Length;
                bool completeFragmentationSeries = true;
                switch (productType)
                {
                case ProductType.aStar:
                case ProductType.bStar:
                case ProductType.yStar:
                case ProductType.aDegree:
                case ProductType.bDegree:
                case ProductType.yDegree:
                {
                    firstUsableIndex            = GetFirstUsableIndex(FullSequence, productType, temporaryFragmentationTerminus);
                    completeFragmentationSeries = false;
                };
                    break;

                default:
                    break;
                }

                for (int f = 0; f < terminalMasses.Length; f++)
                {
                    if (completeFragmentationSeries)
                    {
                        // fragments with neutral loss
                        if (AllModsOneIsNterminus.TryGetValue(terminalMasses[f].AminoAcidPosition + 1, out Modification mod) && mod.NeutralLosses != null &&
                            mod.NeutralLosses.TryGetValue(dissociationType, out List <double> neutralLosses))
                        {
                            foreach (double neutralLoss in neutralLosses)
                            {
                                if (neutralLoss == 0)
                                {
                                    continue;
                                }

                                for (int n = f; n < terminalMasses.Length; n++)
                                {
                                    if (!skippers.Contains((productType, terminalMasses[n].FragmentNumber)))
Ejemplo n.º 15
0
        public static void TestPTMOutput()
        {
            List <ModificationWithMass> variableModifications = new List <ModificationWithMass>();
            List <ModificationWithMass> fixedModifications    = new List <ModificationWithMass>();

            ModificationMotif.TryGetMotif("S", out ModificationMotif motif);
            variableModifications.Add(new ModificationWithMassAndCf("resMod", "HaHa", motif, TerminusLocalization.Any, ChemicalFormula.ParseFormula("H")));

            var proteinList = new List <Protein> {
                new Protein("MNNNSKQQQ", "accession")
            };
            var protease = new Protease("CustomProtease", 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);
            Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > compactPeptideToProteinPeptideMatching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >();
            Dictionary <ModificationWithMass, ushort> modsDictionary = new Dictionary <ModificationWithMass, ushort>
            {
                { variableModifications.Last(), 1 }
            };

            DigestionParams digestionParams = new DigestionParams(protease: protease.Name, maxMissedCleavages: 0, minPeptideLength: 1);

            var modPep = proteinList.First().Digest(digestionParams, fixedModifications, variableModifications).Last();
            HashSet <PeptideWithSetModifications> value = new HashSet <PeptideWithSetModifications> {
                modPep
            };
            CompactPeptide compactPeptide1 = new CompactPeptide(value.First(), TerminusType.None);

            Assert.AreEqual("QQQ", value.First().Sequence);

            var firstProtDigest = proteinList.First().Digest(digestionParams, fixedModifications, variableModifications).ToList();
            HashSet <PeptideWithSetModifications> value2 = new HashSet <PeptideWithSetModifications> {
                firstProtDigest[0]
            };
            CompactPeptide compactPeptide2 = new CompactPeptide(value2.First(), TerminusType.None);

            Assert.AreEqual("MNNNSK", value2.First().Sequence);

            HashSet <PeptideWithSetModifications> value2mod = new HashSet <PeptideWithSetModifications> {
                firstProtDigest[1]
            };
            CompactPeptide compactPeptide2mod = new CompactPeptide(value2mod.Last(), TerminusType.None);

            Assert.AreEqual("MNNNS[HaHa:resMod]K", value2mod.Last().Sequence);

            HashSet <PeptideWithSetModifications> value3 = new HashSet <PeptideWithSetModifications> {
                firstProtDigest[2]
            };
            CompactPeptide compactPeptide3 = new CompactPeptide(value3.First(), TerminusType.None);

            Assert.AreEqual("NNNSK", value3.First().Sequence);
            HashSet <PeptideWithSetModifications> value3mod = new HashSet <PeptideWithSetModifications> {
                firstProtDigest[3]
            };

            CompactPeptide compactPeptide3mod = new CompactPeptide(value3mod.Last(), TerminusType.None);

            Assert.AreEqual("NNNS[HaHa:resMod]K", value3mod.Last().Sequence);

            var peptideList = new HashSet <PeptideWithSetModifications>();

            foreach (var protein in proteinList)
            {
                foreach (var peptide in protein.Digest(digestionParams, new List <ModificationWithMass>(), variableModifications))
                {
                    peptideList.Add(peptide);
                }
            }

            compactPeptideToProteinPeptideMatching.Add(compactPeptide1, value);
            compactPeptideToProteinPeptideMatching.Add(compactPeptide2, value2);
            compactPeptideToProteinPeptideMatching.Add(compactPeptide3, value3);
            compactPeptideToProteinPeptideMatching.Add(compactPeptide2mod, value2mod);
            compactPeptideToProteinPeptideMatching.Add(compactPeptide3mod, value3mod);

            ProteinParsimonyEngine engine = new ProteinParsimonyEngine(compactPeptideToProteinPeptideMatching, true, new CommonParameters(), new List <string> {
                "ff"
            });
            var cool          = (ProteinParsimonyResults)engine.Run();
            var proteinGroups = cool.ProteinGroups;

            MsDataScan jdfk = 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 ms2scan = new Ms2ScanWithSpecificMass(jdfk, 2, 0, "File");

            List <ProductType> lp = new List <ProductType> {
                ProductType.B, ProductType.Y
            };
            Tolerance fragmentTolerance = new AbsoluteTolerance(0.01);

            var match1 = new PeptideSpectralMatch(peptideList.ElementAt(0).CompactPeptide(TerminusType.None), 0, 10, 0, ms2scan, digestionParams)
            {
            };

            match1.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0, 0, false);
            var match2 = new PeptideSpectralMatch(peptideList.ElementAt(1).CompactPeptide(TerminusType.None), 0, 10, 0, ms2scan, digestionParams)
            {
            };

            match2.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0, 0, false);
            var match3 = new PeptideSpectralMatch(peptideList.ElementAt(1).CompactPeptide(TerminusType.None), 0, 10, 0, ms2scan, digestionParams)
            {
            };

            match3.SetFdrValues(0, 0, 0, 0, 0, 0, 0, 0, 0, false);
            match1.MatchToProteinLinkedPeptides(compactPeptideToProteinPeptideMatching);
            match2.MatchToProteinLinkedPeptides(compactPeptideToProteinPeptideMatching);
            match3.MatchToProteinLinkedPeptides(compactPeptideToProteinPeptideMatching);

            List <PeptideSpectralMatch> psms = new List <PeptideSpectralMatch>
            {
                match1,
                match2,
                match3
            };
            ProteinScoringAndFdrEngine f = new ProteinScoringAndFdrEngine(proteinGroups, psms, false, false, true, new CommonParameters(), new List <string>());

            f.Run();

            Assert.AreEqual("#aa5[resMod,info:occupancy=0.67(2/3)];", proteinGroups.First().ModsInfo[0]);
        }
Ejemplo n.º 16
0
        protected override MetaMorpheusEngineResults RunSpecific()
        {
            double       progress           = 0;
            int          oldPercentProgress = 0;
            TerminusType terminusType       = ProductTypeMethods.IdentifyTerminusType(ProductTypes);

            // digest database
            HashSet <CompactPeptide> peptideToId = new HashSet <CompactPeptide>();

            Parallel.ForEach(Partitioner.Create(0, ProteinList.Count), new ParallelOptions {
                MaxDegreeOfParallelism = commonParameters.MaxThreadsToUsePerFile
            }, (range, loopState) =>
            {
                for (int i = range.Item1; i < range.Item2; i++)
                {
                    // Stop loop if canceled
                    if (GlobalVariables.StopLoops)
                    {
                        loopState.Stop();
                        return;
                    }

                    foreach (var digestionParams in CollectionOfDigestionParams)
                    {
                        foreach (var pepWithSetMods in ProteinList[i].Digest(digestionParams, FixedModifications, VariableModifications))
                        {
                            CompactPeptide compactPeptide = pepWithSetMods.CompactPeptide(terminusType);

                            var observed = peptideToId.Contains(compactPeptide);
                            if (observed)
                            {
                                continue;
                            }
                            lock (peptideToId)
                            {
                                observed = peptideToId.Contains(compactPeptide);
                                if (observed)
                                {
                                    continue;
                                }
                                peptideToId.Add(compactPeptide);
                            }
                        }
                    }

                    progress++;
                    var percentProgress = (int)((progress / ProteinList.Count) * 100);

                    if (percentProgress > oldPercentProgress)
                    {
                        oldPercentProgress = percentProgress;
                        ReportProgress(new ProgressEventArgs(percentProgress, "Digesting proteins for precursor...", nestedIds));
                    }
                }
            });

            // sort peptides by mass
            var peptidesSortedByMass = peptideToId.AsParallel().WithDegreeOfParallelism(commonParameters.MaxThreadsToUsePerFile).OrderBy(p => p.MonoisotopicMassIncludingFixedMods).ToList();

            peptideToId = null;

            // create fragment index
            int maxFragmentMass = 0;

            for (int i = peptidesSortedByMass.Count - 1; i >= 0; i--)
            {
                if (!Double.IsNaN(peptidesSortedByMass[i].MonoisotopicMassIncludingFixedMods))
                {
                    maxFragmentMass = (int)Math.Ceiling(Chemistry.ClassExtensions.ToMz(peptidesSortedByMass[i].MonoisotopicMassIncludingFixedMods, 1));
                    break;
                }
            }

            var fragmentIndex = new List <int> [maxFragmentMass * FragmentBinsPerDalton + 1];

            // populate fragment index
            progress           = 0;
            oldPercentProgress = 0;
            for (int i = 0; i < peptidesSortedByMass.Count; i++)
            {
                double mz = Chemistry.ClassExtensions.ToMz(peptidesSortedByMass[i].MonoisotopicMassIncludingFixedMods, 1);
                if (!Double.IsNaN(mz))
                {
                    int fragmentBin = (int)Math.Round(mz * FragmentBinsPerDalton);

                    if (fragmentIndex[fragmentBin] == null)
                    {
                        fragmentIndex[fragmentBin] = new List <int> {
                            i
                        }
                    }
                    ;
                    else
                    {
                        fragmentIndex[fragmentBin].Add(i);
                    }
                }
                progress++;
                var percentProgress = (int)((progress / peptidesSortedByMass.Count) * 100);

                if (percentProgress > oldPercentProgress)
                {
                    oldPercentProgress = percentProgress;
                    ReportProgress(new ProgressEventArgs(percentProgress, "Creating fragment index for precursor...", nestedIds));
                }
            }

            return(new IndexingResults(peptidesSortedByMass, fragmentIndex, this));
        }
Ejemplo n.º 17
0
        public static void TestAnalysisEngineTests()
        {
            CommonParameters CommonParameters = new CommonParameters
            {
                DigestionParams = new DigestionParams
                {
                    Protease = new Protease("Custom Protease", new List <string> {
                        "K"
                    }, new List <string>(), TerminusType.C, CleavageSpecificity.Full, null, null, null),
                    MinPeptideLength        = null,
                    MaxMissedCleavages      = 0,
                    MaxModificationIsoforms = 1042,
                },
                ConserveMemory       = false,
                ScoreCutoff          = 1,
                ProductMassTolerance = new PpmTolerance(10),
            };

            List <ModificationWithMass> localizeableModifications = new List <ModificationWithMass>();
            List <ModificationWithMass> variableModifications     = new List <ModificationWithMass>();
            List <ModificationWithMass> fixedModifications        = new List <ModificationWithMass>();

            Dictionary <ModificationWithMass, ushort> modsDictionary = new Dictionary <ModificationWithMass, ushort>();

            foreach (var mod in fixedModifications)
            {
                modsDictionary.Add(mod, 0);
            }
            int i = 1;

            foreach (var mod in variableModifications)
            {
                modsDictionary.Add(mod, (ushort)i);
                i++;
            }
            foreach (var mod in localizeableModifications)
            {
                modsDictionary.Add(mod, (ushort)i);
                i++;
            }

            var proteinList = new List <Protein> {
                new Protein("MNNNKQQQ", "accession")
            };
            var modPep = proteinList.First().Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).Last();
            HashSet <PeptideWithSetModifications> value1 = new HashSet <PeptideWithSetModifications> {
                modPep
            };
            CompactPeptide compactPeptide1 = new CompactPeptide(value1.First(), TerminusType.None);

            Assert.AreEqual("QQQ", value1.First().BaseSequence);
            var modPep2 = proteinList.First().Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).First();
            HashSet <PeptideWithSetModifications> value2 = new HashSet <PeptideWithSetModifications> {
                modPep2
            };
            CompactPeptide compactPeptide2 = new CompactPeptide(value2.First(), TerminusType.None);

            Assert.AreEqual("MNNNK", value2.First().BaseSequence);

            var modPep3 = proteinList.First().Digest(CommonParameters.DigestionParams, fixedModifications, variableModifications).ToList()[1];
            HashSet <PeptideWithSetModifications> value3 = new HashSet <PeptideWithSetModifications> {
                modPep3
            };
            CompactPeptide compactPeptide3 = new CompactPeptide(value3.First(), TerminusType.None);

            Assert.AreEqual("NNNK", value3.First().BaseSequence);

            //newPsms[0] = new List<PsmParent>[] { new List<PsmParent>{ new PsmModern(compactPeptide1, null, 1,  1, 2, 2, 1,1, 1, 1, 3,0) },
            //                                     new List<PsmParent>{  new PsmModern(compactPeptide2, null, 2,2+132.040,3,3,2,2,2,2,2,0) },
            //                                     new List<PsmParent>{ new PsmModern(compactPeptide3, null, 3, 3, 4, 3, 3, 3, 3, 3, 3, 0)} };

            Ms2ScanWithSpecificMass scanA = new Ms2ScanWithSpecificMass(new MzmlScanWithPrecursor(2, new MzmlMzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 1, null, null, "scan=1"), 1, 1, null);
            Ms2ScanWithSpecificMass scanB = new Ms2ScanWithSpecificMass(new MzmlScanWithPrecursor(3, new MzmlMzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 1, null, null, "scan=2"), 2 + 132.040, 1, null);
            Ms2ScanWithSpecificMass scanC = new Ms2ScanWithSpecificMass(new MzmlScanWithPrecursor(4, new MzmlMzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 1, null, null, "scan=3"), 3, 1, null);

            PeptideSpectralMatch matchA = new PeptideSpectralMatch(compactPeptide1, 0, 0, 0, scanA);
            PeptideSpectralMatch matchB = new PeptideSpectralMatch(compactPeptide2, 0, 0, 0, scanB);
            PeptideSpectralMatch matchC = new PeptideSpectralMatch(compactPeptide3, 0, 0, 0, scanC);

            var newPsms = new List <PeptideSpectralMatch> {
                matchA, matchB, matchC
            };

            IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> {
                value1.First(), value2.First(), value3.First()
            });

            var searchMode = new SinglePpmAroundZeroSearchMode(5);
            Action <List <PeptideSpectralMatch>, string, List <string> > action2 = (List <PeptideSpectralMatch> l, string s, List <string> sdf) => {; };

            bool      DoPrecursorDeconvolution           = true;
            bool      UseProvidedPrecursorInfo           = true;
            double    DeconvolutionIntensityRatio        = 4;
            int       DeconvolutionMaxAssumedChargeState = 10;
            Tolerance DeconvolutionMassTolerance         = new PpmTolerance(5);

            var arrayOfMs2ScansSortedByMass = MetaMorpheusTask.GetMs2Scans(myMsDataFile, null, DoPrecursorDeconvolution, UseProvidedPrecursorInfo, DeconvolutionIntensityRatio, DeconvolutionMaxAssumedChargeState, DeconvolutionMassTolerance).OrderBy(b => b.PrecursorMass).ToArray();

            Action <BinTreeStructure, string> action1 = (BinTreeStructure l, string s) =>
            {
                Assert.AreEqual(1, l.FinalBins.Count);
            };

            SequencesToActualProteinPeptidesEngine sequencesToActualProteinPeptidesEngine = new SequencesToActualProteinPeptidesEngine(newPsms, proteinList, fixedModifications, variableModifications, new List <ProductType> {
                ProductType.B, ProductType.Y
            }, new List <IDigestionParams> {
                CommonParameters.DigestionParams
            }, CommonParameters.ReportAllAmbiguity, new List <string>());

            var res = (SequencesToActualProteinPeptidesEngineResults)sequencesToActualProteinPeptidesEngine.Run();
            var compactPeptideToProteinPeptideMatching = res.CompactPeptideToProteinPeptideMatching;

            foreach (var huh in newPsms)
            {
                if (huh != null)
                {
                    huh.MatchToProteinLinkedPeptides(compactPeptideToProteinPeptideMatching);
                }
            }

            FdrAnalysisEngine engine = new FdrAnalysisEngine(newPsms, searchMode.NumNotches, false, new List <string> {
                "ff"
            });

            engine.Run();
        }
        public static void FdrFilteringPsmsTest()
        {
            string[] sequences =
            {
                "-XYZ--ABC",
                "-XYZ-EFGABC",
            };

            List <Tuple <string, TerminusType> > sequencesInducingCleavage = new List <Tuple <string, TerminusType> > {
                new Tuple <string, TerminusType>("-", TerminusType.C), new Tuple <string, TerminusType>("Z", TerminusType.C)
            };
            List <Tuple <string, TerminusType> > sequencesInducingCleavage2 = new List <Tuple <string, TerminusType> > {
                new Tuple <string, TerminusType>("G", TerminusType.C)
            };

            var protease = new Protease("testC", sequencesInducingCleavage, new List <Tuple <string, TerminusType> >(), CleavageSpecificity.Full, null, null, null);

            ProteaseDictionary.Dictionary.Add(protease.Name, protease);
            var protease2 = new Protease("testD", sequencesInducingCleavage2, new List <Tuple <string, TerminusType> >(), CleavageSpecificity.Full, null, null, null);

            ProteaseDictionary.Dictionary.Add(protease2.Name, protease2);
            var peptideList = new HashSet <PeptideWithSetModifications>();

            var p = new List <Protein>();
            List <Tuple <string, string> > gn = new List <Tuple <string, string> >();

            for (int i = 0; i < sequences.Length; i++)
            {
                p.Add(new Protein(sequences[i], (i + 1).ToString(), null, gn, new Dictionary <int, List <Modification> >()));
            }

            DigestionParams digestionParams  = new DigestionParams(protease: protease.Name, minPeptideLength: 1);
            DigestionParams digestionParams2 = new DigestionParams(protease: protease2.Name, minPeptideLength: 1);

            foreach (var protein in p)
            {
                foreach (var peptide in protein.Digest(digestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()))
                {
                    switch (peptide.BaseSequence)
                    {
                    case "ABC": peptideList.Add(peptide); break;

                    case "EFGABC": peptideList.Add(peptide); break;

                    case "XYZ": peptideList.Add(peptide); break;
                    }
                }
                foreach (var peptide in protein.Digest(digestionParams2, new List <ModificationWithMass>(), new List <ModificationWithMass>()))
                {
                    switch (peptide.BaseSequence)
                    {
                    case "ABC": peptideList.Add(peptide); break;

                    case "-XYZ-EFG": peptideList.Add(peptide); break;
                    }
                }
            }

            // creates the initial dictionary of "peptide" and "virtual peptide" matches
            var dictionary = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >();

            CompactPeptide[] peptides = new CompactPeptide[peptideList.Count];

            PeptideWithSetModifications[] PWSM = new PeptideWithSetModifications[peptideList.Count];

            Dictionary <ModificationWithMass, ushort> modsDictionary = new Dictionary <ModificationWithMass, ushort>();

            // creates peptide list
            for (int i = 0; i < peptideList.Count; i++)
            {
                peptides[i] = new CompactPeptide(peptideList.ElementAt(i), TerminusType.None);
                PWSM[i]     = peptideList.ElementAt(i);
            }

            dictionary.Add(peptides[0], new HashSet <PeptideWithSetModifications> {
                PWSM[0], PWSM[2]
            });
            dictionary.Add(peptides[1], new HashSet <PeptideWithSetModifications> {
                PWSM[1], PWSM[5]
            });
            dictionary.Add(peptides[3], new HashSet <PeptideWithSetModifications> {
                PWSM[3]
            });
            dictionary.Add(peptides[4], new HashSet <PeptideWithSetModifications> {
                PWSM[4]
            });

            // builds psm list to match to peptides
            List <PeptideSpectralMatch> psms = new List <PeptideSpectralMatch>();

            MsDataScan dfb = 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(dfb, 2, 0, "File");

            foreach (var kvp in dictionary)
            {
                foreach (var peptide in kvp.Value)
                {
                    switch (peptide.BaseSequence)
                    {
                    case "ABC":
                        if (peptide.DigestionParams == digestionParams)
                        {
                            psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 10, 0, scan, digestionParams));
                            break;
                        }
                        if (peptide.DigestionParams == digestionParams2)
                        {
                            psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 10, 0, scan, digestionParams2));
                            break;
                        }
                        else
                        {
                            break;
                        }

                    case "EFGABC": psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 10, 0, scan, digestionParams)); break;

                    case "XYZ": psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 10, 0, scan, digestionParams)); break;

                    case "-XYZ-EFG": psms.Add(new PeptideSpectralMatch(peptide.CompactPeptide(TerminusType.None), 0, 10, 0, scan, digestionParams2)); break;
                    }
                }
            }
            double goodFdr = 0.00100;
            double badFdr  = 0.0200;

            psms.ElementAt(0).SetFdrValues(0, 0, goodFdr, 0, 0, badFdr, 0, 0, 0, false);
            psms.ElementAt(1).SetFdrValues(0, 0, badFdr, 0, 0, goodFdr, 0, 0, 0, false);
            psms.ElementAt(2).SetFdrValues(0, 0, goodFdr, 0, 0, goodFdr, 0, 0, 0, false);
            psms.ElementAt(3).SetFdrValues(0, 0, badFdr, 0, 0, badFdr, 0, 0, 0, false);
            psms.ElementAt(4).SetFdrValues(0, 0, goodFdr, 0, 0, goodFdr, 0, 0, 0, false);
            psms.ElementAt(5).SetFdrValues(0, 0, goodFdr, 0, 0, goodFdr, 0, 0, 0, false);

            //this iscopy of code that filteres psms in PostSearch Analysis Task
            var fdrFilteredPsms = new List <PeptideSpectralMatch>();

            foreach (PeptideSpectralMatch psm in psms)
            {
                if (psm != null && psm.FdrInfo.QValue <= 0.0100 && psm.FdrInfo.QValueNotch <= 0.0100)
                {
                    fdrFilteredPsms.Add(psm);
                }
            }

            Assert.AreEqual(3, fdrFilteredPsms.Count);

            var test1 = fdrFilteredPsms.Contains(psms.ElementAt(2));
            var test2 = fdrFilteredPsms.Contains(psms.ElementAt(4));
            var test3 = fdrFilteredPsms.Contains(psms.ElementAt(5));
            var test4 = fdrFilteredPsms.Contains(psms.ElementAt(0));
            var test5 = fdrFilteredPsms.Contains(psms.ElementAt(1));
            var test6 = fdrFilteredPsms.Contains(psms.ElementAt(3));

            Assert.AreEqual(true, test1);
            Assert.AreEqual(true, test2);
            Assert.AreEqual(true, test3);
            Assert.AreEqual(false, test4);
            Assert.AreEqual(false, test5);
            Assert.AreEqual(false, test6);
        }
Ejemplo n.º 19
0
        public static List <PsmCross> ReadTsv(string filePath)
        {
            List <PsmCross> PSMs = new List <PsmCross>();

            Dictionary <string, int> ids = new Dictionary <string, int>();

            //Empty array. Is this correct?
            string[][] resultArray = new string[][] { };
            try
            {
                resultArray = File.ReadLines(filePath).Select(p => p.Split('\t')).ToArray();
            }
            catch (Exception)
            {
                MessageBox.Show("Please check the file.");
                return(null);
            }


            for (int i = 0; i < resultArray[0].Length; i++)
            {
                ids.Add(resultArray[0][i], i);
            }

            for (int i = 1; i < resultArray.Length; i++)
            {
                PsmCross PSM = new PsmCross();
                PSM.ScanNumber = Convert.ToInt32(resultArray[i][ids["Scan Number"]]);
                var baseSeq     = resultArray[i][ids["Base Sequence"]];
                var chargeState = resultArray[i][ids["Precursor Charge"]];
                var fullSeq     = resultArray[i][ids["Full Sequence"]];
                if (baseSeq.Contains("|"))
                {
                    baseSeq = baseSeq.Split('|').First();
                    fullSeq = fullSeq.Split('|').First();
                }
                PSM.BaseSequence           = baseSeq;
                PSM.ScanPrecursorCharge    = Convert.ToInt32(chargeState);
                PSM.FullSequence           = fullSeq;
                PSM.IsDecoy                = (resultArray[i][ids["Decoy"]] == "N" ? false :true);
                PSM.PeptideMonisotopicMass = Convert.ToDouble(resultArray[i][ids["Precursor Mass"]]);

                var mods = GetMods(PSM);

                Dictionary <int, ModificationWithMass> allModsOneIsNterminus = new Dictionary <int, ModificationWithMass>();

                foreach (var item in mods)
                {
                    //I don't really know why use as here.
                    var theMod = GlobalVariables.AllModsKnown.Where(p => p.id == item.Value).First() as ModificationWithMass;

                    allModsOneIsNterminus.Add(item.Key, theMod);
                }

                PepWithSetModForCompactPep pepWithSetModForCompactPep = new PepWithSetModForCompactPep();
                pepWithSetModForCompactPep.allModsOneIsNterminus = allModsOneIsNterminus;
                pepWithSetModForCompactPep.BaseSequence          = PSM.BaseSequence;
                pepWithSetModForCompactPep.Length           = PSM.BaseSequence.Length;
                pepWithSetModForCompactPep.MonoisotopicMass = (double)PSM.PeptideMonisotopicMass;

                var compactPeptide = new CompactPeptide(pepWithSetModForCompactPep, TerminusType.None);

                PSM.CompactPeptide = compactPeptide;
                PSMs.Add(PSM);
            }

            return(PSMs);
        }
Ejemplo n.º 20
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
                   ));
        }
Ejemplo n.º 21
0
        public static void TestModificationAnalysisWithNonLocalizedPtms()
        {
            IScan scan = new ThisTestScan();

            ModificationMotif.TryGetMotif("N", out ModificationMotif motif1);
            ModificationWithMass mod1 = new ModificationWithMass("mod1", "mt", motif1, TerminusLocalization.Any, 10, neutralLosses: new List <double> {
                10
            });

            IDictionary <int, List <Modification> > oneBasedModifications = new Dictionary <int, List <Modification> >
            {
                { 2, new List <Modification> {
                      mod1
                  } },
                { 7, new List <Modification> {
                      mod1
                  } },
            };
            Protein protein1 = new Protein("MNLDLDNDL", "prot1", oneBasedModifications: oneBasedModifications);

            Dictionary <int, ModificationWithMass> allModsOneIsNterminus1 = new Dictionary <int, ModificationWithMass>
            {
                { 2, mod1 },
            };
            PeptideWithSetModifications pwsm1 = new PeptideWithSetModifications(0, protein1, 2, 9, allModsOneIsNterminus1);
            CompactPeptideBase          pep1  = new CompactPeptide(pwsm1, TerminusType.None);

            Dictionary <int, ModificationWithMass> allModsOneIsNterminus3 = new Dictionary <int, ModificationWithMass>
            {
                { 7, mod1 },
            };
            PeptideWithSetModifications pwsm3 = new PeptideWithSetModifications(0, protein1, 2, 9, allModsOneIsNterminus3);
            CompactPeptideBase          pep3  = new CompactPeptide(pwsm3, TerminusType.None);

            var newPsms = new List <PeptideSpectralMatch>
            {
                new PeptideSpectralMatch(pep1, 0, 10, 0, scan),
                new PeptideSpectralMatch(pep3, 0, 10, 0, scan),
            };

            MassDiffAcceptor searchMode  = new SinglePpmAroundZeroSearchMode(5);
            List <Protein>   proteinList = new List <Protein> {
                protein1
            };

            CommonParameters CommonParameters = new CommonParameters
            {
                DigestionParams = new DigestionParams
                {
                    MinPeptideLength        = null,
                    MaxMissedCleavages      = 0,
                    MaxModificationIsoforms = int.MaxValue
                },
                ConserveMemory = false,
                ScoreCutoff    = 1,
            };
            SequencesToActualProteinPeptidesEngine sequencesToActualProteinPeptidesEngine = new SequencesToActualProteinPeptidesEngine(newPsms, proteinList, new List <ModificationWithMass>(), new List <ModificationWithMass>(), new List <ProductType> {
                ProductType.B, ProductType.Y
            }, new List <IDigestionParams> {
                CommonParameters.DigestionParams
            }, CommonParameters.ReportAllAmbiguity, new List <string>());

            var nice = (SequencesToActualProteinPeptidesEngineResults)sequencesToActualProteinPeptidesEngine.Run();

            foreach (var psm in newPsms)
            {
                psm.MatchToProteinLinkedPeptides(nice.CompactPeptideToProteinPeptideMatching);
            }

            Assert.AreEqual(2, nice.CompactPeptideToProteinPeptideMatching[pep1].Count);

            FdrAnalysisEngine fdrAnalysisEngine = new FdrAnalysisEngine(newPsms, searchMode.NumNotches, false, new List <string>());

            fdrAnalysisEngine.Run();
            ModificationAnalysisEngine modificationAnalysisEngine = new ModificationAnalysisEngine(newPsms, new List <string>());
            var res = (ModificationAnalysisResults)modificationAnalysisEngine.Run();

            Assert.AreEqual(1, res.AllModsOnProteins.Count());
            Assert.AreEqual(2, res.AllModsOnProteins[mod1.id]);

            Assert.AreEqual(0, res.ModsSeenAndLocalized.Count());

            Assert.AreEqual(0, res.AmbiguousButLocalizedModsSeen.Count);

            Assert.AreEqual(1, res.UnlocalizedMods[mod1.id]); // Saw it, but not sure where!

            Assert.AreEqual(0, res.UnlocalizedFormulas.Count());
        }