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(); }
private static void TestInstrumentInfo(string resultsPath, string docCurrentPath) { var docCurrent = ResultsUtil.DeserializeDocument(docCurrentPath); var docContainer = new ResultsTestDocumentContainer(docCurrent, docCurrentPath); string replicateName = Path.GetFileNameWithoutExtension(resultsPath); var lockMassParameters = new LockMassParameters(456.78, 567.89, 12.34); var listChromatograms = new List<ChromatogramSet> { new ChromatogramSet(replicateName, new[] { new MsDataFilePath(resultsPath, lockMassParameters) }) }; // Lockmass values are Waters only so don't expect them to be saved to the doc which has no Waters results // So test the serialization here var stringBuilder = new StringBuilder(); using (var xmlWriter = XmlWriter.Create(stringBuilder)) { xmlWriter.WriteStartDocument(); xmlWriter.WriteStartElement("TestDocument"); xmlWriter.WriteElements(listChromatograms, new XmlElementHelper<ChromatogramSet>()); xmlWriter.WriteEndElement(); xmlWriter.WriteEndDocument(); } var xmlReader = XmlReader.Create(new StringReader(stringBuilder.ToString())); xmlReader.ReadStartElement(); var deserializedObjects = new List<ChromatogramSet>(); xmlReader.ReadElements(deserializedObjects); Assert.AreEqual(1, deserializedObjects.Count); var compare = deserializedObjects[0]; Assert.AreEqual(456.78, compare.MSDataFileInfos[0].FilePath.GetLockMassParameters().LockmassPositive.Value); Assert.AreEqual(567.89, compare.MSDataFileInfos[0].FilePath.GetLockMassParameters().LockmassNegative.Value); Assert.AreEqual(12.34, compare.MSDataFileInfos[0].FilePath.GetLockMassParameters().LockmassTolerance.Value); Assert.AreEqual(listChromatograms[0], compare); // We don't expect any new peptides/precursors/transitions added due to the imported results. var docCurrentResults = docContainer.ChangeMeasuredResults(new MeasuredResults(listChromatograms), 0, 0, 0); WriteDocument(docCurrentResults, docCurrentPath); docCurrentResults = ResultsUtil.DeserializeDocument(docCurrentPath); Assert.IsNotNull(docCurrentResults); AssertEx.IsDocumentState(docCurrentResults, 0, 7, 11, 22, 66); Assert.AreEqual(1, docCurrentResults.Settings.MeasuredResults.Chromatograms.Count); XmlDocument xdoc = new XmlDocument(); xdoc.Load(docCurrentPath); var replicateList = xdoc.SelectNodes("/srm_settings/settings_summary/measured_results/replicate"); Assert.IsNotNull(replicateList); Assert.AreEqual(1, replicateList.Count); var replicate = replicateList.Item(0); Assert.IsNotNull(replicate); var attribs = replicate.Attributes; Assert.IsNotNull(attribs); Assert.AreEqual(replicateName, attribs.GetNamedItem(SrmDocument.ATTR.name).Value); var instrumentList = replicate.SelectNodes("sample_file/instrument_info_list/instrument_info"); Assert.IsNotNull(instrumentList); Assert.AreEqual(1, instrumentList.Count); var instrumentInfo = instrumentList.Item(0); Assert.IsNotNull(instrumentInfo); Assert.IsNotNull(instrumentInfo.Attributes); // model var model = instrumentInfo.SelectSingleNode(ChromatogramSet.EL.model.ToString()); Assert.IsNotNull(model); Assert.IsNotNull(model.FirstChild); Assert.IsTrue(model.FirstChild.NodeType == XmlNodeType.Text); Assert.AreEqual("TSQ Vantage", model.FirstChild.Value); // ion source var ionsource = instrumentInfo.SelectSingleNode(ChromatogramSet.EL.ionsource.ToString()); Assert.IsNotNull(ionsource); Assert.IsNotNull(ionsource.FirstChild); Assert.AreEqual(ionsource.FirstChild.NodeType, XmlNodeType.Text); Assert.AreEqual("nanoelectrospray", ionsource.FirstChild.Value); // analyzer var analyzer = instrumentInfo.SelectSingleNode(ChromatogramSet.EL.analyzer.ToString()); Assert.IsNotNull(analyzer); Assert.IsNotNull(analyzer.FirstChild); Assert.AreEqual(analyzer.FirstChild.NodeType, XmlNodeType.Text); Assert.AreEqual("quadrupole/quadrupole/quadrupole", analyzer.FirstChild.Value); // dectector var detector = instrumentInfo.SelectSingleNode(ChromatogramSet.EL.detector.ToString()); Assert.IsNotNull(detector); Assert.IsNotNull(detector.FirstChild); Assert.AreEqual(detector.FirstChild.NodeType, XmlNodeType.Text); Assert.AreEqual("electron multiplier", detector.FirstChild.Value); }
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] == null) 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); } }
public void DoAsymmetricIsolationTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules) { 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("Asym_DIA.sky"); string cachePath = ChromatogramCache.FinalPathForName(docPath, null); FileEx.SafeDelete(cachePath); SrmDocument doc = ResultsUtil.DeserializeDocument(docPath); var refine = new RefinementSettings(); doc = refine.ConvertToSmallMolecules(doc, asSmallMolecules); const int expectedMoleculeCount = 1; // At first small molecules did not support multiple charge states, and this was 2 for that test mode AssertEx.IsDocumentState(doc, null, 1, expectedMoleculeCount, 2, 4); var fullScanInitial = doc.Settings.TransitionSettings.FullScan; Assert.IsTrue(fullScanInitial.IsEnabledMsMs); Assert.AreEqual(FullScanAcquisitionMethod.DIA, fullScanInitial.AcquisitionMethod); Assert.AreEqual(25, fullScanInitial.PrecursorFilter); AssertEx.Serializable(doc); var docContainer = new ResultsTestDocumentContainer(doc, docPath); // Import the first RAW file (or mzML for international) string rawPath = testFilesDir.GetTestPath("Asym_DIA_data.mzML"); var measuredResults = new MeasuredResults(new[] { new ChromatogramSet("Single", new[] { rawPath }) }); TransitionGroupDocNode nodeGroup; double ratio; { // Import with symmetric isolation window SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2); nodeGroup = docResults.MoleculeTransitionGroups.First(); 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.25, ratio, 0.05); // Revert to original document, and get rid of results cache Assert.IsTrue(docContainer.SetDocument(doc, docResults, false)); FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd")); } { // Import with asymmetric isolation window SrmDocument docAsym = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan => fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test asym", 5, 20)))); AssertEx.Serializable(docAsym); Assert.IsTrue(docContainer.SetDocument(docAsym, doc, false)); SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2); nodeGroup = docResults.MoleculeTransitionGroups.First(); ratio = nodeGroup.Results[0][0].Ratio ?? 0; // Asymmetric should be a lot closer to 1.0 if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only) // Can't use labels without a formula Assert.AreEqual(1.05, ratio, 0.05); // Revert to original document, and get rid of results cache Assert.IsTrue(docContainer.SetDocument(doc, docResults, false)); FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd")); } { // Import with prespecified isolation windows var windowList = new List<IsolationWindow> { new IsolationWindow(999.2702214, 1024.270221), new IsolationWindow(1024.27267, 1049.27267) }; SrmDocument docPrespecified = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan => fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test prespecified", windowList)))); AssertEx.Serializable(docPrespecified); Assert.IsTrue(docContainer.SetDocument(docPrespecified, doc, false)); SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2); nodeGroup = docResults.MoleculeTransitionGroups.First(); ratio = nodeGroup.Results[0][0].Ratio ?? 0; // Asymmetric should be a lot closer to 1.0 if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only) // Can't use labels without a formula Assert.AreEqual(1.05, ratio, 0.05); // Revert to original document, and get rid of results cache Assert.IsTrue(docContainer.SetDocument(doc, docResults, false)); FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd")); } { // Import with prespecified targets var windowList = new List<IsolationWindow> { new IsolationWindow(999.2702214, 1024.270221, 1004.27), new IsolationWindow(1024.27267, 1049.27267, 1029.27) }; SrmDocument docPrespecified = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan => fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test target", windowList)))); AssertEx.Serializable(docPrespecified); Assert.IsTrue(docContainer.SetDocument(docPrespecified, doc, false)); SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2); nodeGroup = docResults.MoleculeTransitionGroups.First(); ratio = nodeGroup.Results[0][0].Ratio ?? 0; // Asymmetric should be a lot closer to 1.0 if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.masses_only) // Can't use labels without a formula Assert.AreEqual(1.05, ratio, 0.05); // Revert to original document, and get rid of results cache Assert.IsTrue(docContainer.SetDocument(doc, docResults, false)); FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd")); } { // Import with ambiguous prespecified targets var windowList = new List<IsolationWindow> { new IsolationWindow(999.2702214, 1024.270221, 1004.27), new IsolationWindow(1000.0, 1049.27267, 1004.28) }; SrmDocument docAmbiguous = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan => fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test ambiguous", windowList)))); AssertEx.Serializable(docAmbiguous); Assert.IsTrue(docContainer.SetDocument(docAmbiguous, doc, false)); try { docContainer.ChangeMeasuredResults(measuredResults, expectedMoleculeCount, 1, 1, 2, 2); Assert.Fail("Expected ambiguous isolation targets."); } catch (Exception x) { AssertEx.AreComparableStrings(Resources.SpectrumFilter_FindFilterPairs_Two_isolation_windows_contain_targets_which_match_the_isolation_target__0__, x.Message, 1); } // Revert to original document, and get rid of results cache Assert.IsTrue(docContainer.SetDocument(doc, docContainer.Document, false)); FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd")); } { // Import with one isolation window, so one result is discarded. var windowList = new List<IsolationWindow> { new IsolationWindow(999.2702214, 1024.270221), }; SrmDocument docOneWindow = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fullScan => fullScan.ChangeAcquisitionMethod(fullScan.AcquisitionMethod, new IsolationScheme("Test one window", windowList)))); AssertEx.Serializable(docOneWindow); Assert.IsTrue(docContainer.SetDocument(docOneWindow, doc, false)); SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, 1, 1, 0, 2, 0); nodeGroup = docResults.MoleculeTransitionGroups.First(); Assert.IsNull(nodeGroup.Results[0][0].Ratio); // Revert to original document, and get rid of results cache Assert.IsTrue(docContainer.SetDocument(doc, docResults, false)); FileEx.SafeDelete(testFilesDir.GetTestPath("Asym_DIA.skyd")); } testFilesDir.Dispose(); }
private void DoFullScanFilterTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules, out List<SrmDocument> docCheckpoints, bool centroided = false) { docCheckpoints = new List<SrmDocument>(); TestSmallMolecules = false; // We test small molecules explicitly var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string docPath = testFilesDir.GetTestPath("BSA_Protea_label_free_20100323_meth3_multi.sky"); var expectedPepCount = 7; var expectedTransGroupCount = 7; var expectedTransCount = 49; var doc = InitFullScanDocument(docPath, 2, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules); if (centroided && ExtensionTestContext.CanImportThermoRaw) { const double ppm20 = 20.0; doc = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorResolution(FullScanMassAnalyzerType.centroided, ppm20, 0))); } 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[] {new MsDataFilePath(rawPath)})}); SrmDocument docResults = docContainer.ChangeMeasuredResults(measuredResults, 3, 3, 21); docCheckpoints.Add(docResults); // Refilter allowing multiple precursors per spectrum SrmDocument docMulti = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan( fs => fs.ChangeAcquisitionMethod(FullScanAcquisitionMethod.DIA, new IsolationScheme("Test", 2)))); AssertEx.Serializable(docMulti, AssertEx.DocumentCloned); // Release data cache file Assert.IsTrue(docContainer.SetDocument(docMulti, docResults)); // And remove it FileEx.SafeDelete(Path.ChangeExtension(docPath, ChromatogramCache.EXT)); docCheckpoints.Add(docContainer.ChangeMeasuredResults(measuredResults, 6, 6, 38)); // Import full scan Orbi-Velos data docPath = testFilesDir.GetTestPath("BSA_Protea_label_free_20100323_meth3_long_acc_template.sky"); expectedPepCount = 3; expectedTransGroupCount = 3; expectedTransCount = 21; doc = InitFullScanDocument(docPath, 1, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules); docCheckpoints.Add(doc); Assert.AreEqual(FullScanMassAnalyzerType.orbitrap, doc.Settings.TransitionSettings.FullScan.ProductMassAnalyzer); // Make sure saving this type of document works AssertEx.Serializable(doc, AssertEx.DocumentCloned); Assert.IsTrue(docContainer.SetDocument(doc, docContainer.Document)); rawPath = testFilesDir.GetTestPath("ah_20101029r_BSA_CID_FT_centroid_3uscan_3" + ExtensionTestContext.ExtThermoRaw); measuredResults = new MeasuredResults(new[] { new ChromatogramSet("Accurate", new[] { rawPath }) }); docCheckpoints.Add(docContainer.ChangeMeasuredResults(measuredResults, 3, 3, 21)); // Import LTQ data with MS1 and MS/MS docPath = testFilesDir.GetTestPath("BSA_Protea_label_free_20100323_meth3_test4.sky"); expectedPepCount = 3; expectedTransGroupCount = 4; expectedTransCount = 32; doc = InitFullScanDocument(docPath, 3, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules); Assert.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.ProductMassAnalyzer); Assert.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.PrecursorMassAnalyzer); docCheckpoints.Add(doc); var docBoth = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs => fs.ChangeAcquisitionMethod(FullScanAcquisitionMethod.Targeted, null) .ChangePrecursorResolution(FullScanMassAnalyzerType.qit, TransitionFullScan.DEFAULT_RES_QIT, null))); docCheckpoints.Add(docBoth); AssertEx.Serializable(docBoth, AssertEx.DocumentCloned); Assert.IsTrue(docContainer.SetDocument(docBoth, docContainer.Document)); string dataPath = testFilesDir.GetTestPath("klc_20100329v_Protea_Peptide_Curve_200fmol_uL_tech1.mzML"); var listResults = new List<ChromatogramSet> { new ChromatogramSet("MS1 and MS/MS", new[] { dataPath }), }; measuredResults = new MeasuredResults(listResults.ToArray()); docCheckpoints.Add(docContainer.ChangeMeasuredResults(measuredResults, expectedPepCount, expectedTransGroupCount, expectedTransCount-6)); // The mzML was filtered for the m/z range 410 to 910. foreach (var nodeTran in docContainer.Document.PeptideTransitions) { Assert.IsTrue(nodeTran.HasResults); Assert.IsNotNull(nodeTran.Results[0]); if (410 > nodeTran.Mz || nodeTran.Mz > 910) Assert.IsTrue(nodeTran.Results[0][0].IsEmpty); else Assert.IsFalse(nodeTran.Results[0][0].IsEmpty); } // Import LTQ data with MS1 and MS/MS using multiple files for a single replicate listResults.Add(new ChromatogramSet("Multi-file", new[] { testFilesDir.GetTestPath("both_DRV.mzML"), testFilesDir.GetTestPath("both_KVP.mzML"), })); measuredResults = new MeasuredResults(listResults.ToArray()); docCheckpoints.Add(docContainer.ChangeMeasuredResults(measuredResults, expectedPepCount - 1, expectedTransGroupCount-1, expectedTransCount-6)); int indexResults = listResults.Count - 1; foreach (var nodeTran in docContainer.Document.PeptideTransitions) { Assert.IsTrue(nodeTran.HasResults); Assert.AreEqual(listResults.Count, nodeTran.Results.Count); var peptide = nodeTran.Transition.Group.Peptide; // DRV without FASTA sequence should not have data for non-precursor transitions if (!peptide.Sequence.StartsWith("DRV") || !peptide.Begin.HasValue) { Assert.IsNotNull(nodeTran.Results[indexResults]); Assert.IsFalse(nodeTran.Results[indexResults][0].IsEmpty); } else if (nodeTran.Transition.IonType != IonType.precursor) Assert.IsNull(nodeTran.Results[indexResults]); else { // Random, bogus peaks chosen in both files Assert.IsNotNull(nodeTran.Results[indexResults]); Assert.AreEqual(2, nodeTran.Results[indexResults].Count); Assert.IsFalse(nodeTran.Results[indexResults][0].IsEmpty); Assert.IsFalse(nodeTran.Results[indexResults][1].IsEmpty); } } if (asSmallMolecules == RefinementSettings.ConvertToSmallMoleculesMode.masses_only) return; // Can't work with isotope distributions when we don't have ion formulas // Verify handling of bad request for vendor centroided data - out-of-range PPM docPath = testFilesDir.GetTestPath("Yeast_HI3 Peptides_test.sky"); expectedPepCount = 2; expectedTransGroupCount = 2; expectedTransCount = 2; doc = InitFullScanDocument(docPath, 2, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules); Assert.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.ProductMassAnalyzer); Assert.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.PrecursorMassAnalyzer); var docBad = doc; AssertEx.ThrowsException<InvalidDataException>(() => docBad.ChangeSettings(docBad.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, IsotopeEnrichments.DEFAULT) .ChangePrecursorResolution(FullScanMassAnalyzerType.centroided, 50 * 1000, 400))), string.Format(Resources.TransitionFullScan_ValidateRes_Mass_accuracy_must_be_between__0__and__1__for_centroided_data_, TransitionFullScan.MIN_CENTROID_PPM,TransitionFullScan.MAX_CENTROID_PPM)); // Verify relationship between PPM and resolving power const double ppm = 20.0; // Should yield same filter width as resolving power 50,000 in TOF var docNoCentroid = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, IsotopeEnrichments.DEFAULT) .ChangePrecursorResolution(FullScanMassAnalyzerType.centroided, ppm, 0))); AssertEx.Serializable(docNoCentroid, AssertEx.DocumentCloned); Assert.IsTrue(docContainer.SetDocument(docNoCentroid, docContainer.Document)); const double mzTest = 400.0; var filterWidth = docNoCentroid.Settings.TransitionSettings.FullScan.GetPrecursorFilterWindow(mzTest); Assert.AreEqual(mzTest * 2.0 * ppm * 1E-6, filterWidth); // Verify handling of bad request for vendor centroided data - ask for centroiding in mzML const string fileName = "S_2_LVN.mzML"; var filePath = testFilesDir.GetTestPath(fileName); AssertEx.ThrowsException<AssertFailedException>(() => { listResults = new List<ChromatogramSet> { new ChromatogramSet("rep1", new[] {new MsDataFilePath(filePath, null, true)}), }; docContainer.ChangeMeasuredResults(new MeasuredResults(listResults.ToArray()), 1, 1, 1); }, string.Format(Resources.NoCentroidedDataException_NoCentroidedDataException_No_centroided_data_available_for_file___0_____Adjust_your_Full_Scan_settings_, fileName)); // Import FT data with only MS1 docPath = testFilesDir.GetTestPath("Yeast_HI3 Peptides_test.sky"); expectedPepCount = 2; expectedTransGroupCount = 2; expectedTransCount = 2; doc = InitFullScanDocument(docPath, 2, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules); Assert.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.ProductMassAnalyzer); Assert.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.PrecursorMassAnalyzer); var docMs1 = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, IsotopeEnrichments.DEFAULT) .ChangePrecursorResolution(FullScanMassAnalyzerType.tof, 50 * 1000, null))); Assert.AreEqual(filterWidth, docMs1.Settings.TransitionSettings.FullScan.GetPrecursorFilterWindow(mzTest)); docMs1 = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, IsotopeEnrichments.DEFAULT) .ChangePrecursorResolution(FullScanMassAnalyzerType.ft_icr, 50 * 1000, mzTest))); AssertEx.Serializable(docMs1, AssertEx.DocumentCloned); Assert.IsTrue(docContainer.SetDocument(docMs1, docContainer.Document)); const string rep1 = "rep1"; listResults = new List<ChromatogramSet> { new ChromatogramSet(rep1, new[] {filePath}), }; measuredResults = new MeasuredResults(listResults.ToArray()); docCheckpoints.Add(docContainer.ChangeMeasuredResults(measuredResults, 1, 1, 1)); // Because of the way the mzML files were filtered, all of the LVN peaks should be present // in the first replicate, and all of the NVN peaks should be present in the other. foreach (var nodeTranGroup in docContainer.Document.MoleculeTransitionGroups) { foreach (var docNode in nodeTranGroup.Children) { var nodeTran = (TransitionDocNode) docNode; Assert.IsTrue(nodeTran.HasResults); Assert.AreEqual(1, nodeTran.Results.Count); if ((nodeTran.Transition.Group.Peptide.IsCustomIon ? nodeTranGroup.CustomIon.Name : nodeTran.Transition.Group.Peptide.Sequence).StartsWith("LVN")) Assert.IsFalse(nodeTran.Results[0][0].IsEmpty); else Assert.IsTrue(nodeTran.Results[0][0].IsEmpty); } } const string rep2 = "rep2"; listResults.Add(new ChromatogramSet(rep2, new[] {testFilesDir.GetTestPath("S_2_NVN.mzML")})); measuredResults = new MeasuredResults(listResults.ToArray()); docCheckpoints.Add(docContainer.ChangeMeasuredResults(measuredResults, 1, 1, 1)); // Because of the way the mzML files were filtered, all of the LVN peaks should be present // in the first replicate, and all of the NVN peaks should be present in the other. foreach (var nodeTranGroup in docContainer.Document.MoleculeTransitionGroups) { foreach (var docNode in nodeTranGroup.Children) { var nodeTran = (TransitionDocNode) docNode; Assert.IsTrue(nodeTran.HasResults); Assert.AreEqual(2, nodeTran.Results.Count); if ((nodeTran.Transition.Group.Peptide.IsCustomIon ? nodeTranGroup.CustomIon.Name : nodeTran.Transition.Group.Peptide.Sequence).StartsWith("LVN")) Assert.IsTrue(nodeTran.Results[1][0].IsEmpty); else Assert.IsFalse(nodeTran.Results[1][0].IsEmpty); } } // Chromatograms should be present in the cache for a number of isotopes. var docMs1Isotopes = docContainer.Document.ChangeSettings(doc.Settings .ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 3, IsotopeEnrichments.DEFAULT)) .ChangeTransitionFilter(filter => filter.ChangeIonTypes(new[] {IonType.precursor}))); docCheckpoints.Add(docMs1Isotopes); AssertEx.IsDocumentState(docMs1Isotopes, null, 2, 2, 2 ); // Need to reset auto-manage for transitions var refineAutoSelect = new RefinementSettings { AutoPickChildrenAll = PickLevel.transitions }; docMs1Isotopes = refineAutoSelect.Refine(docMs1Isotopes); AssertEx.IsDocumentState(docMs1Isotopes, null, 2, 2, 6); AssertResult.IsDocumentResultsState(docMs1Isotopes, rep1, 1, 1, 0, 3, 0); AssertResult.IsDocumentResultsState(docMs1Isotopes, rep2, 1, 1, 0, 3, 0); docCheckpoints.Add(docMs1Isotopes); // Add M-1 transitions, and verify that they have chromatogram data also, but // empty peaks in all cases var docMs1All = docMs1Isotopes.ChangeSettings(docMs1Isotopes.Settings .ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Percent, 0, IsotopeEnrichments.DEFAULT)) .ChangeTransitionIntegration(i => i.ChangeIntegrateAll(false))); // For compatibility with v2.5 and earlier docCheckpoints.Add(docMs1All); AssertEx.IsDocumentState(docMs1All, null, 2, 2, 10); AssertResult.IsDocumentResultsState(docMs1All, rep1, 1, 1, 0, 4, 0); AssertResult.IsDocumentResultsState(docMs1All, rep2, 1, 1, 0, 4, 0); var ms1AllTranstions = docMs1All.MoleculeTransitions.ToArray(); var tranM1 = ms1AllTranstions[0]; Assert.AreEqual(-1, tranM1.Transition.MassIndex); Assert.IsTrue(tranM1.Results[0] != null && tranM1.Results[1] != null); Assert.IsTrue(tranM1.Results[0][0].IsEmpty && tranM1.Results[1][0].IsEmpty); tranM1 = ms1AllTranstions[5]; Assert.AreEqual(-1, tranM1.Transition.MassIndex); Assert.IsTrue(tranM1.Results[0] != null && tranM1.Results[1] != null); Assert.IsTrue(tranM1.Results[0][0].IsEmpty && tranM1.Results[1][0].IsEmpty); }
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); 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() .SetDiscardUnmatchedChromatograms(false) .SetNoiseTimeRange(1.0); string minimized1Path = testFilesDir.GetTestPath("NoiseTimeLimited1.sky"); string minimized2Path = testFilesDir.GetTestPath("NoiseTimeLimited2.sky"); ResultsTestDocumentContainer docContainerMinimized1Min = MinimizeCacheFile(docResults, settings.SetNoiseTimeRange(1.0), minimized1Path); ResultsTestDocumentContainer docContainerMinimized2Min = MinimizeCacheFile(docResults, settings.SetNoiseTimeRange(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[] { chromGroupOriginal.Times[0], chromGroup2.Times[0], chromGroup1.Times[0], chromGroup1.Times[chromGroup1.Times.Length - 1], chromGroup2.Times[chromGroup2.Times.Length - 1], chromGroupOriginal.Times[chromGroupOriginal.Times.Length - 1] }; // 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(chromGroup2.Times[0] > chromGroupOriginal.Times[0] || chromGroup2.Times[chromGroup2.Times.Length - 1] < chromGroupOriginal.Times[chromGroupOriginal.Times.Length - 1]); // 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 (chromGroup2.Times[0] > chromGroupOriginal.Times[0]) { Assert.AreEqual(chromGroup2.Times[0], chromGroup1.Times[0] - 1, .1); } if (chromGroup2.Times[chromGroup2.Times.Length - 1] < chromGroupOriginal.Times[chromGroupOriginal.Times.Length - 1]) { Assert.AreEqual(chromGroup2.Times[chromGroup2.Times.Length - 1], chromGroup1.Times[chromGroup1.Times.Length - 1] + 1, .1); } float[] timesSorted = times.ToArray(); Array.Sort(timesSorted); CollectionAssert.AreEqual(times, timesSorted); } } docContainer.Release(); docContainerMinimized1Min.Release(); docContainerMinimized2Min.Release(); }