public void AgilentFileTypeTest() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string extRaw = ExtensionTestContext.ExtAgilentRaw; // Do file type check using (var msData = new MsDataFileImpl(testFilesDir.GetTestPath("081809_100fmol-MichromMix-05" + extRaw))) { Assert.IsTrue(msData.IsAgilentFile); } }
public ChromatogramDataProvider(MsDataFileImpl dataFile, ChromFileInfo fileInfo, ProgressStatus status, int startPercent, int endPercent, IProgressMonitor loader) : base(fileInfo, status, startPercent, endPercent, loader) { _dataFile = dataFile; if (_dataFile.IsThermoFile) { _readMaxMinutes = 4; } int len = dataFile.ChromatogramCount; _chromIndices = new int[len]; bool fixCEOptForShimadzu = dataFile.IsShimadzuFile; int indexPrecursor = -1; double lastPrecursor = 0; for (int i = 0; i < len; i++) { int index; string id = dataFile.GetChromatogramId(i, out index); if (!ChromKey.IsKeyId(id)) continue; var chromKey = ChromKey.FromId(id, fixCEOptForShimadzu); if (chromKey.Precursor != lastPrecursor) { lastPrecursor = chromKey.Precursor; indexPrecursor++; } var ki = new KeyValuePair<ChromKey, int>(chromKey, index); _chromIndices[index] = indexPrecursor; _chromIds.Add(ki); } // Shimadzu can't do the necessary product m/z stepping for itself. // So, they provide the CE values in their IDs and we need to adjust // product m/z values for them to support CE optimization. if (fixCEOptForShimadzu) FixCEOptForShimadzu(); if (_chromIds.Count == 0) throw new NoSrmDataException(dataFile.FilePath); SetPercentComplete(50); }
private static void VerifyInstrumentInfo(string path, string model, string ionization, string analyzer, string detector) { using (var msDataFile = new MsDataFileImpl(path)) { var instrumentInfoList = msDataFile.GetInstrumentConfigInfoList().ToList(); Assert.AreEqual(1, instrumentInfoList.Count); var instrument = instrumentInfoList[0]; Assert.IsFalse(instrument.IsEmpty); Assert.AreEqual(model, instrument.Model); Assert.AreEqual(ionization, instrument.Ionization); Assert.AreEqual(analyzer, instrument.Analyzer); Assert.AreEqual(detector, instrument.Detector); } }
public void FileTypeTest() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string extWiff = ExtensionTestContext.ExtAbWiff; string suffix = ExtensionTestContext.CanImportAbWiff ? "" : "-test"; // Do file type checks using (var msData = new MsDataFileImpl(testFilesDir.GetTestPath("051309_digestion" + suffix + extWiff))) { Assert.IsTrue(msData.IsABFile); } using (var msData = new MsDataFileImpl(testFilesDir.GetTestPath("051309_digestion-s3.mzXML"))) { Assert.IsTrue(msData.IsABFile); Assert.IsTrue(msData.IsMzWiffXml); } }
public static bool HasSpectrumData(MsDataFileImpl dataFile) { return dataFile.SpectrumCount > 0; }
/// <summary> /// Releases and returns the data file associated with this instance, ending any asynchronous processing /// </summary> public MsDataFileImpl Detach() { MsDataFileImpl dataFile; lock (_dataFileLock) { dataFile = _dataFile; _dataFile = null; } if (_runningAsync) { // Just in case the Read thread is waiting to add a spectrum to a full pening list SpectrumInfo info; _pendingInfoList.TryTake(out info); } return dataFile; }
public SpectraChromDataProvider(MsDataFileImpl dataFile, ChromFileInfo fileInfo, SrmDocument document, IRetentionTimePredictor retentionTimePredictor, string cachePath, // We'll write tempfiles in this directory ProgressStatus status, int startPercent, int endPercent, IProgressMonitor loader) : base(fileInfo, status, startPercent, endPercent, loader) { _document = document; _filePath = dataFile.FilePath; _cachePath = cachePath; // If no SRM spectra, then full-scan filtering must be enabled _isSrm = dataFile.HasSrmSpectra; if (!_isSrm) { if (!document.Settings.TransitionSettings.FullScan.IsEnabled) throw new NoFullScanFilteringException(dataFile.FilePath); // Only use the retention time predictor on non-SRM data, and only when // there are enough transitions to cause performance issues with extracting // full-gradient in a single pass, and then trimming. if (_document.Settings.TransitionSettings.FullScan.RetentionTimeFilterType == RetentionTimeFilterType.scheduling_windows && _document.MoleculeTransitionCount > MAX_FULL_GRADIENT_TRANSITIONS) { _retentionTimePredictor = retentionTimePredictor; } } // Only mzXML from mzWiff requires the introduction of zero values // during interpolation. _isProcessedScans = dataFile.IsMzWiffXml; UpdatePercentComplete(); // Create the filter responsible for chromatogram extraction bool firstPass = (_retentionTimePredictor != null); _filter = new SpectrumFilter(_document, FileInfo.FilePath, new DataFileInstrumentInfo(dataFile), _retentionTimePredictor, firstPass); if (!_isSrm && (_filter.EnabledMs || _filter.EnabledMsMs)) { // Full-scan filtering should always match a single precursor // m/z value to a single precursor node in the document tree, // because that is the way the filters are constructed in the // first place. _isSingleMzMatch = true; } // Get data object used to graph all of the chromatograms. if (_loader.HasUI) _allChromData = LoadingStatus.Transitions; try { InitSpectrumReader(dataFile); InitChromatogramExtraction(); } catch(Exception) { // If exception thrown before construction is complete than Dispose will not be called. if (_spectra == null) dataFile.Dispose(); else _spectra.Dispose(); throw; } }
public void Redisplay() { if (!IsHandleCreated) { return; } if (_inRedisplay) { return; } try { _inRedisplay = true; tbxMinCharge.Text = MinCharge.ToString(); tbxMaxCharge.Text = MaxCharge.ToString(); tbxPeptideSequence.Text = PeptideSequence; cbxShowPeptideMzs.Enabled = !string.IsNullOrEmpty(PeptideSequence); tbxMassAccuracy.Text = MassAccuracy.ToString(); TurnoverCalculator turnoverCalculator = null; if (!string.IsNullOrEmpty(PeptideSequence)) { turnoverCalculator = new TurnoverCalculator(Workspace, PeptideSequence); } msGraphControlEx1.GraphPane.GraphObjList.Clear(); msGraphControlEx1.GraphPane.CurveList.Clear(); if (_spectrumData == null || comboChromatogram.SelectedIndex >= 0 && null == _chromatogramDatas[comboChromatogram.SelectedIndex]) { using (var msDataFileImpl = new MsDataFileImpl(Workspace.GetDataFilePath(MsDataFile.Name))) { if (comboChromatogram.SelectedIndex >= 0 && null == _chromatogramDatas[comboChromatogram.SelectedIndex]) { string chromatogramName; float[] timeArray; float[] intensityArray; msDataFileImpl.GetChromatogram(comboChromatogram.SelectedIndex, out chromatogramName, out timeArray, out intensityArray); _chromatogramDatas[comboChromatogram.SelectedIndex] = new ChromatogramData(chromatogramName, timeArray, intensityArray); } _spectrumData = _spectrumData ?? new SpectrumData(msDataFileImpl, ScanIndex); } } ChromatogramData chromatogram = null; if (comboChromatogram.SelectedIndex >= 0) { chromatogram = _chromatogramDatas[comboChromatogram.SelectedIndex]; } tbxMsLevel.Text = _spectrumData.MsLevel.ToString(); tbxTime.Text = _spectrumData.Time.ToString(); if (chromatogram != null && ScanIndex < chromatogram.TimeArray.Length) { tbxChromatogramRetentionTime.Text = chromatogram.TimeArray[ScanIndex].ToString(); tbxChromatogramIonCurrent.Text = chromatogram.IntensityArray[ScanIndex].ToString(NumberFormat); } else { tbxChromatogramRetentionTime.Text = tbxChromatogramIonCurrent.Text = @"N/A"; } if (cbxShowProfile.Checked && _spectrumData.ProfileMzs != null) { msGraphControlEx1.AddGraphItem(msGraphControlEx1.GraphPane, new SpectrumGraphItem() { Points = new PointPairList(_spectrumData.ProfileMzs, _spectrumData.ProfileIntensities), GraphItemDrawMethod = MSGraphItemDrawMethod.line, Color = Color.Blue, }); } if (_spectrumData.ProfileIntensities != null) { tbxSumOfProfileIntensities.Text = _spectrumData.ProfileIntensities.Sum().ToString(NumberFormat); } else { tbxSumOfProfileIntensities.Text = ""; } tbxCentroidIntensitySum.Text = _spectrumData.CentroidIntensities.Sum().ToString(NumberFormat); var spectrum = new SpectrumGraphItem { Points = new PointPairList(_spectrumData.CentroidMzs, _spectrumData.CentroidIntensities), GraphItemDrawMethod = MSGraphItemDrawMethod.stick, Color = Color.Black }; if (turnoverCalculator != null) { var mzRanges = new Dictionary<MzRange, String>(); double monoisotopicMass = Workspace.GetAminoAcidFormulas().GetMonoisotopicMass(PeptideSequence); double peptideIntensity = 0.0; for (int charge = MinCharge; charge <= MaxCharge; charge ++) { foreach (var mzRange in turnoverCalculator.GetMzs(charge)) { double mass = (mzRange.Center - AminoAcidFormulas.ProtonMass)* charge; double massDifference = mass - monoisotopicMass; var label = massDifference.ToString("0.#"); if (label[0] != '-') { label = "+" + label; } label = "M" + label; label += new string('+', charge); mzRanges.Add(mzRange, label); var chromatogramPoint = MsDataFileUtil.GetPoint(mzRange, _spectrumData.CentroidMzs, _spectrumData.CentroidIntensities); peptideIntensity += chromatogramPoint.GetIntensity(mzRange, MassAccuracy); } } spectrum.MassAccuracy = MassAccuracy; spectrum.MzRanges = mzRanges; tbxPeptideIntensity.Text = peptideIntensity.ToString(NumberFormat); } if (cbxShowCentroids.Checked) { msGraphControlEx1.AddGraphItem(msGraphControlEx1.GraphPane, spectrum); } if (turnoverCalculator != null && cbxShowPeptideMzs.Checked) { double massAccuracy = MassAccuracy; for (int charge = MinCharge; charge <= MaxCharge; charge++) { var mzs = turnoverCalculator.GetMzs(charge); var height = int.MaxValue; foreach (var mzRange in mzs) { double min = mzRange.MinWithMassAccuracy(massAccuracy); double max = mzRange.MaxWithMassAccuracy(massAccuracy); msGraphControlEx1.GraphPane.GraphObjList.Add(new BoxObj(min, height, max - min, height, Color.Goldenrod, Color.Goldenrod) { IsClippedToChartRect = true, ZOrder = ZOrder.F_BehindGrid }); } } } msGraphControlEx1.Invalidate(); } finally { _inRedisplay = false; } }
private MsDataFileImpl GetDataFile() { if (_dataFile == null) { string dataFilePath = FindDataFilePath(); var lockMassParameters = DataFilePath.GetLockMassParameters(); if (dataFilePath == null) throw new FileNotFoundException(string.Format(Resources.ScanProvider_GetScans_The_data_file__0__could_not_be_found__either_at_its_original_location_or_in_the_document_or_document_parent_folder_, DataFilePath)); int sampleIndex = SampleHelp.GetPathSampleIndexPart(dataFilePath); if (sampleIndex == -1) sampleIndex = 0; // Full-scan extraction always uses SIM as spectra _dataFile = new MsDataFileImpl(dataFilePath, sampleIndex, lockMassParameters, true, requireVendorCentroidedMS1: DataFilePath.GetCentroidMs1(), requireVendorCentroidedMS2: DataFilePath.GetCentroidMs2()); } return _dataFile; }
public OverlapDemultiplexer(MsDataFileImpl file, SpectrumFilter filter) : base(file, filter) { _isoMapper = new OverlapIsolationWindowMapper(); _overlapRegionsInApprox = 7; }
public MsxTypeDemultiplexer(MsDataFileImpl file, SpectrumFilter filter) : base(file, filter) { }
private static void TestOverlapIsolationWindowMapper(AbstractIsoWindowMapper isoMapper, MsDataFileImpl file) { // ReSharper disable once CollectionNeverQueried.Local var isoWinList = new List<IsoWin>(); // Useful for debugging Assert.AreEqual(40,isoMapper.NumWindows); Assert.AreEqual(41,isoMapper.NumDeconvRegions); // Check that each isolation window has two overlap regions with mz values that are contained in it for (int isoIndex = 0; isoIndex < isoMapper.NumWindows; ++isoIndex) { IsoWin isoWin = isoMapper.GetIsolationWindow(isoIndex); isoWinList.Add(isoWin); Assert.AreEqual(2, isoWin.DeconvRegions.Count); for (int i = 0; i < isoWin.DeconvRegions.Count; ++i) { // Check self-consistency of each deconvRegion in the isolation window var deconvRegion = isoWin.DeconvRegions[i]; var deconvIndex = deconvRegion.Id; Assert.AreEqual(deconvRegion.Start, isoMapper.GetDeconvRegion(deconvIndex).Start); Assert.AreEqual(deconvRegion.Stop, isoMapper.GetDeconvRegion(deconvIndex).Stop); Assert.AreEqual(deconvRegion.Id, isoMapper.GetDeconvRegion(deconvIndex).Id); Assert.IsTrue(isoWin.Contains(deconvRegion)); Assert.IsTrue(isoWin.Start <= deconvRegion.Start && isoWin.Stop >= deconvRegion.Stop); double deconvRegionCenter = (deconvRegion.StartMz + deconvRegion.StopMz) / 2.0; int newDeconvIndex; isoMapper.TryGetDeconvFromMz(deconvRegionCenter, out newDeconvIndex); Assert.AreEqual(deconvIndex, newDeconvIndex); int[] isosForDeconv; isoMapper.TryGetIsosForDeconv(deconvIndex, out isosForDeconv); // 2 isolation windows cover this deconv region, unless it's at beginning or end int deconvInIsos = deconvRegion.Id == 0 || deconvRegion.Id == isoMapper.NumDeconvRegions - 1 ? 1 : 2; Assert.IsTrue(isosForDeconv.Length == deconvInIsos); foreach (var isoForDeconv in isosForDeconv) { IsoWin isoWindow = isoMapper.GetIsolationWindow(isoForDeconv); Assert.IsTrue(isoWindow.Contains(deconvRegion)); } } } }
private static void TestSpectrumProcessor(TransitionBinner transBinner,AbstractIsoWindowMapper isoMapper, MsDataFileImpl file, int testSpectrumNum) { int lastSpectrum = testSpectrumNum + 60; int firstSpectrum = testSpectrumNum - 60; var spectrumProcessor = new SpectrumProcessor(lastSpectrum + 1, isoMapper, transBinner); // Make a new spectrum processor using the testing constructor that takes in // a TransitionBinner, which will be the one used for overlap // Add the spectra to the cache +/- 60 from the spectrum of interest for (int i = firstSpectrum; i <= lastSpectrum; ++i) { var spectrum = file.GetSpectrum(i); spectrumProcessor.AddSpectrum(i, spectrum); } // Check that the caching worked correctly for (int spectrumIndex = firstSpectrum; spectrumIndex <= lastSpectrum; ++spectrumIndex) { ScanCached specData; Assert.IsTrue(spectrumProcessor.TryGetSpectrum(spectrumIndex, out specData)); // Check that the cached processing results match the output of // redoing the processing manually by extracting the spectrum from // the file again and using transBinner to bin the data var testSpectrum = file.GetSpectrum(spectrumIndex); double[] expectedBinnedData = new double[transBinner.NumBins]; transBinner.BinData(testSpectrum.Mzs, testSpectrum.Intensities, ref expectedBinnedData); ScanCached testSpecData; spectrumProcessor.TryGetSpectrum(spectrumIndex, out testSpecData); var seenBinnedData = testSpecData.Data; Assert.AreEqual(expectedBinnedData.Length, seenBinnedData.Length); for (int i = 0; i < expectedBinnedData.Length; ++i) { Assert.AreEqual(expectedBinnedData[i], seenBinnedData[i], 0.0001); } } }
public void TestOverlap(SrmDocument doc, string dataPath) { // Load the file and check MsDataFileImpl using (var file = new MsDataFileImpl(dataPath)) { var filter = new SpectrumFilter(doc, null, null); Assert.IsTrue(filter.EnabledMsMs); var demultiplexer = new OverlapDemultiplexer(file, filter); demultiplexer.ForceInitializeFile(); // Check that the demultiplexer found the correct multiplexing parameters Assert.AreEqual(1, demultiplexer.IsoWindowsPerScan); Assert.AreEqual(40, demultiplexer.NumIsoWindows); Assert.AreEqual(41, demultiplexer.NumDeconvRegions); var isoMapper = demultiplexer.IsoMapperTest; // Basic checks of IsolationWindowMapper TestIsolationWindowMapper(isoMapper, file, 20.009); // Checks of overlap-specific functionality in IsolationWindowMapper TestOverlapIsolationWindowMapper(isoMapper, file); var transBinner = new TransitionBinner(filter, isoMapper); // Test creation of a transition binner from a spectrum filter TestTransitionBinnerFromFilter(transBinner, isoMapper); var testSpectrum = file.GetSpectrum(TEST_SPECTRUM_OVERLAP); // Generate a transition binner containing a lot of tough cases with // overlapping transitions and test double[] binnedExpected = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 }; var transBinnerOverlap = TestTransitionBinnerOverlap(testSpectrum, isoMapper, binnedExpected); TestSpectrumProcessor(transBinnerOverlap, isoMapper, file, TEST_SPECTRUM_OVERLAP); int[] intensityIndices = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 290, 291, 292, 293, 294, 295, 296}; double[] intensityValues = { 0.0, 0.0, 0.0, 0.0, 4545.85, 15660.49, 35050.01, 56321.66, 62715.75, 43598.31, 23179.42, 2745.94, 3870.54, 4060.16, 3148.17, 1656.38, 0.0, 0.0 }; // Test demultiplexing of a real spectrum TestSpectrumDemultiplex(demultiplexer, TEST_SPECTRUM_OVERLAP, testSpectrum, intensityIndices, intensityValues, 0); } }
private static void TestIsolationWindowMapper(AbstractIsoWindowMapper isoMapper, MsDataFileImpl file, double width) { // Check the first five spectra in the file for (int checkIndex = 0 ; checkIndex < 5; ++checkIndex) { var spectrum = file.GetSpectrum(checkIndex); var precursors = spectrum.Precursors; List<int> isoIndices = new List<int>(); // Make sure that each precursor read from the file is included in the isolation // window mapper foreach (var precursor in precursors) { int index; Assert.IsTrue(precursor.IsolationMz.HasValue); Assert.IsTrue(isoMapper.TryGetWindowIndex(precursor.IsolationMz.Value, out index)); isoIndices.Add(index); } int[] isoIndicesFromMapper; int[] overlapIndicesFromMapper; double[] mask = new double[isoMapper.NumWindows]; // Make sure the isolation windows called from GetWindowMask match those // extracted from the spectrum manually above using TryGetWindowIndex isoMapper.GetWindowMask(spectrum, out isoIndicesFromMapper, out overlapIndicesFromMapper, ref mask); Assert.AreEqual(isoIndices.Count,isoIndicesFromMapper.Length); foreach (int index in isoIndicesFromMapper) { Assert.IsTrue(isoIndices.Contains(index)); } // Make sure the overlapIndicesFromMapper matches the mask for (int i = 0; i < mask.Length; ++i) { if (mask[i] < 0.5) Assert.AreEqual(0.0, mask[i]); else { Assert.AreEqual(1.0, mask[i]); Assert.IsTrue(overlapIndicesFromMapper.Contains(i)); } } } var testMzs = new[] {553.49, 623.7, 859, 658.55, 768.7, 621.52}; // For each test m/z, get the matching isolation window from isoMapper and // make sure the m/z does indeed fall within the window foreach (var checkMz in testMzs) { int windowIndex; Assert.IsTrue(isoMapper.TryGetWindowFromMz(checkMz, out windowIndex)); var matchWindowCenterMz = isoMapper.GetPrecursor(windowIndex); Assert.IsTrue(matchWindowCenterMz.IsolationMz.HasValue); // Check that mz is within window (width/2 ) Assert.IsTrue(Math.Abs(matchWindowCenterMz.IsolationMz.Value - checkMz) < width/2); } // Test out of range precursors int dummyIndex; Assert.IsFalse(isoMapper.TryGetDeconvFromMz(315.25, out dummyIndex)); Assert.AreEqual(-1, dummyIndex); Assert.IsFalse(isoMapper.TryGetDeconvFromMz(1005.2, out dummyIndex)); Assert.AreEqual(-1, dummyIndex); }
public override bool IsWatersLockmassCorrectionCandidate() { string filePath = GetFilePath(); // Has to be a Waters .raw file, not just an mzML translation of one if (String.IsNullOrEmpty(filePath)) return false; // Not even a file if (!GetFilePath().ToLowerInvariant().EndsWith(".raw")) // Not L10N return false; // Return without even opening the file if (!Directory.Exists(filePath)) return false; // Thermo .raw is a file, Waters .raw is actually a directory try { using (var f = new MsDataFileImpl(filePath)) return f.IsWatersLockmassCorrectionCandidate; } catch (Exception) { return false; // whatever that was, it wasn't a Waters lockmass file } }
protected void TestUsePredictedTime() { const double FILTER_LENGTH = 2.7; RunUI(() => SkylineWindow.OpenFile(TestFilesDir.GetTestPath("RetentionTimeFilterTest.sky"))); WaitForDocumentLoaded(); RunUI(() => SkylineWindow.SaveDocument(TestFilesDir.GetTestPath("TestUsePredictedTime.sky"))); SetUiDocument(ChangeFullScanSettings(SkylineWindow.Document, SkylineWindow.Document.Settings.TransitionSettings.FullScan .ChangeRetentionTimeFilter(RetentionTimeFilterType.scheduling_windows, FILTER_LENGTH))); Assert.IsNull(SkylineWindow.Document.Settings.PeptideSettings.Prediction.RetentionTime); Assert.IsFalse(SkylineWindow.Document.Settings.PeptideSettings.Prediction.UseMeasuredRTs); // When we try to import a file, we should get an error about not having a peptide prediction algorithm var messageDlg = ShowDialog<MessageDlg>(() => SkylineWindow.ImportResults()); RunUI(() => { Assert.AreEqual(Resources.SkylineWindow_CheckRetentionTimeFilter_NoPredictionAlgorithm, messageDlg.Message); messageDlg.Close(); }); var ssrCalcRegression = new RetentionTimeRegression("SSRCALC_FOR_RtFilterTest", new RetentionScoreCalculator(RetentionTimeRegression.SSRCALC_100_A), .63, 5.8, 1.4, new MeasuredRetentionTime[0]); // Now give the document a prediction algorithm SetUiDocument(ChangePeptidePrediction(SkylineWindow.Document, SkylineWindow.Document.Settings.PeptideSettings. Prediction.ChangeRetentionTime(ssrCalcRegression))); // Now import two result files { var importResultsDlg = ShowDialog<ImportResultsDlg>(SkylineWindow.ImportResults); var openDataSourceDialog = ShowDialog<OpenDataSourceDialog>(importResultsDlg.OkDialog); RunUI(() => { openDataSourceDialog.SelectFile("200fmol" + extension); openDataSourceDialog.SelectFile("20fmol" + extension); }); OkDialog(openDataSourceDialog, openDataSourceDialog.Open); } WaitForResultsImport(); { var document = WaitForDocumentLoaded(); foreach (var chromatogramSet in document.Settings.MeasuredResults.Chromatograms) { foreach (var tuple in LoadAllChromatograms(document, chromatogramSet)) { var peptide = tuple.Item1; if (!peptide.IsProteomic) continue; var transitionGroup = tuple.Item2; var predictedRetentionTime = ssrCalcRegression.GetRetentionTime( document.Settings.GetModifiedSequence(peptide.Peptide.Sequence, transitionGroup.TransitionGroup.LabelType, peptide.ExplicitMods)).Value; AssertChromatogramWindow(document, chromatogramSet, predictedRetentionTime - FILTER_LENGTH, predictedRetentionTime + FILTER_LENGTH, tuple.Item3); } } } ChromatogramSet chromSetForScheduling = SkylineWindow.Document.Settings.MeasuredResults.Chromatograms[1]; // Create a SrmDocument with just the one ChromatogramSet that we are going to use for scheduling, so that // we can assert later that the chromatogram windows are where this document says they should be. SrmDocument documentForScheduling = SkylineWindow.Document.ChangeMeasuredResults( SkylineWindow.Document.Settings.MeasuredResults.ChangeChromatograms(new[] {chromSetForScheduling})); SetUiDocument(ChangePeptidePrediction(SkylineWindow.Document, SkylineWindow.Document.Settings.PeptideSettings .Prediction.ChangeUseMeasuredRTs(true).ChangeRetentionTime(null))); { var chooseSchedulingReplicatesDlg = ShowDialog<ChooseSchedulingReplicatesDlg>(SkylineWindow.ImportResults); // Choose a scheduling replicate (the one saved above) RunUI(() => Assert.IsTrue(chooseSchedulingReplicatesDlg.TrySetReplicateChecked( chromSetForScheduling, true))); var importResultsDlg = ShowDialog<ImportResultsDlg>(chooseSchedulingReplicatesDlg.OkDialog); var openDataSourceDialog = ShowDialog<OpenDataSourceDialog>(importResultsDlg.OkDialog); RunUI(()=>openDataSourceDialog.SelectFile("40fmol" + extension)); OkDialog(openDataSourceDialog, openDataSourceDialog.Open); } WaitForResultsImport(); { var document = WaitForDocumentLoaded(); var chromatogramSet = document.Settings.MeasuredResults.Chromatograms.First(cs => cs.Name == "40fmol"); int countNull = 0; foreach (var tuple in LoadAllChromatograms(document, chromatogramSet)) { var prediction = new PeptidePrediction(null, null, true, 1, false, 0); double windowRtIgnored; var schedulingPeptide = documentForScheduling.Molecules.First(pep => ReferenceEquals(pep.Peptide, tuple.Item1.Peptide)); var schedulingTransitionGroup = (TransitionGroupDocNode) schedulingPeptide.FindNode(tuple.Item2.TransitionGroup); double? predictedRt = prediction.PredictRetentionTime(documentForScheduling, schedulingPeptide, schedulingTransitionGroup, null, ExportSchedulingAlgorithm.Average, true, out windowRtIgnored); if (!predictedRt.HasValue) { countNull++; continue; } AssertChromatogramWindow(document, chromatogramSet, predictedRt.Value - FILTER_LENGTH, predictedRt.Value + FILTER_LENGTH, tuple.Item3); } Assert.AreEqual((TestSmallMolecules ? 1 : 0), countNull); } // Test using iRT with auto-calculated regression { const string calcName = "TestCalculator"; const string regressionName = "TestCalculatorAutoCalcRegression"; var peptideSettingsDlg = ShowDialog<PeptideSettingsUI>(SkylineWindow.ShowPeptideSettingsUI); var editIrtDlg = ShowDialog<EditIrtCalcDlg>(peptideSettingsDlg.AddCalculator); RunUI(() => { editIrtDlg.OpenDatabase(TestFilesDir.GetTestPath("RetentionTimeFilterTest.irtdb")); editIrtDlg.CalcName = calcName; }); SkylineWindow.BeginInvoke(new Action(editIrtDlg.OkDialog)); var multiButtonMsgDlg = WaitForOpenForm<MultiButtonMsgDlg>(); OkDialog(multiButtonMsgDlg, ()=>multiButtonMsgDlg.DialogResult = DialogResult.Yes); var editRtDlg = ShowDialog<EditRTDlg>(peptideSettingsDlg.AddRTRegression); RunUI(() => { editRtDlg.ChooseCalculator(calcName); editRtDlg.SetAutoCalcRegression(true); editRtDlg.SetRegressionName(regressionName); editRtDlg.SetTimeWindow(1.0); }); OkDialog(editRtDlg, editRtDlg.OkDialog); RunUI(() => { peptideSettingsDlg.ChooseRegression(regressionName); peptideSettingsDlg.UseMeasuredRT(false); }); OkDialog(peptideSettingsDlg, peptideSettingsDlg.OkDialog); Assert.IsFalse(SkylineWindow.Document.Settings.PeptideSettings.Prediction.UseMeasuredRTs); var importResultsDlg = ShowDialog<ImportResultsDlg>(SkylineWindow.ImportResults); var openDataSourceDialog = ShowDialog<OpenDataSourceDialog>(importResultsDlg.OkDialog); RunUI(() => openDataSourceDialog.SelectFile("8fmol" + extension)); OkDialog(openDataSourceDialog, openDataSourceDialog.Open); WaitForResultsImport(); var document = WaitForDocumentLoaded(); var chromatogramSet = document.Settings.MeasuredResults.Chromatograms.First(cs => cs.Name == "8fmol"); var regressionLine = document.Settings.PeptideSettings.Prediction.RetentionTime.GetConversion( chromatogramSet.MSDataFileInfos.First().FileId); var calculator = document.Settings.PeptideSettings.Prediction.RetentionTime.Calculator; double fullGradientStartTime; double fullGradientEndTime; using (var msDataFile = new MsDataFileImpl(TestFilesDir.GetTestPath("8fmol" + extension))) { fullGradientStartTime = msDataFile.GetSpectrum(0).RetentionTime.Value; fullGradientEndTime = msDataFile.GetSpectrum(msDataFile.SpectrumCount - 1).RetentionTime.Value; } foreach (var tuple in LoadAllChromatograms(document, chromatogramSet)) { if (tuple.Item1.GlobalStandardType != PeptideDocNode.STANDARD_TYPE_IRT) { double? score = calculator.ScoreSequence(document.Settings.GetModifiedSequence(tuple.Item1.Peptide.Sequence, tuple.Item2.TransitionGroup.LabelType, tuple.Item1.ExplicitMods)); if (score.HasValue) { double? predictedRt = regressionLine.GetY(score.Value); AssertChromatogramWindow(document, chromatogramSet, predictedRt.Value - FILTER_LENGTH, predictedRt.Value + FILTER_LENGTH, tuple.Item3); } } else { // IRT Standards get extracted for the full gradient AssertChromatogramWindow(document, chromatogramSet, fullGradientStartTime, fullGradientEndTime, tuple.Item3); } } } }
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; _dataFile = scanProvider._dataFile; _msDataFileScanIds = scanProvider._msDataFileScanIds; _getMsDataFileScanIds = scanProvider._getMsDataFileScanIds; scanProvider._dataFile = null; return true; }
private void InitSpectrumReader(MsDataFileImpl dataFile) { // Create the spectra object responsible for delivering spectra for extraction _spectra = new Spectra(_document, _filter, _allChromData, dataFile); // Determine what type of demultiplexer, if any, to use based on settings in the // IsolationScheme menu _demultiplexer = _spectra.CreateDemultiplexer(); if (_demultiplexer == null) { _spectra.RunAsync(); } }
public void TestMsx(SrmDocument doc, string dataPath) { // Load the file and check MsDataFileImpl using (var file = new MsDataFileImpl(dataPath)) { var filter = new SpectrumFilter(doc, null, null); Assert.IsTrue(filter.EnabledMsMs); var demultiplexer = new MsxDemultiplexer(file, filter); demultiplexer.ForceInitializeFile(); // Check that the demultiplexer found the correct multiplexing parameters Assert.AreEqual(5, demultiplexer.IsoWindowsPerScan); Assert.AreEqual(100, demultiplexer.NumIsoWindows); Assert.AreEqual(20, demultiplexer.DutyCycleLength); var isoMapper = demultiplexer.IsoMapperTest; Assert.AreEqual(100, isoMapper.NumWindows); // Check the isolation window mapper responsible for mapping each unique isolation // window detected in the file to a unique index TestIsolationWindowMapper(isoMapper, file, 4.00182); var transBinner = new TransitionBinner(filter, isoMapper); // Test creation of a transition binner from a spectrum filter TestTransitionBinnerFromFilter(transBinner, isoMapper); var testSpectrum = file.GetSpectrum(TEST_SPECTRUM); // Generate a transition binner containing a lot of tough cases with // overlapping transitions and test double[] binnedExpected = { 0.0, 25160.11261, 18254.06375, 18254.06375, 18254.06375, 11090.00577, 19780.18628, 19780.18628 }; var transBinnerOverlap = TestTransitionBinnerOverlap(testSpectrum, isoMapper, binnedExpected); TestSpectrumProcessor(transBinnerOverlap, isoMapper, file, TEST_SPECTRUM); TestPeakIntensityCorrection(testSpectrum, isoMapper, demultiplexer); int[] intensityIndices = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 290, 291, 292, 293, 294, 295, 296 }; double[] intensityValues = { 0.0, 0.0, 0.0, 0.0, 142.95, 349.75, 542.87, 511.77, 248.4, 0.0, 49.28, 1033.65, 278.56, 0.0, 0.0, 0.0, 0.0, 0.0 }; // Test demultiplexing of a real spectrum TestSpectrumDemultiplex(demultiplexer, TEST_SPECTRUM, testSpectrum, intensityIndices, intensityValues, 0); } }
public LookaheadContext(SpectrumFilter filter, MsDataFileImpl dataFile) { _lookAheadIndex = 0; _lookAheadDataSpectrum = null; _filter = filter; _dataFile = dataFile; _rt = null; _previousDriftTime = 0; _lenSpectra = dataFile.SpectrumCount; }
private bool MoveToNextScan(int direction, bool onlyMs1) { using (var msDataFileImpl = new MsDataFileImpl(Workspace.GetDataFilePath(MsDataFile.Name))) { int scanIndex = Math.Min(msDataFileImpl.SpectrumCount - 1, Math.Max(0, ScanIndex)); if (scanIndex < 0) { return false; } while (true) { scanIndex += direction; if (scanIndex < 0 || scanIndex >= msDataFileImpl.SpectrumCount) { return false; } if (!onlyMs1 || msDataFileImpl.GetMsLevel(scanIndex) == 1) { break; } } ScanIndex = scanIndex; return true; } }
private void GenerateChromatograms(ChromatogramTask chromatogramTask) { int totalAnalyses = chromatogramTask.AnalysisChromatograms.Count; if (totalAnalyses == 0) { return; } if (!UpdateProgress(chromatogramTask, 0)) { return; } var msDataFile = chromatogramTask.MsDataFile; MsDataFileUtil.InitMsDataFile(chromatogramTask.Workspace, msDataFile); var analyses = new List<AnalysisChromatograms>(chromatogramTask.AnalysisChromatograms); MsDataFileImpl pwizMsDataFileImpl; var path = _workspace.GetDataFilePath(msDataFile.Name); try { pwizMsDataFileImpl = new MsDataFileImpl(path); } catch (Exception exception) { ErrorHandler.LogException("Chromatogram Generator", "Error opening " + path, exception); _workspace.RejectMsDataFile(msDataFile); return; } using (pwizMsDataFileImpl) { var completeAnalyses = new List<AnalysisChromatograms>(); int totalScanCount = pwizMsDataFileImpl.SpectrumCount; var lastTimeInDataFile = chromatogramTask.MsDataFile.GetTime(chromatogramTask.MsDataFile.GetSpectrumCount() - 1); double minTime = lastTimeInDataFile; double maxTime = msDataFile.GetTime(0); foreach (var analysis in analyses) { minTime = Math.Min(minTime, analysis.FirstTime); maxTime = Math.Max(maxTime, analysis.LastTime); } int firstScan = msDataFile.FindScanIndex(minTime); for (int iScan = firstScan; analyses.Count > 0 && iScan < totalScanCount; iScan++) { double time = msDataFile.GetTime(iScan); int progress = (int)(100 * (time - minTime) / (maxTime - minTime)); progress = Math.Min(progress, 100); progress = Math.Max(progress, 0); if (!UpdateProgress(chromatogramTask, progress)) { return; } List<AnalysisChromatograms> activeAnalyses = new List<AnalysisChromatograms>(); double nextTime = Double.MaxValue; if (msDataFile.GetMsLevel(iScan, pwizMsDataFileImpl) != 1) { continue; } foreach (var analysis in analyses) { nextTime = Math.Min(nextTime, analysis.FirstTime); if (analysis.FirstTime <= time) { activeAnalyses.Add(analysis); } } if (activeAnalyses.Count == 0) { int nextScan = msDataFile.FindScanIndex(nextTime); iScan = Math.Max(iScan, nextScan - 1); continue; } bool lowMemory = IsLowOnMemory(); // If we have exceeded the number of analyses we should be working on at once, // throw out any that we haven't started. for (int iAnalysis = activeAnalyses.Count - 1; iAnalysis >= 0 && (activeAnalyses.Count > _maxConcurrentAnalyses || lowMemory); iAnalysis--) { var analysis = activeAnalyses[iAnalysis]; if (analysis.Times.Count > 0) { continue; } activeAnalyses.RemoveAt(iAnalysis); analyses.Remove(analysis); } double[] mzArray, intensityArray; pwizMsDataFileImpl.GetSpectrum(iScan, out mzArray, out intensityArray); if (!pwizMsDataFileImpl.IsCentroided(iScan)) { var centroider = new Centroider(mzArray, intensityArray); centroider.GetCentroidedData(out mzArray, out intensityArray); } foreach (var analysis in activeAnalyses) { var points = new List<ChromatogramPoint>(); foreach (var chromatogram in analysis.Chromatograms) { points.Add(MsDataFileUtil.GetPoint(chromatogram.MzRange, mzArray, intensityArray)); } analysis.AddPoints(iScan, time, points); } var incompleteAnalyses = new List<AnalysisChromatograms>(); foreach (var analysis in analyses) { if (analysis.LastTime <= time) { completeAnalyses.Add(analysis); } else { incompleteAnalyses.Add(analysis); } } SaveChromatograms(chromatogramTask, completeAnalyses, false); completeAnalyses.Clear(); analyses = incompleteAnalyses; } completeAnalyses.AddRange(analyses); SaveChromatograms(chromatogramTask, completeAnalyses, true); } }
public void ThermoFileTypeTest() { var testFilesDir = new TestFilesDir(TestContext, ZIP_FILE); string extRaw = ExtensionTestContext.ExtThermoRaw; // Do file type checks using (var msData = new MsDataFileImpl(testFilesDir.GetTestPath("Site20_STUDY9P_PHASEII_QC_03" + extRaw))) { Assert.IsTrue(msData.IsThermoFile); } using (var msData = new MsDataFileImpl(testFilesDir.GetTestPath("Site20_STUDY9P_PHASEII_QC_03.mzXML"))) { Assert.IsTrue(msData.IsThermoFile); } using (var msData = new MsDataFileImpl(testFilesDir.GetTestPath("Site20_STUDY9P_PHASEII_QC_05" + extRaw))) { Assert.IsTrue(msData.IsThermoFile); } }
public MsxDemultiplexer(MsDataFileImpl file, SpectrumFilter filter) : base(file, filter) { _isoMapper = new MsxIsolationWindowMapper(); }
public Spectra(SrmDocument document, SpectrumFilter filter, ChromatogramLoadingStatus.TransitionData allChromData, MsDataFileImpl dataFile) { _document = document; _filter = filter; _dataFile = dataFile; _allChromData = allChromData; _lookaheadContext = new LookaheadContext(_filter, _dataFile); _countSpectra = dataFile.SpectrumCount; HasSrmSpectra = dataFile.HasSrmSpectra; // If possible, find the maximum retention time in order to scale the chromatogram graph. if (_allChromData != null && (_filter.EnabledMsMs || _filter.EnabledMs)) { var retentionTime = _dataFile.GetStartTime(_countSpectra - 1); if (retentionTime.HasValue) { _allChromData.MaxRetentionTime = (float)retentionTime.Value; _allChromData.MaxRetentionTimeKnown = true; _allChromData.Progressive = true; } } }
private void ComboChromatogramOnDropDown(object sender, EventArgs e) { if (_chromatogramDatas != null) { return; } comboChromatogram.Items.Clear(); using (var msDataFileImpl = new MsDataFileImpl(Workspace.GetDataFilePath(MsDataFile.Name))) { _chromatogramDatas = new ChromatogramData[msDataFileImpl.ChromatogramCount]; for (int i = 0; i < _chromatogramDatas.Length; i++) { int indexId; comboChromatogram.Items.Add(msDataFileImpl.GetChromatogramId(i, out indexId)); } } }
public void Dispose() { lock (this) { if (_dataFile != null) { _dataFile.Dispose(); _dataFile = null; } } }
public SpectrumData(MsDataFileImpl msDataFileImpl, int scanIndex) { ScanIndex = scanIndex; var spectrum = msDataFileImpl.GetSpectrum(scanIndex); if (spectrum.Centroided) { CentroidMzs = spectrum.Mzs; CentroidIntensities = spectrum.Intensities; } else { ProfileMzs = spectrum.Mzs; ProfileIntensities = spectrum.Intensities; var centroider = new Centroider(ProfileMzs, ProfileIntensities); double[] centroidMzs, centroidIntensities; centroider.GetCentroidedData(out centroidMzs, out centroidIntensities); CentroidMzs = centroidMzs; CentroidIntensities = centroidIntensities; } Time = spectrum.RetentionTime; MsLevel = spectrum.Level; }
public DataFileInstrumentInfo(MsDataFileImpl dataFile) { _dataFile = dataFile; }