Esempio n. 1
0
        //MsDeconv Score peak
        private static double MsDeconvScore_peak(MzPeak experiment, MzPeak theory, double mass_error_tolerance = 0.02)
        {
            double score = 0;

            double mass_error = Math.Abs(experiment.Mz - theory.Mz);

            double mass_accuracy = 0;

            if (mass_error <= 0.02)
            {
                mass_accuracy = 1 - mass_error / mass_error_tolerance;
            }

            double abundance_diff = 0;

            if (experiment.Intensity < theory.Intensity && (theory.Intensity - experiment.Intensity) / experiment.Intensity <= 1)
            {
                abundance_diff = 1 - (theory.Intensity - experiment.Intensity) / experiment.Intensity;
            }
            else if (experiment.Intensity >= theory.Intensity && (experiment.Intensity - theory.Intensity) / experiment.Intensity <= 1)
            {
                abundance_diff = Math.Sqrt(1 - (experiment.Intensity - theory.Intensity) / experiment.Intensity);
            }

            score = Math.Sqrt(theory.Intensity) * mass_accuracy * abundance_diff;

            return(score);
        }
Esempio n. 2
0
        //Scale Theoretical Envelope
        private static MzPeak[] ScaleTheoEnvelop(MzPeak[] experiment, MzPeak[] theory, string method = "sum")
        {
            var scale_Theory = new MzPeak[theory.Length];

            switch (method)
            {
            case "sum":
                var total_abundance = experiment.Sum(p => p.Intensity);
                scale_Theory = theory.Select(p => new MzPeak(p.Mz, p.Intensity * total_abundance)).ToArray();
                break;

            default:
                break;
            }
            return(scale_Theory);
        }
Esempio n. 3
0
        //Change the workflow for different score method.
        public static IsoEnvelop GetETEnvelopForPeakAtChargeState(MzSpectrumXY mzSpectrumXY, double candidateForMostIntensePeakMz, int chargeState, DeconvolutionParameter deconvolutionParameter, double noiseLevel, out List <int> arrayOfTheoPeakIndexes)
        {
            var testMostIntenseMass = candidateForMostIntensePeakMz.ToMass(chargeState);

            var massIndex = GetClosestIndexInArray(testMostIntenseMass, mostIntenseMasses).Value;

            var differenceBetweenTheorAndActual = candidateForMostIntensePeakMz.ToMass(chargeState) - mostIntenseMasses[massIndex];

            var theoryIsoEnvelopLength = 0;

            for (int i = 0; i < allIntensities[massIndex].Length; i++)
            {
                theoryIsoEnvelopLength++;

                if (allIntensities[massIndex][i] / allIntensities[massIndex][0] <= 0.05 && i >= 2)
                {
                    break;
                }
            }

            var arrayOfPeaks     = new MzPeak[theoryIsoEnvelopLength];
            var arrayOfTheoPeaks = new MzPeak[theoryIsoEnvelopLength];

            arrayOfTheoPeakIndexes = new List <int>(); //For top-down to calculate MsDeconvSignificance

            for (int indexToLookAt = 0; indexToLookAt < theoryIsoEnvelopLength; indexToLookAt++)
            {
                double theorMassThatTryingToFind = allMasses[massIndex][indexToLookAt] + differenceBetweenTheorAndActual;
                arrayOfTheoPeaks[indexToLookAt] = new MzPeak(theorMassThatTryingToFind.ToMz(chargeState), allIntensities[massIndex][indexToLookAt]);

                var closestPeakToTheorMassIndex = GetClosestIndexInArray(theorMassThatTryingToFind.ToMz(chargeState), mzSpectrumXY.XArray);
                var closestPeakmz        = mzSpectrumXY.XArray[closestPeakToTheorMassIndex.Value];
                var closestPeakIntensity = mzSpectrumXY.YArray[closestPeakToTheorMassIndex.Value];


                if (!deconvolutionParameter.DeconvolutionAcceptor.Within(theorMassThatTryingToFind, closestPeakmz.ToMass(chargeState)) || closestPeakIntensity < noiseLevel)
                {
                    closestPeakmz        = theorMassThatTryingToFind.ToMz(chargeState);
                    closestPeakIntensity = 0;
                }
                else
                {
                    //if the peak was matched
                    arrayOfTheoPeakIndexes.Add(closestPeakToTheorMassIndex.Value);
                }
                arrayOfPeaks[indexToLookAt] = new MzPeak(closestPeakmz, closestPeakIntensity);
            }

            if (FilterEEnvelop(arrayOfPeaks))
            {
                var scaleArrayOfTheoPeaks = ScaleTheoEnvelop(arrayOfPeaks, arrayOfTheoPeaks);

                //The following 3 lines are for calculating monoisotopicMass, origin from Stephan, I don't understand it, and may optimize it in the future. (Lei)
                //var extrapolatedMonoisotopicMass = candidateForMostIntensePeakMz.ToMass(chargeState) - diffToMonoisotopic[massIndex]; // Optimized for proteoforms!!
                //var lowestMass = arrayOfPeaks.Min(b => b.Mz).ToMass(chargeState); // But may actually observe this small peak
                //var monoisotopicMass = Math.Abs(extrapolatedMonoisotopicMass - lowestMass) < 0.5 ? lowestMass : extrapolatedMonoisotopicMass;

                var monoisotopicMass = candidateForMostIntensePeakMz.ToMass(chargeState) - diffToMonoisotopic[massIndex];

                IsoEnvelop isoEnvelop = new IsoEnvelop(arrayOfPeaks, scaleArrayOfTheoPeaks, monoisotopicMass, chargeState, arrayOfTheoPeakIndexes);
                return(isoEnvelop);
            }

            return(null);
        }