Ejemplo n.º 1
0
        public static void AddCompIonsCommonParams()
        {
            CommonParameters cp = new CommonParameters(null, DissociationType.HCD, DissociationType.Unknown, true, true, 3, 12, true, true, 1,
                                                       5, 200, 0.01, null, null, false, false, true, false, null, null, null, -1, null, null, null, 1, true, 4, 1);

            var myMsDataFile              = new TestDataFile();
            var variableModifications     = new List <Modification>();
            var fixedModifications        = new List <Modification>();
            var localizeableModifications = new List <Modification>();
            Dictionary <Modification, ushort> modsDictionary = new Dictionary <Modification, ushort>();

            foreach (var mod in fixedModifications)
            {
                modsDictionary.Add(mod, 0);
            }

            int ii = 1;

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

            var proteinList = new List <Protein> {
                new Protein("MNNNKQQQ", null)
            };

            SearchParameters SearchParameters = new SearchParameters
            {
                MassDiffAcceptorType = MassDiffAcceptorType.Exact,
                SearchTarget         = true,
            };
            List <DigestionMotif> motifs = new List <DigestionMotif> {
                new DigestionMotif("K", null, 1, null)
            };
            Protease protease = new Protease("Test", CleavageSpecificity.Full, null, null, motifs);

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

            var indexEngine = new IndexingEngine(proteinList, variableModifications, fixedModifications, new List <SilacLabel>(),
                                                 1, DecoyType.Reverse, cp, SearchParameters.MaxFragmentSize, false, new List <FileInfo>(), new List <string>());

            var indexResults = (IndexingResults)indexEngine.Run();

            Tolerance DeconvolutionMassTolerance = new PpmTolerance(5);

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

            MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(cp.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac);

            // without complementary ions
            PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            var mse = new ModernSearchEngine(allPsmsArray, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, cp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List <string>()).Run();
        }
Ejemplo n.º 2
0
        public static void TestCompIons_MatchIonsScore()
        {
            TestDataFile t = new TestDataFile();
            Tolerance    productMassTolerance = new AbsoluteTolerance(0.01);
            double       precursorMass        = 300;

            //The below theoretical does not accurately represent B-Y ions
            double[]       sorted_theoretical_product_masses_for_this_peptide = new double[] { precursorMass + (2 * Constants.ProtonMass) - 275.1350, precursorMass + (2 * Constants.ProtonMass) - 258.127, precursorMass + (2 * Constants.ProtonMass) - 257.1244, 50, 60, 70, 147.0764, precursorMass + (2 * Constants.ProtonMass) - 147.0764, precursorMass + (2 * Constants.ProtonMass) - 70, precursorMass + (2 * Constants.ProtonMass) - 60, precursorMass + (2 * Constants.ProtonMass) - 50, 257.1244, 258.127, 275.1350 }; //{ 50, 60, 70, 147.0764, 257.1244, 258.127, 275.1350 }
            List <Product> productsWithLocalizedMassDiff = new List <Product>();

            foreach (double d in sorted_theoretical_product_masses_for_this_peptide)
            {
                productsWithLocalizedMassDiff.Add(new Product(ProductType.b, FragmentationTerminus.Both, d, 1, 1, 0));
            }
            CommonParameters commonParametersNoComp = new CommonParameters {
                ProductMassTolerance = new AbsoluteTolerance(0.01)
            };
            CommonParameters commonParametersWithComp = new CommonParameters(productMassTolerance: new AbsoluteTolerance(0.01), addCompIons: true);

            MsDataScan scan         = t.GetOneBasedScan(2);
            var        scanWithMass = new Ms2ScanWithSpecificMass(scan, precursorMass.ToMz(1), 1, "", new CommonParameters());
            List <MatchedFragmentIon> matchedIons = MetaMorpheusEngine.MatchFragmentIons(scanWithMass, productsWithLocalizedMassDiff, commonParametersNoComp);

            List <MatchedFragmentIon> matchedCompIons = MetaMorpheusEngine.MatchFragmentIons(scanWithMass, productsWithLocalizedMassDiff, commonParametersWithComp);

            matchedCompIons.AddRange(matchedIons);

            // score when the mass-diff is on this residue
            double localizedScore = MetaMorpheusEngine.CalculatePeptideScore(scan, matchedIons);
            double scoreNormal    = MetaMorpheusEngine.CalculatePeptideScore(scan, matchedIons);
            double scoreComp      = MetaMorpheusEngine.CalculatePeptideScore(scan, matchedCompIons);

            Assert.IsTrue(scoreNormal * 2 == scoreComp && scoreComp > scoreNormal + 1);
        }
Ejemplo n.º 3
0
        public static void TestAddCompIonsClassic()
        {
            var myMsDataFile          = new TestDataFile();
            var variableModifications = new List <Modification>();
            var fixedModifications    = new List <Modification>();
            var proteinList           = new List <Protein> {
                new Protein("QXQ", null)
            };

            var productMassTolerance = new AbsoluteTolerance(0.01);
            var searchModes          = new OpenSearchMode();

            Tolerance DeconvolutionMassTolerance = new PpmTolerance(5);

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

            List <DigestionMotif> motifs = new List <DigestionMotif> {
                new DigestionMotif("K", null, 1, null)
            };
            Protease protease = new Protease("Custom Protease3", CleavageSpecificity.Full, null, null, motifs);

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

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

            fsp.Add(("", CommonParameters));
            PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null,
                                    proteinList, searchModes, CommonParameters, fsp, null, new List <string>()).Run();

            CommonParameters CommonParameters2 = new CommonParameters(
                digestionParams: new DigestionParams(protease: protease.Name, maxMissedCleavages: 0, minPeptideLength: 1),
                scoreCutoff: 1,
                addCompIons: true);
            var fsp2 = new List <(string fileName, CommonParameters fileSpecificParameters)>();

            fsp2.Add(("", CommonParameters2));
            PeptideSpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ClassicSearchEngine(allPsmsArray2, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null,
                                    proteinList, searchModes, CommonParameters2, fsp2, null, new List <string>()).Run();

            double scoreT = allPsmsArray2[0].Score;
            double scoreF = allPsmsArray[0].Score;

            // Single search mode
            Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length);

            // Single ms2 scan
            Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length);

            Assert.IsTrue(scoreT > 1);

            Assert.AreEqual(allPsmsArray[0].ScanNumber, allPsmsArray2[0].ScanNumber);

            Assert.IsTrue(scoreT == scoreF * 3 && scoreT > scoreF + 2);
        }
Ejemplo n.º 4
0
        public static void TestContaminantAmbiguity()
        {
            //create an ms file and a database for the peptide
            Protein targetProtein = new Protein("PEPTIDE", "target");
            string  xmlName       = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PEPTIDE.xml");

            ProteinDbWriter.WriteXmlDatabase(null, new List <Protein> {
                targetProtein
            }, xmlName);
            PeptideWithSetModifications pepWithSetMods = targetProtein.Digest(new DigestionParams(), null, null).First();
            TestDataFile msFile   = new TestDataFile(pepWithSetMods);
            string       mzmlName = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PEPTIDE.mzML");

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

            //run a full modern search using two databases (the same database) but one is called a target and the other is called a contaminant
            //KEEP BOTH TARGET AND CONTAMINANT
            SearchParameters modernSearchParams = new SearchParameters();

            modernSearchParams.SearchType  = SearchType.Modern;
            modernSearchParams.TCAmbiguity = TargetContaminantAmbiguity.RenameProtein;
            SearchTask modernTask = new SearchTask();

            modernTask.SearchParameters = modernSearchParams;

            EverythingRunnerEngine engine = new EverythingRunnerEngine(new List <(string, MetaMorpheusTask)> {
                ("task1", modernTask)
            }, new List <string> {
Ejemplo n.º 5
0
        public static void TestAddCompIonsClassic()
        {
            var myMsDataFile          = new TestDataFile();
            var variableModifications = new List <ModificationWithMass>();
            var fixedModifications    = new List <ModificationWithMass>();
            var proteinList           = new List <Protein> {
                new Protein("QXQ", null)
            };

            var productMassTolerance = new AbsoluteTolerance(0.01);
            var searchModes          = new OpenSearchMode();

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

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

            PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length];

            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
                },
                ConserveMemory = false,
                ScoreCutoff    = 1,
            };

            new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, proteinList, new List <ProductType> {
                ProductType.B, ProductType.Y
            }, searchModes, false, CommonParameters, CommonParameters.ProductMassTolerance, new List <string>()).Run();
            PeptideSpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ClassicSearchEngine(allPsmsArray2, listOfSortedms2Scans, variableModifications, fixedModifications, proteinList, new List <ProductType> {
                ProductType.B, ProductType.Y
            }, searchModes, true, CommonParameters, CommonParameters.ProductMassTolerance, new List <string>()).Run();

            double scoreT = allPsmsArray2[0].Score;
            double scoreF = allPsmsArray[0].Score;

            // Single search mode
            Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length);

            // Single ms2 scan
            Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length);

            Assert.IsTrue(scoreT > 1);

            Assert.AreEqual(allPsmsArray[0].ScanNumber, allPsmsArray2[0].ScanNumber);

            Assert.IsTrue(scoreT == scoreF * 3 && scoreT > scoreF + 2);
        }
