private void SetLcMsMatches(int ms2ScanNumber) { var productSpec = _run.GetSpectrum(ms2ScanNumber) as ProductSpectrum; if (productSpec == null) { return; } var isolationWindow = productSpec.IsolationWindow; var minMz = isolationWindow.MinMz; var maxMz = isolationWindow.MaxMz; List <Peak> precursorPeakList = null; var precursorSpec = _run.GetSpectrum(_run.GetPrecursorScanNum(ms2ScanNumber)); if (precursorSpec != null) { precursorPeakList = precursorSpec.GetPeakListWithin(minMz, maxMz); } List <Peak> nextMs1PeakList = null; var nextScanNum = _run.GetNextScanNum(ms2ScanNumber, 1); var nextSpec = _run.GetSpectrum(nextScanNum); if (nextSpec != null) { nextMs1PeakList = nextSpec.GetPeakListWithin(minMz, maxMz); } List <Peak> peakList; if (precursorPeakList != null && nextMs1PeakList != null) { peakList = PeakListUtils.Sum(precursorPeakList, nextMs1PeakList, _comparer); } else if (precursorPeakList != null) { peakList = precursorPeakList; } else if (nextMs1PeakList != null) { peakList = nextMs1PeakList; } else { return; } // Sort by intensity peakList.Sort(new IntensityComparer()); var remainingPeakList = new LinkedList <Peak>(peakList); SetLcMsMatches(remainingPeakList, ms2ScanNumber, MaxNumPeaksToConsider); }
public void TestReadingPbfFile() { var methodName = MethodBase.GetCurrentMethod().Name; Utils.ShowStarting(methodName); var pbfFilePath = Path.Combine(Utils.DEFAULT_TEST_FILE_FOLDER, @"TopDown\ProductionQCShew\QC_Shew_13_04_A_17Feb14_Samwise_13-07-28.pbf"); if (!File.Exists(pbfFilePath)) { Assert.Ignore(@"Skipping test {0} since file not found: {1}", methodName, pbfFilePath); } var pbfRun = new PbfLcMsRun(pbfFilePath); var checksum = pbfRun.PbfFileChecksum; var specFilePath = Path.ChangeExtension(pbfFilePath, "raw"); if (!File.Exists(specFilePath)) { Assert.Ignore(@"Skipping test {0} since file not found: {1}", methodName, specFilePath); } Console.WriteLine(@"Loading .pbf into memory"); //var run = InMemoryLcMsRun.GetLcMsRun(specFilePath); var run = new InMemoryLcMsRun(MassSpecDataReaderFactory.GetMassSpecDataReader(specFilePath), 0, 0); Console.WriteLine(@"Comparing spectra between .pbf and in-memory spectra"); // spectrum comparison //for (var scanNum = run.MinLcScan; scanNum <= run.MaxLcScan; scanNum++) foreach (var scanNum in run.AllScanNumbers) { var spec1 = run.GetSpectrum(scanNum); var spec2 = pbfRun.GetSpectrum(scanNum); Assert.IsTrue(spec1.Peaks.Length == spec2.Peaks.Length); for (var i = 0; i < spec1.Peaks.Length; i++) { var p1 = spec1.Peaks[i]; var p2 = spec2.Peaks[i]; Assert.True(p1.Equals(p2)); Assert.True(Math.Abs(p1.Mz - p2.Mz) < 1e-8); Assert.True(Math.Abs(p1.Intensity - p2.Intensity) < 0.001); } } Console.WriteLine(@"Comparing XICs"); // chromatogram comparison const double targetMz = 655.01; var tolerance = new Tolerance(10); var xic1 = run.GetFullPrecursorIonExtractedIonChromatogram(targetMz, tolerance); var xic2 = pbfRun.GetFullPrecursorIonExtractedIonChromatogram(targetMz, tolerance); Assert.True(xic1.Count == xic2.Count); for (var i = 0; i < xic1.Count; i++) { if (!xic1[i].Equals(xic2[i])) { Console.WriteLine(@"{0} {1} {2}", i, xic1[i], xic2[i]); } Assert.True(xic1[i].Equals(xic2[i])); } Console.WriteLine(@"Done"); }