Example #1
0
 public O18QuantificationSummaryItem()
 {
     this.SpeciesAbundance    = new SpeciesAbundanceInfo();
     this.SampleAbundance     = new SampleAbundanceInfo();
     this.ObservedEnvelopes   = new List <O18QuanEnvelope>();
     this.ScanStartPercentage = 0.0;
     this.ScanEndPercentage   = 1.0;
 }
        /**
         * the whole labelling procedure contains two steps
         * first one is caused by enzyme and labelled the peptide with one O18.
         * the efficiency of this step is 100%.
         * second one is add one O18 on peptide
         * the efficiency of this step is unknown.
         * let's assume the abundance from O16 sample is x,
         * the abundance from O18 labelled sample is y,
         * the purity of O18 H2O is p,
         * the efficiency of second step is k (here k must be less than or equal to p)
         * only one replacement from O16 to O18 for each peptide occurs in second step,
         * then the final abundance of O16, Single O18, Double O18 have those formula:
         * O16 = x + (1 - k) * (1 - p) * y
         * O181 = (k(1-p) + p(1-k)) * y
         * O182 = p * k * y
         **/

        #region ISampleAbundanceCalculator Members

        public SampleAbundanceInfo Calculate(SpeciesAbundanceInfo speciesAbundance)
        {
            double o16   = speciesAbundance.O16;
            double o18_1 = speciesAbundance.O181;
            double o18_2 = speciesAbundance.O182;

            //Console.Out.WriteLine("{0:0.00}\t{1:0.00}\t{2:0.00}", o16, o18_1, o18_2);

            double k;

            if (this.fixedEfficiency)
            {
                k = purityOfO18Water; //consider k equals to p
            }
            else
            {
                //Consider that O16 cannot be labelled to O18 in second step to decrease the complexibility
                //I(O18_1)/I(O18_2) = ((1-p)k + (1-k)p) /pk
                //k = 1 / (2 + O181/O182 - 1/p)
                k = 1 / (2 + o18_1 / o18_2 - 1 / purityOfO18Water);

                Console.Out.WriteLine("k=" + k);

                if (k > purityOfO18Water || k <= 0)
                {
                    k = purityOfO18Water; //consider k equals to p
                }
            }
            //then, calculate the intensity from O18 labelled sample, assume as y
            //I(O18_1) + I(O18_2) = (1-k)py + (1-p)ky + pky
            //y = (I(O18_1) + I(O18_2)) / ((1-k)p + (1-p)k + pk)
            double y = (o18_1 + o18_2) / ((1 - k) * purityOfO18Water + (1 - purityOfO18Water) * k + purityOfO18Water * k);

            //finally, calculate the intensity from O16 labelled sample, assume as x
            //I(O16) = x + (1-k)(1-purity) * y
            //x = I(O16) - (1-k)(1-purity) * y
            double x = o16 - (1 - k) * (1 - purityOfO18Water) * y;

            if (x < 0) // it cannot be fixed, just use simple formula
            {
                x = o16;
                y = o18_1 + o18_2;
                k = purityOfO18Water;
            }

            var result = new SampleAbundanceInfo();

            result.O16 = x;
            result.O18 = y;
            result.LabellingEfficiency = k;
            result.CalculateRatio();
            return(result);
        }
        public void CalculateFromProfile(List <Peak> profile, ISampleAbundanceCalculator calc)
        {
            var top2percentage = profile[0].Intensity + profile[1].Intensity;

            this.SpeciesAbundance     = new SpeciesAbundanceInfo();
            this.SpeciesAbundance.O16 = (this[0].Intensity + this[1].Intensity) / top2percentage;

            var intensity3 = Math.Max(0, this[2].Intensity - this.SpeciesAbundance.O16 * profile[2].Intensity);
            var intensity4 = Math.Max(0, this[3].Intensity - this.SpeciesAbundance.O16 * profile[3].Intensity);

            this.SpeciesAbundance.O181 = (intensity3 + intensity4) / top2percentage;

            var intensity5 = Math.Max(0, this[4].Intensity - this.SpeciesAbundance.O16 * profile[4].Intensity - this.SpeciesAbundance.O181 * profile[2].Intensity);
            var intensity6 = Math.Max(0, this[5].Intensity - this.SpeciesAbundance.O16 * profile[5].Intensity - this.SpeciesAbundance.O181 * profile[3].Intensity);

            this.SpeciesAbundance.O182 = (intensity5 + intensity6) / top2percentage;

            this.SampleAbundance = calc.Calculate(this.SpeciesAbundance);
        }