Ejemplo n.º 6
0
        public static void TestResolveAmbiguities()
        {
            Protease protease = new Protease("Custom Protease4", CleavageSpecificity.Full, null, null, new List <DigestionMotif> {
                new DigestionMotif("K", null, 1, "")
            });

            ProteaseDictionary.Dictionary.Add(protease.Name, protease);
            CommonParameters CommonParameters_t = new CommonParameters(
                dissociationType: MassSpectrometry.DissociationType.HCD,
                digestionParams: new DigestionParams(
                    protease: protease.Name,
                    minPeptideLength: 1),
                scoreCutoff: 1,
                reportAllAmbiguity: true);
            var fsp_t = new List <(string fileName, CommonParameters fileSpecificParameters)>();

            fsp_t.Add(("", CommonParameters_t));

            CommonParameters CommonParameters_f = new CommonParameters(
                dissociationType: MassSpectrometry.DissociationType.HCD,
                digestionParams: new DigestionParams(
                    protease: protease.Name,
                    minPeptideLength: 1),
                scoreCutoff: 1,
                reportAllAmbiguity: false);
            var fsp_f = new List <(string fileName, CommonParameters fileSpecificParameters)>();

            fsp_f.Add(("", CommonParameters_t));

            var myMsDataFile          = new TestDataFile();
            var variableModifications = new List <Modification>();
            var fixedModifications    = new List <Modification>();
            var proteinList           = new List <Protein> {
                new Protein("MNNKNKNKQQQ", "Prot1"), new Protein("MNNNKQQQ", "Prot2")
            };
            var searchModes = new SinglePpmAroundZeroSearchMode(5);

            Tolerance DeconvolutionMassTolerance = new PpmTolerance(5);

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

            PeptideSpectralMatch[] allPsmsArray_withAmbiguity = new PeptideSpectralMatch[listOfSortedms2Scans.Length];

            PeptideSpectralMatch[] allPsmsArray_withOutAmbiguity = new PeptideSpectralMatch[listOfSortedms2Scans.Length];

            bool writeSpectralLibrary = false;

            new ClassicSearchEngine(allPsmsArray_withAmbiguity, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null,
                                    proteinList, searchModes, CommonParameters_t, fsp_t, null, new List <string>(), writeSpectralLibrary).Run(); //report all ambiguity TRUE
            new ClassicSearchEngine(allPsmsArray_withOutAmbiguity, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null,
                                    proteinList, searchModes, CommonParameters_f, fsp_f, null, new List <string>(), writeSpectralLibrary).Run(); //report all ambiguity FALSE

            Assert.AreEqual("QQQ", allPsmsArray_withAmbiguity[0].BaseSequence);
            Assert.AreEqual("QQQ", allPsmsArray_withOutAmbiguity[0].BaseSequence);
            Assert.IsTrue(allPsmsArray_withAmbiguity[0].ProteinLength == null);
            Assert.IsTrue(allPsmsArray_withOutAmbiguity[0].ProteinLength != null);
            Assert.IsTrue(allPsmsArray_withAmbiguity[0].OneBasedStartResidueInProtein == null);
            Assert.IsTrue(allPsmsArray_withOutAmbiguity[0].OneBasedStartResidueInProtein != null);
        }
Ejemplo n.º 7
0
        //[Test]
        public static void TestGetCombinedMs2Scans()
        {
            var myMsDataFile = new TestDataFile(5);

            Tolerance DeconvolutionMassTolerance = new PpmTolerance(5);

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

            //Write prime code to combine MS2MS3
            Dictionary <int, double> listOfScanPrecusor = new Dictionary <int, double>();

            List <MsDataScan> ListOfSortedMsScans = new List <MsDataScan>();
            List <Ms2ScanWithSpecificMass> test   = new List <Ms2ScanWithSpecificMass>();

            foreach (var ms2scan in myMsDataFile.GetAllScansList().Where(x => x.MsnOrder != 1))
            {
                if (ms2scan.MsnOrder == 2 && !listOfScanPrecusor.Contains(new KeyValuePair <int, double>(ms2scan.OneBasedPrecursorScanNumber.Value, ms2scan.SelectedIonMZ.Value)))
                {
                    if (ms2scan.OneBasedPrecursorScanNumber.HasValue)
                    {
                        listOfScanPrecusor.Add(ms2scan.OneBasedPrecursorScanNumber.Value, ms2scan.SelectedIonMZ.Value);
                        List <int> currentScanMS2OneBasedScanNumber = new List <int>
                        {
                            ms2scan.OneBasedScanNumber
                        };
                        var mz2          = ms2scan.MassSpectrum.XArray.ToList();
                        var intensities2 = ms2scan.MassSpectrum.YArray.ToList();
                        for (int i = 1; i < 7; i++)
                        {
                            if (ms2scan.OneBasedScanNumber + i <= myMsDataFile.NumSpectra)
                            {
                                var x = myMsDataFile.GetOneBasedScan(ms2scan.OneBasedScanNumber + i);
                                //var x = myMsDataFile.OfType<IMsDataScanWithPrecursor<IMzSpectrum<IMzPeak>>>().ElementAt(i);

                                if (x.MsnOrder == 2 && x.SelectedIonMZ == ms2scan.SelectedIonMZ)
                                {
                                    currentScanMS2OneBasedScanNumber.Add(x.OneBasedScanNumber);
                                    mz2.AddRange(x.MassSpectrum.XArray.ToList());
                                    intensities2.AddRange(x.MassSpectrum.YArray.ToList());
                                }
                                if (x.MsnOrder == 3 && currentScanMS2OneBasedScanNumber.Contains(x.OneBasedPrecursorScanNumber.Value))
                                {
                                    mz2.AddRange(x.MassSpectrum.XArray.ToList());
                                    intensities2.AddRange(x.MassSpectrum.YArray.ToList());
                                }
                            }
                        }
                        var MassSpectrum2 = new MzSpectrum(mz2.ToArray(), intensities2.ToArray(), false);
                        ListOfSortedMsScans.Add(new MsDataScan(MassSpectrum2, ms2scan.OneBasedScanNumber, ms2scan.MsnOrder, ms2scan.IsCentroid, Polarity.Positive, ms2scan.RetentionTime,
                                                               ms2scan.ScanWindowRange, ms2scan.ScanFilter, ms2scan.MzAnalyzer, ms2scan.TotalIonCurrent, ms2scan.InjectionTime, null, "", ms2scan.SelectedIonMZ, ms2scan.SelectedIonChargeStateGuess, ms2scan.SelectedIonIntensity, ms2scan.IsolationMz, null, ms2scan.DissociationType, ms2scan.OneBasedPrecursorScanNumber, ms2scan.SelectedIonMonoisotopicGuessMz));
                    }
                }
            }
            foreach (var ms2scan in ListOfSortedMsScans.Where(x => x.MsnOrder != 1))
            {
                test.Add(new Ms2ScanWithSpecificMass(ms2scan, ms2scan.SelectedIonMonoisotopicGuessMz.Value, ms2scan.SelectedIonChargeStateGuess.Value, "", new CommonParameters()));
            }
            var testToArray = test.OrderBy(b => b.PrecursorMass).ToArray();
        }
