示例#1
0
        public virtual object Clone()
        {
            var result = new clsHornTransformResults
            {
                PeakIndex          = PeakIndex,
                ScanNum            = ScanNum,
                ChargeState        = ChargeState,
                Abundance          = Abundance,
                Mz                 = Mz,
                Fit                = Fit,
                FitCountBasis      = FitCountBasis,
                AverageMw          = AverageMw,
                MonoMw             = MonoMw,
                MostIntenseMw      = MostIntenseMw,
                FWHM               = FWHM,
                SignalToNoise      = SignalToNoise,
                MonoIntensity      = MonoIntensity,
                MonoPlus2Intensity = MonoPlus2Intensity,
                DeltaMz            = DeltaMz,
                IsotopePeakIndices = new List <int>(IsotopePeakIndices)
            };

            //result.AbundanceInt = this.AbundanceInt;
            return(result);
        }
示例#2
0
 public clsHornTransformResults(clsHornTransformResults a)
 {
     PeakIndex          = a.PeakIndex;
     ScanNum            = a.ScanNum;
     ChargeState        = a.ChargeState;
     Abundance          = a.Abundance;
     Mz                 = a.Mz;
     Fit                = a.Fit;
     FitCountBasis      = a.FitCountBasis;
     AverageMw          = a.AverageMw;
     MonoMw             = a.MonoMw;
     MostIntenseMw      = a.MostIntenseMw;
     FWHM               = a.FWHM;
     SignalToNoise      = a.SignalToNoise;
     MonoIntensity      = a.MonoIntensity;
     MonoPlus2Intensity = a.MonoPlus2Intensity;
     DeltaMz            = a.DeltaMz;
     IsotopePeakIndices = new List <int>(a.IsotopePeakIndices);
 }
示例#3
0
        private void SetIsotopeDistributionToZero(PeakData peakData, clsPeak peak, double zeroingStartMz,
                                                  double zeroingStopMz, double monoMw, int chargeState, bool clearSpectrum, clsHornTransformResults record,
                                                  bool debug = false)
        {
            var peakIndices = new List <int>();

            peakIndices.Add(peak.PeakIndex);
            var mzDelta = record.DeltaMz;

            if (debug)
            {
                Console.Error.WriteLine("Clearing peak data for " + peak.Mz + " Delta = " + mzDelta);
                Console.Error.WriteLine("Zeroing range = " + zeroingStartMz + " to " + zeroingStopMz);
            }

            double maxMz = 0;

            if (TransformParameters.O16O18Media)
            {
                maxMz = (monoMw + 3.5) / chargeState + TransformParameters.CCMass;
            }

            var numUnprocessedPeaks = peakData.GetNumUnprocessedPeaks();

            if (numUnprocessedPeaks == 0)
            {
                record.IsotopePeakIndices.Add(peak.PeakIndex);
                return;
            }

            if (clearSpectrum)
            {
                if (debug)
                {
                    Console.Error.WriteLine("Deleting main peak :" + peak.Mz);
                }
                SetPeakToZero(peak.DataIndex, ref peakData.IntensityList, ref peakData.MzList, debug);
            }

            peakData.RemovePeaks(peak.Mz - peak.FWHM, peak.Mz + peak.FWHM, debug);

            if (1 / (peak.FWHM * chargeState) < 3) // gord:  ??
            {
                record.IsotopePeakIndices.Add(peak.PeakIndex);
                peakData.RemovePeaks(zeroingStartMz, zeroingStopMz, debug);
                return;
            }

            // Delete isotopes of mzs higher than mz of starting isotope
            for (var peakMz = peak.Mz + 1.003 / chargeState;
                 (!TransformParameters.O16O18Media || peakMz <= maxMz) && peakMz <= zeroingStopMz + 2 * peak.FWHM;
                 peakMz += 1.003 / chargeState)
            {
                if (debug)
                {
                    Console.Error.WriteLine("\tFinding next peak top from " + (peakMz - 2 * peak.FWHM) + " to " +
                                            (peakMz + 2 * peak.FWHM) + " pk = " + peakMz + " FWHM = " + peak.FWHM);
                }
                clsPeak nextPeak;
                peakData.GetPeakFromAll(peakMz - 2 * peak.FWHM, peakMz + 2 * peak.FWHM, out nextPeak);

                if (nextPeak.Mz.Equals(0))
                {
                    if (debug)
                    {
                        Console.Error.WriteLine("\t\tNo peak found.");
                    }
                    break;
                }
                if (debug)
                {
                    Console.Error.WriteLine("\t\tFound peak to delete =" + nextPeak.Mz);
                }

                // Before assuming that the next peak is indeed an isotope, we must check for the height of this
                // isotope. If the height is greater than expected by a factor of 3, lets not delete it.
                peakIndices.Add(nextPeak.PeakIndex);
                SetPeakToZero(nextPeak.DataIndex, ref peakData.IntensityList, ref peakData.MzList, debug);

                peakData.RemovePeaks(nextPeak.Mz - peak.FWHM, nextPeak.Mz + peak.FWHM, debug);
                peakMz = nextPeak.Mz;
            }

            // Delete isotopes of mzs lower than mz of starting isotope
            // TODO: Use the delta m/z to make sure to remove 1- peaks from the unprocessed list, but not from the list of peaks?
            for (var peakMz = peak.Mz - 1.003 / chargeState;
                 peakMz > zeroingStartMz - 2 * peak.FWHM;
                 peakMz -= 1.003 / chargeState)
            {
                if (debug)
                {
                    Console.Error.WriteLine("\tFinding previous peak top from " + (peakMz - 2 * peak.FWHM) + " to " +
                                            (peakMz + 2 * peak.FWHM) + " pk = " + peakMz + " FWHM = " + peak.FWHM);
                }
                clsPeak nextPeak;
                peakData.GetPeakFromAll(peakMz - 2 * peak.FWHM, peakMz + 2 * peak.FWHM, out nextPeak);
                if (nextPeak.Mz.Equals(0))
                {
                    if (debug)
                    {
                        Console.Error.WriteLine("\t\tNo peak found.");
                    }
                    break;
                }
                if (debug)
                {
                    Console.Error.WriteLine("\t\tFound peak to delete =" + nextPeak.Mz);
                }
                peakIndices.Add(nextPeak.PeakIndex);
                SetPeakToZero(nextPeak.DataIndex, ref peakData.IntensityList, ref peakData.MzList, debug);
                peakData.RemovePeaks(nextPeak.Mz - peak.FWHM, nextPeak.Mz + peak.FWHM, debug);
                peakMz = nextPeak.Mz;
            }

            if (debug)
            {
                Console.Error.WriteLine("Done Clearing peak data for " + peak.Mz);
            }

            peakIndices.Sort();
            // now insert into array.
            var numPeaksObserved       = peakIndices.Count;
            var numIsotopesObserved    = 0;
            var lastIsotopeNumObserved = int.MinValue;

            for (var i = 0; i < numPeaksObserved; i++)
            {
                var currentIndex = peakIndices[i];
                var currentPeak  = new clsPeak(peakData.PeakTops[currentIndex]);
                var isotopeNum   = (int)(Math.Abs((currentPeak.Mz - peak.Mz) * chargeState / 1.003) + 0.5);
                if (currentPeak.Mz < peak.Mz)
                {
                    isotopeNum = -1 * isotopeNum;
                }
                if (isotopeNum > lastIsotopeNumObserved)
                {
                    lastIsotopeNumObserved = isotopeNum;
                    numIsotopesObserved++;
                    if (numIsotopesObserved > MaxIsotopes)
                    {
                        break;
                    }
                    record.IsotopePeakIndices.Add(peakIndices[i]);
                }
                else
                {
                    record.IsotopePeakIndices[numIsotopesObserved - 1] = peakIndices[i];
                }
            }
            if (debug)
            {
                Console.Error.WriteLine("Copied " + record.NumIsotopesObserved + " isotope peak indices into record ");
            }
        }
