예제 #1
0
        public static void TestRemoveThisAmbiguousePeptide()
        {
            Ms2ScanWithSpecificMass scanB = new Ms2ScanWithSpecificMass(
                new MsDataScan(
                    new MzSpectrum(new double[] { }, new double[] { }, false),
                    2, 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, 1, null),
                100, 1, null, new CommonParameters(), null);

            PeptideSpectralMatch psm1 = new PeptideSpectralMatch(new PeptideWithSetModifications(new Protein("PEPTIDE", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary <int, Modification>(), 0), 0, 10, 1, scanB, new DigestionParams(), new List <MatchedFragmentIon>(), 0);

            PeptideWithSetModifications pwsm = new PeptideWithSetModifications(new Protein("PEPTIDE", "ACCESSION", "ORGANISM"), new DigestionParams(), 1, 2, CleavageSpecificity.Full, "", 0, new Dictionary <int, Modification>(), 0);

            psm1.AddOrReplace(pwsm, 10, 1, true, new List <MatchedFragmentIon>(), 0);

            Assert.AreEqual(2, psm1.BestMatchingPeptides.Count());

            psm1.RemoveThisAmbiguousPeptide(1, pwsm);

            Assert.AreEqual(1, psm1.BestMatchingPeptides.Count());
        }
예제 #2
0
        public static void MatchInternalFragmentIons(PeptideSpectralMatch[] fileSpecificPsms, Ms2ScanWithSpecificMass[] arrayOfMs2ScansSortedByMass, CommonParameters combinedParams, int minInternalFragmentLength)
        {
            //for each PSM with an ID
            for (int index = 0; index < fileSpecificPsms.Length; index++)
            {
                PeptideSpectralMatch psm = fileSpecificPsms[index];
                if (psm != null && psm.BestMatchingPeptides.Count() > 0)
                {
                    //Get the scan
                    Ms2ScanWithSpecificMass scanForThisPsm   = arrayOfMs2ScansSortedByMass[index];
                    DissociationType        dissociationType = combinedParams.DissociationType == DissociationType.Autodetect ?
                                                               scanForThisPsm.TheScan.DissociationType.Value : combinedParams.DissociationType;

                    //Get the theoretical peptides
                    List <PeptideWithSetModifications> ambiguousPeptides = new List <PeptideWithSetModifications>();
                    List <int> notches = new List <int>();
                    foreach (var(Notch, Peptide) in psm.BestMatchingPeptides)
                    {
                        ambiguousPeptides.Add(Peptide);
                        notches.Add(Notch);
                    }

                    //get matched ions for each peptide
                    List <List <MatchedFragmentIon> > matchedIonsForAllAmbiguousPeptides = new List <List <MatchedFragmentIon> >();
                    List <Product> internalFragments = new List <Product>();
                    foreach (PeptideWithSetModifications peptide in ambiguousPeptides)
                    {
                        internalFragments.Clear();
                        peptide.FragmentInternally(combinedParams.DissociationType, minInternalFragmentLength, internalFragments);
                        //TODO: currently, internal and terminal ions can match to the same observed peaks (much like how b- and y-ions can match to the same peaks). Investigate if we should change that...
                        matchedIonsForAllAmbiguousPeptides.Add(MetaMorpheusEngine.MatchFragmentIons(scanForThisPsm, internalFragments, combinedParams));
                    }

                    //Find the max number of matched ions
                    int maxNumMatchedIons = matchedIonsForAllAmbiguousPeptides.Max(x => x.Count);

                    //remove peptides if they have fewer than max-1 matched ions, thus requiring at least two internal ions to disambiguate an ID
                    //if not removed, then add the matched internal ions
                    HashSet <PeptideWithSetModifications> PeptidesToMatchingInternalFragments = new HashSet <PeptideWithSetModifications>();
                    for (int peptideIndex = 0; peptideIndex < ambiguousPeptides.Count; peptideIndex++)
                    {
                        //if we should remove the theoretical, remove it
                        if (matchedIonsForAllAmbiguousPeptides[peptideIndex].Count + 1 < maxNumMatchedIons)
                        {
                            psm.RemoveThisAmbiguousPeptide(notches[peptideIndex], ambiguousPeptides[peptideIndex]);
                        }
                        // otherwise add the matched internal ions to the total ions
                        else
                        {
                            PeptideWithSetModifications currentPwsm = ambiguousPeptides[peptideIndex];
                            //check that we haven't already added the matched ions for this peptide
                            if (!PeptidesToMatchingInternalFragments.Contains(currentPwsm))
                            {
                                PeptidesToMatchingInternalFragments.Add(currentPwsm);                                                    //record that we've seen this peptide
                                psm.PeptidesToMatchingFragments[currentPwsm].AddRange(matchedIonsForAllAmbiguousPeptides[peptideIndex]); //add the matched ions
                            }
                        }
                    }
                }
            }
        }
예제 #3
0
        public static void ResolveModificationsTest()
        {
            double mass = 12.0 + new PeptideWithSetModifications(new Protein("LNLDLDND", "prot1"), new DigestionParams(), 1, 8, CleavageSpecificity.Full, "", 0, new Dictionary <int, Modification>(), 0, null).MonoisotopicMass.ToMz(1);
            Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(new MsDataScan(new MzSpectrum(new double[, ] {
            }), 0, 0, true, Polarity.Positive,
                                                                                      0, new MzLibUtil.MzRange(0, 0), "", MZAnalyzerType.FTICR, 0, null, null, ""), mass, 1, "", new CommonParameters());

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

            Dictionary <DissociationType, List <double> > NeutralLosses = new Dictionary <DissociationType, List <double> >();

            NeutralLosses.Add(DissociationType.HCD, new List <double> {
                0
            });

            Modification modFormula_C1 = new Modification(_originalId: "modC", _accession: "", _modificationType: "mt", _featureType: "", _target: motif1, _locationRestriction: "Anywhere.", _chemicalFormula: new ChemicalFormula(ChemicalFormula.ParseFormula("C1")), null, null, null, null, _neutralLosses: NeutralLosses, null, null);
            Modification modFormula_H1 = new Modification(_originalId: "modH", _accession: "", _modificationType: "mt", _featureType: "", _target: motif1, _locationRestriction: "Anywhere.", _chemicalFormula: new ChemicalFormula(ChemicalFormula.ParseFormula("H1")), null, null, null, null, _neutralLosses: NeutralLosses, null, null);

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

            Dictionary <int, Modification> allModsOneIsNterminus1 = new Dictionary <int, Modification>
            {
                { 2, modFormula_C1 },
            };

            PeptideWithSetModifications pwsm1 = new PeptideWithSetModifications(protein1, new DigestionParams(), 2, 9, CleavageSpecificity.Unknown, null, 0, allModsOneIsNterminus1, 0);

            Dictionary <int, Modification> allModsOneIsNterminus2 = new Dictionary <int, Modification>
            {
                { 2, modFormula_H1 },
            };

            PeptideWithSetModifications pwsm2 = new PeptideWithSetModifications(protein1, new DigestionParams(), 2, 9, CleavageSpecificity.Unknown, null, 0, allModsOneIsNterminus2, 0);

            CommonParameters CommonParameters = new CommonParameters(digestionParams: new DigestionParams(maxMissedCleavages: 0, minPeptideLength: 1), scoreCutoff: 1);
            var fsp = new List <(string fileName, CommonParameters fileSpecificParameters)>();

            fsp.Add(("", CommonParameters));

            List <MatchedFragmentIon> mfi = new List <MatchedFragmentIon>();

            //we're adding a neutral loss of 5 to the product to make sure we hit the right spot in the unit test to add that loss to the product ion string
            Product p = new Product(ProductType.b, FragmentationTerminus.N, 1, 1, 1, 5);

            mfi.Add(new MatchedFragmentIon(ref p, 1, 1, 1));
            PeptideSpectralMatch myPsm = new PeptideSpectralMatch(pwsm1, 0, 10, 0, scan, new CommonParameters(), mfi);

            myPsm.AddOrReplace(pwsm2, 10, 0, true, mfi, 10);

            myPsm.ResolveAllAmbiguities();

            //Here we have a situation where there are two mods at the same position with different chemical formuala. They cannot be resolved and so the return value is null.
            Assert.IsNull(myPsm.ModsChemicalFormula);

            string myPsmString = myPsm.ToString();

            string[] myPsmStringSplit = myPsmString.Split('\t');
            string   ppmErrorString   = myPsmStringSplit[23];

            //The two different mods produce two separate mass errors, which are both then reported
            Assert.AreEqual("0.00|11801.30", ppmErrorString);

            //Make sure we see produt ion neutral losses in the output.
            string matchedIonSeries = myPsmStringSplit[38];

            Assert.AreEqual("[(b1-5.00)+1]", matchedIonSeries);


            //removing one of the peptides to reset for the next test
            myPsm.RemoveThisAmbiguousPeptide(0, pwsm2);

            PeptideWithSetModifications pwsm3 = new PeptideWithSetModifications(protein1, new DigestionParams(), 2, 9, CleavageSpecificity.Unknown, null, 0, allModsOneIsNterminus1, 0);

            myPsm.AddOrReplace(pwsm3, 10, 0, true, mfi, 10);

            myPsm.ResolveAllAmbiguities();

            //Now we have removed one of the peptides with a different chemical formual and replaced it with a mod that has the same chemical formula as the remaining original best peptide
            //Here we have a situation where there are two mods at the same position have the same chemical formuala and they can be resolved and so the return value the chemical formual of the mod.
            Assert.AreEqual("C", myPsm.ModsChemicalFormula.Formula.ToString());

            myPsmString      = myPsm.ToString();
            myPsmStringSplit = myPsmString.Split('\t');
            ppmErrorString   = myPsmStringSplit[23];

            Assert.AreEqual("0.00", ppmErrorString);
        }