Ejemplo n.º 8
0
        public static void TestLocalization()
        {
            var protease = new Protease("Custom Protease", new List <string> {
                "K"
            }, new List <string>(), TerminusType.C, CleavageSpecificity.Full, null, null, null);

            Protein         parentProteinForMatch = new Protein("MEK", null);
            DigestionParams digestionParams       = new DigestionParams
            {
                MinPeptideLength = 1,
            };

            ModificationMotif.TryGetMotif("E", out ModificationMotif motif);
            List <ModificationWithMass> variableModifications = new List <ModificationWithMass> {
                new ModificationWithMass("21", null, motif, TerminusLocalization.Any, 21.981943)
            };

            List <PeptideWithSetModifications> allPeptidesWithSetModifications = parentProteinForMatch.Digest(digestionParams, new List <ModificationWithMass>(), variableModifications).ToList();

            Assert.AreEqual(4, allPeptidesWithSetModifications.Count());
            PeptideWithSetModifications ps = allPeptidesWithSetModifications.First();

            List <ProductType> lp = new List <ProductType> {
                ProductType.BnoB1ions, ProductType.Y
            };

            PeptideWithSetModifications pepWithSetModsForSpectrum            = allPeptidesWithSetModifications[1];
            IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> {
                pepWithSetModsForSpectrum
            });
            Tolerance fragmentTolerance = new AbsoluteTolerance(0.01);

            Ms2ScanWithSpecificMass scan   = new Ms2ScanWithSpecificMass(myMsDataFile.Last() as IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >, pepWithSetModsForSpectrum.MonoisotopicMass.ToMz(1), 1, null);
            PeptideSpectralMatch    newPsm = new PeptideSpectralMatch(ps.CompactPeptide(TerminusType.None), 0, 0, 2, scan);

            Dictionary <ModificationWithMass, ushort> modsDictionary = new Dictionary <ModificationWithMass, ushort>();
            Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > matching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >
            {
                { ps.CompactPeptide(TerminusType.None), new HashSet <PeptideWithSetModifications> {
                      ps
                  } }
            };

            newPsm.MatchToProteinLinkedPeptides(matching);

            LocalizationEngine f = new LocalizationEngine(new List <PeptideSpectralMatch> {
                newPsm
            }, lp, myMsDataFile, fragmentTolerance, new List <string>(), false);

            f.Run();

            // Was single peak!!!
            Assert.AreEqual(0, newPsm.MatchedIonDictOnlyMatches[ProductType.BnoB1ions].Count(b => b > 0));
            Assert.AreEqual(1, newPsm.MatchedIonDictOnlyMatches[ProductType.Y].Count(b => b > 0));
            // If localizing, three match!!!
            Assert.IsTrue(newPsm.LocalizedScores[1] > 3 && newPsm.LocalizedScores[1] < 4);
        }
Ejemplo n.º 9
0
        public static void TestPsmHeader()
        {
            DigestionParams             digestionParams = new DigestionParams();
            PeptideWithSetModifications pepWithSetMods  = new Protein(
                "MQQQQQQQ",
                "accession1",
                "org",
                new List <Tuple <string, string> > {
                new Tuple <string, string>("geneNameType", "geneName")
            },
                new Dictionary <int, List <Modification> > {
                { 2, new List <Modification> {
                      new Modification("mod", "mod")
                  } }
            },
                name: "name",
                full_name: "fullName",
                sequenceVariations: new List <SequenceVariation> {
                new SequenceVariation(2, "P", "Q", "changed this sequence")
            })
                                                          .Digest(digestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).First();
            MsDataFile myMsDataFile      = new TestDataFile(pepWithSetMods, "quadratic");
            MsDataScan scann             = myMsDataFile.GetOneBasedScan(2);
            Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(scann, 4, 1, null);
            PeptideSpectralMatch    psm  = new PeptideSpectralMatch(pepWithSetMods.CompactPeptide(TerminusType.None), 1, 2, 3, scan, digestionParams);

            var t            = psm.ToString();
            var tabsepheader = PeptideSpectralMatch.GetTabSeparatedHeader();

            Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t'));

            Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > matching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >
            {
                { pepWithSetMods.CompactPeptide(TerminusType.None), new HashSet <PeptideWithSetModifications> {
                      pepWithSetMods
                  } }
            };

            psm.MatchToProteinLinkedPeptides(matching);

            Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t'));

            Tolerance          fragmentTolerance = new PpmTolerance(10);
            List <ProductType> lp = new List <ProductType> {
                ProductType.B
            };

            new LocalizationEngine(new List <PeptideSpectralMatch> {
                psm
            }, lp, myMsDataFile, new CommonParameters(productMassTolerance: fragmentTolerance), new List <string>()).Run();

            Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t'));

            psm.SetFdrValues(6, 6, 6, 6, 6, 6, 0, 0, 0, true);

            Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t'));
        }
Ejemplo n.º 10
0
        public static void TestLocalization()
        {
            Protein         parentProteinForMatch = new Protein("MEK", null);
            DigestionParams digestionParams       = new DigestionParams(minPeptideLength: 1);

            ModificationMotif.TryGetMotif("E", out ModificationMotif motif);
            List <ModificationWithMass> variableModifications = new List <ModificationWithMass> {
                new ModificationWithMass("21", null, motif, TerminusLocalization.Any, 21.981943)
            };

            List <PeptideWithSetModifications> allPeptidesWithSetModifications = parentProteinForMatch.Digest(digestionParams, new List <ModificationWithMass>(), variableModifications).ToList();

            Assert.AreEqual(4, allPeptidesWithSetModifications.Count());
            PeptideWithSetModifications ps = allPeptidesWithSetModifications.First();

            List <ProductType> lp = new List <ProductType> {
                ProductType.BnoB1ions, ProductType.Y
            };

            PeptideWithSetModifications pepWithSetModsForSpectrum = allPeptidesWithSetModifications[1];
            MsDataFile myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> {
                pepWithSetModsForSpectrum
            });
            Tolerance fragmentTolerance = new AbsoluteTolerance(0.01);

            Ms2ScanWithSpecificMass scan   = new Ms2ScanWithSpecificMass(myMsDataFile.GetAllScansList().Last(), pepWithSetModsForSpectrum.MonoisotopicMass.ToMz(1), 1, null);
            PeptideSpectralMatch    newPsm = new PeptideSpectralMatch(ps.CompactPeptide(TerminusType.None), 0, 0, 2, scan, digestionParams);

            Dictionary <ModificationWithMass, ushort> modsDictionary = new Dictionary <ModificationWithMass, ushort>();
            Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > matching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >
            {
                { ps.CompactPeptide(TerminusType.None), new HashSet <PeptideWithSetModifications> {
                      ps
                  } }
            };

            newPsm.MatchToProteinLinkedPeptides(matching);

            CommonParameters   commonParameters = new CommonParameters(productMassTolerance: fragmentTolerance);
            LocalizationEngine f = new LocalizationEngine(new List <PeptideSpectralMatch> {
                newPsm
            }, lp, myMsDataFile, commonParameters, new List <string>());

            f.Run();

            // Was single peak!!!
            Assert.AreEqual(0, newPsm.MatchedIonMassToChargeRatioDict[ProductType.BnoB1ions].Count(b => b > 0));
            Assert.AreEqual(1, newPsm.MatchedIonMassToChargeRatioDict[ProductType.Y].Count(b => b > 0));
            Assert.AreEqual(0, newPsm.MatchedIonIntensitiesDict[ProductType.BnoB1ions].Count(b => b > 0));
            Assert.AreEqual(1, newPsm.MatchedIonIntensitiesDict[ProductType.Y].Count(b => b > 0));
            // If localizing, three match!!!
            Assert.IsTrue(newPsm.LocalizedScores[1] > 3 && newPsm.LocalizedScores[1] < 4);
        }
Ejemplo n.º 11
0
        public static void TestPsmHeader()
        {
            CommonParameters            commonParameters = new CommonParameters();
            PeptideWithSetModifications pepWithSetMods   = new Protein(
                "MQQQQQQQ",
                "accession1",
                "org",
                new List <Tuple <string, string> > {
                new Tuple <string, string>("geneNameType", "geneName")
            },
                new Dictionary <int, List <Modification> > {
                { 2, new List <Modification> {
                      new Modification("mod", "mod")
                  } }
            },
                name: "name",
                fullName: "fullName",
                sequenceVariations: new List <SequenceVariation> {
                new SequenceVariation(2, "P", "Q", "changed this sequence")
            })
                                                           .Digest(commonParameters.DigestionParams, new List <Modification>(), new List <Modification>()).First();
            MsDataFile myMsDataFile      = new TestDataFile(pepWithSetMods, "quadratic");
            MsDataScan scann             = myMsDataFile.GetOneBasedScan(2);
            Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(scann, 4, 1, null, new CommonParameters());

            var theoreticalIons = new List <Product>();

            pepWithSetMods.Fragment(DissociationType.HCD, FragmentationTerminus.Both, theoreticalIons);
            var matchedIons          = MetaMorpheusEngine.MatchFragmentIons(scan, theoreticalIons, new CommonParameters());
            PeptideSpectralMatch psm = new PeptideSpectralMatch(pepWithSetMods, 1, 2, 3, scan, commonParameters, matchedIons);

            psm.ResolveAllAmbiguities();

            var t            = psm.ToString();
            var tabsepheader = PeptideSpectralMatch.GetTabSeparatedHeader();

            Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t'));

            Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t'));

            Tolerance fragmentTolerance = new PpmTolerance(10);

            new LocalizationEngine(new List <PeptideSpectralMatch> {
                psm
            }, myMsDataFile, new CommonParameters(productMassTolerance: fragmentTolerance), null, new List <string>()).Run();

            Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t'));

            psm.SetFdrValues(6, 6, 6, 6, 6, 0, 0, 0);

            Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t'));
        }
