/// <summary> /// Deconvolute mass spectrum using deconvolution algorithm described in Mann et al., Anal. Chem. 1989 /// </summary> /// <returns>deconvoluted spectrum</returns> public DeconvolutedSpectrum GetDeconvolutedSpectrum() { if (_deconvolutedSpectrum != null) { return(_deconvolutedSpectrum); } var minBinIndex = _massBinning.GetBinNumber(_minMass); var maxBinIndex = _massBinning.GetBinNumber(_maxMass); var massIntensity = new double[maxBinIndex - minBinIndex + 1]; foreach (var peak in _spectrum.Peaks) { for (var charge = _minCharge; charge <= _maxCharge; charge++) { var mass = (peak.Mz - Constants.Proton) * charge; if (mass < _minMass) { continue; } if (mass > _maxMass) { break; } var massBinNum = _massBinning.GetBinNumber(mass); massIntensity[massBinNum - minBinIndex] += peak.Intensity; } } var deconvPeaks = new List <DeconvolutedPeak>(); for (var i = 0; i < massIntensity.Length; i++) { var intensity = massIntensity[i]; if (intensity < float.Epsilon) { continue; } var mass = _massBinning.GetMzAverage(i + minBinIndex); deconvPeaks.Add(new DeconvolutedPeak(mass, intensity, 1, 0, 0)); } _deconvolutedSpectrum = new DeconvolutedSpectrum(_spectrum, deconvPeaks.ToArray()); return(_deconvolutedSpectrum); }
public CompositeScorerBasedOnDeconvolutedSpectrum(DeconvolutedSpectrum deconvolutedSpectrum, ProductSpectrum spec, Tolerance productTolerance, IMassBinning comparer) : base(deconvolutedSpectrum, productTolerance) { ReferencePeakIntensity = GetRefIntensity(spec.Peaks); _comparer = comparer; _massBinToPeakMap = new Dictionary <int, DeconvolutedPeak>(); foreach (var p in deconvolutedSpectrum.Peaks) { var mass = p.Mz; var deltaMass = productTolerance.GetToleranceAsDa(mass, 1); var minMass = mass - deltaMass; var maxMass = mass + deltaMass; var binNum = comparer.GetBinNumber(mass); if (binNum < 0) { binNum = comparer.GetBinNumber(minMass); if (binNum < 0) { binNum = comparer.GetBinNumber(maxMass); } } // filter out if (binNum < 0) { continue; } UpdateDeconvPeak(binNum, p as DeconvolutedPeak); // going up for (var nextBinNum = binNum + 1; nextBinNum < comparer.NumberOfBins; nextBinNum++) { var nextBinMass = comparer.GetMassStart(nextBinNum); if (minMass < nextBinMass && nextBinMass < maxMass) { UpdateDeconvPeak(nextBinNum, p as DeconvolutedPeak); //_ionMassChkBins[nextBinNum] = true; } else { break; } } // going down for (var prevBinNum = binNum - 1; prevBinNum < comparer.NumberOfBins; prevBinNum--) { var prevBinMass = comparer.GetMassEnd(prevBinNum); if (minMass < prevBinMass && prevBinMass < maxMass) { UpdateDeconvPeak(prevBinNum, p as DeconvolutedPeak); //_ionMassChkBins[prevBinNum] = true; } else { break; } } } }
/// <summary> /// Read a spectrum from the current position in <paramref name="reader"/>, with the option to only read the metadata. /// </summary> /// <param name="reader"></param> /// <param name="includePeaks"></param> /// <returns></returns> protected internal override Spectrum ReadSpectrum(BinaryReader reader, bool includePeaks = true) { // Must reflect all changes to WriteSpectrum var scanNum = reader.ReadInt32(); var c = new char[NativeIdLength]; reader.Read(c, 0, NativeIdLength); var nativeId = (new string(c)).Trim(); var msLevel = reader.ReadByte(); var elutionTime = reader.ReadDouble(); var tic = reader.ReadSingle(); double?precursorMass = reader.ReadDouble(); if (Math.Abs(precursorMass.Value) < float.Epsilon) { precursorMass = null; } int?precursorCharge = reader.ReadInt32(); if (precursorCharge == 0) { precursorCharge = null; } var activationMethod = (ActivationMethod)reader.ReadByte(); var isolationWindowTargetMz = reader.ReadDouble(); var isolationWindowLowerOffset = reader.ReadDouble(); var isolationWindowUpperOffset = reader.ReadDouble(); var peakList = new List <DeconvolutedPeak>(); var numPeaks = reader.ReadInt32(); for (var i = 0; i < numPeaks; i++) { var mz = reader.ReadDouble(); var intensity = reader.ReadSingle(); var charge = reader.ReadInt32(); var corr = reader.ReadSingle(); var dist = reader.ReadSingle(); var peak = new DeconvolutedPeak(mz, intensity, charge, corr, dist); var isoPeakCount = (int)reader.ReadByte(); peak.ObservedPeakIndices.Capacity = isoPeakCount; for (var j = 0; j < isoPeakCount; j++) { peak.ObservedPeakIndices.Add(reader.ReadUInt16()); } peakList.Add(peak); } var spec = new DeconvolutedSpectrum(peakList, scanNum) { ActivationMethod = activationMethod, IsolationWindow = new IsolationWindow( isolationWindowTargetMz, isolationWindowLowerOffset, isolationWindowUpperOffset, precursorMass, precursorCharge ), MsLevel = msLevel, ElutionTime = elutionTime, NativeId = nativeId, TotalIonCurrent = tic }; return(spec); }