public ObservedIsotopeEnvelope(double monoMass, int charge, int scanNum, Ms1Peak[] peaks, TheoreticalIsotopeEnvelope theoreticalEnvelope) { MonoMass = monoMass; Charge = charge; ScanNum = scanNum; TheoreticalEnvelope = theoreticalEnvelope; Peaks = new Ms1Peak[theoreticalEnvelope.Size]; Array.Copy(peaks, Peaks, theoreticalEnvelope.Size); GoodEnough = false; }
public Ms1Spectrum(int scanNum, int index, Peak[] peaks) : base(scanNum) { Index = index; MsLevel = 1; Peaks = new Peak[peaks.Length]; var sIndex = (ushort)index; for (var i = 0; i < Peaks.Length; i++) { Peaks[i] = new Ms1Peak(peaks[i].Mz, peaks[i].Intensity, i) { Ms1SpecIndex = sIndex } } ; MedianIntensity = Peaks.Select(p => p.Intensity).Median(); PreArrangeLocalMzWindows(); }
public double GetBhattacharyyaDistance(Ms1Peak[] isotopePeaks) { var s2 = 0d; for (var i = 0; i < Size; i++) { if (isotopePeaks[i] != null && isotopePeaks[i].Active) s2 += isotopePeaks[i].Intensity; } if (!(s2 > 0)) return MaxBhattacharyyaDistance; var bc = 0d; for (var i = 0; i < Size; i++) { var p = Probability[i]; var q = (isotopePeaks[i] != null && isotopePeaks[i].Active) ? isotopePeaks[i].Intensity / s2 : 0; bc += Math.Sqrt(p * q); } if (!(bc > 0)) return MaxBhattacharyyaDistance; return -Math.Log(bc); }
public void UpdateWithDecoyScore(List<Ms1Spectrum> ms1Spectra, int targetMinCharge, int targetMaxCharge) { var ms1ScanNumToIndex = _run.GetMs1ScanNumToIndex(); var ms1ScanNums = _run.GetMs1ScanVector(); var minCol = ms1ScanNumToIndex[MinScanNum]; var maxCol = ms1ScanNumToIndex[MaxScanNum]; MinCharge = targetMinCharge; MaxCharge = targetMaxCharge; var rnd = new Random(); var comparer = new MzComparerWithBinning(28); var mostAbuInternalIndex = TheoreticalEnvelope.IndexOrderByRanking[0]; var nRows = MaxCharge - MinCharge + 1; var nCols = maxCol - minCol + 1; Envelopes = new ObservedIsotopeEnvelope[nRows][]; for (var i = 0; i < nRows; i++) Envelopes[i] = new ObservedIsotopeEnvelope[nCols]; for (var charge = targetMinCharge; charge <= targetMaxCharge; charge++) { var mostAbuMz = TheoreticalEnvelope.GetIsotopeMz(charge, mostAbuInternalIndex); if (_run.MaxMs1Mz < mostAbuMz || mostAbuMz < _run.MinMs1Mz) continue; for (var col = minCol; col <= maxCol; col++) { var localWin = ms1Spectra[col].GetLocalMzWindow(mostAbuMz); var numMzBins = comparer.GetBinNumber(localWin.MaxMz) - comparer.GetBinNumber(localWin.MinMz) + 1; var peakSet = new Ms1Peak[TheoreticalEnvelope.Size]; for (var k = 0; k < peakSet.Length; k++) { var r = rnd.Next(0, numMzBins); if (r < localWin.PeakCount) peakSet[k] = (Ms1Peak) ms1Spectra[col].Peaks[r + localWin.PeakStartIndex]; } var env = new ObservedIsotopeEnvelope(Mass, charge, ms1ScanNums[col], peakSet, TheoreticalEnvelope); //AddObservedEnvelope(env); Envelopes[charge - MinCharge][col - minCol] = env; } } UpdateScore(ms1Spectra, false); }
public Ms1Peak[] GetAllIsotopePeaks(double monoIsotopeMass, int charge, TheoreticalIsotopeEnvelope isotopeList, Tolerance tolerance) { var observedPeaks = new Ms1Peak[isotopeList.Size]; var mz = isotopeList.GetIsotopeMz(charge, 0); var tolTh = tolerance.GetToleranceAsTh(mz); var minMz = mz - tolTh; var maxMz = mz + tolTh; var index = Array.BinarySearch(Peaks, new Ms1Peak(minMz, 0, 0)); if (index < 0) { index = ~index; } var bestPeakIndex = -1; var bestIntensity = 0.0; // go up var i = index; while (i >= 0 && i < Peaks.Length) { if (Peaks[i].Mz >= maxMz) { break; } if (Peaks[i].Intensity > bestIntensity) { bestIntensity = Peaks[i].Intensity; bestPeakIndex = i; observedPeaks[0] = (Ms1Peak)Peaks[bestPeakIndex]; } ++i; } var peakIndex = (bestPeakIndex >= 0) ? bestPeakIndex + 1 : index; // go up for (var j = 1; j < isotopeList.Size; j++) { var isotopeMz = isotopeList.GetIsotopeMz(charge, j); tolTh = tolerance.GetToleranceAsTh(isotopeMz); minMz = isotopeMz - tolTh; maxMz = isotopeMz + tolTh; for (i = peakIndex; i < Peaks.Length; i++) { var peakMz = Peaks[i].Mz; if (peakMz > maxMz) { peakIndex = i; break; } if (peakMz >= minMz) // find match, move to prev isotope { var peak = Peaks[i]; if (observedPeaks[j] == null || peak.Intensity > observedPeaks[j].Intensity) { observedPeaks[j] = (Ms1Peak)peak; } } } } return(observedPeaks); }
public double GetPearsonCorrelation(Ms1Peak[] isotopePeaks) { var m1 = 1.0/Size; var m2 = 0.0; for (var i = 0; i < Size; i++) { if (isotopePeaks[i] != null && isotopePeaks[i].Active) m2 += isotopePeaks[i].Intensity; } m2 /= Size; // compute Pearson correlation var cov = 0.0; var s1 = 0.0; var s2 = 0.0; for (var i = 0; i < Size; i++) { var d1 = Probability[i] - m1; var d2 = (isotopePeaks[i] != null && isotopePeaks[i].Active) ? isotopePeaks[i].Intensity - m2 : -m2; cov += d1 * d2; s1 += d1 * d1; s2 += d2 * d2; } if (s1 <= 0 || s2 <= 0) return 0; return cov < 0 ? 0d : cov / Math.Sqrt(s1 * s2); }