Ejemplo n.º 12
0
        public static void SingleEventArgsTest()
        {
            Protein          parentProteinForMatch = new Protein("MEK", null);
            CommonParameters commonParameters      = new CommonParameters(digestionParams: new DigestionParams(minPeptideLength: 1));
            var fsp = new List <(string fileName, CommonParameters fileSpecificParameters)>();

            fsp.Add(("", commonParameters));
            ModificationMotif.TryGetMotif("E", out ModificationMotif motif);
            List <Modification> variableModifications = new List <Modification> {
                new Modification(_originalId: "21", _target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 21.981943)
            };

            List <PeptideWithSetModifications> allPeptidesWithSetModifications = parentProteinForMatch.Digest(commonParameters.DigestionParams, new List <Modification>(), variableModifications).ToList();

            Assert.AreEqual(4, allPeptidesWithSetModifications.Count());
            PeptideWithSetModifications ps = allPeptidesWithSetModifications.First();

            PeptideWithSetModifications pepWithSetModsForSpectrum = allPeptidesWithSetModifications[1];
            MsDataFile myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> {
                pepWithSetModsForSpectrum
            });
            Tolerance fragmentTolerance = new AbsoluteTolerance(0.01);

            Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(myMsDataFile.GetAllScansList().Last(), pepWithSetModsForSpectrum.MonoisotopicMass.ToMz(1), 1, null, new CommonParameters());

            var theoreticalProducts = new List <Product>();

            ps.Fragment(DissociationType.HCD, FragmentationTerminus.Both, theoreticalProducts);

            var matchedIons             = MetaMorpheusEngine.MatchFragmentIons(scan, theoreticalProducts, new CommonParameters());
            PeptideSpectralMatch newPsm = new PeptideSpectralMatch(ps, 0, 0, 2, scan, commonParameters, matchedIons);

            LocalizationEngine f = new LocalizationEngine(new List <PeptideSpectralMatch> {
                newPsm
            }, myMsDataFile, new CommonParameters(), fsp, new List <string>());

            var singleEngine = new SingleEngineEventArgs(f);

            Assert.That(singleEngine.MyEngine.Equals(f));

            var singleFile = new SingleFileEventArgs("", new List <string>());

            Assert.That(singleFile.WrittenFile.Equals(""));

            var stringList = new StringListEventArgs(new List <string>());
            var rr         = (stringList.StringList.DefaultIfEmpty().First());

            Assert.That(stringList.StringList.DefaultIfEmpty().First() == null);
        }
Ejemplo n.º 13
0
        public static void TestLocalization()
        {
            Protein          parentProteinForMatch = new Protein("MEK", null);
            CommonParameters commonParameters      = new CommonParameters(digestionParams: new DigestionParams(minPeptideLength: 1));
            var fsp = new List <(string fileName, CommonParameters fileSpecificParameters)>();

            fsp.Add(("", commonParameters));
            ModificationMotif.TryGetMotif("E", out ModificationMotif motif);
            List <Modification> variableModifications = new List <Modification> {
                new Modification(_originalId: "21", _target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 21.981943)
            };

            List <PeptideWithSetModifications> allPeptidesWithSetModifications = parentProteinForMatch.Digest(commonParameters.DigestionParams, new List <Modification>(), variableModifications).ToList();

            Assert.AreEqual(4, allPeptidesWithSetModifications.Count());
            PeptideWithSetModifications ps = allPeptidesWithSetModifications.First();

            PeptideWithSetModifications pepWithSetModsForSpectrum = allPeptidesWithSetModifications[1];
            MsDataFile myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> {
                pepWithSetModsForSpectrum
            });
            Tolerance fragmentTolerance = new AbsoluteTolerance(0.01);

            Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(myMsDataFile.GetAllScansList().Last(), pepWithSetModsForSpectrum.MonoisotopicMass.ToMz(1), 1, null, new CommonParameters());

            var theoreticalProducts = new List <Product>();

            ps.Fragment(DissociationType.HCD, FragmentationTerminus.Both, theoreticalProducts);
            var matchedIons             = MetaMorpheusEngine.MatchFragmentIons(scan, theoreticalProducts, new CommonParameters());
            PeptideSpectralMatch newPsm = new PeptideSpectralMatch(ps, 0, 0, 2, scan, commonParameters, matchedIons);

            newPsm.ResolveAllAmbiguities();

            LocalizationEngine f = new LocalizationEngine(new List <PeptideSpectralMatch> {
                newPsm
            }, myMsDataFile, commonParameters, fsp, new List <string>());

            f.Run();

            // single peak matches
            Assert.AreEqual(1, newPsm.MatchedFragmentIons.Where(p => p.NeutralTheoreticalProduct.ProductType == ProductType.b).Count());//including b1 now
            Assert.AreEqual(1, newPsm.MatchedFragmentIons.Where(p => p.NeutralTheoreticalProduct.ProductType == ProductType.y).Count());

            // when localizing, three peaks match
            Assert.IsTrue(newPsm.LocalizedScores[1] > 4 && newPsm.LocalizedScores[1] < 5);//we have another matched ion
        }
Ejemplo n.º 14
0
        public static void TestSilacWhenProteinIsMissing()
        {
            //make heavy residue and add to search task
            Residue heavyLysine = new Residue("a", 'a', "a", Chemistry.ChemicalFormula.ParseFormula("C{13}6H12N{15}2O"), ModificationSites.All); //+8 lysine
            Residue lightLysine = Residue.GetResidue('K');

            SearchTask task = new SearchTask
            {
                SearchParameters = new SearchParameters
                {
                    SilacLabels = new List <SilacLabel> {
                        new SilacLabel(lightLysine.Letter, heavyLysine.Letter, heavyLysine.ThisChemicalFormula.Formula, heavyLysine.MonoisotopicMass - lightLysine.MonoisotopicMass)
                    },
                    NoOneHitWonders = true
                                      //The NoOneHitWonders=true doesn't really seem like a SILAC test, but we're testing that there's no crash if a quantified peptide's proteinGroup isn't quantified
                                      //This happens if somebody messed with parsimony (picked TDS) or from requiring two peptides per protein (and we're only finding one). We're testing the second case here.
                }
            };

            PeptideWithSetModifications lightPeptide = new PeptideWithSetModifications("PEPTIDEK", new Dictionary <string, Modification>());

            List <double> massDifferences = new List <double> {
                heavyLysine.MonoisotopicMass - lightLysine.MonoisotopicMass
            };
            MsDataFile myMsDataFile1 = new TestDataFile(lightPeptide, massDifferences);
            string     mzmlName      = @"silac.mzML";

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

            string  xmlName    = "SilacDb.xml";
            Protein theProtein = new Protein("PEPTIDEK", "accession1");

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

            string outputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestSilac");

            Directory.CreateDirectory(outputFolder);
            var theStringResult = task.RunTask(outputFolder, new List <DbForTask> {
                new DbForTask(xmlName, false)
            }, new List <string> {
                mzmlName
            }, "taskId1").ToString();
        }
