コード例 #1
0
        protected virtual bool FindTransform(PeakData peakData, ref ThrashV1Peak peak, out HornTransformResults record,
                                             double backgroundIntensity = 0)
        {
            SetIsotopeFitScorerOptions();
            record = new HornTransformResults();
            if (peak.SignalToNoiseDbl < MinSignalToNoise || peak.FWHM.Equals(0))
            {
                return(false);
            }

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

            /*/
             * // This chunk of code tries to use the DeconTools Patterson Algorithm Charge State Calculator, but it gets vastly different results.
             * var xyData = new XYData();
             * var mzArray = peakData.MzList.ToArray();
             * var intensityArray = peakData.IntensityList.ToArray();
             * xyData.SetXYValues(ref mzArray, ref intensityArray);
             * var peakList = new List<Peak>();
             * for (int i = 0; i < peakData.MzList.Count; i++)
             * {
             *  peakList.Add(new Peak(peakData.MzList[i], (float)peakData.IntensityList[i], 1));
             * }
             * var chargeState = DeconTools.Backend.Algorithms.ChargeStateDetermination.PattersonAlgorithm.PattersonChargeStateCalculator.GetChargeState(xyData, peakList, convertDeconPeakToMSPeak(peak));
             * /**/

            if (chargeState == -1 && CheckPatternsAgainstChargeOne)
            {
                chargeState = 1;
            }

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

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

            if ((peak.Mz + ChargeCarrierMass) * chargeState > MaxMWAllowed)
            {
                return(false);
            }

            if (IsO16O18Data)
            {
                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;
                    ThrashV1Peak 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 ThrashV1Peak(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 = DeleteIntensityThreshold;
            int fitCountBasis;
            var bestFit = _isotopeFitScorer.GetFitScore(peakData, chargeState, ref peak, out record, deleteThreshold,
                                                        MinIntensityForScore, LeftFitStringencyFactor, RightFitStringencyFactor, out fitCountBasis,
                                                        ShowTraceMessages);

            // 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;

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

            if (CheckPatternsAgainstChargeOne && chargeState != 1)
            {
                HornTransformResults recordCharge1;
                int fitCountBasisCharge1;
                var bestFitCharge1 = _isotopeFitScorer.GetFitScore(peakData, 1, ref peakCharge1, out recordCharge1,
                                                                   deleteThreshold, MinIntensityForScore, LeftFitStringencyFactor,
                                                                   RightFitStringencyFactor, out fitCountBasisCharge1, ShowTraceMessages);

                //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;
                _isotopeFitScorer.GetZeroingMassRange(out startMz1, out stopMz1, record.DeltaMz, deleteThreshold,
                                                      ShowTraceMessages);
                if (bestFit > MaxFitAllowed && bestFitCharge1 < MaxFitAllowed)
                {
                    bestFit        = bestFitCharge1;
                    fitCountBasis  = fitCountBasisCharge1;
                    peak           = peakCharge1;
                    record         = new HornTransformResults(recordCharge1);
                    zeroingStartMz = startMz1;
                    zeroingStopMz  = stopMz1;
                    chargeState    = 1;
                }
            }

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

            if (ShowTraceMessages)
            {
                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;

            ThrashV1Peak monoPeak;
            var          monoMz = record.MonoMw / record.ChargeState + ChargeCarrierMass;

            // used when _reportO18Plus2Da is true.
            ThrashV1Peak m3Peak;
            var          monoPlus2Mz = record.MonoMw / record.ChargeState + 2.0 / record.ChargeState + ChargeCarrierMass;

            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.SignalToNoiseDbl;
            record.FWHM      = peak.FWHM;
            record.PeakIndex = peak.PeakIndex;

            SetIsotopeDistributionToZero(peakData, peak, zeroingStartMz, zeroingStopMz, record.MonoMw, chargeState, true,
                                         record, ShowTraceMessages);
            if (ShowTraceMessages)
            {
                Console.Error.WriteLine("Performed deisotoping of " + peak.Mz);
            }
            return(true);
        }
コード例 #2
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);
        }