Example #4
0
        public void CalculateSpeciesAbundanceByLinearRegression()
        {
            var mergedPeaks = MergeEnvelopes();

            int maxLength = Math.Min(PeptideProfile.Count + 4, mergedPeaks.Count);

            double[][] a = GetProfileMatrix(maxLength);

            double[] x;

            this.SpeciesAbundance = CalculateSpeciesAbundance(maxLength, a, mergedPeaks, out x);

            double[] theoreticalIntensities = GetTheoreticalIntensities(maxLength, x);
            double[] observedIntensities    = GetObservedIntensities(maxLength, mergedPeaks);

            double corr = StatisticsUtils.PearsonCorrelation(theoreticalIntensities, observedIntensities);

            this.SpeciesAbundance.RegressionCorrelation = corr;
            this.SpeciesAbundance.RegressionItems.Clear();

            int    pepCharge = GetCharge();
            var    gap       = (Atom.O18.MonoMass - Atom.O.MonoMass) / pepCharge;
            var    gapC      = (Atom.C13.MonoMass - Atom.C.MonoMass) / pepCharge;
            double mzO16     = TheoreticalO16Mz;
            double mzO181    = TheoreticalO16Mz + gap;
            double mzO182    = mzO181 + gap;

            double[] mzs = { mzO16, mzO16 + gapC, mzO181, mzO181 + gapC, mzO182, mzO182 + gapC };

            for (int i = 0; i < maxLength && i < mzs.Length; i++)
            {
                var ri = new SpeciesRegressionItem();
                ri.Mz = mzs[i];
                ri.ObservedIntensity   = observedIntensities[i];
                ri.RegressionIntensity = theoreticalIntensities[i];
                this.SpeciesAbundance.RegressionItems.Add(ri);
            }

            var calc = this.GetCalculator();

            this.SampleAbundance = calc.Calculate(this.SpeciesAbundance);
        }
Example #5
0
        /**
         * the whole procedure contains two steps:
         * first one is digestion at normal condition.
         * second one is labelling at 18O water,the efficiency of this step is unknown.
         * let's assume the abundance from O16 sample is x,
         * the abundance from O18 labelled sample is y,
         * the purity of O18 H2O is p,
         * the efficiency of second step is k (here k must be less than or equal to p),
         * then the final abundance of O16, Single O18, Double O18 have those formula:
         * O16 = x + (1 - k) * (1 - k) * y
         * O181 = 2 * k * (1 - k) * y
         * O182 = k * k * y
         *
         * since it's very difficult to distinguish between extreme high O16 sample and extreme low labelling efficiency,
         * we prefer extreme high o16 sample than extreme low labelling efficiency. So when labelling efficiency is lower than 0.2,
         * we will consider it as full labelling efficiency (equals to purity of O18 water).
         **/

        #region ISampleAbundanceCalculator Members

        public SampleAbundanceInfo Calculate(SpeciesAbundanceInfo speciesAbundance)
        {
            double o16   = speciesAbundance.O16;
            double o18_1 = speciesAbundance.O181;
            double o18_2 = speciesAbundance.O182;

            //Console.Out.WriteLine("{0:0.00}\t{1:0.00}\t{2:0.00}", o16, o18_1, o18_2);

            double k;

            if (o18_2 == 0.0)
            {
                k = purityOfO18Water;
            }
            else
            {
                k = 2 / (2 + o18_1 / o18_2);
            }

            //Console.Out.WriteLine("k=" + k);
            if (k > purityOfO18Water)
            {
//consider k equals to p
                k = purityOfO18Water;
            }
            else if (k <= MIN_LABELLING_EFFICIENCY)
            {
                if (o18_1 > o18_2)
                {
                    Console.Out.WriteLine("k={0}; O16={1}; O181={2}; O182={3}", k, o16, o18_1, o18_2);
                }
                else
                {
                    k = purityOfO18Water;
                }
            }

            double x, y;

            if (k == 1.0)
            {
                y = o18_1 + o18_2;
                x = o16;
            }
            else
            {
                double y1 = o18_1 / (2 * k * (1 - k));
                double y2 = o18_2 / (k * k);

                y = Math.Max(y1, y2);

                x = o16 - y * (1 - k) * (1 - k);
                if (x < 0) // it cannot be fixed, just use simple formula
                {
                    x = 0;
                }
            }

            var result = new SampleAbundanceInfo();

            result.O16 = x;
            result.O18 = y;
            result.LabellingEfficiency = k;
            result.CalculateRatio();
            return(result);
        }