public bool Adopt(IScanProvider other) { if (!Equals(DocFilePath, other.DocFilePath) || !Equals(DataFilePath, other.DataFilePath)) { return(false); } var scanProvider = other as ScanProvider; if (scanProvider == null) { return(false); } MeasuredResults thisMeasuredResults, otherMeasuredResults; if (!_measuredResultsReference.TryGetTarget(out thisMeasuredResults) || !scanProvider._measuredResultsReference.TryGetTarget(out otherMeasuredResults)) { return(false); } if (!ReferenceEquals(thisMeasuredResults, otherMeasuredResults)) { return(false); } _dataFile = scanProvider._dataFile; _msDataFileScanIds = scanProvider._msDataFileScanIds; _cachedFile = scanProvider._cachedFile; _measuredResults = scanProvider._measuredResults; scanProvider._dataFile = null; return(true); }
public MeasuredResults UpdateReplicateAnnotations(MeasuredResults measuredResults) { if (measuredResults == null) { return(null); } AnnotationUpdater updater; if (!_annotationUpdaters.TryGetValue(AnnotationDef.AnnotationTarget.replicate, out updater)) { return(measuredResults); } var chromatograms = measuredResults.Chromatograms.ToArray(); for (int replicateIndex = 0; replicateIndex < measuredResults.Chromatograms.Count; replicateIndex++) { var chromatogramSet = chromatograms[replicateIndex]; var replicate = new Replicate(SkylineDataSchema, replicateIndex); var annotations = updater.UpdateAnnotations(chromatogramSet.Annotations, replicate); if (!Equals(annotations, chromatogramSet.Annotations)) { chromatograms[replicateIndex] = chromatogramSet.ChangeAnnotations(annotations); } } if (ArrayUtil.ReferencesEqual(measuredResults.Chromatograms, chromatograms)) { return(measuredResults); } return(measuredResults.ChangeChromatograms(chromatograms)); }
protected ChromInfoData(MeasuredResults measuredResults, int replicateIndex, ChromFileInfo chromFileInfo, ChromInfo chromInfo) { MeasuredResults = measuredResults; ReplicateIndex = replicateIndex; ChromFileInfo = chromFileInfo; ChromInfo = chromInfo; }
private void RemoveCorrespondingLibraryRunsForReplicates() { if (listLibraries.Items.Count != 0) { foreach (var chrom in ChromatogramsRemovedList) { foreach (var chromFileInfo in chrom.MSDataFileInfos) { foreach (var documentLibrary in DocumentLibraries) { foreach (var dataFile in documentLibrary.LibraryFiles.FilePaths) { if (MeasuredResults.IsBaseNameMatch(chromFileInfo.FilePath.GetFileNameWithoutExtension(), Path.GetFileNameWithoutExtension(dataFile))) { int foundIndex = listLibraries.FindString(dataFile); if (ListBox.NoMatches != foundIndex) { LibraryRunsRemovedList.Add(dataFile); listLibraries.Items.RemoveAt(foundIndex); if (listLibraries.Items.Count == 0) { return; } } } } } } } } }
public void TryMatch(string potentialMatch, bool overwrite) { if (string.IsNullOrEmpty(potentialMatch)) { return; } foreach (var spectrumSourceFile in SpectrumSourceFiles.Keys) { if (spectrumSourceFile == null || (!overwrite && SpectrumSourceFiles[spectrumSourceFile].HasMatches)) { continue; } if (Path.GetFileName(spectrumSourceFile).Equals(Path.GetFileName(potentialMatch))) { if (overwrite || !SpectrumSourceFiles[spectrumSourceFile].HasExactMatch) { SpectrumSourceFiles[spectrumSourceFile].ExactMatch = potentialMatch; } } else if (MeasuredResults.IsBaseNameMatch(Path.GetFileNameWithoutExtension(spectrumSourceFile), Path.GetFileNameWithoutExtension(potentialMatch)) && (overwrite || !SpectrumSourceFiles[spectrumSourceFile].HasAlternateMatch)) { SpectrumSourceFiles[spectrumSourceFile].AlternateMatch = potentialMatch; } } }
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); } } }
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 void CancelLoad(MeasuredResults results) { if (results.StatusLoading != null) { _manager.UpdateProgress(results.StatusLoading.Cancel()); } _manager.EndProcessing(_document); }
public ChromatogramExporter(SrmDocument document) { Document = document; _settings = Document.Settings; _measuredResults = _settings.MeasuredResults; _matchTolerance = (float)_settings.TransitionSettings.Instrument.MzMatchTolerance; _chromatogramSets = _measuredResults.Chromatograms; }
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(); }
protected ChromInfoData(MeasuredResults measuredResults, int replicateIndex, ChromFileInfo chromFileInfo, ChromInfo chromInfo, PeptideDocNode peptideDocNode, TransitionGroupDocNode transitionGroupDocNode) { MeasuredResults = measuredResults; ReplicateIndex = replicateIndex; ChromFileInfo = chromFileInfo; ChromInfo = chromInfo; PeptideDocNode = peptideDocNode; TransitionGroupDocNode = transitionGroupDocNode; }
public void TestBaseNameMatch() { Assert.IsTrue(MeasuredResults.IsBaseNameMatch("BaseName123", "BaseName123.wiff")); Assert.IsTrue(MeasuredResults.IsBaseNameMatch("BaseName123.c", "BaseName123")); Assert.IsTrue(MeasuredResults.IsBaseNameMatch("BaseName123.c", "BASENAME123")); Assert.IsTrue(MeasuredResults.IsBaseNameMatch("BASENAME123", "basename123")); Assert.IsFalse(MeasuredResults.IsBaseNameMatch("BaseName123", "BaseName123-wiff")); Assert.IsFalse(MeasuredResults.IsBaseNameMatch("BaseName123", "BaseName123_wiff")); Assert.IsFalse(MeasuredResults.IsBaseNameMatch("BaseName123", "BaseName1234")); Assert.IsFalse(MeasuredResults.IsBaseNameMatch("BaseName1234", "BaseName123")); }
public ScanProvider(string docFilePath, MsDataFileUri dataFilePath, ChromSource source, IList <float> times, TransitionFullScanInfo[] transitions, MeasuredResults measuredResults) { DocFilePath = docFilePath; DataFilePath = dataFilePath; Source = source; Times = times; Transitions = transitions; _measuredResults = measuredResults; _measuredResultsReference = new WeakReference <MeasuredResults>(measuredResults); }
public static ResultNameMap <RetentionTimeSource> ListSourcesForResults(MeasuredResults results, ResultNameMap <RetentionTimeSource> availableSources) { if (results == null) { return(ResultNameMap <RetentionTimeSource> .EMPTY); } var sourcesForResults = results.Chromatograms .SelectMany(chromatogramSet => chromatogramSet.MSDataFileInfos) .Select(availableSources.Find); return(ResultNameMap.FromNamedElements(sourcesForResults.Where(source => null != source))); }
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 void FinishLoad(string documentPath, MeasuredResults resultsLoad, bool changeSets) { if (resultsLoad == null) { // Loading was cancelled _manager.EndProcessing(_document); return; } SrmDocument docNew, docCurrent; do { docCurrent = _container.Document; var results = docCurrent.Settings.MeasuredResults; // If current document has no results, then cancel if (results == null) { CancelLoad(resultsLoad); return; } try { using (var settingsChangeMonitor = new SrmSettingsChangeMonitor(new LoadMonitor(_manager, _container, null), Resources.Loader_FinishLoad_Updating_peak_statistics, _container, docCurrent)) { if (changeSets) { // Result is empty cache, due to cancelation results = resultsLoad.Chromatograms.Count != 0 ? resultsLoad : null; docNew = docCurrent.ChangeMeasuredResults(results, settingsChangeMonitor); } else { // Otherwise, switch to new cache results = results.UpdateCaches(documentPath, resultsLoad); docNew = docCurrent.ChangeMeasuredResults(results, settingsChangeMonitor); } } } catch (OperationCanceledException) { // Restart the processing form the top docNew = null; } }while (docNew == null || !_manager.CompleteProcessing(_container, docNew, docCurrent)); // Force a document changed event to keep progressive load going // until it is complete _manager.OnDocumentChanged(_container, new DocumentChangedEventArgs(docCurrent)); }
private void FinishLoad(string documentPath, MeasuredResults resultsLoad, MeasuredResults resultsPrevious) { if (resultsLoad == null) { // Loading was cancelled _manager.EndProcessing(_document); return; } SrmDocument docNew, docCurrent; do { docCurrent = _container.Document; var results = docCurrent.Settings.MeasuredResults; // If current document has no results, then cancel if (results == null) { CancelLoad(resultsLoad); return; } else if (results.IsLoaded) { // No need to continue _manager.EndProcessing(_document); return; } try { using (var settingsChangeMonitor = new SrmSettingsChangeMonitor(new LoadMonitor(_manager, _container, null), Resources.Loader_FinishLoad_Updating_peak_statistics, _container, docCurrent)) { // First remove any chromatogram sets that were removed during processing results = results.ApplyChromatogramSetRemovals(resultsLoad, resultsPrevious); // Then update caches if (results != null) { results = results.UpdateCaches(documentPath, resultsLoad); } docNew = docCurrent.ChangeMeasuredResults(results, settingsChangeMonitor); } } catch (OperationCanceledException) { // Restart the processing form the top docNew = null; } }while (docNew == null || !_manager.CompleteProcessing(_container, docNew, docCurrent)); }
private static IDictionary <ChromFileInfoId, Tuple <ChromatogramSet, ChromFileInfo> > GetChromSetInfos( MeasuredResults measuredResults) { var dict = new Dictionary <ChromFileInfoId, Tuple <ChromatogramSet, ChromFileInfo> >( new ChromFileIdEqualityComparer()); foreach (var chromatogramSet in measuredResults.Chromatograms) { foreach (var chromFileInfo in chromatogramSet.MSDataFileInfos) { dict.Add(chromFileInfo.FileId, new Tuple <ChromatogramSet, ChromFileInfo>(chromatogramSet, chromFileInfo)); } } return(dict); }
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(); }
/// <summary> /// Retrieve a run of raw spectra with common retention time and changing ion mobility, or a single raw spectrum if no drift info /// </summary> /// <param name="internalScanIndex">an index in pwiz.Skyline.Model.Results space</param> /// <param name="ignoreZeroIntensityPoints">display uses want zero intensity points, data processing uses typically do not</param> /// <returns>Array of spectra with the same retention time (potentially different ion mobility values for IMS, or just one spectrum)</returns> public MsDataSpectrum[] GetMsDataFileSpectraWithCommonRetentionTime(int internalScanIndex, bool ignoreZeroIntensityPoints) { var spectra = new List <MsDataSpectrum>(); if (_measuredResults != null) { _msDataFileScanIds = _measuredResults.LoadMSDataFileScanIds(DataFilePath, out _cachedFile); _measuredResults = null; } int dataFileSpectrumStartIndex = internalScanIndex; // For backward compatibility support SKYD files that did not store scan ID bytes if (_msDataFileScanIds != null) { var scanIdText = _msDataFileScanIds.GetMsDataFileSpectrumId(internalScanIndex); dataFileSpectrumStartIndex = GetDataFile(ignoreZeroIntensityPoints).GetSpectrumIndex(scanIdText); // TODO(brendanx): Improve this error message post-UI freeze // if (dataFileSpectrumStartIndex == -1) // throw new ArgumentException(string.Format("The stored scan ID {0} was not found in the file {1}.", scanIdText, DataFilePath)); } var currentSpectrum = GetDataFile(ignoreZeroIntensityPoints).GetSpectrum(dataFileSpectrumStartIndex); spectra.Add(currentSpectrum); if (currentSpectrum.IonMobilities != null) // Sort combined IMS spectra by m/z order { ArrayUtil.Sort(currentSpectrum.Mzs, currentSpectrum.Intensities, currentSpectrum.IonMobilities); } else if (currentSpectrum.IonMobility.HasValue) // Look ahead for uncombined IMS spectra { // Look for spectra with identical retention time and changing ion mobility values while (true) { dataFileSpectrumStartIndex++; var nextSpectrum = GetDataFile(ignoreZeroIntensityPoints).GetSpectrum(dataFileSpectrumStartIndex); if (!nextSpectrum.IonMobility.HasValue || nextSpectrum.RetentionTime != currentSpectrum.RetentionTime) { break; } spectra.Add(nextSpectrum); currentSpectrum = nextSpectrum; } } return(spectra.ToArray()); }
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); } }
public SrmDocument ChangeMeasuredResults(MeasuredResults measuredResults, int peptides, int tranGroups, int tranGroupsHeavy, int transitions, int transitionsHeavy) { var doc = Document; var docResults = doc.ChangeMeasuredResults(measuredResults); ResetProgress(); Assert.IsTrue(SetDocument(docResults, doc, true)); AssertComplete(); docResults = Document; // Check the result state of the most recently added chromatogram set. var chroms = measuredResults.Chromatograms; AssertResult.IsDocumentResultsState(docResults, chroms[chroms.Count - 1].Name, peptides, tranGroups, tranGroupsHeavy, transitions, transitionsHeavy); return(docResults); }
private void TestRemoveOneReplicateAndCorrespondingLibraryRuns() { var chromatograms = SkylineWindow.Document.Settings.MeasuredResults.Chromatograms; var chromToRemove = chromatograms[0]; List <string> dataFilesToRemove = new List <string>(); foreach (var chromFileInfo in chromToRemove.MSDataFileInfos) { foreach (var dataFile in DocumentLibrary.LibraryFiles.FilePaths) { if (MeasuredResults.IsBaseNameMatch(chromFileInfo.FilePath.GetFileNameWithoutExtension(), Path.GetFileNameWithoutExtension(dataFile))) { dataFilesToRemove.Add(dataFile); } } } using (new WaitDocumentChange(null, true)) { RunDlg <ManageResultsDlg>(SkylineWindow.ManageResults, dlg => { dlg.SelectReplicatesTab(); dlg.SelectedChromatograms = new[] { chromToRemove }; dlg.RemoveReplicates(); dlg.IsRemoveCorrespondingLibraries = true; dlg.OkDialog(); }); } // Make sure the replicate was removed var updatedChromatograms = SkylineWindow.Document.Settings.MeasuredResults.Chromatograms; var findChrom = updatedChromatograms.FirstOrDefault(chrom => ReferenceEquals(chrom, chromToRemove)); Assert.IsNull(findChrom); // Make sure the library runs corresponding to the replicate were removed foreach (var dataFile in dataFilesToRemove) { Assert.IsFalse(DocumentLibrary.LibraryFiles.FilePaths.Contains(dataFile)); } }
private static bool EqualExceptAnnotations(MeasuredResults measuredResultsNew, MeasuredResults measuredResultsOld) { if (ReferenceEquals(measuredResultsNew, measuredResultsOld)) { return true; } if (measuredResultsNew == null || measuredResultsOld == null) { return false; } if (measuredResultsNew.Chromatograms.Count != measuredResultsOld.Chromatograms.Count) { return false; } if (!ArrayUtil.EqualsDeep(measuredResultsNew.CachedFilePaths.ToArray(), measuredResultsOld.CachedFilePaths.ToArray())) { return false; } for (int i = 0; i < measuredResultsNew.Chromatograms.Count; i++) { var chromatogramSetNew = measuredResultsNew.Chromatograms[i].ChangeAnnotations(Annotations.EMPTY).ChangeUseForRetentionTimeFilter(false) .ChangeAnalyteConcentration(null).ChangeSampleType(SampleType.DEFAULT); var chromatogramSetOld = measuredResultsOld.Chromatograms[i].ChangeAnnotations(Annotations.EMPTY).ChangeUseForRetentionTimeFilter(false) .ChangeAnalyteConcentration(null).ChangeSampleType(SampleType.DEFAULT); if (!chromatogramSetNew.Equals(chromatogramSetOld)) { return false; } } return true; }
private TransitionChromInfoData(MeasuredResults measuredResults, int replicateIndex, ChromFileInfo chromFileInfo, TransitionChromInfo transitionChromInfo, PeptideDocNode peptideDocNode, TransitionGroupDocNode transitionGroupDocNode, TransitionDocNode transitionDocNode) : base(measuredResults, replicateIndex, chromFileInfo, transitionChromInfo, peptideDocNode, transitionGroupDocNode) { TransitionDocNode = transitionDocNode; }
private void FinishLoad(string documentPath, MeasuredResults resultsLoad, bool changeSets) { if (resultsLoad == null) { // Loading was cancelled _manager.EndProcessing(_document); return; } SrmDocument docNew, docCurrent; do { docCurrent = _container.Document; var results = docCurrent.Settings.MeasuredResults; // If current document has no results, then cancel if (results == null) { CancelLoad(resultsLoad); return; } try { using (var settingsChangeMonitor = new SrmSettingsChangeMonitor(new LoadMonitor(_manager, _container, null), Resources.Loader_FinishLoad_Updating_peak_statistics, _container, docCurrent)) { if (changeSets) { // Result is empty cache, due to cancelation results = resultsLoad.Chromatograms.Count != 0 ? resultsLoad : null; docNew = docCurrent.ChangeMeasuredResults(results, settingsChangeMonitor); } else { // Otherwise, switch to new cache results = results.UpdateCaches(documentPath, resultsLoad); docNew = docCurrent.ChangeMeasuredResults(results, settingsChangeMonitor); } } } catch (OperationCanceledException) { // Restart the processing form the top docNew = null; } } while (docNew == null || !_manager.CompleteProcessing(_container, docNew, docCurrent)); // Force a document changed event to keep progressive load going // until it is complete _manager.OnDocumentChanged(_container, new DocumentChangedEventArgs(docCurrent)); }
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(); }
public static IList<ICollection<TransitionGroupChromInfoData>> GetTransitionGroupChromInfoDatas(MeasuredResults measuredResults, Results<TransitionGroupChromInfo> transitionGroupResults) { var list = new List<ICollection<TransitionGroupChromInfoData>>(); if (null == transitionGroupResults) { return list; } Assume.IsTrue(transitionGroupResults.Count == measuredResults.Chromatograms.Count, string.Format("Unexpected mismatch between precursor results {0} and chromatogram sets {1}", transitionGroupResults.Count, measuredResults.Chromatograms.Count)); // Not L10N? Will users see this? for (int replicateIndex = 0; replicateIndex < transitionGroupResults.Count; replicateIndex++) { var datas = new List<TransitionGroupChromInfoData>(); var chromatograms = measuredResults.Chromatograms[replicateIndex]; var transitionGroupChromInfos = transitionGroupResults[replicateIndex]; if (transitionGroupChromInfos == null) datas.Add(new TransitionGroupChromInfoData(measuredResults, replicateIndex, null, null)); else { foreach (var transitionGroupChromInfo in transitionGroupChromInfos) { var chromFileInfo = chromatograms.GetFileInfo(transitionGroupChromInfo.FileId); datas.Add(new TransitionGroupChromInfoData(measuredResults, replicateIndex, chromFileInfo, transitionGroupChromInfo)); } } list.Add(datas); } return list; }
private SrmDocument ImportFiles(SrmDocument docOrig, ILongWaitBroker longWaitBroker, IList<string> filePaths, MeasuredResults.MergeAction resultsAction, bool mergePeptides, IdentityPath to, out IdentityPath firstAdded) { firstAdded = null; var docResult = docOrig; int filesRead = 0; // Add files in reverse order, so their nodes will end up in the right order. IdentityPath first = null; foreach (var filePath in filePaths) { if (longWaitBroker != null) { if (longWaitBroker.IsCanceled || longWaitBroker.IsDocumentChanged(docOrig)) return docOrig; longWaitBroker.ProgressValue = filesRead*100/filePaths.Count; longWaitBroker.Message = string.Format(Resources.SkylineWindow_ImportFiles_Importing__0__, Path.GetFileName(filePath)); } using (var reader = new StreamReader(filePath)) { IdentityPath firstAddedForFile, nextAdd; docResult = docResult.ImportDocumentXml(reader, filePath, resultsAction, mergePeptides, FindSpectralLibrary, Settings.Default.StaticModList, Settings.Default.HeavyModList, to, out firstAddedForFile, out nextAdd, false); // Add the next document at the specified location to = nextAdd; // Store the first added node only for the first document if (first == null) first = firstAddedForFile; } filesRead++; } firstAdded = first; return docResult; }
public static ResultNameMap<RetentionTimeSource> ListSourcesForResults(MeasuredResults results, ResultNameMap<RetentionTimeSource> availableSources) { if (results == null) { return ResultNameMap<RetentionTimeSource>.EMPTY; } var sourcesForResults = results.Chromatograms .SelectMany(chromatogramSet => chromatogramSet.MSDataFileInfos) .Select(availableSources.Find); return ResultNameMap.FromNamedElements(sourcesForResults.Where(source => null != source)); }
private bool EnsureChromInfo(MeasuredResults results, ChromatogramSet chromatograms, TransitionGroupDocNode[] nodeGroups, IdentityPath[] groupPaths, ChromExtractor extractor, out bool changedGroups, out bool changedGroupIds) { if (UpdateGroups(nodeGroups, groupPaths, out changedGroups, out changedGroupIds) && _extractor == extractor) return true; _extractor = extractor; bool success = false; try { // Get chromatogram sets for all transition groups, recording unique // file paths in the process. var listArrayChromInfo = new List<ChromatogramGroupInfo[]>(); var listFiles = new List<MsDataFileUri>(); ChromatogramGroupInfo[] arrayAllIonsChromInfo; if (!results.TryLoadAllIonsChromatogram(chromatograms, extractor, true, out arrayAllIonsChromInfo)) { return false; } else { listArrayChromInfo.Add(arrayAllIonsChromInfo); foreach (var chromInfo in arrayAllIonsChromInfo) { var filePath = chromInfo.FilePath; if (!listFiles.Contains(filePath)) listFiles.Add(filePath); } } _hasMergedChromInfo = false; _arrayChromInfo = new ChromatogramGroupInfo[listFiles.Count][]; for (int i = 0; i < _arrayChromInfo.Length; i++) { var arrayNew = new ChromatogramGroupInfo[listArrayChromInfo.Count]; for (int j = 0; j < arrayNew.Length; j++) { var arrayChromInfo = listArrayChromInfo[j]; if (arrayChromInfo == null) continue; foreach (var chromInfo in arrayChromInfo) { if (arrayNew[j] == null && Equals(listFiles[i], chromInfo.FilePath)) arrayNew[j] = chromInfo; } } _arrayChromInfo[i] = arrayNew; } success = true; } finally { // Make sure the info array is set to null on failure. if (!success) _arrayChromInfo = null; } return true; }
private bool EnsureChromInfo(MeasuredResults results, ChromatogramSet chromatograms, PeptideDocNode[] nodePeps, TransitionGroupDocNode[] nodeGroups, IdentityPath[] groupPaths, float mzMatchTolerance, out bool changedGroups, out bool changedGroupIds) { if (UpdateGroups(nodeGroups, groupPaths, out changedGroups, out changedGroupIds) && !_extractor.HasValue) return true; _extractor = null; bool success = false; try { // Get chromatogram sets for all transition groups, recording unique // file paths in the process. var listArrayChromInfo = new List<ChromatogramGroupInfo[]>(); var listFiles = new List<MsDataFileUri>(); for (int i = 0; i < nodeGroups.Length; i++) { ChromatogramGroupInfo[] arrayChromInfo; if (!results.TryLoadChromatogram( chromatograms, nodePeps[i], nodeGroups[i], mzMatchTolerance, true, out arrayChromInfo)) { listArrayChromInfo.Add(null); continue; } listArrayChromInfo.Add(arrayChromInfo); foreach (var chromInfo in arrayChromInfo) { var filePath = chromInfo.FilePath; if (!listFiles.Contains(filePath)) listFiles.Add(filePath); } } // If no data was found, then return false if (listFiles.Count == 0) return false; // Make a list of chromatogram info by unique file path corresponding // to the groups passed in. _arrayChromInfo = new ChromatogramGroupInfo[listFiles.Count][]; for (int i = 0; i < _arrayChromInfo.Length; i++) { var arrayNew = new ChromatogramGroupInfo[listArrayChromInfo.Count]; for (int j = 0; j < arrayNew.Length; j++) { var arrayChromInfo = listArrayChromInfo[j]; if (arrayChromInfo == null) continue; foreach (var chromInfo in arrayChromInfo) { if (arrayNew[j] == null && Equals(listFiles[i], chromInfo.FilePath)) arrayNew[j] = chromInfo; } } _arrayChromInfo[i] = arrayNew; } // If multiple replicate files contain mutually exclusive data, create "all files" option. var mergedChromGroupInfo = GetMergedChromInfo(); _hasMergedChromInfo = (mergedChromGroupInfo != null); if (_hasMergedChromInfo) { var arrayNew = new ChromatogramGroupInfo[_arrayChromInfo.Length + 1][]; arrayNew[0] = mergedChromGroupInfo; for (int i = 1; i < arrayNew.Length; i++) arrayNew[i] = _arrayChromInfo[i - 1]; _arrayChromInfo = arrayNew; } success = true; } finally { // Make sure the info array is set to null on failure. if (!success) _arrayChromInfo = null; } return true; }
public SrmDocument ChangeMeasuredResults(MeasuredResults measuredResults, int peptides, int tranGroups, int transitions) { return ChangeMeasuredResults(measuredResults, peptides, tranGroups, 0, transitions, 0); }
public SrmDocument ChangeMeasuredResults(MeasuredResults measuredResults, int peptides, int tranGroups, int tranGroupsHeavy, int transitions, int transitionsHeavy) { var doc = Document; var docResults = doc.ChangeMeasuredResults(measuredResults); ResetProgress(); Assert.IsTrue(SetDocument(docResults, doc, true)); AssertComplete(); docResults = Document; // Check the result state of the most recently added chromatogram set. var chroms = measuredResults.Chromatograms; AssertResult.IsDocumentResultsState(docResults, chroms[chroms.Count - 1].Name, peptides, tranGroups, tranGroupsHeavy, transitions, transitionsHeavy); return docResults; }
public void DoAsymmetricIsolationTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules) { if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none && !RunSmallMoleculeTestVersions) { Console.Write(MSG_SKIPPING_SMALLMOLECULE_TEST_VERSION); return; } 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, testFilesDir.FullPath, 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); using (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; const double poorRatio = 0.25; const double fixedRatio = 1.05; { // 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(poorRatio, 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(fixedRatio, 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(fixedRatio, 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(fixedRatio, 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 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 static IList <ICollection <PeptideChromInfoData> > GetPeptideChromInfoDatas(MeasuredResults measuredResults, PeptideDocNode peptideDocNode) { var list = new List <ICollection <PeptideChromInfoData> >(); var peptideResults = peptideDocNode.Results; if (null == peptideResults) { return(list); } Assume.IsTrue(peptideResults.Count == measuredResults.Chromatograms.Count, string.Format(@"Unexpected mismatch between precursor results {0} and chromatogram sets {1}", peptideResults.Count, measuredResults.Chromatograms.Count)); // CONSIDER: localize? Will users see this? for (int replicateIndex = 0; replicateIndex < peptideResults.Count; replicateIndex++) { var datas = new List <PeptideChromInfoData>(); var chromatograms = measuredResults.Chromatograms[replicateIndex]; var peptideChromInfos = peptideResults[replicateIndex]; if (peptideChromInfos.IsEmpty) { datas.Add(new PeptideChromInfoData(measuredResults, replicateIndex, null, null, peptideDocNode)); } else { foreach (var peptideChromInfo in peptideChromInfos) { var chromFileInfo = chromatograms.GetFileInfo(peptideChromInfo.FileId); datas.Add(new PeptideChromInfoData(measuredResults, replicateIndex, chromFileInfo, peptideChromInfo, peptideDocNode)); } } list.Add(datas); } return(list); }
public SrmSettings ChangeMeasuredResults(MeasuredResults prop) { return ChangeProp(ImClone(this), im => im.MeasuredResults = prop); }
private PeptideChromInfoData(MeasuredResults measuredResults, int replicateIndex, ChromFileInfo chromFileInfo, PeptideChromInfo peptideChromInfo, PeptideDocNode peptideDocNode) : base(measuredResults, replicateIndex, chromFileInfo, peptideChromInfo, peptideDocNode, null) { }
private void DoFullScanFilterTest(RefinementSettings.ConvertToSmallMoleculesMode asSmallMolecules, out List <SrmDocument> docCheckpoints, bool centroided = false) { docCheckpoints = new List <SrmDocument>(); 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(ref 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))); } 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[] { 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 Assume.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(ref docPath, 1, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules); docCheckpoints.Add(doc); Assume.AreEqual(FullScanMassAnalyzerType.orbitrap, doc.Settings.TransitionSettings.FullScan.ProductMassAnalyzer); // Make sure saving this type of document works AssertEx.Serializable(doc, AssertEx.DocumentCloned); Assume.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(ref docPath, 3, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules); Assume.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.ProductMassAnalyzer); Assume.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); Assume.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.MoleculeTransitions) { Assume.IsTrue(nodeTran.HasResults); Assume.IsNotNull(nodeTran.Results[0]); if (410 > nodeTran.Mz || nodeTran.Mz > 910) { Assume.IsTrue(nodeTran.Results[0][0].IsForcedIntegration); } else { Assume.IsFalse(nodeTran.Results[0][0].IsForcedIntegration); } } // 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)); if (asSmallMolecules == RefinementSettings.ConvertToSmallMoleculesMode.masses_only) { return; // Can't work with isotope distributions when we don't have ion formulas } int indexResults = listResults.Count - 1; var matchIdentifierDRV = "DRV"; if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none) { matchIdentifierDRV = RefinementSettings.TestingConvertedFromProteomicPeptideNameDecorator + matchIdentifierDRV; } int index = 0; foreach (var nodeTran in docContainer.Document.MoleculeTransitions) { Assume.IsTrue(nodeTran.HasResults); Assume.AreEqual(listResults.Count, nodeTran.Results.Count); var peptide = nodeTran.Transition.Group.Peptide; if (peptide.IsCustomMolecule && index == 24) { // Conversion to small molecule loses some of the nuance of "Sequence" vs "FastaSequence", comparisons are inexact Assume.AreEqual("pep_DRVY[+80.0]IHPF", nodeTran.PrimaryCustomIonEquivalenceKey); break; } // DRV without FASTA sequence should not have data for non-precursor transitions if (!peptide.TextId.StartsWith(matchIdentifierDRV) || (!peptide.IsCustomMolecule && !peptide.Begin.HasValue)) { Assume.IsNotNull(nodeTran.Results[indexResults]); Assume.IsFalse(nodeTran.Results[indexResults][0].IsEmpty); } else if (nodeTran.Transition.IonType != IonType.precursor) { Assert.IsTrue(nodeTran.Results[indexResults].IsEmpty); } else { // Random, bogus peaks chosen in both files Assume.IsNotNull(nodeTran.Results[indexResults]); Assume.AreEqual(2, nodeTran.Results[indexResults].Count); Assume.IsFalse(nodeTran.Results[indexResults][0].IsEmpty); Assume.IsFalse(nodeTran.Results[indexResults][1].IsEmpty); } index++; } // 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(ref docPath, 2, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules); Assume.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.ProductMassAnalyzer); Assume.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, IsotopeEnrichmentsList.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, IsotopeEnrichmentsList.DEFAULT) .ChangePrecursorResolution(FullScanMassAnalyzerType.centroided, ppm, 0))); AssertEx.Serializable(docNoCentroid, AssertEx.DocumentCloned); Assume.IsTrue(docContainer.SetDocument(docNoCentroid, docContainer.Document)); const double mzTest = 400.0; var filterWidth = docNoCentroid.Settings.TransitionSettings.FullScan.GetPrecursorFilterWindow(mzTest); Assume.AreEqual(mzTest * 2.0 * ppm * 1E-6, filterWidth); // Verify relationship between normal and high-selectivity extraction var docTofNormal = docNoCentroid.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorResolution(FullScanMassAnalyzerType.tof, 50 * 1000, null))); AssertEx.Serializable(docTofNormal, AssertEx.DocumentCloned); var docTofSelective = docTofNormal.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorResolution(FullScanMassAnalyzerType.tof, 25 * 1000, null) .ChangeUseSelectiveExtraction(true))); AssertEx.Serializable(docTofSelective, AssertEx.DocumentCloned); var filterWidthTof = docTofNormal.Settings.TransitionSettings.FullScan.GetPrecursorFilterWindow(mzTest); var filterWidthSelective = docTofSelective.Settings.TransitionSettings.FullScan.GetPrecursorFilterWindow(mzTest); Assume.AreEqual(filterWidth, filterWidthTof); Assume.AreEqual(filterWidth, filterWidthSelective); // 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) }), }; 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_, filePath)); // Import FT data with only MS1 docPath = testFilesDir.GetTestPath("Yeast_HI3 Peptides_test.sky"); expectedPepCount = 2; expectedTransGroupCount = 2; expectedTransCount = 2; doc = InitFullScanDocument(ref docPath, 2, ref expectedPepCount, ref expectedTransGroupCount, ref expectedTransCount, asSmallMolecules); Assume.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.ProductMassAnalyzer); Assume.AreEqual(FullScanMassAnalyzerType.none, doc.Settings.TransitionSettings.FullScan.PrecursorMassAnalyzer); var docMs1 = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, IsotopeEnrichmentsList.DEFAULT) .ChangePrecursorResolution(FullScanMassAnalyzerType.tof, 50 * 1000, null))); Assume.AreEqual(filterWidth, docMs1.Settings.TransitionSettings.FullScan.GetPrecursorFilterWindow(mzTest)); docMs1 = doc.ChangeSettings(doc.Settings.ChangeTransitionFullScan(fs => fs.ChangePrecursorIsotopes(FullScanPrecursorIsotopes.Count, 1, IsotopeEnrichmentsList.DEFAULT) .ChangePrecursorResolution(FullScanMassAnalyzerType.ft_icr, 50 * 1000, mzTest))); AssertEx.Serializable(docMs1, AssertEx.DocumentCloned); Assume.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. var matchIdentifierLVN = "LVN"; if (asSmallMolecules != RefinementSettings.ConvertToSmallMoleculesMode.none) { matchIdentifierLVN = RefinementSettings.TestingConvertedFromProteomicPeptideNameDecorator + matchIdentifierLVN; } foreach (var nodeTranGroup in docContainer.Document.MoleculeTransitionGroups) { foreach (var docNode in nodeTranGroup.Children) { var nodeTran = (TransitionDocNode)docNode; Assume.IsTrue(nodeTran.HasResults); Assume.AreEqual(1, nodeTran.Results.Count); if (nodeTran.Transition.Group.Peptide.Target.ToString().StartsWith(matchIdentifierLVN)) { Assume.IsFalse(nodeTran.Results[0][0].IsEmpty); } else { Assume.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; Assume.IsTrue(nodeTran.HasResults); Assume.AreEqual(2, nodeTran.Results.Count); if (nodeTran.Transition.Group.Peptide.Target.ToString().StartsWith(matchIdentifierLVN)) { Assume.IsTrue(nodeTran.Results[1][0].IsEmpty); } else { Assume.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, IsotopeEnrichmentsList.DEFAULT)) .ChangeTransitionFilter(filter => filter.ChangePeptideIonTypes(new[] { IonType.precursor }) .ChangeSmallMoleculeIonTypes(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, IsotopeEnrichmentsList.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].IsEmpty && !tranM1.Results[1].IsEmpty); Assert.IsTrue(tranM1.Results[0][0].IsEmpty && tranM1.Results[1][0].IsForcedIntegration); tranM1 = ms1AllTranstions[5]; Assert.AreEqual(-1, tranM1.Transition.MassIndex); Assert.IsTrue(!tranM1.Results[0].IsEmpty && !tranM1.Results[1].IsEmpty); Assert.IsTrue(tranM1.Results[0][0].IsForcedIntegration && tranM1.Results[1][0].IsEmpty); } }
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); }
private static ChromatogramSet GetChromatogramByName(string name, MeasuredResults results) { return (results == null ? null : results.Chromatograms.FirstOrDefault(set => Equals(name, set.Name))); }
public SrmDocument ImportResults(SrmDocument doc, List<KeyValuePair<string, MsDataFileUri[]>> namedResults, string optimize) { OptimizableRegression optimizationFunction = doc.Settings.TransitionSettings.Prediction.GetOptimizeFunction(optimize); if (namedResults.Count == 1) return ImportResults(doc, namedResults[0].Key, namedResults[0].Value, optimizationFunction); // Add all chosen files as separate result sets. var results = doc.Settings.MeasuredResults; var listChrom = new List<ChromatogramSet>(); if (results != null) listChrom.AddRange(results.Chromatograms); foreach (var namedResult in namedResults) { string nameResult = namedResult.Key; // Skip results that have already been loaded. if (GetChromatogramByName(nameResult, results) != null) continue; // Delete caches that will be overwritten FileEx.SafeDelete(ChromatogramCache.FinalPathForName(DocumentFilePath, nameResult), true); listChrom.Add(new ChromatogramSet(nameResult, namedResult.Value, Annotations.EMPTY, optimizationFunction)); } var arrayChrom = listChrom.ToArray(); if (arrayChrom.Length == 0) { results = null; } else { if (results == null) { results = new MeasuredResults(arrayChrom); } else { results = results.ChangeChromatograms(arrayChrom); } } if (results != null && Program.DisableJoining) results = results.ChangeIsJoiningDisabled(true); return doc.ChangeMeasuredResults(results); }
public SrmDocument ChangeMeasuredResults(MeasuredResults measuredResults, int peptides, int tranGroups, int transitions) { return(ChangeMeasuredResults(measuredResults, peptides, tranGroups, 0, transitions, 0)); }
private SrmDocument ImportResults(SrmDocument doc, string nameResult, IEnumerable<MsDataFileUri> dataSources, OptimizableRegression optimizationFunction) { var results = doc.Settings.MeasuredResults; var chrom = GetChromatogramByName(nameResult, results); if (chrom == null) { // If the chromatogram, is not in the current set, then delete the cache // file to make sure it is not on disk before starting. FileEx.SafeDelete(ChromatogramCache.FinalPathForName(DocumentFilePath, nameResult), true); chrom = new ChromatogramSet(nameResult, dataSources, Annotations.EMPTY, optimizationFunction); if (results == null) results = new MeasuredResults(new[] {chrom}); else { // Add the new result to the end. var listChrom = new List<ChromatogramSet>(results.Chromatograms) {chrom}; results = results.ChangeChromatograms(listChrom.ToArray()); } } else { // Append to an existing chromatogram set var dataFilePaths = new List<MsDataFileUri>(chrom.MSDataFilePaths); foreach (var sourcePath in dataSources) { if (!dataFilePaths.Contains(sourcePath)) dataFilePaths.Add(sourcePath); } // If no new paths added, just return without changing. if (dataFilePaths.Count == chrom.FileCount) return doc; int replaceIndex = results.Chromatograms.IndexOf(chrom); var arrayChrom = results.Chromatograms.ToArray(); arrayChrom[replaceIndex] = chrom.ChangeMSDataFilePaths(dataFilePaths); results = results.ChangeChromatograms(arrayChrom); } if (results != null && Program.DisableJoining) results = results.ChangeIsJoiningDisabled(true); return doc.ChangeMeasuredResults(results); }
private TransitionChromInfoData(MeasuredResults measuredResults, int replicateIndex, ChromFileInfo chromFileInfo, TransitionChromInfo transitionChromInfo) : base(measuredResults, replicateIndex, chromFileInfo, transitionChromInfo) { }
private void CancelLoad(MeasuredResults results) { if (results.StatusLoading != null) _manager.UpdateProgress(results.StatusLoading.Cancel()); _manager.EndProcessing(_document); }
public IEnumerable <SkylineDocumentProto.Types.TransitionPeak> GetTransitionPeakProtos(MeasuredResults measuredResults) { if (Results == null) { yield break; } for (int replicateIndex = 0; replicateIndex < Results.Count; replicateIndex++) { var replicateResults = Results[replicateIndex]; if (replicateResults.IsEmpty) { continue; } foreach (var transitionChromInfo in replicateResults) { if (transitionChromInfo == null) { continue; } var transitionPeak = new SkylineDocumentProto.Types.TransitionPeak(); transitionPeak.OptimizationStep = transitionChromInfo.OptimizationStep; if (null != transitionChromInfo.Annotations) { transitionPeak.Annotations = transitionChromInfo.Annotations.ToProtoAnnotations(); } transitionPeak.ReplicateIndex = replicateIndex; transitionPeak.FileIndexInReplicate = measuredResults.Chromatograms[replicateIndex].IndexOfId(transitionChromInfo.FileId); transitionPeak.MassError = DataValues.ToOptional(transitionChromInfo.MassError); transitionPeak.RetentionTime = transitionChromInfo.RetentionTime; transitionPeak.StartRetentionTime = transitionChromInfo.StartRetentionTime; transitionPeak.EndRetentionTime = transitionChromInfo.EndRetentionTime; transitionPeak.IonMobility = DataValues.ToOptional(transitionChromInfo.IonMobility.IonMobility.Mobility); transitionPeak.IonMobilityWindow = DataValues.ToOptional(transitionChromInfo.IonMobility.IonMobilityExtractionWindowWidth); transitionPeak.Area = transitionChromInfo.Area; transitionPeak.BackgroundArea = transitionChromInfo.BackgroundArea; transitionPeak.Height = transitionChromInfo.Height; transitionPeak.Fwhm = transitionChromInfo.Fwhm; transitionPeak.IsFwhmDegenerate = transitionChromInfo.IsFwhmDegenerate; transitionPeak.Truncated = DataValues.ToOptional(transitionChromInfo.IsTruncated); transitionPeak.UserSet = DataValues.ToUserSet(transitionChromInfo.UserSet); transitionPeak.ForcedIntegration = transitionChromInfo.IsForcedIntegration; switch (transitionChromInfo.Identified) { case PeakIdentification.ALIGNED: transitionPeak.Identified = SkylineDocumentProto.Types.PeakIdentification.Aligned; break; case PeakIdentification.FALSE: transitionPeak.Identified = SkylineDocumentProto.Types.PeakIdentification.False; break; case PeakIdentification.TRUE: transitionPeak.Identified = SkylineDocumentProto.Types.PeakIdentification.True; break; } transitionPeak.Rank = transitionChromInfo.Rank; transitionPeak.RankByLevel = transitionChromInfo.RankByLevel; transitionPeak.PointsAcrossPeak = DataValues.ToOptional(transitionChromInfo.PointsAcrossPeak); yield return(transitionPeak); } } }
public static IList <ICollection <TransitionChromInfoData> > GetTransitionChromInfoDatas(MeasuredResults measuredResults, PeptideDocNode peptideDocNode, TransitionGroupDocNode transitionGroupDocNode, TransitionDocNode transitionDocNode) { var transitionResults = transitionDocNode.Results; var list = new List <ICollection <TransitionChromInfoData> >(); if (null == transitionResults) { return(list); } Assume.IsTrue(transitionResults.Count == measuredResults.Chromatograms.Count, string.Format(@"Unexpected mismatch between transition results {0} and chromatogram sets {1}", transitionResults.Count, measuredResults.Chromatograms.Count)); // CONSIDER: localize? for (int replicateIndex = 0; replicateIndex < transitionResults.Count; replicateIndex++) { var datas = new List <TransitionChromInfoData>(); var chromatograms = measuredResults.Chromatograms[replicateIndex]; var transitionChromInfos = transitionResults[replicateIndex]; if (transitionChromInfos.IsEmpty) { datas.Add(new TransitionChromInfoData(measuredResults, replicateIndex, null, null, peptideDocNode, transitionGroupDocNode, transitionDocNode)); } else { foreach (var transitionChromInfo in transitionChromInfos) { var chromFileInfo = chromatograms.GetFileInfo(transitionChromInfo.FileId); datas.Add(new TransitionChromInfoData(measuredResults, replicateIndex, chromFileInfo, transitionChromInfo, peptideDocNode, transitionGroupDocNode, transitionDocNode)); } } list.Add(datas); } return(list); }
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 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(); }