Exemplo n.º 1
0
        /// <summary>
        ///     Gets the most intense peak(whether or not it is processed) in the m/z range (mz - width to mz + width). The
        ///     intensity returned is the intensity in the original raw data in <see cref="IntensityList" />
        /// </summary>
        /// <param name="startMz">minimum m/z of the Peak.</param>
        /// <param name="stopMz">maximum m/z of the Peak.</param>
        /// <param name="peak">is set to the peak that was found.</param>
        /// <param name="excludeMass">is the mass we need to exclude in this search.</param>
        /// <returns>returns true if a peak was found in the window (mz - width to mz + width) and false if not found.</returns>
        /// <remarks>The returned peak has the intensity in the original raw data in <see cref="IntensityList" /></remarks>
        public bool GetPeakFromAllOriginalIntensity(double startMz, double stopMz, out ThrashV1Peak peak, double excludeMass)
        {
            peak = new ThrashV1Peak(0)
            {
                Intensity = -10
            };

            var found = false;

            foreach (var item in _allPeakMzToIndexDict.Where(x => x.Key >= startMz))
            {
                var peakIndex = item.Value;
                var mzVal     = item.Key;
                if (mzVal.Equals(excludeMass))
                {
                    continue;
                }
                if (mzVal > stopMz)
                {
                    return(found);
                }
                var dataIndex = PeakTops[peakIndex].DataIndex;
                if (IntensityList[dataIndex] >= peak.Intensity && mzVal >= startMz)
                {
                    //double thisMz = PeakTops[peakIndex].Mz;
                    peak  = new ThrashV1Peak(PeakTops[peakIndex]);
                    found = true;
                }
            }
            return(found);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Gets the most intense peak(whether or not it is processed) in the m/z range (mz - width to mz + width). The
        ///     intensity returned is the intensity in the original raw data in <see cref="IntensityList" />
        /// </summary>
        /// <param name="startMz">minimum m/z of the Peak.</param>
        /// <param name="stopMz">maximum m/z of the Peak.</param>
        /// <param name="peak">is set to the peak that was found.</param>
        /// <returns>returns true if a peak was found in the window (mz - width to mz + width) and false if not found.</returns>
        /// <remarks>The returned peak has the intensity in the original raw data in <see cref="IntensityList" />.</remarks>
        public bool GetPeakFromAllOriginalIntensity(double startMz, double stopMz, out ThrashV1Peak peak)
        {
            peak = new ThrashV1Peak(0)
            {
                Intensity = -10
            };

            var found = false;

            foreach (var item in _allPeakMzToIndexDict.Where(x => x.Key <= stopMz).Reverse())
            {
                var peakIndex = item.Value;
                var mzVal     = item.Key;
                if (mzVal < startMz)
                {
                    return(found);
                }
                if (PeakTops[peakIndex].Intensity > peak.Intensity && mzVal >= startMz &&
                    mzVal <= stopMz)
                {
                    //double thisMz = PeakTops[peakIndex].Mz;
                    peak  = new ThrashV1Peak(PeakTops[peakIndex]);
                    found = true;
                }
            }
            return(found);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Get the most intense unprocessed peak in the given m/z range and remove it from the processing list.
        /// </summary>
        /// <param name="startMz">minimum m/z of the peak.</param>
        /// <param name="stopMz">maximum m/z of the peak.</param>
        /// <param name="peak">is assigned the most intense peak with m/z between the startMz and stopMz.</param>
        /// <returns>returns true if a peak was found and false if none was found.</returns>
        /// <remarks>
        ///     The peak that is returned by this function is removed from the processing list. This is essentially the
        ///     function that is called repeatedly in the deconvolution process which deisotopes peaks in order of decreasing
        ///     intensity.
        /// </remarks>
        public bool GetNextPeak(double startMz, double stopMz, out ThrashV1Peak peak)
        {
            peak = new ThrashV1Peak(-1, -1);

            var found = false;

            foreach (var indexList in _peakIntensityToIndexDict)
            {
                foreach (var peakIndex in indexList.Value)
                {
                    var mz = PeakTops[peakIndex].Mz;
                    if (mz > startMz && mz <= stopMz)
                    {
                        peak  = new ThrashV1Peak(PeakTops[peakIndex]);
                        found = true;
                        break;
                    }
                }
                if (found)
                {
                    break;
                }
            }
            if (found)
            {
                RemovePeak(peak);
            }
            return(found);
        }
Exemplo n.º 4
0
        /// <summary>
        ///     Get the most intense unprocessed peak in the given m/z range.
        /// </summary>
        /// <param name="startMz">minimum m/z of the peak.</param>
        /// <param name="stopMz">maximum m/z of the peak.</param>
        /// <param name="peak">is assigned the most intense Peak with m/z between the startMz and stopMz.</param>
        /// <returns>returns true if a peak was found and false if none was found.</returns>
        public bool GetPeak(double startMz, double stopMz, out ThrashV1Peak peak)
        {
            peak = new ThrashV1Peak(0)
            {
                Intensity = -10
            };

            var found = false;

            foreach (var item in _peakMzToIndexDict.Where(x => x.Key >= startMz))
            {
                var peakIndex = item.Value;
                var mzVal     = item.Key;
                if (mzVal > stopMz)
                {
                    return(found);
                }
                if (PeakTops[peakIndex].Intensity > peak.Intensity && mzVal >= startMz)
                {
                    peak  = new ThrashV1Peak(PeakTops[peakIndex]);
                    found = true;
                }
            }
            return(found);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets the closest to peakMz among the peak list mzList
        /// </summary>
        /// <param name="peakMz"></param>
        /// <param name="peak"></param>
        /// <returns></returns>
        public double GetClosestPeakMz(double peakMz, out ThrashV1Peak peak)
        {
            //looks through the peak list and finds the closest peak to peakMz
            var minScore = 1.00727638; //enough for one charge away

            peak = new ThrashV1Peak(0.0);

            try
            {
                var numberPeaks = PeakData.PeakTops.Count;
                for (var peakCount = 0; peakCount < numberPeaks; peakCount++)
                {
                    var thisPeak = PeakData.PeakTops[peakCount];
                    var score    = Math.Pow(peakMz - thisPeak.Mz, 2);
                    if (score < minScore)
                    {
                        minScore = score;
                        peak     = new ThrashV1Peak(thisPeak);
                    }
                }
            }
            catch (Exception)
            {
                peak.Mz        = 0.0;
                peak.Intensity = 0.0;
#if DEBUG
                throw;
#endif
            }

            return(peak.Mz);
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Finds the highest peak from the raw data vectors withing the specified m/z range (reduced from original FindPeak
        /// </summary>
        /// <param name="startMz">minimum m\z at which to look for the peak</param>
        /// <param name="stopMz">maximum m\z at which to look for the peak.</param>
        /// <param name="peak"> instance whose mz and intensity are set to the peak that is found.</param>
        /// <remarks>The function only sets the mz, intensity of the peak, not the other members (SN, FWHM etc).</remarks>
        public void FindPeakAbsolute(double startMz, double stopMz, out ThrashV1Peak peak)
        {
            // Anoop : modified from original FindPEak so as to return peaks only
            // and not shoulders, eliminates all the +ve Da DelM regions
            peak           = new ThrashV1Peak();
            peak.Mz        = -1;
            peak.Intensity = 0;
            var width             = (stopMz - startMz) / 2;
            var foundExistingPeak = GetClosestPeak(startMz + width, width, out peak);

            if (foundExistingPeak)
            {
                // peak already exists. Send it back.
            }
            else
            {
                // peak doesn't exist. Lets find a starting index to start looking at.
                // perhaps there was a peak there.
                var foundPeak = GetClosestPeakFromAll(startMz + width, width, out peak);
                var numPts    = MzList.Count;
                if (foundPeak)
                {
                    var index = peak.DataIndex;
                    while (index > 0 && MzList[index] >= startMz)
                    {
                        var intensity = IntensityList[index];
                        var mz        = MzList[index];
                        if (intensity > peak.Intensity && mz <= stopMz)
                        {
                            peak.Mz        = mz;
                            peak.Intensity = intensity;
                            peak.DataIndex = index;
                        }
                        index--;
                    }
                    index = peak.DataIndex;
                    while (index < numPts && MzList[index] <= stopMz)
                    {
                        var intensity = IntensityList[index];
                        if (intensity > peak.Intensity)
                        {
                            var mz = MzList[index];
                            peak.Mz        = mz;
                            peak.Intensity = intensity;
                            peak.DataIndex = index;
                        }
                        index++;
                    }
                    if (peak.Intensity <= 0)
                    {
                        peak.Mz = 0;
                    }
                }
            }
        }
Exemplo n.º 7
0
 /// <summary>
 ///     Gets the peak in <see cref="PeakTops" /> whose m/z is exactly equal to mz.
 /// </summary>
 /// <param name="mz">m/z of the peak we are looking for.</param>
 /// <param name="peak">the peak whose m/z equals input parameter.</param>
 /// <returns>true is the peak was found; false otherwise</returns>
 public bool GetPeak(double mz, out ThrashV1Peak peak)
 {
     peak = new ThrashV1Peak();
     if (_peakMzToIndexDict.ContainsKey(mz))
     {
         var peakIndex = _peakMzToIndexDict[mz];
         peak = new ThrashV1Peak(PeakTops[peakIndex]);
         return(true);
     }
     return(false);
 }
Exemplo n.º 8
0
        /// <summary>
        ///     Removes the peak from the unprocessed list.
        /// </summary>
        /// <param name="peak">is the peak we want to remove from the unprocessed peaks.</param>
        /// <remarks>
        ///     In order to remove the peak from the processing "list", we clear the indices of the peak from the unprocessed
        ///     maps <see cref="_peakMzToIndexDict" /> and <see cref="_peakIntensityToIndexDict" />
        /// </remarks>
        public void RemovePeak(ThrashV1Peak peak)
        {
            if (peak == null)
            {
                return;
            }
            var found = false;

            if (_peakIntensityToIndexDict.ContainsKey((int)peak.Intensity))
            {
                var indexList = _peakIntensityToIndexDict[(int)peak.Intensity];
                found = indexList.Remove(peak.PeakIndex);
                if (indexList.Count == 0)
                {
                    _peakIntensityToIndexDict.Remove((int)peak.Intensity);
                }
            }
            if (!found)
            {
                return;
            }

            found = false;
            if (_peakMzToIndexDict.ContainsKey(peak.Mz))
            {
                if (_peakMzToIndexDict[peak.Mz] == peak.PeakIndex)
                {
                    _peakMzToIndexDict.Remove(peak.Mz);
                    found = true;
                }
            }
            else
            {
                var items = _peakMzToIndexDict.Where(x => x.Value == peak.PeakIndex).ToList();
                foreach (var item in items)
                {
                    if (peak.Mz.Equals(item.Key))
                    {
                        _peakMzToIndexDict.Remove(item.Key);
                        found = true;
                    }
                }
            }
            if (!found)
            {
                // so how did this happen ?
                return;
            }

            PeakTops[peak.PeakIndex].Intensity = -1;
        }
Exemplo n.º 9
0
        /// <summary>
        ///     Adds a peak to the processing list.
        /// </summary>
        /// <param name="pk">is the peak that we want to add to our processing list.</param>
        /// <remarks>
        ///     The processing list is really the set of peaks that are unprocessed and the way these are tracked, are by putting
        ///     these indices in the processing maps <see cref="_peakIntensityToIndexDict" /> and <see cref="_peakMzToIndexDict" />
        /// </remarks>
        public void AddPeakToProcessingList(ThrashV1Peak pk)
        {
            // The assumption is that this peak already exists in the List.
            // The peak was removed from the processing list, so we're going to add it in.
            // The map for all peaks is unaffected so we won't add to it.
            // Also the intensity is set to 0 when deletion happens. So lets copy
            // the peak back into our peak vector.
            var peakIndex = pk.PeakIndex;
            var mz        = pk.Mz;
            var intensity = (int)pk.Intensity;

            PeakTops[peakIndex] = new ThrashV1Peak(pk);
            _peakMzToIndexDict.Add(mz, peakIndex);
            AddIntensityToPeakMapping(intensity, peakIndex);
        }
Exemplo n.º 10
0
        /// <summary>
        ///     Gets the peak (whether or not it is processed) whose m/z is closest to supplied mz in the m/z range (mz - width to
        ///     mz + width).
        /// </summary>
        /// <param name="mz">the center m\z around which we want to look for a Peak.</param>
        /// <param name="width">the width of the m\z window in which we want to look for the peak.</param>
        /// <param name="peak">is the peak closest to m/z.</param>
        /// <returns>returns true if a peak was found in the window (mz - width to mz + width) and false if not found.</returns>
        /// <remarks>The returned peak can have an intensity of 0 because it was already processed and removed.</remarks>
        public bool GetClosestPeakFromAll(double mz, double width, out ThrashV1Peak peak)
        {
            peak = new ThrashV1Peak(0);
            var found = false;

            var startMz = mz - width;
            var stopMz  = mz + width;

            foreach (var item in _allPeakMzToIndexDict.Where(x => x.Key >= startMz))
            {
                var peakIndex = item.Value;
                var mzVal     = item.Key;
                if (mzVal > stopMz)
                {
                    return(found);
                }
                if (mzVal >= startMz && Math.Abs(mzVal - mz) < Math.Abs(peak.Mz - mz))
                {
                    peak  = new ThrashV1Peak(PeakTops[peakIndex]);
                    found = true;
                }
            }
            return(found);
        }
Exemplo n.º 11
0
 /// <summary>
 ///     Adds a peak to <see cref="PeakTops" />
 /// </summary>
 /// <param name="peak">is the peak that we want to add to <see cref="PeakTops" />.</param>
 public void AddPeak(ThrashV1Peak peak)
 {
     PeakTops.Add(new ThrashV1Peak(peak));
 }
Exemplo n.º 12
0
        /// <summary>
        ///     Finds the highest peak from the raw data lists withing the specified m/z range.
        /// </summary>
        /// <param name="startMz">minimum m\z at which to look for the peak</param>
        /// <param name="stopMz">maximum m\z at which to look for the peak.</param>
        /// <param name="peak"> instance whose mz and intensity are set to the peak that is found.</param>
        /// <remarks>The function only sets the mz, intensity of the peak, not the other members (SN, FWHM etc).</remarks>
        public void FindPeak(double startMz, double stopMz, out ThrashV1Peak peak)
        {
            peak = new ThrashV1Peak(-1);

            var width             = (stopMz - startMz) / 2;
            var foundExistingPeak = GetClosestPeak(startMz + width, width, out peak);

            if (foundExistingPeak)
            {
                // peak already exists. Send it back.
            }
            else
            {
                // peak doesn't exist. Lets find a starting index to start looking at.
                // perhaps there was a peak there.
                var foundPeak = GetClosestPeakFromAll(startMz + width, width, out peak);
                var numPts    = MzList.Count;
                if (foundPeak)
                {
                    var index = peak.DataIndex;
                    while (index > 0 && MzList[index] >= startMz)
                    {
                        var intensity = IntensityList[index];
                        var mz        = MzList[index];
                        if (intensity > peak.Intensity && mz <= stopMz)
                        {
                            peak.Mz        = mz;
                            peak.Intensity = intensity;
                            peak.DataIndex = index;
                        }
                        index--;
                    }
                    index = peak.DataIndex;
                    while (index < numPts && MzList[index] <= stopMz)
                    {
                        var intensity = IntensityList[index];
                        if (intensity > peak.Intensity)
                        {
                            var mz = MzList[index];
                            peak.Mz        = mz;
                            peak.Intensity = intensity;
                            peak.DataIndex = index;
                        }
                        index++;
                    }
                    if (peak.Intensity <= 0)
                    {
                        peak.Mz = 0;
                    }
                }
                else
                {
                    var startIndex = PeakIndex.GetNearestBinary(MzList, startMz, 0, numPts - 1);

                    if (startIndex > numPts - 1)
                    {
                        startIndex = numPts - 1;
                    }
                    if (startIndex < 0)
                    {
                        startIndex = 0;
                    }

                    if (MzList[startIndex] > startMz)
                    {
                        while (startIndex > 0 && MzList[startIndex] > startMz)
                        {
                            startIndex--;
                        }
                    }
                    else
                    {
                        while (startIndex < numPts && MzList[startIndex] < startMz)
                        {
                            startIndex++;
                        }
                        startIndex--;
                    }

                    for (var i = startIndex; i < numPts; i++)
                    {
                        var mz        = MzList[i];
                        var intensity = IntensityList[i];
                        if (mz > stopMz)
                        {
                            break;
                        }
                        if (intensity > peak.Intensity)
                        {
                            peak.Mz        = mz;
                            peak.Intensity = intensity;
                            peak.DataIndex = i;
                        }
                    }
                }
            }
        }