private static ResultsTestDocumentContainer MinimizeCacheFile(SrmDocument document, ChromCacheMinimizer.Settings settings, string skyFilePath) { Assert.IsNotNull(skyFilePath); // For ReSharper string skydFilePath = Path.ChangeExtension(skyFilePath, ChromatogramCache.EXT); ChromCacheMinimizer chromCacheMinimizer = document.Settings.MeasuredResults.GetChromCacheMinimizer(document); using (var fs = new FileSaver(skydFilePath)) using (var fsScans = new FileSaver(skydFilePath + ChromatogramCache.SCANS_EXT, true)) using (var fsPeaks = new FileSaver(skydFilePath + ChromatogramCache.PEAKS_EXT, true)) using (var fsScores = new FileSaver(skydFilePath + ChromatogramCache.SCORES_EXT, true)) { fs.Stream = File.OpenWrite(fs.SafeName); chromCacheMinimizer.Minimize(settings, null, fs.Stream, fsScans.FileStream, fsPeaks.FileStream, fsScores.FileStream); fs.Commit(); } using (var writer = new XmlTextWriter(skyFilePath, Encoding.UTF8) { Formatting = Formatting.Indented }) { var ser = new XmlSerializer(typeof(SrmDocument)); ser.Serialize(writer, document); writer.Flush(); writer.Close(); } var container = new ResultsTestDocumentContainer(document, skyFilePath, false); Assert.IsTrue(container.SetDocument(ResultsUtil.DeserializeDocument(skyFilePath), document, true)); return(container); }
public void TestMeasuredDriftValues() { var testFilesDir = new TestFilesDir(TestContext, @"Test\Results\BlibDriftTimeTest.zip"); // Re-used from BlibDriftTimeTest // Open document with some peptides but no results var docPath = testFilesDir.GetTestPath("BlibDriftTimeTest.sky"); SrmDocument docOriginal = ResultsUtil.DeserializeDocument(docPath); var docContainer = new ResultsTestDocumentContainer(docOriginal, docPath); var doc = docContainer.Document; // Import an mz5 file that contains drift info const string replicateName = "ID12692_01_UCA168_3727_040714"; var chromSets = new[] { new ChromatogramSet(replicateName, new[] { new MsDataFilePath(testFilesDir.GetTestPath("ID12692_01_UCA168_3727_040714.mz5")), }), }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets)); Assert.IsTrue(docContainer.SetDocument(docResults, docOriginal, true)); docContainer.AssertComplete(); var document = docContainer.Document; document = document.ChangeSettings(document.Settings.ChangePeptidePrediction(prediction => new PeptidePrediction(null, DriftTimePredictor.EMPTY))); // Verify ability to extract predictions from raw data var newPred = document.Settings.PeptideSettings.Prediction.DriftTimePredictor.ChangeMeasuredDriftTimesFromResults( document, docContainer.DocumentFilePath); var result = newPred.MeasuredDriftTimePeptides; Assert.AreEqual(TestSmallMolecules? 2: 1, result.Count); const double expectedDT = 4.0019; var expectedOffset = .4829; Assert.AreEqual(expectedDT, result.Values.First().DriftTimeMsec(false).Value, .001); Assert.AreEqual(expectedOffset, result.Values.First().HighEnergyDriftTimeOffsetMsec, .001); // Check ability to update, and to preserve unchanged var revised = new Dictionary <LibKey, DriftTimeInfo>(); var libKey = result.Keys.First(); revised.Add(libKey, new DriftTimeInfo(4, 0.234)); var libKey2 = new LibKey("DEADEELS", 2); revised.Add(libKey2, new DriftTimeInfo(5, 0.123)); document = document.ChangeSettings( document.Settings.ChangePeptidePrediction(prediction => new PeptidePrediction(null, new DriftTimePredictor("test", revised, null, null, 40)))); newPred = document.Settings.PeptideSettings.Prediction.ChangeDriftTimePredictor( document.Settings.PeptideSettings.Prediction.DriftTimePredictor.ChangeMeasuredDriftTimesFromResults( document, docContainer.DocumentFilePath)).DriftTimePredictor; result = newPred.MeasuredDriftTimePeptides; Assert.AreEqual(TestSmallMolecules ? 3 : 2, result.Count); Assert.AreEqual(expectedDT, result[libKey].DriftTimeMsec(false).Value, .001); Assert.AreEqual(expectedOffset, result[libKey].HighEnergyDriftTimeOffsetMsec, .001); Assert.AreEqual(5, result[libKey2].DriftTimeMsec(false).Value, .001); Assert.AreEqual(0.123, result[libKey2].HighEnergyDriftTimeOffsetMsec, .001); docContainer.Release(); }
public void ShimadzuFormatsTest() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath; SrmDocument doc = InitShimadzuDocument(testFilesDir, out docPath); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { const string replicateName = "ShimadzuTest"; string extRaw = ExtensionTestContext.ExtShimadzuRaw; var chromSets = new[] { new ChromatogramSet(replicateName, new[] { new MsDataFilePath(testFilesDir.GetTestPath("BSA-digest__MRM_optimisation_SL_scheduled_001" + extRaw)), }), }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); docResults = docContainer.Document; AssertResult.IsDocumentResultsState(docResults, replicateName, doc.PeptideCount, doc.PeptideTransitionGroupCount, 0, doc.PeptideTransitionCount, 0); } testFilesDir.Dispose(); }
protected void DoTest() { if (TestFilesZipPaths != null) { TestFilesDirs = new TestFilesDir[TestFilesZipPaths.Length]; for (int i = 0; i < TestFilesZipPaths.Length; i++) { TestFilesDirs[i] = new TestFilesDir(TestContext, TestFilesZipPaths[i], TestDirectoryName, TestFilesPersistent, IsExtractHere(i)); } } File.Copy(_baseSkyFile, _skyFile, true); Stopwatch loadStopwatch = new Stopwatch(); loadStopwatch.Start(); var doc = ResultsUtil.DeserializeDocument(_skyFile); doc = ConnectLibrarySpecs(doc, _skyFile); using (var docContainer = new ResultsTestDocumentContainer(doc, _skyFile)) { var chromSets = new[] { new ChromatogramSet(_replicateName, new[] { new MsDataFilePath(_dataFile, null, _centroided, _centroided), }), }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); } loadStopwatch.Stop(); DebugLog.Info("{0} load time = {1}", _dataFile, loadStopwatch.ElapsedMilliseconds); }
public void AgilentFormatsTest() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath; SrmDocument doc = InitAgilentDocument(testFilesDir, out docPath); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { const string replicateName = "AgilentTest"; string extRaw = ExtensionTestContext.ExtAgilentRaw; var chromSets = new[] { new ChromatogramSet(replicateName, new[] { new MsDataFilePath(testFilesDir.GetTestPath("081809_100fmol-MichromMix-05" + extRaw)), }), }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); docResults = docContainer.Document; AssertResult.IsDocumentResultsState(docResults, replicateName, doc.PeptideCount, doc.PeptideTransitionGroupCount, 0, doc.PeptideTransitionCount, 0); } testFilesDir.Dispose(); }
public void Wiff2ResultsTest() { TestFilesDir testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath("OnyxTOFMS.sky"); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); //AssertEx.IsDocumentState(doc, 0, 1, 1, 4); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { const string replicateName = "Wiff2Test"; string extRaw = ExtensionTestContext.ExtAbWiff2; string suffix = ExtensionTestContext.CanImportAbWiff2 ? "" : "-sample-centroid"; var chromSets = new[] { new ChromatogramSet(replicateName, new[] { new MsDataFilePath(TestFilesDir.GetVendorTestData(TestFilesDir.VendorDir.ABI, "swath.api" + suffix + extRaw)), }), }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); docResults = docContainer.Document; //AssertResult.IsDocumentResultsState(docResults, replicateName, // doc.MoleculeCount, doc.MoleculeTransitionGroupCount, 0, doc.MoleculeTransitionCount, 0); } testFilesDir.Dispose(); }
private void Import(ResultsTestDocumentContainer docContainer, string resultsPath, double minMz, double maxMz) { var measuredResults = new MeasuredResults(new[] { new ChromatogramSet("Single", new[] { resultsPath }) }); docContainer.ChangeMeasuredResults(measuredResults, 1, 1, 3); // Check expected Mz range. foreach (var nodeTran in docContainer.Document.MoleculeTransitions) { Assert.IsTrue(nodeTran.HasResults, "No results for transition Mz: {0}", nodeTran.Mz); if (nodeTran.Results[0].IsEmpty) { continue; } //Assert.IsNotNull(nodeTran.Results[0], "Null results for transition Mz: {0}", nodeTran.Mz); if (minMz > nodeTran.Mz || nodeTran.Mz > maxMz) { Assert.IsTrue(nodeTran.Results[0][0].IsEmpty, "Non-empty transition Mz: {0}", nodeTran.Mz); } else { Assert.IsFalse(nodeTran.Results[0][0].IsEmpty, "Empty transition Mz: {0}", nodeTran.Mz); } } }
private void DoTestImportSim(bool asSmallMolecules) { if (asSmallMolecules && !RunSmallMoleculeTestVersions) { System.Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION); return; } var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath(DOCUMENT_NAME); string cachePath = ChromatogramCache.FinalPathForName(docPath, null); FileEx.SafeDelete(cachePath); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); var pepdoc = doc; if (asSmallMolecules) { var refine = new RefinementSettings(); doc = refine.ConvertToSmallMolecules(pepdoc, TestContext.ResultsDirectory); } using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { // Import the mzML file and verify Mz range Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME), 510, 512); Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME2), 555, 557); } }
public void TestCollectStatistics() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath("BSA_Protea_label_free_20100323_meth3_multi.sky"); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); var docContainer = new ResultsTestDocumentContainer(doc, docPath); // Import the first RAW file (or mzML for international) string rawPath = testFilesDir.GetTestPath("ah_20101011y_BSA_MS-MS_only_5-2" + ExtensionTestContext.ExtThermoRaw); var measuredResults = new MeasuredResults(new[] { new ChromatogramSet("Single", new[] { MsDataFileUri.Parse(rawPath) }) }); SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, 3, 3, 21); ChromCacheMinimizer chromCacheMinimizer = docResults.Settings.MeasuredResults.GetChromCacheMinimizer(docResults); ChromCacheMinimizer.Settings settings = new ChromCacheMinimizer.Settings().SetDiscardUnmatchedChromatograms(true); ChromCacheMinimizer.MinStatistics minStatistics = null; chromCacheMinimizer.Minimize(settings, s => minStatistics = s, null); Assert.AreEqual(100, minStatistics.PercentComplete); Assert.AreEqual(1.0, minStatistics.MinimizedRatio); var docMissingFirstPeptide = (SrmDocument) docResults.ReplaceChild( docResults.PeptideGroups.First().RemoveChild(docResults.PeptideGroups.First().Children[0])); var docWithOnlyFirstPeptide = (SrmDocument) docResults.ReplaceChild( docResults.PeptideGroups.First().ChangeChildren(new[] { docResults.PeptideGroups.First().Children[0] })); ChromCacheMinimizer.MinStatistics statsMissingFirstProtein = null; ChromCacheMinimizer.MinStatistics statsWithOnlyFirstProtein = null; settings = settings.SetDiscardUnmatchedChromatograms(true); ChromCacheMinimizer minimizerMissingFirstProtein = docMissingFirstPeptide.Settings.MeasuredResults.GetChromCacheMinimizer(docMissingFirstPeptide); ChromCacheMinimizer minimizerWithOnlyFirstProtein = docWithOnlyFirstPeptide.Settings.MeasuredResults.GetChromCacheMinimizer(docWithOnlyFirstPeptide); minimizerMissingFirstProtein.Minimize(settings, s => statsMissingFirstProtein = s, null); minimizerWithOnlyFirstProtein.Minimize(settings, s => statsWithOnlyFirstProtein = s, null); Assert.AreEqual(100, statsMissingFirstProtein.PercentComplete); Assert.AreEqual(100, statsWithOnlyFirstProtein.PercentComplete); Assert.AreEqual(1.0, statsMissingFirstProtein.MinimizedRatio + statsWithOnlyFirstProtein.MinimizedRatio, .00001); settings = settings.SetDiscardUnmatchedChromatograms(false); ChromCacheMinimizer.MinStatistics statsMissingFirstProteinKeepAll = null; ChromCacheMinimizer.MinStatistics statsWithOnlyFirstProteinKeepAll = null; minimizerMissingFirstProtein.Minimize(settings, s => statsMissingFirstProteinKeepAll = s, null); minimizerWithOnlyFirstProtein.Minimize(settings, s => statsWithOnlyFirstProteinKeepAll = s, null); Assert.AreEqual(100, statsMissingFirstProteinKeepAll.PercentComplete); Assert.AreEqual(1.0, statsMissingFirstProteinKeepAll.MinimizedRatio); Assert.AreEqual(100, statsWithOnlyFirstProteinKeepAll.PercentComplete); Assert.AreEqual(1.0, statsWithOnlyFirstProteinKeepAll.MinimizedRatio); docContainer.Release(); }
public void DoAgilentMseChromatogramTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules) { if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none && !RunSmallMoleculeTestVersions) { System.Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION); return; } var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); TestSmallMolecules = false; // We have an explicit test for that here string docPath; SrmDocument document = InitAgilentMseDocument(testFilesDir, out docPath); if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none) { var refine = new RefinementSettings(); document = refine.ConvertToSmallMolecules(document, asSmallMolecules); } using (var docContainer = new ResultsTestDocumentContainer(document, docPath)) { var doc = docContainer.Document; var listChromatograms = new List <ChromatogramSet>(); var path = MsDataFileUri.Parse(@"AgilentMse\BSA-AI-0-10-25-41_first_100_scans.mzML"); listChromatograms.Add(AssertResult.FindChromatogramSet(doc, path) ?? new ChromatogramSet(path.GetFileName().Replace('.', '_'), new[] { path })); var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); document = docContainer.Document; float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance; var results = document.Settings.MeasuredResults; foreach (var pair in document.MoleculePrecursorPairs) { ChromatogramGroupInfo[] chromGroupInfo; Assert.IsTrue(results.TryLoadChromatogram(0, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupInfo)); Assert.AreEqual(1, chromGroupInfo.Length); } // now drill down for specific values int nPeptides = 0; foreach (var nodePep in document.Molecules.Where(nodePep => nodePep.Results[0] != null)) { // expecting just one peptide result in this small data set if (nodePep.Results[0].Sum(chromInfo => chromInfo.PeakCountRatio > 0 ? 1 : 0) > 0) { Assert.AreEqual(0.2462, (double)nodePep.GetMeasuredRetentionTime(0), .0001, "averaged retention time differs in node " + nodePep.RawTextId); Assert.AreEqual(0.3333, (double)nodePep.GetPeakCountRatio(0), 0.0001); nPeptides++; } } Assert.AreEqual(1, nPeptides); } testFilesDir.Dispose(); }
private void RunMultiplePeptidesSameMz(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules) { if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none) { TestDirectoryName = asSmallMolecules.ToString(); } TestSmallMolecules = false; // Don't need the magic test node, we have an explicit test var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath; SrmDocument document = InitMultiplePeptidesSameMzDocument(testFilesDir, out docPath); document = (new RefinementSettings()).ConvertToSmallMolecules(document, asSmallMolecules); var docContainer = new ResultsTestDocumentContainer(document, docPath); var doc = docContainer.Document; var listChromatograms = new List <ChromatogramSet>(); var path = MsDataFileUri.Parse(@"AMultiplePeptidesSameMz\ljz_20131201k_Newvariant_standards_braf.mzML"); listChromatograms.Add(AssertResult.FindChromatogramSet(doc, path) ?? new ChromatogramSet(path.GetFileName().Replace('.', '_'), new[] { path })); var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); document = docContainer.Document; float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance; var results = document.Settings.MeasuredResults; foreach (var pair in document.MoleculePrecursorPairs) { ChromatogramGroupInfo[] chromGroupInfo; Assert.IsTrue(results.TryLoadChromatogram(0, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupInfo)); Assert.AreEqual(1, chromGroupInfo.Length); // without the fix, only the first pair will have a chromatogram } // now drill down for specific values int nPeptides = 0; foreach (var nodePep in document.Molecules.Where(nodePep => nodePep.Results[0] != null)) { // expecting three peptide result in this small data set if (nodePep.Results[0].Sum(chromInfo => chromInfo.PeakCountRatio > 0 ? 1 : 0) > 0) { Assert.AreEqual(34.2441024780273, (double)nodePep.GetMeasuredRetentionTime(0), .0001); nPeptides++; } } Assert.AreEqual(3, nPeptides); // without the fix this will give just one result // Release file handles docContainer.Release(); testFilesDir.Dispose(); }
public void TestBlibDriftTimes() { var testFilesDir = new TestFilesDir(TestContext, @"Test\Results\BlibDriftTimeTest.zip"); // Open document with some peptides but no results var docPath = testFilesDir.GetTestPath("BlibDriftTimeTest.sky"); SrmDocument docOriginal = ResultsUtil.DeserializeDocument(docPath); var docContainer = new ResultsTestDocumentContainer(docOriginal, docPath); var doc = docContainer.Document; // Use the bare drift times in the spectral library var librarySpec = new BiblioSpecLiteSpec("drift test", testFilesDir.GetTestPath("BlibDriftTimeTest.blib")); doc = doc.ChangeSettings( doc.Settings.ChangePeptideLibraries(lib => lib.ChangeLibrarySpecs(new[] { librarySpec })). ChangePeptidePrediction(p => p.ChangeLibraryDriftTimesResolvingPower(20)). ChangePeptidePrediction(p => p.ChangeUseLibraryDriftTimes(true)) ); // Import an mz5 file that needs drift info that's in the original data set, // but preserved in the .blib file associated with a different raw source // Without the bugfix this won't get any drift time filtering. const string replicateName = "ID12692_01_UCA168_3727_040714"; var chromSets = new[] { new ChromatogramSet(replicateName, new[] { new MsDataFilePath(testFilesDir.GetTestPath("ID12692_01_UCA168_3727_040714.mz5")), }), }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets)); Assert.IsTrue(docContainer.SetDocument(docResults, docOriginal, true)); docContainer.AssertComplete(); var document = docContainer.Document; float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance; double maxHeight = 0; var results = document.Settings.MeasuredResults; Assert.AreEqual(2, document.PeptidePrecursorPairs.Count()); var pair = document.PeptidePrecursorPairs.ToArray()[1]; ChromatogramGroupInfo[] chromGroupInfo; Assert.IsTrue(results.TryLoadChromatogram(0, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupInfo)); Assert.AreEqual(1, chromGroupInfo.Length); var chromGroup = chromGroupInfo[0]; Assert.AreEqual(2, chromGroup.NumPeaks); // This will be higher if we don't filter on DT foreach (var tranInfo in chromGroup.TransitionPointSets) { maxHeight = Math.Max(maxHeight, tranInfo.MaxIntensity); } Assert.AreEqual(278, maxHeight, 1); // Without DT filtering, this will be much greater - about 996 docContainer.Release(); }
public void FullScanPrecursorTransitionsTest() { TestFilesDir testFilesDir = new TestFilesDir(TestContext, @"Test\FullScanPrecursor.zip"); string docPath = testFilesDir.GetTestPath("FullScanPrecursor.sky"); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); AssertEx.IsDocumentState(doc, 0, 1, 4, 5, 52); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { var mitoLibSpec = new BiblioSpecLiteSpec("mito2", testFilesDir.GetTestPath("mito2.blib")); doc = docContainer.ChangeLibSpecs(new[] { mitoLibSpec }); Assert.IsTrue(doc.IsLoaded); // Switch to only precursor ions var docPrecOnly = doc.ChangeSettings(doc.Settings.ChangeTransitionFilter(filter => filter.ChangePeptideIonTypes(new[] { IonType.precursor }))); // All precursors should have 3 precursor transitions (M, M+1 and M+2) AssertEx.IsDocumentState(docPrecOnly, 3, 1, 4, 5, 15); Assert.IsFalse(docPrecOnly.PeptideTransitions.Any(nodeTran => nodeTran.Transition.IonType != IonType.precursor)); // Use low resolution MS1 filtering var docLowMs1 = docPrecOnly.ChangeSettings(docPrecOnly.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, null) .ChangePrecursorResolution(FullScanMassAnalyzerType.qit, 0.5, null))); // All precursors should have one precursor transition AssertEx.IsDocumentState(docLowMs1, 4, 1, 4, 5, 5); // Add y-ions to low resolution filtering var docLowMs1Y = docLowMs1.ChangeSettings(docLowMs1.Settings.ChangeTransitionFilter(filter => filter.ChangePeptideIonTypes(new[] { IonType.precursor, IonType.y }))); AssertEx.IsDocumentState(docLowMs1Y, 5, 1, 4, 5, 33); // Turn off MS1 filtering var docNoMs1 = docPrecOnly.ChangeSettings(docPrecOnly.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.None, null, null))); // One of the precursors should have no transitions, since its spectrum has no precursor match AssertEx.IsDocumentState(docNoMs1, 4, 1, 4, 5, 4); // Turn off MS/MS library matching var docNoLibMatch = docNoMs1.ChangeSettings(docNoMs1.Settings.ChangeTransitionLibraries(lib => lib.ChangePick(TransitionLibraryPick.none))); // All precursors should have a single precursor transition AssertEx.IsDocumentState(docNoLibMatch, 5, 1, 4, 5, 5); // Use library plus filter matching var docLibPlusMatch = docNoMs1.ChangeSettings(docNoMs1.Settings.ChangeTransitionLibraries(lib => lib.ChangePick(TransitionLibraryPick.all_plus))); // All precursors should have a single precursor transition AssertEx.IsDocumentState(docLibPlusMatch, 5, 1, 4, 5, 5); // Release the library stream, and dispose of the directory docContainer.ChangeLibSpecs(new LibrarySpec[0]); } testFilesDir.Dispose(); }
public void TestQcTraces() { const string testZipPath = @"TestData\PressureTracesTest.zip"; var testFilesDir = new TestFilesDir(TestContext, testZipPath); using (var msDataFile = new MsDataFileImpl(testFilesDir.GetTestPath("PressureTrace1" + ExtensionTestContext.ExtAbWiff))) { var pressureTraces = msDataFile.GetQcTraces(); VerifyQcTrace(pressureTraces[0], "Column Pressure (channel 1)", 1148, 0, 9.558333, 1470, 210, MsDataFileImpl.QcTraceQuality.Pressure, MsDataFileImpl.QcTraceUnits.PoundsPerSquareInch); VerifyQcTrace(pressureTraces[1], "Pump A Flowrate (channel 2)", 1148, 0, 9.558333, 91590, 89120, MsDataFileImpl.QcTraceQuality.FlowRate, MsDataFileImpl.QcTraceUnits.MicrolitersPerMinute); VerifyQcTrace(pressureTraces[2], "Pump B Flowrate (channel 3)", 1148, 0, 9.558333, 0, 840, MsDataFileImpl.QcTraceQuality.FlowRate, MsDataFileImpl.QcTraceUnits.MicrolitersPerMinute); VerifyQcTrace(pressureTraces[3], "Column Pressure (channel 4)", 3508, 0, 29.225, 1396, 1322, MsDataFileImpl.QcTraceQuality.Pressure, MsDataFileImpl.QcTraceUnits.PoundsPerSquareInch); VerifyQcTrace(pressureTraces[4], "Pump A Flowrate (channel 5)", 3508, 0, 29.225, 7038, 7833, MsDataFileImpl.QcTraceQuality.FlowRate, MsDataFileImpl.QcTraceUnits.MicrolitersPerMinute); VerifyQcTrace(pressureTraces[5], "Pump B Flowrate (channel 6)", 3508, 0, 29.225, 680, 151, MsDataFileImpl.QcTraceQuality.FlowRate, MsDataFileImpl.QcTraceUnits.MicrolitersPerMinute); string docPath = testFilesDir.GetTestPath("PressureTrace1.sky"); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); AssertEx.IsDocumentState(doc, 0, 1, 3, 9); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { const string replicateName = "PressureTrace1"; string extRaw = ExtensionTestContext.ExtAbWiff; var chromSets = new[] { new ChromatogramSet(replicateName, new[] { new MsDataFilePath(testFilesDir.GetTestPath("PressureTrace1" + extRaw)), }), }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(chromSets)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); docResults = docContainer.Document; var chromCache = docResults.Settings.MeasuredResults.GetChromCacheMinimizer(docResults).ChromatogramCache; var tic = chromCache.LoadAllIonsChromatogramInfo(ChromExtractor.summed, chromSets[0]); var bpc = chromCache.LoadAllIonsChromatogramInfo(ChromExtractor.base_peak, chromSets[0]); var qc = chromCache.LoadAllIonsChromatogramInfo(ChromExtractor.qc, chromSets[0]); Assert.AreEqual(0, tic.Count()); // No longer expect these in SRM data Assert.AreEqual(0, bpc.Count()); // No longer expect these in SRM data var qcNames = qc.Select(o => o.TextId).ToArray(); Assert.AreEqual(6, qcNames.Length); CollectionAssert.IsSubsetOf(new [] { "Column Pressure (channel 1)", "Pump A Flowrate (channel 2)", "Pump B Flowrate (channel 3)", "Column Pressure (channel 4)", "Pump A Flowrate (channel 5)", "Pump B Flowrate (channel 6)" }, qcNames); } } }
private static void doTest(TestFilesDir testFilesDir, string skyFile, double expectedRT, string[] filenames, double?expectedRatio) { string docPath; var document = InitExplicitRTDocument(testFilesDir, skyFile, out docPath); var docContainer = new ResultsTestDocumentContainer(document, docPath); var doc = docContainer.Document; var listChromatograms = new List <ChromatogramSet>(); foreach (var filename in filenames) { var path = MsDataFileUri.Parse(filename + ExtensionTestContext.ExtWatersRaw); listChromatograms.Add(AssertResult.FindChromatogramSet(doc, path) ?? new ChromatogramSet(path.GetFileName().Replace('.', '_'), new[] { path })); } var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); document = docContainer.Document; float tolerance = (float)document.Settings.TransitionSettings.Instrument.MzMatchTolerance; foreach (var pair in document.MoleculePrecursorPairs) { ChromatogramGroupInfo[] chromGroupInfo; Assert.IsTrue(document.Settings.MeasuredResults.TryLoadChromatogram(0, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupInfo)); Assert.IsTrue(document.Settings.MeasuredResults.TryLoadChromatogram(1, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupInfo)); } var nResults = 0; foreach (var nodePep in document.Molecules) { foreach (var results in nodePep.Results) { foreach (var result in results) { Assert.AreEqual(expectedRT, result.RetentionTime ?? 0, .1); // We should pick peaks based on explicit RT if (expectedRatio.HasValue) // If we didn't, ratios won't be right { Assert.IsNotNull(result.LabelRatios[0].Ratio); Assert.AreEqual(expectedRatio.Value, result.LabelRatios[0].Ratio.Ratio, .1); } nResults++; } } } Assert.AreEqual(filenames.Length * document.MoleculeGroupCount, nResults); // Release file handles docContainer.Release(); }
private void ExportImport(ResultsTestDocumentContainer docContainer, string resultsPath) { var optRegression = docContainer.Document.Settings.TransitionSettings.Prediction.CollisionEnergy; int optSteps = optRegression.StepCount * 2 + 1; int optSteps1 = optSteps - 1; // First precursor is below 10 volts CE for 1 step int optSteps2 = optSteps - 3; // Second precursor is below 10 volts CE for 3 steps // First export var exporter = new AbiMassListExporter(docContainer.Document) { OptimizeType = ExportOptimize.CE, OptimizeStepCount = optRegression.StepCount, OptimizeStepSize = optRegression.StepSize }; string tranListPath = Path.ChangeExtension(docContainer.DocumentFilePath, TextUtil.EXT_CSV); exporter.Export(tranListPath); // Make sure line count matches expectations for steps below 10 volts CE Assert.AreEqual(5 * optSteps1 + 5 * optSteps2, File.ReadAllLines(tranListPath).Length); // Then import var resultsUri = new MsDataFilePath(resultsPath); var chromSet = new ChromatogramSet("Optimize", new[] { resultsUri }, Annotations.EMPTY, optRegression); var measuredResults = new MeasuredResults(new[] { chromSet }); docContainer.ChangeMeasuredResults(measuredResults, 2, optSteps1 + optSteps2, 5 * optSteps1 + 5 * optSteps2); // Check expected optimization data with missing values for steps below 10 volts CE int expectedMissingSteps = optSteps - optSteps1; foreach (var nodeGroup in docContainer.Document.MoleculeTransitionGroups) { foreach (var nodeTran in nodeGroup.Transitions) { Assert.IsTrue(nodeTran.HasResults, "No results for transition Mz: {0}", nodeTran.Mz); Assert.IsNotNull(nodeTran.Results[0]); Assert.AreEqual(optSteps, nodeTran.Results[0].Count); for (int i = 0; i < optSteps; i++) { if (i < expectedMissingSteps) { Assert.IsTrue(nodeTran.Results[0][i].IsEmpty); } else { Assert.IsFalse(nodeTran.Results[0][i].IsEmpty); } } } expectedMissingSteps = optSteps - optSteps2; } }
private static void ValidateRelativeRT(RelativeRT relativeRT, SrmDocument doc, string docPath, List <ChromatogramSet> listChromatograms) { FileEx.SafeDelete(Path.ChangeExtension(docPath, ChromatogramCache.EXT)); SrmSettings settings = doc.Settings.ChangePeptideModifications(mods => mods.ChangeHeavyModifications( mods.HeavyModifications.Select(m => m.ChangeRelativeRT(relativeRT)).ToArray())); var docMods = doc.ChangeSettings(settings); var docResults = docMods.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); var docContainer = new ResultsTestDocumentContainer(docMods, docPath); Assert.IsTrue(docContainer.SetDocument(docResults, docMods, true)); docContainer.AssertComplete(); docContainer.Release(); }
private void DoTestAgilentCEOpt() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath(DOCUMENT_NAME); string cachePath = ChromatogramCache.FinalPathForName(docPath, null); FileEx.SafeDelete(cachePath); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { // Import the .wiff file ExportImport(docContainer, testFilesDir.GetTestPath(RESULTS_NAME)); } }
public void DoAsymmetricIsolationTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules) { if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none && !RunSmallMoleculeTestVersions) { Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION); return; } TestSmallMolecules = false; // We test small molecules explicitly in this test LocalizationHelper.InitThread(); // TODO: All unit tests should be correctly initialized var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath("TROUBLED_File.sky"); string cachePath = ChromatogramCache.FinalPathForName(docPath, null); FileEx.SafeDelete(cachePath); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); var refine = new RefinementSettings(); doc = refine.ConvertToSmallMolecules(doc, testFilesDir.FullPath, asSmallMolecules); const int expectedMoleculeCount = 1; // At first small molecules did not support multiple label types AssertEx.IsDocumentState(doc, null, 1, expectedMoleculeCount, 2, 6); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { // Import the first RAW file (or mzML for international) string rawPath = testFilesDir.GetTestPath("Rush_p3_96_21May16_Smeagol.mzML"); var measuredResults = new MeasuredResults(new[] { new ChromatogramSet("Single", new[] { rawPath }) }); { // Import with symmetric isolation window var docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 3, 3); var nodeGroup = docResults.MoleculeTransitionGroups.First(); double ratio = nodeGroup.Results[0][0].Ratio ?? 0; // The expected ratio is 1.0, but the symmetric isolation window should produce poor results if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only) // Can't use labels without a formula { Assert.AreEqual(0.008, ratio, 0.001); } } } testFilesDir.Dispose(); }
public void ThermoMixedPeptidesTest() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath; SrmDocument docMixed = InitMixedDocument(testFilesDir, out docPath); FileEx.SafeDelete(Path.ChangeExtension(docPath, ChromatogramCache.EXT)); SrmDocument docUnmixed = InitUnmixedDocument(testFilesDir, out docPath); FileEx.SafeDelete(Path.ChangeExtension(docPath, ChromatogramCache.EXT)); string extRaw = ExtensionTestContext.ExtThermoRaw; var listChromatograms = new List <ChromatogramSet> { new ChromatogramSet("rep03", new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath( "Site20_STUDY9P_PHASEII_QC_03" + extRaw)) }), new ChromatogramSet("rep05", new[] { MsDataFileUri.Parse(testFilesDir.GetTestPath( "Site20_STUDY9P_PHASEII_QC_05" + extRaw)) }) }; var docResults = docMixed.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); var docContainerMixed = new ResultsTestDocumentContainer(docMixed, docPath); Assert.IsTrue(docContainerMixed.SetDocument(docResults, docMixed, true)); docContainerMixed.AssertComplete(); docMixed = docContainerMixed.Document; SrmDocument docMixedUnmixed = (SrmDocument)docMixed.ChangeChildren(new DocNode[0]); IdentityPath tempPath; docMixedUnmixed = docMixedUnmixed.AddPeptideGroups(docUnmixed.PeptideGroups, true, IdentityPath.ROOT, out tempPath, out tempPath); docResults = docUnmixed.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); var docContainerUnmixed = new ResultsTestDocumentContainer(docUnmixed, docPath); Assert.IsTrue(docContainerUnmixed.SetDocument(docResults, docUnmixed, true)); docContainerUnmixed.AssertComplete(); docUnmixed = docContainerUnmixed.Document; AssertEx.DocumentCloned(docMixedUnmixed, docUnmixed); docContainerMixed.Release(); docContainerUnmixed.Release(); }
private void Import(ResultsTestDocumentContainer docContainer, string resultsPath, bool optFlag) { var optRegression = optFlag ? docContainer.Document.Settings.TransitionSettings.Prediction.CollisionEnergy : null; int optSteps = optRegression != null ? optRegression.StepCount * 2 + 1 : 1; var resultsUri = new MsDataFilePath(resultsPath); var chromSet = new ChromatogramSet("Optimize", new[] { resultsUri }, Annotations.EMPTY, optRegression); var measuredResults = new MeasuredResults(new[] { chromSet }); docContainer.ChangeMeasuredResults(measuredResults, 1, 1 * optSteps, 3 * optSteps); // Check expected optimization data. foreach (var nodeTran in docContainer.Document.MoleculeTransitions) { Assert.IsTrue(nodeTran.HasResults, "No results for transition Mz: {0}", nodeTran.Mz); Assert.IsNotNull(nodeTran.Results[0]); Assert.AreEqual(optSteps, nodeTran.Results[0].Count); } }
private void DoTestAgilentCEOpt() { // The special mode for exercising non-proteomic molecules just doesn't make sense with this test TestSmallMolecules = false; var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath(DOCUMENT_NAME); string cachePath = ChromatogramCache.FinalPathForName(docPath, null); FileEx.SafeDelete(cachePath); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { // Import the .wiff file ExportImport(docContainer, testFilesDir.GetTestPath(RESULTS_NAME)); } }
public void WatersMzXmlTest() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath; SrmDocument doc = InitWatersDocument(testFilesDir, out docPath); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { // Verify mzXML and mzML contained same results // TODO: Figure out why these don't match well enough to use strict compare AssertResult.MatchChromatograms(docContainer, testFilesDir.GetTestPath("160109_Mix1_calcurve_070.mzML"), testFilesDir.GetTestPath("160109_Mix1_calcurve_070.mzXML"), -1, 0); } testFilesDir.Dispose(); }
private static double driftTimeMax = 13.799765403988133; // Known max drift time for this file - use to mimic resolving power logic for test purposes private static SrmDocument InitWatersImsMseDocument(TestFilesDir testFilesDir, IonMobilityWindowWidthCalculator.IonMobilityPeakWidthType driftPeakWidthCalcType, bool withDriftTimeFilter, bool withDriftTimePredictor, out string docPath) { var skyFile = withDriftTimePredictor ? "single_with_driftinfo.sky" : "single_no_driftinfo.sky"; docPath = testFilesDir.GetTestPath(skyFile); var cmdline = new CommandLine(); Assert.IsTrue(cmdline.OpenSkyFile(docPath)); // Handles any path shifts in database files, like our .imdb file SrmDocument doc = cmdline.Document; // Cause library load and subsequent document update using (var docContainer = new ResultsTestDocumentContainer(null, docPath)) { docContainer.SetDocument(doc, null, true); docContainer.AssertComplete(); doc = docContainer.Document; double resolvingPower = 100; // Test was originally written with resolving power 100 double widthAtDtMax = 2 * driftTimeMax / resolvingPower; var driftTimeWindowWidthCalculator = new IonMobilityWindowWidthCalculator(driftPeakWidthCalcType, resolvingPower, 0, widthAtDtMax); if (withDriftTimeFilter && !withDriftTimePredictor) { // Use the bare drift times in the spectral library var librarySpec = new BiblioSpecLiteSpec("drift test", testFilesDir.GetTestPath("waters-mobility.filtered-scaled.blib")); doc = doc.ChangeSettings( doc.Settings.ChangePeptideLibraries(lib => lib.ChangeLibrarySpecs(new[] { librarySpec })). ChangePeptidePrediction(p => p.ChangeLibraryDriftTimesWindowWidthCalculator(driftTimeWindowWidthCalculator)). ChangePeptidePrediction(p => p.ChangeUseLibraryIonMobilityValues(true)) ); } else if (withDriftTimeFilter) { doc = doc.ChangeSettings( doc.Settings.ChangePeptideSettings(ps => ps.ChangePrediction( ps.Prediction.ChangeDriftTimePredictor(ps.Prediction.IonMobilityPredictor.ChangeDriftTimeWindowWidthCalculator(driftTimeWindowWidthCalculator))))); } } return(doc); }
public void ChromatogramExportTest() { var testFilesDir = new TestFilesDir(TestContext, TEST_ZIP_PATH); string chromExportDoc = testFilesDir.GetTestPath("ChromToExport.sky"); string fileExpected1 = testFilesDir.GetTestPathLocale(EXPORT_1); string fileActual1 = GetActualName(fileExpected1); string fileExpected2 = testFilesDir.GetTestPathLocale(EXPORT_2); string fileActual2 = GetActualName(fileExpected2); string fileExpectedAll = testFilesDir.GetTestPathLocale(EXPORT_ALL); string fileActualAll = GetActualName(fileExpectedAll); SrmDocument doc = ResultsUtil.DeserializeDocument(chromExportDoc); // Load an empty doc, so that we can make a change and // cause the .skyd to be loaded using (var docContainer = new ResultsTestDocumentContainer(null, chromExportDoc)) { docContainer.SetDocument(doc, null, true); docContainer.AssertComplete(); SrmDocument docResults = docContainer.Document; if (IsSaveAll) { // For regenerating all of the required expected files, if things change SaveChrom(docResults, testFilesDir.GetTestPath(EXPORT_1), FILE_NAMES_1.ToList(), CultureInfo.GetCultureInfo("en-US"), EXTRACTOR_1, SOURCES_1); SaveChrom(docResults, testFilesDir.GetTestPath(EXPORT_2), FILE_NAMES_2.ToList(), CultureInfo.GetCultureInfo("en-US"), EXTRACTOR_2, SOURCES_2); SaveChrom(docResults, testFilesDir.GetTestPath(EXPORT_ALL), FILE_NAMES_ALL.ToList(), CultureInfo.GetCultureInfo("en-US"), EXTRACTOR_ALL, SOURCES_ALL); SaveChrom(docResults, testFilesDir.GetTestPathIntl(EXPORT_1), FILE_NAMES_1.ToList(), CultureInfo.GetCultureInfo("fr-FR"), EXTRACTOR_1, SOURCES_1); SaveChrom(docResults, testFilesDir.GetTestPathIntl(EXPORT_2), FILE_NAMES_2.ToList(), CultureInfo.GetCultureInfo("fr-FR"), EXTRACTOR_2, SOURCES_2); SaveChrom(docResults, testFilesDir.GetTestPathIntl(EXPORT_ALL), FILE_NAMES_ALL.ToList(), CultureInfo.GetCultureInfo("fr-FR"), EXTRACTOR_ALL, SOURCES_ALL); } SaveChrom(docResults, fileActual1, FILE_NAMES_1.ToList(), LocalizationHelper.CurrentCulture, EXTRACTOR_1, SOURCES_1); SaveChrom(docResults, fileActual2, FILE_NAMES_2.ToList(), LocalizationHelper.CurrentCulture, EXTRACTOR_2, SOURCES_2); SaveChrom(docResults, fileActualAll, FILE_NAMES_ALL.ToList(), LocalizationHelper.CurrentCulture, EXTRACTOR_ALL, SOURCES_ALL); var tolerance = new Dictionary <int, double> { { 3, .0001 } }; // Allow a little wiggle in mz column since we tweak the calculation with Adduct work AssertEx.FileEquals(fileExpected1, fileActual1, tolerance); AssertEx.FileEquals(fileExpected2, fileActual2, tolerance); AssertEx.FileEquals(fileExpectedAll, fileActualAll, tolerance); } }
protected override void DoTest() { var resultsPath = TestFilesDir.GetTestPath("PeakSortingIssue.raw"); var docPath = TestFilesDir.GetTestPath("PeakSortingIssue.sky"); var doc = ResultsUtil.DeserializeDocument(docPath); AssertEx.IsDocumentState(doc, 0, 1, 3, 6, 90); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { var replicateName = Path.GetFileNameWithoutExtension(resultsPath); var listChromatograms = new List <ChromatogramSet> { new ChromatogramSet(replicateName, new[] { MsDataFileUri.Parse(resultsPath) }) }; var docResults = doc.ChangeMeasuredResults(new MeasuredResults(listChromatograms)); Assert.IsTrue(docContainer.SetDocument(docResults, doc, true)); docContainer.AssertComplete(); docResults = docContainer.Document; AssertResult.IsDocumentResultsState(docResults, replicateName, 0, 0, 0, 0, 3); } }
public void ThermoFormatsTest() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath; SrmDocument doc = InitThermoDocument(testFilesDir, out docPath); var docContainer = new ResultsTestDocumentContainer(doc, docPath); // Verify mzML and RAW contain same results string extRaw = ExtensionTestContext.ExtThermoRaw; AssertResult.MatchChromatograms(docContainer, testFilesDir.GetTestPath("Site20_STUDY9P_PHASEII_QC_03" + extRaw), testFilesDir.GetTestPath("Site20_STUDY9P_PHASEII_QC_03.mzML"), 0, 0); // Verify mzXML and RAW contain same results (some small peaks are different) AssertResult.MatchChromatograms(docContainer, testFilesDir.GetTestPath("Site20_STUDY9P_PHASEII_QC_03" + extRaw), testFilesDir.GetTestPath("Site20_STUDY9P_PHASEII_QC_03.mzXML"), 2, 0); // Release file handles docContainer.Release(); testFilesDir.Dispose(); }
private void DoTestImportSim(bool asSmallMolecules) { TestSmallMolecules = false; // Don't need that magic extra node var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath(DOCUMENT_NAME); string cachePath = ChromatogramCache.FinalPathForName(docPath, null); FileEx.SafeDelete(cachePath); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); var pepdoc = doc; if (asSmallMolecules) { var refine = new RefinementSettings(); doc = refine.ConvertToSmallMolecules(pepdoc); } var docContainer = new ResultsTestDocumentContainer(doc, docPath); // Import the mzML file and verify Mz range Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME), 510, 512); Import(docContainer, testFilesDir.GetTestPath(RESULTS_NAME2), 555, 557); }
public void TestNoiseTimeLimit() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath("BSA_Protea_label_free_20100323_meth3_multi.sky"); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); using (var docContainer = new ResultsTestDocumentContainer(doc, docPath)) { // Import the first RAW file (or mzML for international) string rawPath = testFilesDir.GetTestPath("ah_20101011y_BSA_MS-MS_only_5-2" + ExtensionTestContext.ExtThermoRaw); var measuredResults = new MeasuredResults(new[] { new ChromatogramSet("Single", new[] { rawPath }) }); SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, 3, 3, 21); var tolerance = (float)docResults.Settings.TransitionSettings.Instrument.MzMatchTolerance; ChromCacheMinimizer.Settings settings = new ChromCacheMinimizer.Settings() .ChangeDiscardUnmatchedChromatograms(false) .ChangeNoiseTimeRange(1.0); string minimized1Path = testFilesDir.GetTestPath("NoiseTimeLimited1.sky"); string minimized2Path = testFilesDir.GetTestPath("NoiseTimeLimited2.sky"); using (var docContainerMinimized1Min = MinimizeCacheFile(docResults, settings.ChangeNoiseTimeRange(1.0), minimized1Path)) using (var docContainerMinimized2Min = MinimizeCacheFile(docResults, settings.ChangeNoiseTimeRange(2.0), minimized2Path)) { SrmDocument docMinimized1Min = docContainerMinimized1Min.Document; SrmDocument docMinimized2Min = docContainerMinimized2Min.Document; ChromatogramSet chromSet1Min = docMinimized1Min.Settings.MeasuredResults.Chromatograms[0]; ChromatogramSet chromSet2Min = docMinimized2Min.Settings.MeasuredResults.Chromatograms[0]; ChromatogramSet chromSetOriginal = docResults.Settings.MeasuredResults.Chromatograms[0]; foreach (var pair in docResults.PeptidePrecursorPairs) { ChromatogramGroupInfo[] chromGroupsOriginal; ChromatogramGroupInfo[] chromGroups1; ChromatogramGroupInfo[] chromGroups2; docMinimized1Min.Settings.MeasuredResults.TryLoadChromatogram(chromSet1Min, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroups1); docMinimized2Min.Settings.MeasuredResults.TryLoadChromatogram(chromSet2Min, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroups2); docResults.Settings.MeasuredResults.TryLoadChromatogram(chromSetOriginal, pair.NodePep, pair.NodeGroup, tolerance, true, out chromGroupsOriginal); Assert.AreEqual(chromGroups1.Length, chromGroups2.Length); Assert.AreEqual(chromGroups1.Length, chromGroupsOriginal.Length); for (int iChromGroup = 0; iChromGroup < chromGroups1.Length; iChromGroup++) { ChromatogramGroupInfo chromGroup1 = chromGroups1[iChromGroup]; ChromatogramGroupInfo chromGroup2 = chromGroups2[iChromGroup]; ChromatogramGroupInfo chromGroupOriginal = chromGroupsOriginal[iChromGroup]; var times = new[] { GetTimes(chromGroupOriginal)[0], GetTimes(chromGroup2)[0], GetTimes(chromGroup1)[0], GetTimes(chromGroup1).Last(), GetTimes(chromGroup2).Last(), GetTimes(chromGroupOriginal).Last() }; // The two minute window around the peak might overlap with either the start or end of the original chromatogram, // but will never overlap with both. Assert.IsTrue(GetTimes(chromGroup2)[0] > GetTimes(chromGroupOriginal)[0] || GetTimes(chromGroup2).Last() < GetTimes(chromGroupOriginal).Last()); // If the two minute window does not overlap with the start/end of the original chromatogram, then the difference // in time between the one minute window and the two minute window will be approximately 1 minute. if (GetTimes(chromGroup2)[0] > GetTimes(chromGroupOriginal)[0]) { Assert.AreEqual(GetTimes(chromGroup2)[0], GetTimes(chromGroup1)[0] - 1, .1); } if (GetTimes(chromGroup2).Last() < GetTimes(chromGroupOriginal).Last()) { Assert.AreEqual(GetTimes(chromGroup2).Last(), GetTimes(chromGroup1).Last() + 1, .1); } float[] timesSorted = times.ToArray(); Array.Sort(timesSorted); CollectionAssert.AreEqual(times, timesSorted); } } } } }
public void DocLoadLibrary() { // Load the document var testFilesDir = new TestFilesDir(TestContext, TEST_ZIP_PATH); string loadPath = testFilesDir.GetTestPath("DocWithLibrary.sky"); string libraryPath = testFilesDir.GetTestPath("Yeast_MRMer_min.blib"); var doc = ResultsUtil.DeserializeDocument(loadPath); doc = doc.ChangeSettings(doc.Settings.ChangePeptideLibraries( lib => lib.ChangeLibrarySpecs(new[] { new BiblioSpecLiteSpec(lib.Libraries[0].Name, libraryPath), }))); // Cause library load and subsequent document update using (var docContainer = new ResultsTestDocumentContainer(null, loadPath)) { docContainer.SetDocument(doc, null, true); docContainer.WaitForProcessing(); docContainer.AssertComplete(); // Check that library info on peptides and transitions were not recalculated // during document load var docLoaded = docContainer.Document; Assert.AreEqual(6, docLoaded.PeptideCount); Assert.AreEqual(36, docLoaded.PeptideTransitionCount); var transitions = docLoaded.PeptideTransitions.ToArray(); Assert.AreEqual("y12", transitions[0].FragmentIonName); Assert.AreEqual(1, transitions[0].LibInfo.Rank); Assert.AreEqual("y12", transitions[3].FragmentIonName); Assert.AreEqual(1, transitions[3].LibInfo.Rank); Assert.AreEqual("b3", transitions[14].FragmentIonName); Assert.AreEqual(2, transitions[14].LibInfo.Rank); Assert.AreEqual("b3", transitions[17].FragmentIonName); Assert.AreEqual(2, transitions[17].LibInfo.Rank); var docLibraryChanged = docLoaded.ChangeSettings(docLoaded.Settings.ChangePeptideLibraries( lib => lib.ChangeLibraries(new LibrarySpec[0], new Library[0]) .ChangeLibrarySpecs(new[] { new BiblioSpecLiteSpec("Test reload", libraryPath), }))); docContainer.SetDocument(docLibraryChanged, docLoaded, true); var docChangedLoaded = docContainer.Document; // Check that document changed to be in synch with the library Assert.AreEqual(3, docChangedLoaded.PeptideCount); Assert.AreEqual(18, docChangedLoaded.PeptideTransitionCount); var transitionsNew = docChangedLoaded.PeptideTransitions.ToArray(); Assert.AreEqual("y7", transitionsNew[0].FragmentIonName); Assert.AreEqual(1, transitionsNew[0].LibInfo.Rank); Assert.AreEqual("y7", transitionsNew[3].FragmentIonName); Assert.AreEqual(1, transitionsNew[3].LibInfo.Rank); Assert.AreEqual("y6", transitionsNew[8].FragmentIonName); Assert.AreEqual(2, transitionsNew[8].LibInfo.Rank); Assert.AreEqual("y6", transitionsNew[11].FragmentIonName); Assert.AreEqual(2, transitionsNew[11].LibInfo.Rank); for (int i = 1; i < 3; i++) { Assert.AreSame(transitions[i], transitionsNew[i]); Assert.AreSame(transitions[i + 3], transitionsNew[i + 3]); } for (int i = 12; i < 14; i++) { Assert.AreSame(transitions[i], transitionsNew[i - 6]); Assert.AreSame(transitions[i + 3], transitionsNew[i - 3]); } for (int i = 24; i < 27; i++) { Assert.AreSame(transitions[i], transitionsNew[i - 12]); Assert.AreSame(transitions[i + 3], transitionsNew[i - 9]); } } PeakAnnotationsTest(); }