示例#4
0
        public virtual bool FindTransform(PeakData peakData, ref clsPeak peak, out clsHornTransformResults record,
                                          double backgroundIntensity = 0)
        {
            record = new clsHornTransformResults();
            if (peak.SignalToNoise < TransformParameters.MinS2N || peak.FWHM.Equals(0))
            {
                return(false);
            }

            //var resolution = peak.Mz / peak.FWHM;
            var chargeState = AutoCorrelationChargeDetermination.GetChargeState(peak, peakData, DebugFlag);

            if (chargeState == -1 && TransformParameters.CheckAllPatternsAgainstCharge1)
            {
                chargeState = 1;
            }

            if (DebugFlag)
            {
                Console.Error.WriteLine("Deisotoping :" + peak.Mz);
                Console.Error.WriteLine("Charge = " + chargeState);
            }

            if (chargeState == -1)
            {
                return(false);
            }

            if ((peak.Mz + TransformParameters.CCMass) * chargeState > TransformParameters.MaxMW)
            {
                return(false);
            }

            if (TransformParameters.O16O18Media)
            {
                if (peak.FWHM < 1.0 / chargeState)
                {
                    // move back by 4 Da and see if there is a peak.
                    var     minMz = peak.Mz - 4.0 / chargeState - peak.FWHM;
                    var     maxMz = peak.Mz - 4.0 / chargeState + peak.FWHM;
                    clsPeak o16Peak;
                    var     found = peakData.GetPeak(minMz, maxMz, out o16Peak);
                    if (found && !o16Peak.Mz.Equals(peak.Mz))
                    {
                        // put back the current into the to be processed list of peaks.
                        peakData.AddPeakToProcessingList(peak);
                        // reset peak to the right peak so that the calling function may
                        // know that the peak might have changed in the O16/O18 business
                        peak = o16Peak;
                        peakData.RemovePeak(peak);
                        return(FindTransform(peakData, ref peak, out record, backgroundIntensity));
                    }
                }
            }

            var peakCharge1 = new clsPeak(peak);

            // Until now, we have been using constant theoretical delete intensity threshold..
            // instead, from now, we should use one that is proportional to intensity, for more intense peaks.
            // However this will not solve all problems. If thrashing occurs, then the peak intensity will
            // change when the function returns and we may not delete far enough.
            //double deleteThreshold = backgroundIntensity / peak.Intensity * 100;
            //if (backgroundIntensity ==0 || deleteThreshold > _deleteIntensityThreshold)
            //  deleteThreshold = _deleteIntensityThreshold;
            var deleteThreshold = TransformParameters.DeleteIntensityThreshold;
            int fitCountBasis;
            var bestFit = TransformParameters.IsotopeFitScorer.GetFitScore(peakData, chargeState, ref peak, out record, deleteThreshold,
                                                                           TransformParameters.MinIntensityForScore, TransformParameters.LeftFitStringencyFactor, TransformParameters.RightFitStringencyFactor, out fitCountBasis,
                                                                           DebugFlag);

            // When deleting an isotopic profile, this value is set to the first m/z to perform deletion at.
            double zeroingStartMz;
            // When deleting an isotopic profile, this value is set to the last m/z to perform deletion at.
            double zeroingStopMz;

            TransformParameters.IsotopeFitScorer.GetZeroingMassRange(out zeroingStartMz, out zeroingStopMz, record.DeltaMz, deleteThreshold,
                                                                     DebugFlag);
            //bestFit = _isotopeFitter.GetFitScore(peakData, chargeState, peak, record, _deleteIntensityThreshold, _minTheoreticalIntensityForScore, DebugFlag);
            //_isotopeFitter.GetZeroingMassRange(_zeroingStartMz, _zeroingStopMz, record.DeltaMz, _deleteIntensityThreshold, DebugFlag);

            if (TransformParameters.CheckAllPatternsAgainstCharge1 && chargeState != 1)
            {
                clsHornTransformResults recordCharge1;
                int fitCountBasisCharge1;
                var bestFitCharge1 = TransformParameters.IsotopeFitScorer.GetFitScore(peakData, 1, ref peakCharge1, out recordCharge1,
                                                                                      deleteThreshold, TransformParameters.MinIntensityForScore, TransformParameters.LeftFitStringencyFactor,
                                                                                      TransformParameters.RightFitStringencyFactor, out fitCountBasisCharge1, DebugFlag);

                //double bestFitCharge1 = _isotopeFitter.GetFitScore(peakData, 1, peakCharge1, recordCharge1, _deleteIntensityThreshold, _minTheoreticalIntensityForScore, DebugFlag);
                //_isotopeFitter.GetZeroingMassRange(_zeroingStartMz, _zeroingStopMz, record.DeltaMz, _deleteIntensityThreshold, DebugFlag);
                double startMz1 = 0;
                double stopMz1  = 0;
                TransformParameters.IsotopeFitScorer.GetZeroingMassRange(out startMz1, out stopMz1, record.DeltaMz, deleteThreshold, DebugFlag);
                if (bestFit > TransformParameters.MaxFit && bestFitCharge1 < TransformParameters.MaxFit)
                {
                    bestFit        = bestFitCharge1;
                    fitCountBasis  = fitCountBasisCharge1;
                    peak           = peakCharge1;
                    record         = new clsHornTransformResults(recordCharge1);
                    zeroingStartMz = startMz1;
                    zeroingStopMz  = stopMz1;
                    chargeState    = 1;
                }
            }

            if (bestFit > TransformParameters.MaxFit) // check if fit is good enough
            {
                return(false);
            }

            if (DebugFlag)
            {
                Console.Error.WriteLine("\tBack with fit = " + record.Fit);
            }

            // Applications using this DLL should use Abundance instead of AbundanceInt
            record.Abundance   = peak.Intensity;
            record.ChargeState = chargeState;

            clsPeak monoPeak;
            var     monoMz = record.MonoMw / record.ChargeState + TransformParameters.CCMass;

            // used when _reportO18Plus2Da is true.
            clsPeak m3Peak;
            var     monoPlus2Mz = record.MonoMw / record.ChargeState + 2.0 / record.ChargeState + TransformParameters.CCMass;

            peakData.FindPeak(monoMz - peak.FWHM, monoMz + peak.FWHM, out monoPeak);
            peakData.FindPeak(monoPlus2Mz - peak.FWHM, monoPlus2Mz + peak.FWHM, out m3Peak);

            record.MonoIntensity      = (int)monoPeak.Intensity;
            record.MonoPlus2Intensity = (int)m3Peak.Intensity;
            record.SignalToNoise      = peak.SignalToNoise;
            record.FWHM      = peak.FWHM;
            record.PeakIndex = peak.PeakIndex;

            SetIsotopeDistributionToZero(peakData, peak, zeroingStartMz, zeroingStopMz, record.MonoMw, chargeState, true,
                                         record, DebugFlag);
            if (DebugFlag)
            {
                Console.Error.WriteLine("Performed deisotoping of " + peak.Mz);
            }
            return(true);
        }