Ejemplo n.º 15
0
        public static void TestCompIons_MatchIons()
        {
            TestDataFile t = new TestDataFile(0.0001);
            Tolerance    productMassTolerance = new AbsoluteTolerance(0.01);
            double       precursorMass        = 402.18629720155;

            //The below theoretical does not accurately represent B-Y ions
            double[]      sorted_theoretical_product_masses_for_this_peptide = new double[] { 50, 60, 70, 147.0764 - Constants.ProtonMass, 200, 215, 230, 245, precursorMass + Constants.ProtonMass - 147.0764, 258.127, 275.1350, precursorMass + (2 * Constants.ProtonMass) - 70, precursorMass + (2 * Constants.ProtonMass) - 60, precursorMass + (2 * Constants.ProtonMass) - 50 }; //{ 50, 60, 70, 147.0764, 257.1244, 258.127, 275.1350 }
            List <double> matchedIonMassesT    = new List <double>();
            List <double> matchedDaErrorT      = new List <double>();
            List <double> matchedPpmErrorT     = new List <double>();
            List <double> matchedIonIntensityT = new List <double>();
            List <double> matchedIonMassesF    = new List <double>();
            List <double> matchedDaErrorF      = new List <double>();
            List <double> matchedPpmErrorF     = new List <double>();
            List <double> matchedIonIntensityF = new List <double>();

            List <int> matchedIonSeriesT = new List <int>();
            List <int> matchedIonSeriesF = new List <int>();

            //MetaMorpheusEngine.MatchIons(t.GetOneBasedScan(2), productMassTolerance, sorted_theoretical_product_masses_for_this_peptide, matchedIonSeriesT, matchedIonMassesT, matchedDaErrorT, matchedPpmErrorT, matchedIonIntensityT, precursorMass, ProductType.B, true);
            //MetaMorpheusEngine.MatchIons(t.GetOneBasedScan(2), productMassTolerance, sorted_theoretical_product_masses_for_this_peptide, matchedIonSeriesF, matchedIonMassesF, matchedDaErrorF, matchedPpmErrorF, matchedIonIntensityF, precursorMass, ProductType.B, false);

            //Test the number of series is doubled
            Assert.IsTrue(matchedIonSeriesT.Count == matchedIonSeriesF.Count * 2);
            //Test the number of ions is doubled
            Assert.IsTrue(matchedIonMassesT.Count == matchedIonMassesF.Count * 2);
            //Test the number of da errors is doubled
            Assert.IsTrue(matchedDaErrorT.Count == matchedDaErrorF.Count * 2);
            //test the number of ppm errors is doubled
            Assert.IsTrue(matchedPpmErrorT.Count == matchedPpmErrorF.Count * 2);
            //test the number of the intensity values is doubled
            Assert.IsTrue(matchedIonIntensityT.Count == matchedIonIntensityF.Count * 2);
            foreach (double d in matchedDaErrorF)
            {
                Assert.IsTrue(d <= 0.01);
            }

            foreach (double d in matchedDaErrorT)
            {
                Assert.IsTrue(d <= 0.01);
            }
        }
Ejemplo n.º 16
0
        public void MoreTests(string filename, DecoyType decoyType = DecoyType.None)
        {
            string xmlName  = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", filename);
            var    proteins = ProteinDbLoader.LoadProteinXML(xmlName, decoyType == DecoyType.None, decoyType, null, false, null, out var un);
            var    peps     = proteins[1].Digest(CommonParameters.DigestionParams, null, null).ToList();
            PeptideWithSetModifications pep = peps[peps.Count - 2];

            string     mzmlName     = $"ajgdiv{filename}{decoyType.ToString()}.mzML";
            MsDataFile myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> {
                pep
            });

            IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile, mzmlName, false);
            string outputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, $"TestSearchWithVariants{filename}{decoyType.ToString()}");

            Directory.CreateDirectory(outputFolder);

            SearchTask st = new SearchTask
            {
                SearchParameters = new SearchParameters
                {
                    DoParsimony             = true,
                    DecoyType               = decoyType,
                    SearchTarget            = decoyType == DecoyType.None,
                    ModPeptidesAreDifferent = false
                },
                CommonParameters = new CommonParameters(scoreCutoff: 1, digestionParams: new DigestionParams(minPeptideLength: 2), precursorMassTolerance: new PpmTolerance(20)),
            };

            st.RunTask(outputFolder, new List <DbForTask> {
                new DbForTask(xmlName, false)
            }, new List <string> {
                mzmlName
            }, "");
            var psms = File.ReadAllLines(Path.Combine(outputFolder, "AllPSMs.psmtsv"));

            //Assert.IsTrue(psms.Any(line => line.Contains($"\t{variantPsmShort}\t" + (containsVariant ? variantPsmShort : "\t"))));

            Directory.Delete(outputFolder, true);
            File.Delete(mzmlName);
            //Directory.Delete(Path.Combine(TestContext.CurrentContext.TestDirectory, @"Task Settings"), true);
        }
Ejemplo n.º 17
0
        public static void TestCompIons_MatchIonsScore()
        {
            TestDataFile t = new TestDataFile();
            Tolerance    productMassTolerance = new AbsoluteTolerance(0.01);
            double       precursorMass        = 300;

            //The below theoretical does not accurately represent B-Y ions
            double[]           sorted_theoretical_product_masses_for_this_peptide = new double[] { precursorMass + (2 * Constants.protonMass) - 275.1350, precursorMass + (2 * Constants.protonMass) - 258.127, precursorMass + (2 * Constants.protonMass) - 257.1244, 50, 60, 70, 147.0764, precursorMass + (2 * Constants.protonMass) - 147.0764, precursorMass + (2 * Constants.protonMass) - 70, precursorMass + (2 * Constants.protonMass) - 60, precursorMass + (2 * Constants.protonMass) - 50, 257.1244, 258.127, 275.1350 }; //{ 50, 60, 70, 147.0764, 257.1244, 258.127, 275.1350 }
            List <ProductType> lp = new List <ProductType> {
                ProductType.B, ProductType.Y
            };
            double scoreT = MetaMorpheusEngine.CalculatePeptideScore(t.GetOneBasedScan(2), productMassTolerance, sorted_theoretical_product_masses_for_this_peptide, precursorMass, new List <DissociationType> {
                DissociationType.HCD
            }, true, 0);
            double scoreF = MetaMorpheusEngine.CalculatePeptideScore(t.GetOneBasedScan(2), productMassTolerance, sorted_theoretical_product_masses_for_this_peptide, precursorMass, new List <DissociationType> {
                DissociationType.HCD
            }, false, 0);

            Assert.IsTrue(scoreT == scoreF * 2 && scoreT > scoreF + 1);
        }
Ejemplo n.º 18
0
        public static void TestPsmHeader()
        {
            DigestionParams             digestionParams = new DigestionParams();
            PeptideWithSetModifications pepWithSetMods  = new Protein("MQQQQQQQ", "accession1").Digest(digestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).First();
            IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile = new TestDataFile(pepWithSetMods, "quadratic");
            IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >   scann        = myMsDataFile.GetOneBasedScan(2) as IMsDataScanWithPrecursor <IMzSpectrum <IMzPeak> >;
            Ms2ScanWithSpecificMass scan = new Ms2ScanWithSpecificMass(scann, 4, 1, null);
            PeptideSpectralMatch    psm  = new PeptideSpectralMatch(pepWithSetMods.CompactPeptide(TerminusType.None), 1, 2, 3, scan);

            var t            = psm.ToString();
            var tabsepheader = PeptideSpectralMatch.GetTabSeparatedHeader();

            Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t'));

            Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> > matching = new Dictionary <CompactPeptideBase, HashSet <PeptideWithSetModifications> >
            {
                { pepWithSetMods.CompactPeptide(TerminusType.None), new HashSet <PeptideWithSetModifications> {
                      pepWithSetMods
                  } }
            };

            psm.MatchToProteinLinkedPeptides(matching);

            Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t'));

            Tolerance          fragmentTolerance = new PpmTolerance(10);
            List <ProductType> lp = new List <ProductType> {
                ProductType.B
            };

            new LocalizationEngine(new List <PeptideSpectralMatch> {
                psm
            }, lp, myMsDataFile, fragmentTolerance, new List <string>(), false).Run();

            Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t'));

            psm.SetFdrValues(6, 6, 6, 6, 6, 6, 0, 0, 0, false);

            Assert.AreEqual(psm.ToString().Count(f => f == '\t'), PeptideSpectralMatch.GetTabSeparatedHeader().Count(f => f == '\t'));
        }
Ejemplo n.º 19
0
        public static void FdrTestMethod()
        {
            MassDiffAcceptor searchModes = new DotMassDiffAcceptor(null, new List <double> {
                0, 1.0029
            }, new PpmTolerance(5));
            List <string> nestedIds = new List <string>();

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

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

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

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

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

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

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

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

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

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

            fdr.Run();

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

            Assert.AreEqual(0, newPsms[0].FdrInfo.CumulativeDecoy);
            Assert.AreEqual(1, newPsms[0].FdrInfo.CumulativeTarget);
            Assert.AreEqual(0, newPsms[1].FdrInfo.CumulativeDecoy);
            Assert.AreEqual(2, newPsms[1].FdrInfo.CumulativeTarget);
            Assert.AreEqual(0, newPsms[2].FdrInfo.CumulativeDecoy);
            Assert.AreEqual(3, newPsms[2].FdrInfo.CumulativeTarget);
        }
