public static void PostSearchNormalizeTest() { SearchTask searchTask = new SearchTask() { SearchParameters = new SearchParameters { Normalize = true }, }; string myFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PrunedDbSpectra.mzml"); string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\DbForPrunedDb.fasta"); string folderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestNormalizationExperDesign"); string experimentalDesignFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\ExperimentalDesign.tsv"); using (StreamWriter output = new StreamWriter(experimentalDesignFile)) { output.WriteLine("FileName\tCondition\tBiorep\tFraction\tTechrep"); output.WriteLine("PrunedDbSpectra.mzml" + "\t" + "condition" + "\t" + "1" + "\t" + "1" + "\t" + "1"); } DbForTask db = new DbForTask(myDatabase, false); // run the task Directory.CreateDirectory(folderPath); searchTask.RunTask(folderPath, new List <DbForTask> { db }, new List <string> { myFile }, "normal"); Directory.Delete(folderPath, true); // delete the exper design and try again. this should skip quantification File.Delete(experimentalDesignFile); // run the task Directory.CreateDirectory(folderPath); searchTask.RunTask(folderPath, new List <DbForTask> { db }, new List <string> { myFile }, "normal"); // PSMs should be present but no quant output Assert.That(!File.Exists(Path.Combine(folderPath, "AllQuantifiedPeptides.tsv"))); Assert.That(File.Exists(Path.Combine(folderPath, "AllPSMs.psmtsv"))); Directory.Delete(folderPath, true); }
public static void ProteinGroupsNoParsimonyTest() { SearchTask searchTask = new SearchTask() { SearchParameters = new SearchParameters { DoParsimony = false }, }; string myFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PrunedDbSpectra.mzml"); string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\DbForPrunedDb.fasta"); string folderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestProteinGroupsNoParsimony"); DbForTask db = new DbForTask(myDatabase, false); Directory.CreateDirectory(folderPath); searchTask.RunTask(folderPath, new List <DbForTask> { db }, new List <string> { myFile }, "normal"); Directory.Delete(folderPath, true); }
public static void PrunedDbWithContaminantsTest() { SearchTask searchTask = new SearchTask() { SearchParameters = new SearchParameters { WritePrunedDatabase = true }, }; string myFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PrunedDbSpectra.mzml"); string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\DbForPrunedDb.fasta"); string folderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestNormalization"); string filePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\ExperimentalDesign.tsv"); // contaminant DB DbForTask db = new DbForTask(myDatabase, true); Directory.CreateDirectory(folderPath); searchTask.RunTask(folderPath, new List <DbForTask> { db }, new List <string> { myFile }, "normal"); Assert.That(File.ReadAllLines(Path.Combine(folderPath, @"DbForPrunedDbproteinPruned.xml")).Length > 0); Assert.That(File.ReadAllLines(Path.Combine(folderPath, @"DbForPrunedDbPruned.xml")).Length > 0); Directory.Delete(folderPath, true); }
public static void TestMetaDrawReadPsmFile() { SearchTask searchTask = new SearchTask(); string myFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PrunedDbSpectra.mzml"); string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\DbForPrunedDb.fasta"); string folderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMetaDrawReadPsmFile"); DbForTask db = new DbForTask(myDatabase, false); Directory.CreateDirectory(folderPath); searchTask.RunTask(folderPath, new List <DbForTask> { db }, new List <string> { myFile }, "metadraw"); string psmFile = Directory.GetFiles(folderPath).First(f => f.Contains("AllPSMs.psmtsv")); List <PsmFromTsv> parsedPsms = PsmTsvReader.ReadTsv(psmFile, out var warnings); Assert.AreEqual(11, parsedPsms.Count); Assert.AreEqual(0, warnings.Count); Directory.Delete(folderPath, true); }
public static void TestPsmFromTsvIonParsing() { string outputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestPsmFromTsvIonParsing"); string proteinDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SpectralLibrarySearch\P16858.fasta"); string spectraFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SpectralLibrarySearch\slicedMouse.raw"); Directory.CreateDirectory(outputFolder); // run search task var searchtask = new SearchTask(); searchtask.RunTask(outputFolder, new List <DbForTask> { new DbForTask(proteinDatabase, false), }, new List <string> { spectraFile }, ""); var psmFile = Path.Combine(outputFolder, @"AllPSMs.psmtsv"); // load results into metadraw var metadrawLogic = new MetaDrawLogic(); metadrawLogic.SpectraFilePaths.Add(spectraFile); metadrawLogic.PsmResultFilePaths.Add(psmFile); var errors = metadrawLogic.LoadFiles(true, true); Assert.That(!errors.Any()); // assert PsmFromTsv matched ion properties var lines = File.ReadAllLines(psmFile); int ind = Array.IndexOf(lines[0].Split('\t'), "Matched Ion Mass-To-Charge Ratios"); var ionStrings = lines[1].Split('\t')[ind].Split(new char[] { ',', ';' }) .Select(p => p.Trim().Replace("[", string.Empty).Replace("]", string.Empty)).ToList(); var parsedIons = metadrawLogic.FilteredListOfPsms[0].MatchedIons; for (int i = 0; i < ionStrings.Count; i++) { var ionString = ionStrings[i]; var parsedIon = parsedIons[i]; var split = ionString.Split(new char[] { '+', ':' }); string ion = split[0]; int charge = int.Parse(split[1]); double mz = double.Parse(split[2]); Assert.That(mz == parsedIon.Mz); Assert.That(mz.ToMass(charge) == parsedIon.NeutralTheoreticalProduct.NeutralMass); Assert.That(charge == parsedIon.Charge); Assert.That(ion == parsedIon.NeutralTheoreticalProduct.ProductType.ToString() + parsedIon.NeutralTheoreticalProduct.FragmentNumber); } // delete output Directory.Delete(outputFolder, true); }
public static void TestMetaDrawLoadingWithWeirdFileNames() { // test loading when the file has a periods, commas, spaces in the name string outputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMetaDrawLoadingWithWeirdFileNames"); string proteinDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\smalldb.fasta"); string spectraFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SmallCalibratible_Yeast.mzML"); string pathWithPeriodInIt = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\S.m,al. lC,al.ib r.at,i ble_Ye.ast.mzML"); File.Copy(spectraFile, pathWithPeriodInIt, true); spectraFile = pathWithPeriodInIt; Directory.CreateDirectory(outputFolder); // run search task var searchtask = new SearchTask(); searchtask.RunTask(outputFolder, new List <DbForTask> { new DbForTask(proteinDatabase, false) }, new List <string> { spectraFile }, ""); var psmFile = Path.Combine(outputFolder, @"AllPSMs.psmtsv"); // load results into metadraw var metadrawLogic = new MetaDrawLogic(); metadrawLogic.PsmResultFilePaths.Add(psmFile); metadrawLogic.SpectraFilePaths.Add(pathWithPeriodInIt); var errors = metadrawLogic.LoadFiles(true, true); Assert.That(!errors.Any()); Assert.That(metadrawLogic.FilteredListOfPsms.First().FileNameWithoutExtension == "S.m,al. lC,al.ib r.at,i ble_Ye.ast"); var plotView = new OxyPlot.Wpf.PlotView(); var canvas = new Canvas(); var parentChildScanPlotsView = new ParentChildScanPlotsView(); // plot PSM metadrawLogic.DisplaySpectrumMatch(plotView, canvas, metadrawLogic.FilteredListOfPsms.First(), parentChildScanPlotsView, out errors); Assert.That(errors == null || !errors.Any()); // export to PDF metadrawLogic.ExportToPdf(plotView, canvas, new List <PsmFromTsv> { metadrawLogic.FilteredListOfPsms.First() }, parentChildScanPlotsView, outputFolder, out errors); Assert.That(!errors.Any()); // clean up resources metadrawLogic.CleanUpResources(); // delete output File.Delete(pathWithPeriodInIt); Directory.Delete(outputFolder, true); }
public static void TestMetaDrawErrors() { string outputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMetaDrawErrors"); string proteinDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\smalldb.fasta"); string spectraFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SmallCalibratible_Yeast.mzML"); Directory.CreateDirectory(outputFolder); // run search task var searchtask = new SearchTask(); searchtask.RunTask(outputFolder, new List <DbForTask> { new DbForTask(proteinDatabase, false) }, new List <string> { spectraFile }, ""); var psmFile = Path.Combine(outputFolder, @"AllPSMs.psmtsv"); // load results into metadraw (skipping spectra file, to produce an error msg) var metadrawLogic = new MetaDrawLogic(); metadrawLogic.PsmResultFilePaths.Add(psmFile); // this should produce an error because an expected spectra file is not present var errors = metadrawLogic.LoadFiles(loadSpectra: true, loadPsms: true); Assert.That(errors.Any()); Assert.That(!metadrawLogic.FilteredListOfPsms.Any()); // this should not produce an error because we said not to load spectra errors = metadrawLogic.LoadFiles(loadSpectra: false, loadPsms: true); Assert.That(!errors.Any()); var psmsFromTsv = PsmTsvReader.ReadTsv(psmFile, out var warnings); var plotView = new OxyPlot.Wpf.PlotView(); var canvas = new Canvas(); var parentChildScanPlotsView = new ParentChildScanPlotsView(); // plotting PSM should produce an error because spectra are not loaded metadrawLogic.DisplaySpectrumMatch(plotView, canvas, psmsFromTsv.First(), parentChildScanPlotsView, out errors); Assert.That(errors.Any()); // export to PDF should produce an error because spectra are not loaded metadrawLogic.ExportToPdf(plotView, canvas, new List <PsmFromTsv> { psmsFromTsv.First() }, parentChildScanPlotsView, outputFolder, out errors); Assert.That(errors.Any()); // clean up resources metadrawLogic.CleanUpResources(); // delete output Directory.Delete(outputFolder, true); }
public static void PostSearchNormalizeTest() { SearchTask searchTask = new SearchTask() { SearchParameters = new SearchParameters { Normalize = true }, }; string myFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\PrunedDbSpectra.mzml"); string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\DbForPrunedDb.fasta"); string folderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestNormalization"); string filePath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\ExperimentalDesign.tsv"); using (StreamWriter output = new StreamWriter(filePath)) { output.WriteLine("FileName\tCondition\tBiorep\tFraction\tTechrep"); output.WriteLine("PrunedDbSpectra" + "\t" + "condition" + "\t" + "1" + "\t" + "1" + "\t" + "1"); } DbForTask db = new DbForTask(myDatabase, false); Directory.CreateDirectory(folderPath); searchTask.RunTask(folderPath, new List <DbForTask> { db }, new List <string> { myFile }, "normal"); File.Delete(filePath); Assert.That(() => searchTask.RunTask(folderPath, new List <DbForTask> { db }, new List <string> { myFile }, "normal"), Throws.TypeOf <MetaMorpheusException>()); Directory.Delete(folderPath, true); }
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(); }
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); }
public static void SpectralLibrarySearchTest() { var testDir = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SpectralLibrarySearch"); var outputDir = Path.Combine(testDir, @"SpectralLibrarySearchTest"); string library1 = Path.Combine(testDir, @"P16858_target.msp"); string library2 = Path.Combine(testDir, @"P16858_decoy.msp"); string fastaDb = Path.Combine(testDir, @"P16858.fasta"); string spectraFile = Path.Combine(testDir, @"slicedMouse.raw"); Directory.CreateDirectory(outputDir); var searchTask = new SearchTask(); searchTask.RunTask(outputDir, new List <DbForTask> { new DbForTask(library1, false), new DbForTask(library2, false), new DbForTask(fastaDb, false) }, new List <string> { spectraFile }, ""); var results = File.ReadAllLines(Path.Combine(outputDir, @"AllPSMs.psmtsv")); var split = results[0].Split('\t'); int ind = Array.IndexOf(split, "Normalized Spectral Angle"); Assert.That(ind >= 0); var spectralAngle = double.Parse(results[1].Split('\t')[ind]); Assert.That(Math.Round(spectralAngle, 2) == 0.82); Directory.Delete(outputDir, true); }
public static void FdrFilteredParsimonyTest() { SearchTask Task1 = new SearchTask { CommonParameters = new CommonParameters ( qValueOutputFilter: 1 ), SearchParameters = new SearchParameters { DoParsimony = true, SearchTarget = true, WritePrunedDatabase = true, SearchType = SearchType.Classic } }; string mzmlName = @"TestData\PrunedDbSpectra.mzml"; string fastaName = @"TestData\DbForPrunedDb.fasta"; var results = Task1.RunTask(Environment.CurrentDirectory, new List <DbForTask>() { new DbForTask(fastaName, false) }, new List <string>() { mzmlName }, "test"); var thisTaskOutputFolder = MySetUpClass.outputFolder; var psms = Path.Combine(thisTaskOutputFolder, "AllPSMs.psmtsv"); Assert.AreEqual(12, File.ReadLines(psms).Count()); var protGroups = Path.Combine(thisTaskOutputFolder, "AllProteinGroups.tsv"); Assert.AreEqual(7, File.ReadLines(protGroups).Count()); }
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); }
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); }
public static void TestProteinPrunedWithModSelectionAndVariants() { var modToWrite = GlobalVariables.AllModsKnown.Where(p => p.ModificationType == "UniProt" && p.Target.ToString() == "T").First(); var modToNotWrite = GlobalVariables.AllModsKnown.Where(p => p.ModificationType == "Common Artifact" && p.Target.ToString() == "X").First(); Dictionary <int, List <Modification> > variantMods = new Dictionary <int, List <Modification> >(); variantMods.Add(1, new List <Modification>() { modToNotWrite }); List <SequenceVariation> variants = new List <SequenceVariation> { new SequenceVariation(4, 4, "V", "T", @"20\t41168825\t.\tT\tC\t14290.77\t.\tANN=C|missense_variant|MODERATE|PLCG1|ENSG00000124181|transcript|ENST00000244007.7|protein_coding|22/33|c.2438T>C|p.Ile813Thr|2635/5285|2438/3876|813/1291||\tGT:AD:DP:GQ:PL\t1/1:1,392:393:99:14319,1142,0", variantMods) }; var protein1 = new Protein("PEPVIDEKPEPT", "1", oneBasedModifications: new Dictionary <int, List <Modification> > { { 1, new List <Modification> { modToNotWrite } }, { 12, new List <Modification> { modToWrite } } }, sequenceVariations: variants); var protein2 = new Protein("PEPIDPEPT", "2", oneBasedModifications: new Dictionary <int, List <Modification> > { { 1, new List <Modification> { modToNotWrite } }, { 9, new List <Modification> { modToWrite } } }); var protein1Variants = protein1.GetVariantProteins(1, 0); string path = @"temp"; var proteinList = new List <Protein> { protein1, protein2 }; proteinList.AddRange(protein1Variants); ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), proteinList, path); Directory.CreateDirectory(Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTestVariant")); Dictionary <string, HashSet <Tuple <int, Modification> > > modList = new Dictionary <string, HashSet <Tuple <int, Modification> > >(); var Hash = new HashSet <Tuple <int, Modification> > { new Tuple <int, Modification>(1, modToWrite), new Tuple <int, Modification>(2, modToNotWrite), }; var db = ProteinDbWriter.WriteXmlDatabase(modList, proteinList, Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTestVariant/fakeDb.xml")); var peptideObserved = protein1Variants.First().Digest(new DigestionParams(minPeptideLength: 1), new List <Modification>(), new List <Modification>()) .Where(p => p.BaseSequence == "PEPT").First(); PostSearchAnalysisParameters testPostTaskParameters = new PostSearchAnalysisParameters(); CommonParameters commonParam = new CommonParameters(useDeltaScore: false); double[,] noiseData = new double[10000, 10000]; noiseData[0, 0] = 1.0; List <Proteomics.Fragmentation.MatchedFragmentIon> matchedFragmentIons = new List <Proteomics.Fragmentation.MatchedFragmentIon>() { }; MzSpectrum spectrum = new MzSpectrum(noiseData); MsDataScan scan = new MsDataScan(spectrum, 1, 1, true, Polarity.Unknown, 2, new MzLibUtil.MzRange(10, 1000), "", MZAnalyzerType.Orbitrap, 10000, null, noiseData, ""); testPostTaskParameters.ProteinList = proteinList; testPostTaskParameters.AllPsms = new List <PeptideSpectralMatch> { new PeptideSpectralMatch(peptideObserved, 0, 20, 1, new Ms2ScanWithSpecificMass(scan, 100, 1, @"", commonParam), commonParam, matchedFragmentIons) }; testPostTaskParameters.SearchParameters = new SearchParameters(); testPostTaskParameters.SearchParameters.WritePrunedDatabase = true; testPostTaskParameters.SearchParameters.DoQuantification = false; testPostTaskParameters.SearchParameters.WriteMzId = false; testPostTaskParameters.DatabaseFilenameList = new List <DbForTask>() { new DbForTask(Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest/fakeDb.xml"), false) }; testPostTaskParameters.OutputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest"); Directory.CreateDirectory(Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest/individual")); testPostTaskParameters.IndividualResultsOutputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest/individual"); int[] stuffForSpectraFile = new int[2]; stuffForSpectraFile[0] = 10; stuffForSpectraFile[1] = 10; Dictionary <string, int[]> numSpectraPerFile = new Dictionary <string, int[]>(); numSpectraPerFile.Add("", stuffForSpectraFile); testPostTaskParameters.NumMs2SpectraPerFile = numSpectraPerFile; MsDataFile myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> { peptideObserved }); string mzmlName = @"newMzml.mzML"; IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile, mzmlName, false); modList.Add("test", Hash); testPostTaskParameters.CurrentRawFileList = new List <string>() { mzmlName }; SearchTask task5 = new SearchTask { SearchParameters = new SearchParameters { WritePrunedDatabase = true, SearchTarget = true, MassDiffAcceptorType = MassDiffAcceptorType.Exact, }, CommonParameters = new CommonParameters() }; var test = task5.RunTask(Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest"), new List <DbForTask>() { new DbForTask(Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest/fakeDb.xml"), false) }, new List <string>() { mzmlName }, "name"); testPostTaskParameters.SearchTaskResults = test; PostSearchAnalysisTask testPostTask = new PostSearchAnalysisTask(); testPostTask.Parameters = testPostTaskParameters; testPostTask.CommonParameters = commonParam; testPostTask.FileSpecificParameters = new List <(string FileName, CommonParameters Parameters)> { ("newMzMl.mzml", commonParam) }; testPostTask.Run(); var proteinsLoaded = ProteinDbLoader.LoadProteinXML(path, true, DecoyType.None, GlobalVariables.AllModsKnown, false, new List <string>(), out var unknownMods); // assert that mods on proteins are the same before/after task is run Assert.AreEqual(protein1Variants.First().Accession, proteinsLoaded.First().Accession); Assert.AreEqual(protein1Variants.First().OneBasedPossibleLocalizedModifications.Count(), proteinsLoaded.First().OneBasedPossibleLocalizedModifications.Count()); Assert.AreEqual(protein2.OneBasedPossibleLocalizedModifications.Count(), proteinsLoaded.ElementAt(1).OneBasedPossibleLocalizedModifications.Count()); // assert that protein pruned DB has correct proteins mods var proteinPruned = ProteinDbLoader.LoadProteinXML(Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest/fakeDbproteinPruned.xml"), true, DecoyType.None, GlobalVariables.AllModsKnown, false, new List <string>(), out var unknownMods1); Assert.That(proteinPruned.Count().Equals(1)); Assert.That(proteinPruned.FirstOrDefault().OneBasedPossibleLocalizedModifications.Count().Equals(1)); // assert that mod-pruned DB has correct proteins and mods var modPruned = ProteinDbLoader.LoadProteinXML(Path.Combine(TestContext.CurrentContext.TestDirectory, @"PrunedDbTest/fakeDbpruned.xml"), true, DecoyType.None, GlobalVariables.AllModsKnown, false, new List <string>(), out var unknownMods2); Assert.That(modPruned.Count().Equals(2)); Assert.That(modPruned.ElementAt(0).OneBasedPossibleLocalizedModifications.Count().Equals(1)); Assert.That(modPruned.ElementAt(1).OneBasedPossibleLocalizedModifications.Count().Equals(1)); }
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); }
public static void TestBinGeneration() { SearchTask st = new SearchTask { CommonParameters = new CommonParameters { ScoreCutoff = 1, DigestionParams = new DigestionParams { InitiatorMethionineBehavior = InitiatorMethionineBehavior.Retain, }, ConserveMemory = false, }, SearchParameters = new SearchParameters { DoHistogramAnalysis = true, MassDiffAcceptorType = MassDiffAcceptorType.Open, DecoyType = DecoyType.None, DoParsimony = true, DoQuantification = true }, }; string proteinDbFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "BinGenerationTest.xml"); string mzmlFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "BinGenerationTest.mzml"); Protein prot1 = new Protein("MEDEEK", "prot1"); Protein prot2 = new Protein("MENEEK", "prot2"); ModificationMotif.TryGetMotif("D", out ModificationMotif motif); ModificationWithMass mod = new ModificationWithMass(null, null, motif, TerminusLocalization.Any, 10); var pep1_0 = prot1.Digest(st.CommonParameters.DigestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).First(); var pep1_10 = prot1.Digest(st.CommonParameters.DigestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).Last(); Protein prot3 = new Protein("MAAADAAAAAAAAAAAAAAA", "prot3"); var pep2_0 = prot3.Digest(st.CommonParameters.DigestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).First(); var pep2_10 = prot3.Digest(st.CommonParameters.DigestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass> { mod }).Last(); Protein prot4 = new Protein("MNNDNNNN", "prot4"); var pep3_10 = prot4.Digest(st.CommonParameters.DigestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass> { mod }).Last(); List <PeptideWithSetModifications> pepsWithSetMods = new List <PeptideWithSetModifications> { pep1_0, pep1_10, pep2_0, pep2_10, pep3_10 }; IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile = new TestDataFile(pepsWithSetMods); List <Protein> proteinList = new List <Protein> { prot1, prot2, prot3, prot4 }; IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile, mzmlFilePath, false); ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), proteinList, proteinDbFilePath); string output_folder = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestBinGeneration"); Directory.CreateDirectory(output_folder); st.RunTask( output_folder, new List <DbForTask> { new DbForTask(proteinDbFilePath, false) }, new List <string> { mzmlFilePath }, null); Assert.AreEqual(3, File.ReadLines(Path.Combine(output_folder, @"aggregate.mytsv")).Count()); }
[TestCase(9, 0, true, "EDITPEPEDITP2PPP", DecoyType.Reverse)] // MPEPPP becomes MPPPEP with the variant beginning at position 2 public static void SearchTests(int proteinIdx, int peptideIdx, bool containsVariant, string variantPsmShort, DecoyType decoyType = DecoyType.None) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); // 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, SearchTarget = decoyType == DecoyType.None, ModPeptidesAreDifferent = false }, CommonParameters = new CommonParameters(scoreCutoff: 1, digestionParams: new DigestionParams(minPeptideLength: 2), precursorMassTolerance: new PpmTolerance(20)), }; ModificationMotif.TryGetMotif("V", out ModificationMotif motifV); Modification mv = new Modification("mod", null, "type", null, motifV, "Anywhere.", null, 42.01, new Dictionary <string, IList <string> >(), null, null, null, null, null); ModificationMotif.TryGetMotif("P", out ModificationMotif motifP); Modification mp = new Modification("mod", null, "type", null, motifP, "Anywhere.", null, 42.01, new Dictionary <string, IList <string> >(), null, null, null, null, null); List <Protein> proteins = new List <Protein> { new Protein("MPEPTIDE", "protein1", sequenceVariations: new List <SequenceVariation> { new SequenceVariation(4, 4, "P", "V", @"1\t50000000\t.\tA\tG\t.\tPASS\tANN=G||||||||||||||||\tGT:AD:DP\t1/1:30,30:30", null) }), new Protein("MPEPTIDE", "protein2", sequenceVariations: new List <SequenceVariation> { new SequenceVariation(4, 5, "PT", "KT", @"1\t50000000\t.\tA\tG\t.\tPASS\tANN=G||||||||||||||||\tGT:AD:DP\t1/1:30,30:30", null) }), new Protein("MPEPTIDE", "protein3", sequenceVariations: new List <SequenceVariation> { new SequenceVariation(4, 4, "P", "PPP", @"1\t50000000\t.\tA\tG\t.\tPASS\tANN=G||||||||||||||||\tGT:AD:DP\t1/1:30,30:30", null) }), new Protein("MPEPPPTIDE", "protein3", sequenceVariations: new List <SequenceVariation> { new SequenceVariation(4, 6, "PPP", "P", @"1\t50000000\t.\tA\tG\t.\tPASS\tANN=G||||||||||||||||\tGT:AD:DP\t1/1:30,30:30", null) }), new Protein("MPEPKPKTIDE", "protein3", sequenceVariations: new List <SequenceVariation> { new SequenceVariation(4, 7, "PKPK", "PK", @"1\t50000000\t.\tA\tG\t.\tPASS\tANN=G||||||||||||||||\tGT:AD:DP\t1/1:30,30:30", null) }), new Protein("MPEPTAIDE", "protein2", sequenceVariations: new List <SequenceVariation> { new SequenceVariation(4, 5, "PTA", "KT", @"1\t50000000\t.\tA\tG\t.\tPASS\tANN=G||||||||||||||||\tGT:AD:DP\t1/1:30,30:30", null) }), new Protein("MPEKKAIDE", "protein2", sequenceVariations: new List <SequenceVariation> { new SequenceVariation(4, 4, "KKA", "K", @"1\t50000000\t.\tA\tG\t.\tPASS\tANN=G||||||||||||||||\tGT:AD:DP\t1/1:30,30:30", null) }), new Protein("MPEPTIDE", "protein1", sequenceVariations: new List <SequenceVariation> { new SequenceVariation(4, 4, "P", "V", @"1\t50000000\t.\tA\tG\t.\tPASS\tANN=G||||||||||||||||\tGT:AD:DP\t1/1:30,30:30", new Dictionary <int, List <Modification> > { { 4, new[] { mv }.ToList() } }) }), new Protein("MPEPTIDE", "protein3", sequenceVariations: new List <SequenceVariation> { new SequenceVariation(4, 4, "P", "PPP", @"1\t50000000\t.\tA\tG\t.\tPASS\tANN=G||||||||||||||||\tGT:AD:DP\t1/1:30,30:30", new Dictionary <int, List <Modification> > { { 5, new[] { mp }.ToList() } }) }), new Protein("MPEPTIDEPEPTIDE", "protein3", sequenceVariations: new List <SequenceVariation> { new SequenceVariation(4, 4, "PTIDEPEPTIDE", "PPP", @"1\t50000000\t.\tA\tG\t.\tPASS\tANN=G||||||||||||||||\tGT:AD:DP\t1/1:30,30:30", null) }), }; PeptideWithSetModifications pep = proteins[proteinIdx].GetVariantProteins().SelectMany(p => p.Digest(CommonParameters.DigestionParams, null, null)).ToList()[peptideIdx]; string xmlName = $"andguiaheov{proteinIdx.ToString()}.xml"; ProteinDbWriter.WriteXmlDatabase(null, new List <Protein> { proteins[proteinIdx] }, xmlName); string mzmlName = $"ajgdiv{proteinIdx.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{proteinIdx.ToString()}"); Directory.CreateDirectory(outputFolder); 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(containsVariant ? variantPsmShort : "\t"))); Directory.Delete(outputFolder, true); File.Delete(mzmlName); File.Delete(xmlName); Directory.Delete(Path.Combine(TestContext.CurrentContext.TestDirectory, @"Task Settings"), true); Console.WriteLine($"Analysis time for VariantSearchTests.SearchTests({proteinIdx.ToString()},{peptideIdx.ToString()},{containsVariant.ToString()},{variantPsmShort}): {stopwatch.Elapsed.Hours}h {stopwatch.Elapsed.Minutes}m {stopwatch.Elapsed.Seconds}s"); }
public static void TestSilacMultipleModsPerCondition() { //The concern with multiple mods per label is the conversions back and forth between "light" and "heavy" labels Residue heavyLysine = new Residue("a", 'a', "a", Chemistry.ChemicalFormula.ParseFormula("C{13}6H12N{15}2O"), ModificationSites.All); //+8 lysine Residue heavyArginine = new Residue("b", 'b', "b", Chemistry.ChemicalFormula.ParseFormula("C{13}6H12N4O"), ModificationSites.All); //+6 arginine Residue lightLysine = Residue.GetResidue('K'); Residue lightArginine = Residue.GetResidue('R'); SilacLabel krLabel = new SilacLabel(lightLysine.Letter, heavyLysine.Letter, heavyLysine.ThisChemicalFormula.Formula, heavyLysine.MonoisotopicMass - lightLysine.MonoisotopicMass); krLabel.AddAdditionalSilacLabel(new SilacLabel(lightArginine.Letter, heavyArginine.Letter, heavyArginine.ThisChemicalFormula.Formula, heavyArginine.MonoisotopicMass - lightArginine.MonoisotopicMass)); SearchTask task = new SearchTask { SearchParameters = new SearchParameters { SilacLabels = new List <SilacLabel> { krLabel } }, CommonParameters = new CommonParameters(digestionParams: new DigestionParams(minPeptideLength: 2)) }; PeptideWithSetModifications lightPeptide = new PeptideWithSetModifications("SEQENEWITHAKANDANR", new Dictionary <string, Modification>()); List <double> massDifferences = new List <double> { (heavyLysine.MonoisotopicMass + heavyArginine.MonoisotopicMass) - (lightLysine.MonoisotopicMass + lightArginine.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("MPRTEINRSEQENEWITHAKANDANRANDSMSTFF", "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); task.RunTask(outputFolder, new List <DbForTask> { new DbForTask(xmlName, false) }, new List <string> { mzmlName }, "taskId1"); //test proteins string[] output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllProteinGroups.tsv"); Assert.AreEqual(output.Length, 2); Assert.IsTrue(output[0].Contains("Intensity_silac\tIntensity_silac(K+8.014 & R+6.020)")); //test that two files were made Assert.IsTrue(output[1].Contains("875000\t437500")); //test the heavy intensity is half that of the light (per the raw file) //test peptides output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllQuantifiedPeptides.tsv"); Assert.AreEqual(output.Length, 2); Assert.IsTrue(output[1].Contains("SEQENEWITHAKANDANR\taccession1\t")); //test the sequence and accession were not modified Assert.IsTrue(output[1].Contains("875000")); //test intensity Assert.IsFalse(output[1].Contains("SEQENEWITHAK(+8.014)ANDANR(+6.020)")); //test the sequence was not doubled modified Assert.IsTrue(output[1].Contains("437500")); //test intensity //test peaks output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllQuantifiedPeaks.tsv"); Assert.AreEqual(output.Length, 3); Assert.IsTrue(output[1].Contains("silac\t")); //test the filename was NOT modified (it was for proteins, but we don't want it for peptides) Assert.IsTrue(output[2].Contains("silac\t")); //test the filename was NOT modified (it was for proteins, but we don't want it for peptides) Assert.IsTrue(output[1].Contains("SEQENEWITHAKANDANR\t")); //test light sequence was not modified Assert.IsTrue(output[2].Contains("SEQENEWITHAK(+8.014)ANDANR(+6.020)\t")); //test heavy sequence was output correctly (do NOT want "PEPTIDEa") Assert.IsTrue(output[1].Contains("2111.96")); //test light mass Assert.IsTrue(output[2].Contains("2125.99")); //test heavy mass Assert.IsTrue(output[2].Contains("accession1")); //test heavy accesssion is light in output ///Test for when an additional label is the only label on a peptide ///Usually crashes in mzId //Delete old files File.Delete(mzmlName); Directory.Delete(outputFolder, true); lightPeptide = new PeptideWithSetModifications("ANDANR", new Dictionary <string, Modification>()); //has the additional, but not the original massDifferences = new List <double> { (heavyArginine.MonoisotopicMass) - (lightArginine.MonoisotopicMass) }; myMsDataFile1 = new TestDataFile(lightPeptide, massDifferences, true); mzmlName = @"silac.mzML"; IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile1, mzmlName, false); Directory.CreateDirectory(outputFolder); task.RunTask(outputFolder, new List <DbForTask> { new DbForTask(xmlName, false) }, new List <string> { mzmlName }, "taskId1"); //Clear the old files Directory.Delete(outputFolder, true); File.Delete(xmlName); File.Delete(mzmlName); }
public static void TestProteinSplitAcrossFiles() { SearchTask st = new SearchTask() { CommonParameters = new CommonParameters { ScoreCutoff = 1, DigestionParams = new DigestionParams { InitiatorMethionineBehavior = InitiatorMethionineBehavior.Retain, MaxMissedCleavages = 0 }, ConserveMemory = false, }, SearchParameters = new SearchParameters { DoHistogramAnalysis = true, MassDiffAcceptorType = MassDiffAcceptorType.Open, MatchBetweenRuns = true, DoQuantification = true }, }; string proteinDbFilePath = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestProteinSplitAcrossFiles.xml"); string mzmlFilePath1 = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestProteinSplitAcrossFiles1.mzml"); string mzmlFilePath2 = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestProteinSplitAcrossFiles2.mzml"); ModificationMotif.TryGetMotif("D", out ModificationMotif motif); ModificationWithMass mod = new ModificationWithMass("mod1", "mt", motif, TerminusLocalization.Any, 10); IDictionary <int, List <Modification> > oneBasedModification = new Dictionary <int, List <Modification> > { { 3, new List <Modification> { mod } } }; Protein prot1 = new Protein("MEDEEK", "prot1", oneBasedModifications: oneBasedModification); var pep1 = prot1.Digest(st.CommonParameters.DigestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).First(); var pep2 = prot1.Digest(st.CommonParameters.DigestionParams, new List <ModificationWithMass>(), new List <ModificationWithMass>()).Last(); List <PeptideWithSetModifications> listForFile1 = new List <PeptideWithSetModifications> { pep1, pep2 }; List <PeptideWithSetModifications> listForFile2 = new List <PeptideWithSetModifications> { pep2 }; IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile1 = new TestDataFile(listForFile1); IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile2 = new TestDataFile(listForFile2); List <Protein> proteinList = new List <Protein> { prot1 }; IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile1, mzmlFilePath1, false); IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile2, mzmlFilePath2, false); ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), proteinList, proteinDbFilePath); string output_folder = Path.Combine(TestContext.CurrentContext.TestDirectory, "TestProteinSplitAcrossFiles"); Directory.CreateDirectory(output_folder); st.RunTask( output_folder, new List <DbForTask> { new DbForTask(proteinDbFilePath, false) }, new List <string> { mzmlFilePath1, mzmlFilePath2, }, null); }
public static void SearchWithPeptidesAddedInParsimonyTest() { // Make sure can run the complete search task when multiple compact peptides may correspond to a single PWSM SearchTask st = new SearchTask { SearchParameters = new SearchParameters { DoParsimony = true, DecoyType = DecoyType.None, ModPeptidesAreDifferent = false }, CommonParameters = new CommonParameters { ScoreCutoff = 1, DigestionParams = new DigestionParams { MinPeptideLength = 2 } } }; string xmlName = "andguiaheow.xml"; #region Generate protein and write to file CommonParameters CommonParameters = new CommonParameters { DigestionParams = new DigestionParams { MaxMissedCleavages = 0, MinPeptideLength = null, InitiatorMethionineBehavior = InitiatorMethionineBehavior.Retain, MaxModsForPeptide = 1, MaxModificationIsoforms = 2 }, ScoreCutoff = 1 }; ModificationMotif.TryGetMotif("A", out ModificationMotif motifA); ModificationWithMass alanineMod = new ModificationWithMass("111", "mt", motifA, TerminusLocalization.Any, 111); var variableModifications = new List <ModificationWithMass>(); IDictionary <int, List <Modification> > oneBasedModifications1 = new Dictionary <int, List <Modification> > { { 2, new List <Modification> { alanineMod } } }; Protein protein1 = new Protein("MA", "protein1", oneBasedModifications: oneBasedModifications1); // Alanine = Glycine + CH2 ModificationMotif.TryGetMotif("G", out ModificationMotif motif1); ModificationWithMass glycineMod = new ModificationWithMass("CH2 on Glycine", "mt", motif1, TerminusLocalization.Any, Chemistry.ChemicalFormula.ParseFormula("CH2").MonoisotopicMass); IDictionary <int, List <Modification> > oneBasedModifications2 = new Dictionary <int, List <Modification> > { { 2, new List <Modification> { glycineMod } } }; Protein protein2 = new Protein("MG", "protein3", oneBasedModifications: oneBasedModifications2); PeptideWithSetModifications pepMA = protein1.Digest(CommonParameters.DigestionParams, new List <ModificationWithMass>(), variableModifications).First(); PeptideWithSetModifications pepMA111 = protein1.Digest(CommonParameters.DigestionParams, new List <ModificationWithMass>(), variableModifications).Last(); var pepMG = protein2.Digest(CommonParameters.DigestionParams, new List <ModificationWithMass>(), variableModifications).First(); ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), new List <Protein> { protein1, protein2 }, xmlName); #endregion Generate protein and write to file string mzmlName = @"ajgdiu.mzML"; #region Generate and write the mzml { IMsDataFile <IMsDataScan <IMzSpectrum <IMzPeak> > > myMsDataFile = new TestDataFile(new List <PeptideWithSetModifications> { pepMA, pepMG, pepMA111 }, true); IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile, mzmlName, false); } #endregion Generate and write the mzml st.RunTask("", new List <DbForTask> { new DbForTask(xmlName, false) }, new List <string> { mzmlName }, ""); }
public static void TestProteinQuantFileHeaders(bool hasDefinedExperimentalDesign, int bioreps, int fractions, int techreps) { // create the unit test directory string unitTestFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestProteinQuantFileHeaders"); Directory.CreateDirectory(unitTestFolder); List <SpectraFileInfo> fileInfos = new List <SpectraFileInfo>(); string peptide = "PEPTIDE"; double ionIntensity = 1e6; string condition = hasDefinedExperimentalDesign ? "TestCondition" : ""; // create the protein database Protein prot = new Protein(peptide, @""); string dbName = Path.Combine(unitTestFolder, "testDB.fasta"); UsefulProteomicsDatabases.ProteinDbWriter.WriteFastaDatabase(new List <Protein> { prot }, dbName, ">"); // create the .mzML files to search/quantify for (int b = 0; b < bioreps; b++) { for (int f = 0; f < fractions; f++) { for (int r = 0; r < techreps; r++) { string fileToWrite = "file_" + "b" + b + "f" + f + "r" + r + ".mzML"; // generate mzml file MsDataScan[] scans = new MsDataScan[2]; // create the MS1 scan ChemicalFormula cf = new Proteomics.AminoAcidPolymer.Peptide(peptide).GetChemicalFormula(); IsotopicDistribution dist = IsotopicDistribution.GetDistribution(cf, 0.125, 1e-8); double[] mz = dist.Masses.Select(v => v.ToMz(1)).ToArray(); double[] intensities = dist.Intensities.Select(v => v * ionIntensity).ToArray(); scans[0] = new MsDataScan(massSpectrum: new MzSpectrum(mz, intensities, false), oneBasedScanNumber: 1, msnOrder: 1, isCentroid: true, polarity: Polarity.Positive, retentionTime: 1.0, scanWindowRange: new MzRange(400, 1600), scanFilter: "f", mzAnalyzer: MZAnalyzerType.Orbitrap, totalIonCurrent: intensities.Sum(), injectionTime: 1.0, noiseData: null, nativeId: "scan=1"); // create the MS2 scan var pep = new PeptideWithSetModifications(peptide, new Dictionary <string, Proteomics.Modification>()); List <Product> frags = new List <Product>(); pep.Fragment(DissociationType.HCD, FragmentationTerminus.Both, frags); double[] mz2 = frags.Select(v => v.NeutralMass.ToMz(1)).ToArray(); double[] intensities2 = frags.Select(v => 1e6).ToArray(); scans[1] = new MsDataScan(massSpectrum: new MzSpectrum(mz2, intensities2, false), oneBasedScanNumber: 2, msnOrder: 2, isCentroid: true, polarity: Polarity.Positive, retentionTime: 1.01, scanWindowRange: new MzRange(100, 1600), scanFilter: "f", mzAnalyzer: MZAnalyzerType.Orbitrap, totalIonCurrent: intensities.Sum(), injectionTime: 1.0, noiseData: null, nativeId: "scan=2", selectedIonMz: pep.MonoisotopicMass.ToMz(1), selectedIonChargeStateGuess: 1, selectedIonIntensity: 1e6, isolationMZ: pep.MonoisotopicMass.ToMz(1), isolationWidth: 1.5, dissociationType: DissociationType.HCD, oneBasedPrecursorScanNumber: 1, selectedIonMonoisotopicGuessMz: pep.MonoisotopicMass.ToMz(1), hcdEnergy: "35"); // write the .mzML string fullPath = Path.Combine(unitTestFolder, fileToWrite); IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra( new MsDataFile(scans, new SourceFile(@"scan number only nativeID format", "mzML format", null, "SHA-1", @"C:\fake.mzML", null)), fullPath, false); var spectraFileInfo = new SpectraFileInfo(fullPath, condition, b, r, f); fileInfos.Add(spectraFileInfo); } } } // write the experimental design for this quantification test if (hasDefinedExperimentalDesign) { ExperimentalDesign.WriteExperimentalDesignToFile(fileInfos); } // run the search/quantification SearchTask task = new SearchTask(); task.RunTask(unitTestFolder, new List <DbForTask> { new DbForTask(dbName, false) }, fileInfos.Select(p => p.FullFilePathWithExtension).ToList(), ""); // read in the protein quant results Assert.That(File.Exists(Path.Combine(unitTestFolder, "AllQuantifiedProteinGroups.tsv"))); var lines = File.ReadAllLines(Path.Combine(unitTestFolder, "AllQuantifiedProteinGroups.tsv")); // check the intensity column headers var splitHeader = lines[0].Split(new char[] { '\t' }).ToList(); var intensityColumnHeaders = splitHeader.Where(p => p.Contains("Intensity", StringComparison.OrdinalIgnoreCase)).ToList(); Assert.That(intensityColumnHeaders.Count == 2); if (!hasDefinedExperimentalDesign) { Assert.That(intensityColumnHeaders[0] == "Intensity_file_b0f0r0"); Assert.That(intensityColumnHeaders[1] == "Intensity_file_b1f0r0"); } else { Assert.That(intensityColumnHeaders[0] == "Intensity_TestCondition_1"); Assert.That(intensityColumnHeaders[1] == "Intensity_TestCondition_2"); } // check the protein intensity values int ind1 = splitHeader.IndexOf(intensityColumnHeaders[0]); int ind2 = splitHeader.IndexOf(intensityColumnHeaders[1]); double intensity1 = double.Parse(lines[1].Split(new char[] { '\t' })[ind1]); double intensity2 = double.Parse(lines[1].Split(new char[] { '\t' })[ind2]); Assert.That(intensity1 > 0); Assert.That(intensity2 > 0); Assert.That(intensity1 == intensity2); Directory.Delete(unitTestFolder, true); }
public static void MetaDraw_SearchTaskTest() { string outputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"MetaDraw_SearchTaskTest"); string proteinDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\smalldb.fasta"); string spectraFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SmallCalibratible_Yeast.mzML"); Directory.CreateDirectory(outputFolder); // run search task var searchtask = new SearchTask(); searchtask.RunTask(outputFolder, new List <DbForTask> { new DbForTask(proteinDatabase, false) }, new List <string> { spectraFile }, ""); var psmFile = Path.Combine(outputFolder, @"AllPSMs.psmtsv"); // load results into metadraw var metadrawLogic = new MetaDrawLogic(); metadrawLogic.SpectraFilePaths.Add(spectraFile); metadrawLogic.PsmResultFilePaths.Add(psmFile); var errors = metadrawLogic.LoadFiles(true, true); Assert.That(!errors.Any()); Assert.That(metadrawLogic.FilteredListOfPsms.Any()); // test results filter MetaDrawSettings.QValueFilter = 0.01; MetaDrawSettings.ShowDecoys = false; metadrawLogic.FilterPsms(); Assert.That(metadrawLogic.FilteredListOfPsms.All(p => p.DecoyContamTarget == "T")); Assert.That(metadrawLogic.FilteredListOfPsms.All(p => p.QValue <= 0.01)); MetaDrawSettings.QValueFilter = 1.0; MetaDrawSettings.ShowDecoys = true; metadrawLogic.FilterPsms(); Assert.That(metadrawLogic.FilteredListOfPsms.Any(p => p.DecoyContamTarget == "D")); Assert.That(metadrawLogic.FilteredListOfPsms.Any(p => p.QValue > 0.01)); // test text search filter (filter by full sequence) string filterString = @"QIVHDSGR"; metadrawLogic.FilterPsmsByString(filterString); int c = 0; foreach (var filteredPsm in metadrawLogic.PeptideSpectralMatchesView) { var psmObj = (PsmFromTsv)filteredPsm; Assert.That(psmObj.FullSequence.Contains(filterString)); c++; } Assert.That(c > 0); // test text search filter (filter by MS2 scan number) filterString = @"120"; metadrawLogic.FilterPsmsByString(filterString); c = 0; foreach (var filteredPsm in metadrawLogic.PeptideSpectralMatchesView) { var psmObj = (PsmFromTsv)filteredPsm; Assert.That(psmObj.Ms2ScanNumber.ToString().Contains(filterString)); c++; } Assert.That(c > 0); // draw PSM var plotView = new OxyPlot.Wpf.PlotView(); var canvas = new Canvas(); var parentChildView = new ParentChildScanPlotsView(); var psm = metadrawLogic.FilteredListOfPsms.First(); metadrawLogic.DisplaySpectrumMatch(plotView, canvas, psm, parentChildView, out errors); Assert.That(errors == null || !errors.Any()); // test that plot was drawn var plotSeries = plotView.Model.Series; var series = plotSeries[0]; // the first m/z peak var peakPoints = ((LineSeries)series).Points; Assert.That(Math.Round(peakPoints[0].X, 2) == 101.07); // m/z Assert.That(Math.Round(peakPoints[1].X, 2) == 101.07); Assert.That((int)peakPoints[0].Y == 0); // intensity Assert.That((int)peakPoints[1].Y == 35045); var plotAxes = plotView.Model.Axes; Assert.That(plotAxes.Count == 2); // test that base sequence annotation was drawn int numAnnotatedResidues = psm.BaseSeq.Length; int numAnnotatedIons = psm.MatchedIons.Count; int numAnnotatedMods = psm.FullSequence.Count(p => p == '['); Assert.That(canvas.Children.Count == numAnnotatedResidues + numAnnotatedIons + numAnnotatedMods); // write pdf var psmsToExport = metadrawLogic.FilteredListOfPsms.Where(p => p.FullSequence == "QIVHDSGR").Take(3).ToList(); metadrawLogic.ExportToPdf(plotView, canvas, psmsToExport, parentChildView, outputFolder, out errors); // test that pdf exists Assert.That(File.Exists(Path.Combine(outputFolder, @"116_QIVHDSGR.pdf"))); Assert.That(File.Exists(Path.Combine(outputFolder, @"120_QIVHDSGR.pdf"))); Assert.That(File.Exists(Path.Combine(outputFolder, @"127_QIVHDSGR.pdf"))); // test displaying a PSM with a mod var modPsm = metadrawLogic.FilteredListOfPsms.First(p => p.FullSequence.Contains("[")); metadrawLogic.DisplaySpectrumMatch(plotView, canvas, modPsm, parentChildView, out errors); Assert.That(errors == null || !errors.Any()); Assert.That(canvas.Children.Count == modPsm.BaseSeq.Length + modPsm.MatchedIons.Count + modPsm.FullSequence.Count(p => p == '[')); // clean up resources metadrawLogic.CleanUpResources(); Assert.That(!metadrawLogic.FilteredListOfPsms.Any()); Assert.That(!metadrawLogic.PsmResultFilePaths.Any()); Assert.That(!metadrawLogic.SpectraFilePaths.Any()); // delete output Directory.Delete(outputFolder, true); }
public static void TestSilacQuantification() { //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) } } }; 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(); Assert.IsTrue(theStringResult.Contains("All target PSMS within 1% FDR: 1")); //it's not a psm, it's a MBR feature ///Normal Peptide //test proteins string[] output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllProteinGroups.tsv"); Assert.AreEqual(output.Length, 2); Assert.IsTrue(output[0].Contains("Intensity_silac\tIntensity_silac(K+8.014)")); //test that two files were made Assert.IsTrue(output[1].Contains("875000\t437500")); //test the heavy intensity is half that of the light (per the raw file) //test peptides output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllQuantifiedPeptides.tsv"); Assert.AreEqual(output.Length, 2); Assert.IsTrue(output[1].Contains("PEPTIDEK\taccession1\t")); //test the sequence and accession were not modified Assert.IsTrue(output[1].Contains("875000")); //test intensity Assert.IsFalse(output[1].Contains("PEPTIDEK(+8.014)")); //test the sequence was not doubled modified Assert.IsTrue(output[1].Contains("437500")); //test intensity //test peaks output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllQuantifiedPeaks.tsv"); Assert.AreEqual(output.Length, 3); Assert.IsTrue(output[1].Contains("silac\t")); //test the filename was NOT modified (it was for proteins, but we don't want it for peptides) Assert.IsTrue(output[2].Contains("silac\t")); //test the filename was NOT modified (it was for proteins, but we don't want it for peptides) Assert.IsTrue(output[1].Contains("PEPTIDEK\t")); //test light sequence was not modified Assert.IsTrue(output[2].Contains("PEPTIDEK(+8.014)\t")); //test heavy sequence was output correctly (do NOT want "PEPTIDEa") Assert.IsTrue(output[1].Contains("927.45")); //test light mass Assert.IsTrue(output[2].Contains("935.46")); //test heavy mass ///Ambiguous base sequence peptide //Clear the old files Directory.Delete(outputFolder, true); File.Delete(xmlName); File.Delete(mzmlName); //make a heavy peptide massDifferences = new List <double> { heavyLysine.MonoisotopicMass - lightLysine.MonoisotopicMass }; myMsDataFile1 = new TestDataFile(lightPeptide, massDifferences, true); IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile1, mzmlName, false); //make an ambiguous database Protein theProtein2 = new Protein("PEPTLDEKPEPTIDEK", "accession2"); ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), new List <Protein> { theProtein, theProtein2 }, xmlName); Directory.CreateDirectory(outputFolder); theStringResult = task.RunTask(outputFolder, new List <DbForTask> { new DbForTask(xmlName, false) }, new List <string> { mzmlName }, "taskId1").ToString(); output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllPSMs.psmtsv"); Assert.IsTrue(output[1].Contains("silac\t")); //test the filename was NOT modified (it was for proteins, but we don't want it for peptides) Assert.IsTrue(output[1].Contains("PEPTIDEK(+8.014)|PEPTLDEK(+8.014)|PEPTIDEK(+8.014)") || output[1].Contains("PEPTIDEK(+8.014)|PEPTIDEK(+8.014)|PEPTLDEK(+8.014)") || output[1].Contains("PEPTLDEK(+8.014)|PEPTIDEK(+8.014)|PEPTIDEK(+8.014)")); //test the heavy ambiguous peptides were all found //Need the options, because output isn't consistent as of 3/26/19 ///Ambiguous proteinGroup //Clear the old files Directory.Delete(outputFolder, true); File.Delete(xmlName); //make an ambiguous database theProtein2 = new Protein("PEPTIDEK", "accession2"); ProteinDbWriter.WriteXmlDatabase(new Dictionary <string, HashSet <Tuple <int, Modification> > >(), new List <Protein> { theProtein, theProtein2 }, xmlName); Directory.CreateDirectory(outputFolder); theStringResult = task.RunTask(outputFolder, new List <DbForTask> { new DbForTask(xmlName, false) }, new List <string> { mzmlName }, "taskId1").ToString(); output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllPSMs.psmtsv"); Assert.IsTrue(output[1].Contains("accession1|accession2") || output[1].Contains("accession2|accession1")); //test the heavy ambiguous peptides were all found //Need the options, because output isn't consistent as of 3/26/19 Assert.IsTrue(output[1].Contains("\tPEPTIDEK(+8.014)\t")); //test the heavy ambiguous peptides were all found //delete files Directory.Delete(outputFolder, true); File.Delete(xmlName); File.Delete(mzmlName); }
public static void TestSilacNoLightProtein() { //The concern with multiple mods per label is the conversions back and forth between "light" and "heavy" labels Residue heavyArginine = new Residue("c", 'c', "c", Chemistry.ChemicalFormula.ParseFormula("C6H12N{15}4O"), ModificationSites.All); //+4 arginine Residue heavierArginine = new Residue("d", 'd', "d", Chemistry.ChemicalFormula.ParseFormula("C{13}6H12N{15}4O"), ModificationSites.All); //+10 arginine Residue.AddNewResiduesToDictionary(new List <Residue> { heavyArginine }); //These should be added in the search task, but we need to add this one earlier so that we can create a heavy pwsm Residue lightArginine = Residue.GetResidue('R'); SilacLabel heavyLabel = new SilacLabel(lightArginine.Letter, heavyArginine.Letter, heavyArginine.ThisChemicalFormula.Formula, heavyArginine.MonoisotopicMass - lightArginine.MonoisotopicMass); SilacLabel heavierLabel = new SilacLabel(lightArginine.Letter, heavierArginine.Letter, heavierArginine.ThisChemicalFormula.Formula, heavierArginine.MonoisotopicMass - lightArginine.MonoisotopicMass); SearchTask task = new SearchTask { SearchParameters = new SearchParameters { SilacLabels = new List <SilacLabel> { heavyLabel, heavierLabel } }, CommonParameters = new CommonParameters(digestionParams: new DigestionParams(generateUnlabeledProteinsForSilac: false)) //this is the important part of the unit test }; PeptideWithSetModifications heavyPeptide = new PeptideWithSetModifications("PEPTIDEc", new Dictionary <string, Modification>()); List <double> massDifferences = new List <double> { heavierArginine.MonoisotopicMass - heavyArginine.MonoisotopicMass }; MsDataFile myMsDataFile1 = new TestDataFile(heavyPeptide, massDifferences); string mzmlName = @"silac.mzML"; IO.MzML.MzmlMethods.CreateAndWriteMyMzmlWithCalibratedSpectra(myMsDataFile1, mzmlName, false); string xmlName = "SilacDb.xml"; Protein theProtein = new Protein("PEPTIDER", "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(); //test proteins string[] output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllProteinGroups.tsv"); Assert.AreEqual(output.Length, 2); Assert.IsTrue(output[0].Contains("Modification Info List\tIntensity_silac(R+3.988)\tIntensity_silac(R+10.008)")); //test that two files were made and no light file Assert.IsTrue(output[1].Contains("875000\t437500")); //test the heavier intensity is half that of the heavy (per the raw file) //test peptides output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllQuantifiedPeptides.tsv"); Assert.AreEqual(output.Length, 2); Assert.IsTrue(output[0].Contains("Organism\tIntensity_silac(R+3.988)\tIntensity_silac(R+10.008)")); //test the two files were made and no light file Assert.IsTrue(output[1].Contains("875000\t437500")); //test intensity //test peaks output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllQuantifiedPeaks.tsv"); Assert.AreEqual(output.Length, 3); Assert.IsTrue(output[1].Contains("silac\t")); //test the filename was NOT modified (it was for proteins, but we don't want it for peptides) Assert.IsTrue(output[2].Contains("silac\t")); //test the filename was NOT modified (it was for proteins, but we don't want it for peptides) Assert.IsTrue(output[1].Contains("PEPTIDER(+3.988)\t")); //test light sequence was not modified Assert.IsTrue(output[2].Contains("PEPTIDER(+10.008)\t")); //test heavy sequence was output correctly (do NOT want "PEPTIDEa") Assert.IsTrue(output[1].Contains("959.44")); //test light mass Assert.IsTrue(output[2].Contains("965.46")); //test heavy mass //test PSMs output = File.ReadAllLines(TestContext.CurrentContext.TestDirectory + @"/TestSilac/AllPSMs.psmtsv"); Assert.IsTrue(output[1].Contains("959.44")); //test the correct monoisotopic mass Assert.IsTrue(output[1].Contains("PEPTIDER(+3.988)")); //test the correct psm Assert.IsTrue(output[1].Contains("silac\t")); //test the filename was NOT modified (it was for proteins, but we don't want it for peptides) //Clear the old files Directory.Delete(outputFolder, true); File.Delete(xmlName); File.Delete(mzmlName); }
public static void TestMetaDrawWithSpectralLibrary() { string outputFolder = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestMetaDrawWithSpectraLibrary"); string proteinDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SpectralLibrarySearch\P16858.fasta"); string library1 = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SpectralLibrarySearch\P16858_target.msp"); string library2 = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SpectralLibrarySearch\P16858_decoy.msp"); string spectraFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SpectralLibrarySearch\slicedMouse.raw"); Directory.CreateDirectory(outputFolder); // run search task var searchtask = new SearchTask(); searchtask.RunTask(outputFolder, new List <DbForTask> { new DbForTask(proteinDatabase, false), new DbForTask(library1, false), new DbForTask(library2, false), }, new List <string> { spectraFile }, ""); var psmFile = Path.Combine(outputFolder, @"AllPSMs.psmtsv"); // load results into metadraw var metadrawLogic = new MetaDrawLogic(); metadrawLogic.SpectraFilePaths.Add(spectraFile); metadrawLogic.PsmResultFilePaths.Add(psmFile); metadrawLogic.SpectralLibraryPaths.Add(library1); metadrawLogic.SpectralLibraryPaths.Add(library2); var errors = metadrawLogic.LoadFiles(true, true); Assert.That(!errors.Any()); // draw PSM var plotView = new OxyPlot.Wpf.PlotView(); var canvas = new Canvas(); var parentChildView = new ParentChildScanPlotsView(); var psm = metadrawLogic.FilteredListOfPsms.First(); metadrawLogic.DisplaySpectrumMatch(plotView, canvas, psm, parentChildView, out errors); Assert.That(errors == null || !errors.Any()); // test that plot was drawn var plotSeries = plotView.Model.Series; // test that library peaks were drawn in the mirror plot (these peaks have negative intensities) var mirrorPlotPeaks = plotSeries.Where(p => ((LineSeries)p).Points[1].Y < 0).ToList(); Assert.That(mirrorPlotPeaks.Count == 52); var plotAxes = plotView.Model.Axes; Assert.That(plotAxes.Count == 2); // write pdf var psmsToExport = metadrawLogic.FilteredListOfPsms.Where(p => p.FullSequence == "VIHDNFGIVEGLMTTVHAITATQK").Take(1).ToList(); metadrawLogic.ExportToPdf(plotView, canvas, psmsToExport, parentChildView, outputFolder, out errors); // test that pdf exists Assert.That(File.Exists(Path.Combine(outputFolder, @"6_VIHDNFGIVEGLMTTVHAITATQK.pdf"))); // clean up resources metadrawLogic.CleanUpResources(); Assert.That(!metadrawLogic.FilteredListOfPsms.Any()); Assert.That(!metadrawLogic.PsmResultFilePaths.Any()); Assert.That(!metadrawLogic.SpectraFilePaths.Any()); Assert.That(!metadrawLogic.SpectralLibraryPaths.Any()); // delete output Directory.Delete(outputFolder, true); }
public static void TestAutodetectDissocationTypeFromScanHeader() { SearchTask searchTask = new SearchTask() { SearchParameters = new SearchParameters { DoQuantification = false // quant disabled just to save some time }, // use DissociationType.Autodetect as the dissociation type. this signals to the search that the dissociation type // should be taken from the scan header on a scan-specific basis CommonParameters = new CommonParameters(dissociationType: DissociationType.Autodetect) }; string myFile = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\SmallCalibratible_Yeast.mzML"); string myDatabase = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestData\smalldb.fasta"); string folderPath = Path.Combine(TestContext.CurrentContext.TestDirectory, @"TestAutodetectDissocationTypeFromScanHeader"); DbForTask db = new DbForTask(myDatabase, false); // run the task var autoTaskFolder = Path.Combine(folderPath, @"Autodetect"); Directory.CreateDirectory(autoTaskFolder); searchTask.RunTask(autoTaskFolder, new List <DbForTask> { db }, new List <string> { myFile }, ""); // run identical task but select the HCD dissociation type instead of autodetect var hcdTaskFolder = Path.Combine(folderPath, @"HCD"); Directory.CreateDirectory(hcdTaskFolder); searchTask = new SearchTask() { SearchParameters = new SearchParameters { DoQuantification = false }, CommonParameters = new CommonParameters(dissociationType: DissociationType.HCD) }; searchTask.RunTask(hcdTaskFolder, new List <DbForTask> { db }, new List <string> { myFile }, ""); // check search results var psmFileAutodetect = File.ReadAllLines(Path.Combine(autoTaskFolder, "AllPSMs.psmtsv")); var psmFileHcd = File.ReadAllLines(Path.Combine(hcdTaskFolder, "AllPSMs.psmtsv")); Assert.That(psmFileAutodetect.Length == psmFileHcd.Length); for (int i = 0; i < psmFileAutodetect.Length; i++) { Assert.That(psmFileAutodetect[i].Equals(psmFileHcd[i])); } // clean up Directory.Delete(folderPath, true); }