public void TestAbpSumMs1Spectra() { var methodName = MethodBase.GetCurrentMethod().Name; Utils.ShowStarting(methodName); var specFilePath = Path.Combine(Utils.DEFAULT_TEST_FILE_FOLDER, @"TestYufengData\QC_ShewIntact_2ug_3k_CID_4Apr14_Bane_PL011402.raw"); if (!File.Exists(specFilePath)) { Assert.Ignore(@"Skipping test " + methodName + @" since file not found: " + specFilePath); } const int minScanNum = 5657; const int maxScanNum = 5699; const int MAX_POINTS = 50; var run = PbfLcMsRun.GetLcMsRun(specFilePath); if (run == null) { return; } var summedSpec = run.GetSummedMs1Spectrum(minScanNum, maxScanNum); var peakList = summedSpec.GetPeakListWithin(1180.0, 1192.0); var filteredPeakList = new List <Peak>(); PeakListUtils.FilterNoise(peakList, ref filteredPeakList); new Spectrum(filteredPeakList, 0).Display(MAX_POINTS); }
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; List <Peak> precursorSpecWindow = null; var precursorSpec = _run.GetSpectrum(_run.GetPrecursorScanNum(ms2ScanNumber)); if (precursorSpec != null) { precursorPeakList = precursorSpec.GetPeakListWithin(minMz, maxMz); precursorSpecWindow = precursorSpec.GetPeakListWithin(minMz - 1.0, maxMz + 1.0); } List <Peak> nextMs1PeakList = null; List <Peak> nextMs1SpecWindow = null; var nextScanNum = _run.GetNextScanNum(ms2ScanNumber, 1); var nextSpec = _run.GetSpectrum(nextScanNum); if (nextSpec != null) { nextMs1PeakList = nextSpec.GetPeakListWithin(minMz, maxMz); nextMs1SpecWindow = nextSpec.GetPeakListWithin(minMz - 1.0, maxMz + 1.0); } 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, precursorSpecWindow, nextMs1SpecWindow, MaxNumPeaksToConsider); }
private IEnumerable <DeisotopedPeak> GetDeisotopedPeaks(List <Peak> specWindow, IEnumerable <Peak> peakList, int numDeisotopedPeaksToGet) { var peakListSortedByIntensity = new List <Peak>(peakList); peakListSortedByIntensity.Sort(new IntensityComparer()); var remainingPeakList = new LinkedList <Peak>(peakListSortedByIntensity); var deisotopedPeakSet = new SortedSet <DeisotopedPeak>(); while (remainingPeakList.Any()) { var peakWithHighestIntensity = remainingPeakList.First.Value; var peakMz = peakWithHighestIntensity.Mz; var score = new double[_maxCharge + 1]; for (var charge = _maxCharge; charge >= _minCharge; charge--) { // check whether next isotope peak exists var nextIsotopeMz = peakMz + Constants.C13MinusC12 / charge; var nextIsotopePeak = PeakListUtils.FindPeak(specWindow, nextIsotopeMz, _tolerance); if (nextIsotopePeak == null) { continue; } var mostAbundantIsotopeMass = (peakMz - Constants.Proton) * charge; var averagineIsoEnv = Averagine.GetIsotopomerEnvelope(mostAbundantIsotopeMass); var approxMostAbundantIsotopeIndex = averagineIsoEnv.MostAbundantIsotopeIndex; var monoIsotopicMass = mostAbundantIsotopeMass - approxMostAbundantIsotopeIndex * Constants.C13MinusC12; var averagineIsotopeProfile = Averagine.GetTheoreticalIsotopeProfile(monoIsotopicMass, charge); var corr = PeakListUtils.GetPearsonCorrelation(specWindow, averagineIsotopeProfile, _comparer); score[charge] = corr; var isValid = true; for (var mult = 2; mult <= _maxCharge / charge; mult++) { var multiple = charge * mult; if (score[multiple] > 0.8 * corr) { isValid = false; break; } } if (!isValid) { continue; } deisotopedPeakSet.Add(new DeisotopedPeak(monoIsotopicMass, charge, corr)); if (deisotopedPeakSet.Count > numDeisotopedPeaksToGet) { deisotopedPeakSet.Remove(deisotopedPeakSet.Min); } } remainingPeakList.RemoveFirst(); } return(deisotopedPeakSet); }
private void ApplyDeconvolution(List <Peak> specWindow, ref LinkedList <Peak> remainingPeakList, ref List <double> deisotopedMassList) { if (!remainingPeakList.Any()) { return; } var peakWithHighestIntensity = remainingPeakList.First.Value; var peakMz = peakWithHighestIntensity.Mz; var score = new double[_maxCharge + 1]; for (var charge = _maxCharge; charge >= _minCharge; charge--) { // check whether next isotope peak exists var nextIsotopeMz = peakMz + Constants.C13MinusC12 / charge; var nextIsotopePeak = PeakListUtils.FindPeak(specWindow, nextIsotopeMz, _tolerance); if (nextIsotopePeak == null) { continue; } var mostAbundantIsotopeMass = (peakMz - Constants.Proton) * charge; var averagineIsoEnv = Averagine.GetIsotopomerEnvelope(mostAbundantIsotopeMass); var approxMostAbundantIsotopeIndex = averagineIsoEnv.MostAbundantIsotopeIndex; var monoIsotopicMass = mostAbundantIsotopeMass - approxMostAbundantIsotopeIndex * Constants.C13MinusC12; var averagineIsotopeProfile = Averagine.GetTheoreticalIsotopeProfile(monoIsotopicMass, charge); var corr = PeakListUtils.GetPearsonCorrelation(specWindow, averagineIsotopeProfile, _comparer); score[charge] = corr; var isValid = true; for (var mult = 2; mult <= _maxCharge / charge; mult++) { var multiple = charge * mult; if (score[multiple] > 0.8 * corr) { isValid = false; break; } } if (!isValid) { continue; } if (corr > _corrThreshold) { deisotopedMassList.Add(monoIsotopicMass); } } remainingPeakList.RemoveFirst(); }
private void FindMatchedIons(double peakMz, List <Peak> peakList, ref List <Ms2Match> matchList) { for (var charge = _maxCharge; charge >= _minCharge; charge--) { // check whether next isotope peak exists var nextIsotopeMz = peakMz + Constants.C13MinusC12 / charge; var nextIsotopePeak = PeakListUtils.FindPeak(peakList, nextIsotopeMz, _tolerance); if (nextIsotopePeak == null) { continue; } matchList.Add(new Ms2Match(peakMz, charge)); } }
public void TestIcrTools() { var methodName = MethodBase.GetCurrentMethod().Name; Utils.ShowStarting(methodName); const string icrToolsPath = @"H:\Research\Yufeng\TopDownYufeng\ICRTools\yufeng_column_test2_Isos.csv"; if (!File.Exists(icrToolsPath)) { Assert.Ignore(@"Skipping test {0} since file not found: {1}", methodName, icrToolsPath); } const double fitScoreThreshold = 0.15; var icrToolsparser = new TsvFileParser(icrToolsPath, ','); var monoMassArr = icrToolsparser.GetData("monoisotopic_mw").Select(Convert.ToDouble).ToArray(); var scanArray = icrToolsparser.GetData("scan_num").Select(s => Convert.ToInt32(s)).ToArray(); var fitArray = icrToolsparser.GetData("fit").Select(Convert.ToDouble).ToArray(); var peakList = fitArray.Where(fit => fit < fitScoreThreshold).Select((fit, i) => new Peak(monoMassArr[i], scanArray[i])).OrderBy(p => p.Mz).ToList(); Console.WriteLine("FitScoreThreshold: {0}", fitScoreThreshold); Console.WriteLine("NumFeatures: {0}", peakList.Count); //var peakList = monoMassArr.Select((mass, i) => new Peak(mass, scanArray[i])).OrderBy(p => p.Mz).ToList(); var massTolerance = new Tolerance(10); const double scanTolerance = 10.0; const string resultFilePath = @"H:\Research\Yufeng\TopDownYufeng\M1_V31\yufeng_column_test2_IcTda.tsv"; if (!File.Exists(resultFilePath)) { Assert.Ignore(@"Skipping test {0} since file not found: {1}", methodName, resultFilePath); } var parser = new TsvFileParser(resultFilePath); var qValues = parser.GetData("QValue").Select(Convert.ToDouble).ToArray(); var masses = parser.GetData("Mass").Select(Convert.ToDouble).ToArray(); var scans = parser.GetData("Scan").Select(s => Convert.ToInt32(s)).ToArray(); var compositions = parser.GetData("Composition").ToArray(); var numTotal = 0; var numMatch = 0; var compSet = new HashSet <string>(); var matchedCompSet = new HashSet <string>(); for (var i = 0; i < qValues.Length; i++) { if (qValues[i] > 0.01) { break; } var mass = masses[i]; var scan = scans[i]; var matches = PeakListUtils.FindAllPeaks(peakList, mass, massTolerance) .Where(p => p.Intensity >= scan - scanTolerance && p.Intensity <= scan + scanTolerance); if (matches.Any()) { ++numMatch; matchedCompSet.Add(compositions[i]); } ++numTotal; compSet.Add(compositions[i]); } Console.WriteLine("PrSMs: {0} / {1} = {2}", numMatch, numTotal, numMatch / (float)numTotal); Console.WriteLine("Compositions: {0} / {1} = {2}", matchedCompSet.Count, compSet.Count, matchedCompSet.Count / (float)compSet.Count); }
private void SetLcMsMatches(double peakMz, int scanNum, IList <Peak> precursorSpecWindow, IList <Peak> nextMs1SpecWindow) { var xicThisPeak = _run.GetPrecursorExtractedIonChromatogram(peakMz, _tolerance, scanNum); if (xicThisPeak.Count < 2) { return; } for (var charge = _maxCharge; charge >= _minCharge; charge--) { // check whether next isotope peak exists var nextIsotopeMz = peakMz + Constants.C13MinusC12 / charge; var xicNextIsotope = _run.GetPrecursorExtractedIonChromatogram(nextIsotopeMz, _tolerance, scanNum); if (!xicNextIsotope.Any()) { continue; } if (xicThisPeak.GetCorrelation(xicNextIsotope) < _mostAbundantPlusOneIsotopeCorrThreshold) { continue; } var mostAbundantIsotopeMass = (peakMz - Constants.Proton) * charge; var averagineIsoEnv = Averagine.GetIsotopomerEnvelope(mostAbundantIsotopeMass); var approxMostAbundantIsotopeIndex = averagineIsoEnv.MostAbundantIsotopeIndex; var monoIsotopicMass = mostAbundantIsotopeMass - approxMostAbundantIsotopeIndex * Constants.C13MinusC12; // Isotope correlation var averagineIsotopeProfile = Averagine.GetTheoreticalIsotopeProfile(monoIsotopicMass, charge); var precursorIsotopeCorr = precursorSpecWindow != null?PeakListUtils.GetPearsonCorrelation(precursorSpecWindow, averagineIsotopeProfile, _comparer) : 0; var nextMs1IsotopeCorr = nextMs1SpecWindow != null?PeakListUtils.GetPearsonCorrelation(nextMs1SpecWindow, averagineIsotopeProfile, _comparer) : 0; var isotopeCorr = Math.Max(precursorIsotopeCorr, nextMs1IsotopeCorr); if (isotopeCorr < _isotopeCorrThresholdThreshold) { continue; } if (_chargeCorrThresholdThreshold > 0.0) { var mzChargePlusOne = Ion.GetIsotopeMz(monoIsotopicMass, charge + 1, approxMostAbundantIsotopeIndex); var xicPlusOneCharge = _run.GetPrecursorExtractedIonChromatogram(mzChargePlusOne, _tolerance, scanNum); var corrPlusOneCharge = xicPlusOneCharge.Count >= 3 ? xicThisPeak.GetCorrelation(xicPlusOneCharge) : 0; double corrMinusOneCharge; if (charge > 1) { var mzChargeMinusOne = Ion.GetIsotopeMz(monoIsotopicMass, charge - 1, approxMostAbundantIsotopeIndex); var xicMinusOneCharge = _run.GetPrecursorExtractedIonChromatogram(mzChargeMinusOne, _tolerance, scanNum); corrMinusOneCharge = xicMinusOneCharge.Count >= 3 ? xicThisPeak.GetCorrelation(xicMinusOneCharge) : 0; } else { corrMinusOneCharge = 0.0; } var chargeCorr = Math.Max(corrPlusOneCharge, corrMinusOneCharge); if (chargeCorr < _chargeCorrThresholdThreshold) { continue; } } _lcMsMatchMap.SetMatches(monoIsotopicMass, xicThisPeak[0].ScanNum, xicThisPeak[xicThisPeak.Count - 1].ScanNum); } }