Ejemplo n.º 20
0
        public static void TestIndividualFileOutput()
        {
            string subFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"IndividualOutputTest");

            Directory.CreateDirectory(subFolder);
            string     outputFolder   = Path.Combine(subFolder, "Results");
            SearchTask allowFilesTask = new SearchTask();

            allowFilesTask.SearchParameters.WriteIndividualFiles    = true;
            allowFilesTask.SearchParameters.CompressIndividualFiles = false;

            SearchTask compressFilesTask = new SearchTask();

            compressFilesTask.SearchParameters.WriteIndividualFiles    = true;
            compressFilesTask.SearchParameters.CompressIndividualFiles = true;

            SearchTask noFilesTask = new SearchTask();

            noFilesTask.SearchParameters.WriteIndividualFiles = false;

            PeptideWithSetModifications       pwsm  = new PeptideWithSetModifications("AAFNSGK", null);
            List <(string, MetaMorpheusTask)> tasks = new List <(string, MetaMorpheusTask)> {
                ("allowFiles", allowFilesTask), ("compressFiles", compressFilesTask), ("noFiles", noFilesTask)
            };
            DbForTask db = new DbForTask(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData", "gapdh.fasta"), false);

            TestDataFile datafile = new TestDataFile(pwsm);
            string       pathOne  = Path.Combine(subFolder, "fileOne.mzml");
            string       pathTwo  = Path.Combine(subFolder, "fileTwo.mzml");

            MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(datafile, pathOne, false);
            MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(datafile, pathTwo, false);

            new EverythingRunnerEngine(tasks, new List <string> {
                pathOne, pathTwo
            }, new List <DbForTask> {
                db
            }, outputFolder).Run();

            //check that the first task wrote everything fine
            HashSet <string> expectedFiles = new HashSet <string>
            {
                ".mzID",
                "_Peptides.psmtsv",
                "_ProteinGroups.tsv",
                "_PSMs.psmtsv",
                "_PSMsFormattedForPercolator.tab",
                "_QuantifiedPeaks.tsv"
            };
            HashSet <string> writtenFiles = new HashSet <string>(Directory.GetFiles(Path.Combine(outputFolder, "allowFiles", "Individual File Results")).Select(v => Path.GetFileName(v).Substring(7)));

            //check they're the same
            Assert.IsTrue(expectedFiles.Except(writtenFiles).Count() == 0);

            //check the second one is compressed and contains all the information
            writtenFiles = new HashSet <string>(Directory.GetFiles(Path.Combine(outputFolder, "compressFiles")).Select(v => Path.GetFileName(v)));
            //check the zip exists
            Assert.IsTrue(writtenFiles.Contains("Individual File Results.zip"));
            //check the original folder does not exist
            string[] subfolders = Directory.GetDirectories(Path.Combine(outputFolder, "compressFiles"));
            Assert.IsTrue(subfolders.Length == 0);
            ZipFile.ExtractToDirectory(Path.Combine(outputFolder, "compressFiles", "Individual File Results.zip"), Path.Combine(outputFolder, "compressFiles", "Individual File Results"));
            //read the extracted files
            writtenFiles = new HashSet <string>(Directory.GetFiles(Path.Combine(outputFolder, "compressFiles", "Individual File Results")).Select(v => Path.GetFileName(v).Substring(7)));
            //check they're the same
            Assert.IsTrue(expectedFiles.Except(writtenFiles).Count() == 0);

            //check the last one to make sure nothing was written except for the mzID files
            writtenFiles = new HashSet <string>(Directory.GetFiles(Path.Combine(outputFolder, "noFiles", "Individual File Results")).Select(v => Path.GetFileName(v).Substring(7)));
            Assert.IsTrue(writtenFiles.Count == 1);
            Assert.IsTrue(writtenFiles.Contains(".mzID"));

            Directory.Delete(outputFolder, true);

            //Do a check that we don't crash if there's only one file but somebody tries to zip the individual file results
            SearchTask weirdTask = new SearchTask();

            weirdTask.SearchParameters.CompressIndividualFiles = true;
            weirdTask.SearchParameters.WriteMzId = false;
            new EverythingRunnerEngine(new List <(string, MetaMorpheusTask)> {
                ("weird", weirdTask)
            }, new List <string> {
Ejemplo n.º 21
0
        public static void TestCompIons_ModernSearch()
        {
            var myMsDataFile              = new TestDataFile();
            var variableModifications     = new List <Modification>();
            var fixedModifications        = new List <Modification>();
            var localizeableModifications = new List <Modification>();
            Dictionary <Modification, ushort> modsDictionary = new Dictionary <Modification, ushort>();

            foreach (var mod in fixedModifications)
            {
                modsDictionary.Add(mod, 0);
            }

            int ii = 1;

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

            var proteinList = new List <Protein> {
                new Protein("MNNNKQQQ", null)
            };

            SearchParameters SearchParameters = new SearchParameters
            {
                MassDiffAcceptorType = MassDiffAcceptorType.Exact,
                SearchTarget         = true,
            };
            List <DigestionMotif> motifs = new List <DigestionMotif> {
                new DigestionMotif("K", null, 1, null)
            };
            Protease protease = new Protease("singleN4", CleavageSpecificity.Full, null, null, motifs);

            ProteaseDictionary.Dictionary.Add(protease.Name, protease);
            CommonParameters CommonParameters = new CommonParameters(digestionParams: new DigestionParams(protease: protease.Name, minPeptideLength: 1), scoreCutoff: 1);
            var fsp = new List <(string fileName, CommonParameters fileSpecificParameters)>();

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

            CommonParameters withCompIons = new CommonParameters(digestionParams: new DigestionParams(protease: protease.Name, minPeptideLength: 1), scoreCutoff: 1, addCompIons: true);
            var fspComp = new List <(string fileName, CommonParameters fileSpecificParameters)>();

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

            var indexEngine = new IndexingEngine(proteinList, variableModifications, fixedModifications, null, null, null,
                                                 1, DecoyType.Reverse, CommonParameters, fsp, SearchParameters.MaxFragmentSize, false, new List <FileInfo>(), TargetContaminantAmbiguity.RemoveContaminant, new List <string>());

            var indexResults = (IndexingResults)indexEngine.Run();

            Tolerance DeconvolutionMassTolerance = new PpmTolerance(5);

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

            MassDiffAcceptor massDiffAcceptor = SearchTask.GetMassDiffAcceptor(CommonParameters.PrecursorMassTolerance, SearchParameters.MassDiffAcceptorType, SearchParameters.CustomMdac);

            // without complementary ions
            PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ModernSearchEngine(allPsmsArray, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, CommonParameters, fsp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List <string>()).Run();

            // with complementary ions
            PeptideSpectralMatch[] allPsmsArray2 = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ModernSearchEngine(allPsmsArray2, listOfSortedms2Scans, indexResults.PeptideIndex, indexResults.FragmentIndex, 0, withCompIons, fspComp, massDiffAcceptor, SearchParameters.MaximumMassThatFragmentIonScoreIsDoubled, new List <string>()).Run();

            // Single search mode
            Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length);

            // Single ms2 scan
            Assert.AreEqual(allPsmsArray.Length, allPsmsArray2.Length);
            Assert.That(allPsmsArray[0] != null);
            Assert.That(allPsmsArray2[0] != null);

            Assert.IsTrue(allPsmsArray2[0].Score > 1);

            Assert.AreEqual(allPsmsArray[0].ScanNumber, allPsmsArray2[0].ScanNumber);

            Assert.IsTrue(allPsmsArray2[0].Score <= allPsmsArray[0].Score * 2 && allPsmsArray2[0].Score > allPsmsArray[0].Score + 3);
        }
Ejemplo n.º 22
0
        public static void TestProteinSplitAcrossFiles()
        {
            SearchTask st = new SearchTask()
            {
                CommonParameters = new CommonParameters(
                    scoreCutoff: 1,
                    digestionParams: new DigestionParams(
                        maxMissedCleavages: 0,
                        minPeptideLength: 5,
                        initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain)),

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

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

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

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

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

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

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

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

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

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

            Directory.CreateDirectory(output_folder);

            st.RunTask(
                output_folder,
                new List <DbForTask> {
                new DbForTask(proteinDbFilePath, false)
            },
                new List <string> {
                mzmlFilePath1, mzmlFilePath2,
            },
                null);
            Directory.Delete(output_folder, true);
            File.Delete(proteinDbFilePath);
            File.Delete(mzmlFilePath1);
            File.Delete(mzmlFilePath2);
            Directory.Delete(Path.Combine(TestContext.CurrentContext.TestDirectory, @"Task Settings"), true);
        }
Ejemplo n.º 23
0
        public static void TestBinGeneration()
        {
            SearchTask st = new SearchTask
            {
                CommonParameters = new CommonParameters(scoreCutoff: 1, digestionParams: new DigestionParams(minPeptideLength: 5, initiatorMethionineBehavior: InitiatorMethionineBehavior.Retain)),

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

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

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

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

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

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

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

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

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

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

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

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

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

            Assert.AreEqual(3, File.ReadLines(Path.Combine(output_folder, @"MassDifferenceHistogram.tsv")).Count());
            Directory.Delete(output_folder, true);
            File.Delete(proteinDbFilePath);
            File.Delete(mzmlFilePath);
            Directory.Delete(Path.Combine(TestContext.CurrentContext.TestDirectory, @"Task Settings"), true);
        }
Ejemplo n.º 24
0
        public static void TestMatchIonsOfAllChargesBottomUp()
        {
            CommonParameters CommonParameters = new CommonParameters();

            MetaMorpheusTask.DetermineAnalyteType(CommonParameters);

            var variableModifications = new List <Modification>();
            var fixedModifications    = new List <Modification>();

            var proteinList = new List <Protein>
            {
                new Protein("AAAHSSLK", ""), new Protein("RQPAQPR", ""), new Protein("EKAEAEAEK", "")
            };
            var myMsDataFile = Mzml.LoadAllStaticData(Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SmallCalibratible_Yeast.mzML"));


            var searchMode = new SinglePpmAroundZeroSearchMode(5);

            Tolerance DeconvolutionMassTolerance = new PpmTolerance(5);

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

            //search by new method of looking for all charges
            PeptideSpectralMatch[] allPsmsArray = new PeptideSpectralMatch[listOfSortedms2Scans.Length];

            new ClassicSearchEngine(allPsmsArray, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null,
                                    proteinList, searchMode, CommonParameters, null, null, new List <string>(), true).Run();
            var psm = allPsmsArray.Where(p => p != null).ToList();

            Assert.That(psm[1].MatchedFragmentIons.Count == 14);
            //there are ions with same product type and same fragment number but different charges
            Assert.That(psm[1].MatchedFragmentIons[8].NeutralTheoreticalProduct.ProductType == psm[1].MatchedFragmentIons[9].NeutralTheoreticalProduct.ProductType &&
                        psm[1].MatchedFragmentIons[8].NeutralTheoreticalProduct.FragmentNumber == psm[1].MatchedFragmentIons[9].NeutralTheoreticalProduct.FragmentNumber &&
                        psm[1].MatchedFragmentIons[8].Charge != psm[1].MatchedFragmentIons[9].Charge);
            Assert.That(psm[2].MatchedFragmentIons.Count == 14);
            Assert.That(psm[4].MatchedFragmentIons.Count == 16);

            //search by old method of looking for only one charge
            PeptideSpectralMatch[] allPsmsArray_oneCharge = new PeptideSpectralMatch[listOfSortedms2Scans.Length];
            new ClassicSearchEngine(allPsmsArray_oneCharge, listOfSortedms2Scans, variableModifications, fixedModifications, null, null, null,
                                    proteinList, searchMode, CommonParameters, null, null, new List <string>(), false).Run();
            var psm_oneCharge = allPsmsArray_oneCharge.Where(p => p != null).ToList();

            //compare 2 scores , they should have same integer part but new search has a little higher score than old search
            Assert.That(psm[1].Score > psm_oneCharge[1].Score);
            Assert.AreEqual(Math.Truncate(psm[1].Score), 12);
            Assert.AreEqual(Math.Truncate(psm_oneCharge[1].Score), 12);

            //compare 2 results and evaluate the different matched ions
            var peptideTheorProducts = new List <Product>();

            Assert.That(psm_oneCharge[1].MatchedFragmentIons.Count == 12);
            var differences = psm[1].MatchedFragmentIons.Except(psm_oneCharge[1].MatchedFragmentIons);

            psm[1].BestMatchingPeptides.First().Peptide.Fragment(CommonParameters.DissociationType, CommonParameters.DigestionParams.FragmentationTerminus, peptideTheorProducts);
            foreach (var ion in differences)
            {
                foreach (var product in peptideTheorProducts)
                {
                    if (product.Annotation.ToString().Equals(ion.NeutralTheoreticalProduct.Annotation.ToString()))
                    {
                        //to see if the different matched ions are qualified
                        Assert.That(CommonParameters.ProductMassTolerance.Within(ion.Mz.ToMass(ion.Charge), product.NeutralMass));
                    }
                }
            }

            //test specific condition: unknown fragment mass; this only happens rarely for sequences with unknown amino acids
            var myMsDataFile1          = new TestDataFile();
            var variableModifications1 = new List <Modification>();
            var fixedModifications1    = new List <Modification>();
            var proteinList1           = new List <Protein> {
                new Protein("QXQ", null)
            };
            var productMassTolerance = new AbsoluteTolerance(0.01);
            var searchModes          = new OpenSearchMode();

            Tolerance DeconvolutionMassTolerance1 = new PpmTolerance(5);

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

            List <DigestionMotif> motifs = new List <DigestionMotif> {
                new DigestionMotif("K", null, 1, null)
            };
            Protease protease = new Protease("Custom Protease3", CleavageSpecificity.Full, null, null, motifs);

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

            CommonParameters CommonParameters1 = new CommonParameters(
                digestionParams: new DigestionParams(protease: protease.Name, maxMissedCleavages: 0, minPeptideLength: 1),
                scoreCutoff: 1,
                addCompIons: false);
            var fsp = new List <(string fileName, CommonParameters fileSpecificParameters)>();

            fsp.Add(("", CommonParameters));
            PeptideSpectralMatch[] allPsmsArray1 = new PeptideSpectralMatch[listOfSortedms2Scans.Length];

            bool writeSpectralLibrary = true;

            new ClassicSearchEngine(allPsmsArray1, listOfSortedms2Scans1, variableModifications1, fixedModifications1, null, null, null,
                                    proteinList1, searchModes, CommonParameters1, fsp, null, new List <string>(), writeSpectralLibrary).Run();

            var psm1 = allPsmsArray1.Where(p => p != null).ToList();

            Assert.AreEqual(psm1.Count, 222);
        }
Ejemplo n.º 25
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.º 26
0
        public static void TestDeltaValues()
        {
            CommonParameters CommonParameters = new CommonParameters(scoreCutoff: 1, useDeltaScore: true, digestionParams: new DigestionParams(minPeptideLength: 5));

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

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

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

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

            var searchModes = new SinglePpmAroundZeroSearchMode(5);

            Tolerance DeconvolutionMassTolerance = new PpmTolerance(5);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            //check no change when using score
            fdrResultsClassic = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArray.ToList(), 1, CommonParameters, new List <string>()).Run());
            fdrResultsModern  = (FdrAnalysisResults)(new FdrAnalysisEngine(allPsmsArrayModern.ToList(), 1, CommonParameters, new List <string>()).Run());
            Assert.IsTrue(fdrResultsClassic.PsmsWithin1PercentFdr == 3);
            Assert.IsTrue(fdrResultsModern.PsmsWithin1PercentFdr == 3);
        }
        public static void SearchWithPeptidesAddedInParsimonyTest()
        {
            // Make sure can run the complete search task when multiple compact peptides may correspond to a single PWSM
            SearchTask st = new SearchTask
            {
                SearchParameters = new SearchParameters
                {
                    DoParsimony             = true,
                    DecoyType               = DecoyType.None,
                    ModPeptidesAreDifferent = false
                },
                CommonParameters = new CommonParameters
                {
                    ScoreCutoff     = 1,
                    DigestionParams = new DigestionParams
                    {
                        MinPeptideLength = 2
                    }
                }
            };

            string xmlName = "andguiaheow.xml";

            #region Generate protein and write to file

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

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

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

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

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

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

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

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

            #endregion Generate protein and write to file

            string mzmlName = @"ajgdiu.mzML";

            #region Generate and write the mzml

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

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

            #endregion Generate and write the mzml

            st.RunTask("",
                       new List <DbForTask> {
                new DbForTask(xmlName, false)
            },
                       new List <string> {
                mzmlName
            }, "");
        }
Ejemplo n.º 28
0
        public static void TestPrunedDatabase()
        {
            //Create Search Task
            SearchTask task1 = new SearchTask
            {
                SearchParameters = new SearchParameters
                {
                    WritePrunedDatabase  = true,
                    SearchTarget         = true,
                    MassDiffAcceptorType = MassDiffAcceptorType.Exact,
                    ModsToWriteSelection = new Dictionary <string, int>
                    {
                        { "ConnorModType", 1 }
                    }
                },
                CommonParameters = new CommonParameters(digestionParams: new DigestionParams(minPeptideLength: 5))
            };

            //add task to task list
            List <(string, MetaMorpheusTask)> taskList = new List <(string, MetaMorpheusTask)>
            {
                ("task1", task1)
            };

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

            var connorMod = new Modification(_originalId: "ConnorMod on P", _modificationType: "ConnorModType", _target: motif, _locationRestriction: "Anywhere.", _monoisotopicMass: 10);

            GlobalVariables.AddMods(new List <Modification>
            {
                connorMod
            }, false);

            //create modification lists
            List <Modification> variableModifications = GlobalVariables.AllModsKnown.OfType <Modification>()
                                                        .Where(b => task1.CommonParameters.ListOfModsVariable.Contains((b.ModificationType, b.IdWithMotif))).ToList();

            //add modification to Protein object
            var          dictHere  = new Dictionary <int, List <Modification> >();
            Modification modToAdd  = connorMod;
            Modification modToAdd2 = connorMod;

            dictHere.Add(1, new List <Modification> {
                modToAdd
            });
            dictHere.Add(3, new List <Modification> {
                modToAdd2
            });

            //protein Creation (One with mod and one without)
            Protein TestProteinWithMod = new Protein("PEPTID", "accession1", "organism", new List <Tuple <string, string> >(), dictHere);

            //First Write XML Database
            string xmlName = "okkk.xml";

            //Add Mod to list and write XML input database
            Dictionary <string, HashSet <Tuple <int, Modification> > > modList = new Dictionary <string, HashSet <Tuple <int, Modification> > >();
            var Hash = new HashSet <Tuple <int, Modification> >
            {
                new Tuple <int, Modification>(3, modToAdd)
            };

            modList.Add("test", Hash);
            ProteinDbWriter.WriteXmlDatabase(modList, new List <Protein> {
                TestProteinWithMod
            }, xmlName);

            //now write MZML file
            var protein = ProteinDbLoader.LoadProteinXML(xmlName, true,
                                                         DecoyType.Reverse, new List <Modification>(), false, new List <string>(), out Dictionary <string, Modification> ok);

            //Dictionary 'ok' contains unknown modifications. There are no unknown modifications in this test.
            Assert.AreEqual(0, ok.Count);
            //One protein is read from the .xml database and one decoy is created. Therefore, the list of proteins contains 2 entries.
            Assert.AreEqual(2, protein.Count);
            //The original database had two localized mods on the protein. Therefore. both protein and decoy should have two mods.
            Assert.AreEqual(2, protein[0].OneBasedPossibleLocalizedModifications.Count);
            List <int> foundResidueIndicies   = protein[0].OneBasedPossibleLocalizedModifications.Select(k => k.Key).ToList();
            List <int> expectedResidueIndices = new List <int>()
            {
                1, 3
            };

            Assert.That(foundResidueIndicies, Is.EquivalentTo(expectedResidueIndices));
            Assert.AreEqual(2, protein[1].OneBasedPossibleLocalizedModifications.Count);
            foundResidueIndicies   = protein[1].OneBasedPossibleLocalizedModifications.Select(k => k.Key).ToList();
            expectedResidueIndices = new List <int>()
            {
                4, 6
            };                                                 //originally modified residues are now at the end in the decoy
            Assert.That(foundResidueIndicies, Is.EquivalentTo(expectedResidueIndices));

            var thisOk = ok;                                                      //for debugging
            var commonParamsAtThisPoint = task1.CommonParameters.DigestionParams; //for debugging

            var digestedList = protein[0].Digest(task1.CommonParameters.DigestionParams, new List <Modification> {
            },
                                                 variableModifications).ToList();

            Assert.AreEqual(4, digestedList.Count);

            //Set Peptide with 1 mod at position 3
            PeptideWithSetModifications pepWithSetMods1 = digestedList[1];

            //Finally Write MZML file
            Assert.AreEqual("PEP[ConnorModType:ConnorMod on P]TID", pepWithSetMods1.FullSequence);//this might be base sequence
            MsDataFile myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> {
                pepWithSetMods1
            });
            string mzmlName = @"hello.mzML";

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

            //run!
            string outputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestPrunedDatabase");
            var    engine       = new EverythingRunnerEngine(taskList, new List <string> {
                mzmlName
            },
                                                             new List <DbForTask> {
                new DbForTask(xmlName, false)
            }, outputFolder);

            engine.Run();

            string final = Path.Combine(MySetUpClass.outputFolder, "task1", "okkkpruned.xml");

            var proteins = ProteinDbLoader.LoadProteinXML(final, true, DecoyType.Reverse, new List <Modification>(), false, new List <string>(), out ok);

            //check length
            Assert.AreEqual(1, proteins[0].OneBasedPossibleLocalizedModifications.Count);
            //check location (key)
            Assert.AreEqual(true, proteins[0].OneBasedPossibleLocalizedModifications.ContainsKey(3));
            List <Modification> listOfMods = proteins[0].OneBasedPossibleLocalizedModifications[3];

            //check Type, count, ID
            Assert.AreEqual(listOfMods[0].ModificationType, "ConnorModType");
            Assert.AreEqual(listOfMods[0].IdWithMotif, "ConnorMod on P");
            Assert.AreEqual(listOfMods.Count, 1);
            Directory.Delete(outputFolder, true);
            File.Delete(xmlName);
            File.Delete(mzmlName);
        }
Ejemplo n.º 29
0
        public static void TestAnalysisEngineTests()
        {
            List <DigestionMotif> motifs = new List <DigestionMotif> {
                new DigestionMotif("K", null, 1, null)
            };
            Protease protease = new Protease("Custom Protease5", CleavageSpecificity.Full, null, null, motifs);

            ProteaseDictionary.Dictionary.Add(protease.Name, protease);
            CommonParameters CommonParameters = new CommonParameters(
                digestionParams: new DigestionParams(
                    protease: protease.Name,
                    maxMissedCleavages: 0,
                    minPeptideLength: 1,
                    maxModificationIsoforms: 1042),
                scoreCutoff: 1,
                productMassTolerance: new PpmTolerance(10));
            var fsp = new List <(string fileName, CommonParameters fileSpecificParameters)>();

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

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

            Dictionary <Modification, ushort> modsDictionary = new Dictionary <Modification, 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
            };
            PeptideWithSetModifications compactPeptide1 = value1.First();

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

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

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

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


            Ms2ScanWithSpecificMass scanA = new Ms2ScanWithSpecificMass(new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, 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), 1, 1, null, new CommonParameters());
            Ms2ScanWithSpecificMass scanB = new Ms2ScanWithSpecificMass(new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 3, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=2", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 1, null), 2 + 132.040, 1, null, new CommonParameters());
            Ms2ScanWithSpecificMass scanC = new Ms2ScanWithSpecificMass(new MsDataScan(new MzSpectrum(new double[] { 1 }, new double[] { 1 }, false), 4, 1, true, Polarity.Positive, double.NaN, null, null, MZAnalyzerType.Orbitrap, double.NaN, null, null, "scan=3", double.NaN, null, null, double.NaN, null, DissociationType.AnyActivationType, 1, null), 3, 1, null, new CommonParameters());

            PeptideSpectralMatch matchA = new PeptideSpectralMatch(compactPeptide1, 0, 0, 0, scanA, CommonParameters, new List <MatchedFragmentIon>());
            PeptideSpectralMatch matchB = new PeptideSpectralMatch(compactPeptide2, 0, 0, 0, scanB, CommonParameters, new List <MatchedFragmentIon>());
            PeptideSpectralMatch matchC = new PeptideSpectralMatch(compactPeptide3, 0, 0, 0, scanC, CommonParameters, new List <MatchedFragmentIon>());

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

            MsDataFile 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) => {; };

            Tolerance DeconvolutionMassTolerance = new PpmTolerance(5);

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

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

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

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

            string xmlName = "andguiaheow.xml";

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

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

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

            // Alanine = Glycine + CH2

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

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

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

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

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

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

            string mzmlName = @"ajgdiu.mzML";

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

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

            Directory.CreateDirectory(outputFolder);

            st.RunTask(outputFolder,
                       new List <DbForTask> {
                new DbForTask(xmlName, false)
            },
                       new List <string> {
                mzmlName
            }, "");
            Directory.Delete(outputFolder, true);
            File.Delete(mzmlName);
            File.Delete(xmlName);
            Directory.Delete(Path.Combine(TestContext.CurrentContext.TestDirectory, @"Task Settings"), true);
        }