Exemplo n.º 1
0
        public double GetRankSumTestPvalue(Ms1Peak[] peaks, int envelopeSize)
        {
            if (PeakRanking == null)
            {
                return(1.0d);
            }

            // calculate ranksum test score
            var ranksum  = 0;
            var nRankSum = 0;

            for (var i = 0; i < envelopeSize; i++)
            {
                if (peaks[i] == null || !peaks[i].Active)
                {
                    continue;
                }

                var localIndex = peaks[i].IndexInSpectrum - PeakStartIndex;
                if (localIndex >= PeakCount || localIndex < 0)
                {
                    continue;
                }
                ranksum += PeakRanking[localIndex];
                nRankSum++;
            }

            var pvalue = FitScoreCalculator.GetRankSumPvalue(PeakCount, nRankSum, ranksum);

            return(pvalue);
        }
Exemplo n.º 2
0
        private double GetRankSumScore()
        {
            var rankSum        = 0d;
            var nMatchedIons   = _prefixIonPeakIndex.Count + _suffixIonPeakIndex.Count;
            var nObservedPeaks = _ms2Spec.Peaks.Length;

            foreach (var peakIndex in _prefixIonPeakIndex)
            {
                rankSum += _peakRanking[peakIndex];
            }
            foreach (var peakIndex in _suffixIonPeakIndex)
            {
                rankSum += _peakRanking[peakIndex];
            }

            var pvalue = FitScoreCalculator.GetRankSumPvalue(nObservedPeaks, nMatchedIons, rankSum);

            if (pvalue > 0)
            {
                return(-Math.Log(pvalue, 2));
            }
            return(50);
        }
Exemplo n.º 3
0
        public IsotopeEnvelopeStatisticalInfo PreformStatisticalSignificanceTest(ObservedIsotopeEnvelope envelope)
        {
            int peakStartIndex;
            Tuple <double, double> mzBoundary;

            //var refPeak = envelope.Peaks[envelope.RefIsotopeInternalIndex];

            var mostAbuMz = 0d;
            var mostAbutPeakInternalIndex = envelope.TheoreticalEnvelope.IndexOrderByRanking[0];

            if (envelope.Peaks[mostAbutPeakInternalIndex] != null)
            {
                mostAbuMz = envelope.Peaks[mostAbutPeakInternalIndex].Mz;
            }
            else
            {
                mostAbuMz = envelope.TheoreticalEnvelope.GetIsotopeMz(envelope.Charge, mostAbutPeakInternalIndex);
            }

            var rankings = GetLocalRankings(mostAbuMz, out peakStartIndex, out mzBoundary);

            // smallest delta_mz = 0.01 (th) ?
            var ret = new IsotopeEnvelopeStatisticalInfo
            {
                LocalMzStart          = mzBoundary.Item1,
                LocalMzEnd            = mzBoundary.Item2,
                NumberOfLocalPeaks    = rankings.Length,
                NumberOfPossiblePeaks = (int)Math.Ceiling(100 * (mzBoundary.Item2 - mzBoundary.Item1)),
                NumberOfIsotopePeaks  = envelope.Size,
            };

            // calculate ranksum test score
            var ranksum  = 0;
            var nRankSum = 0;

            for (var i = 0; i < envelope.Size; i++)
            {
                if (envelope.Peaks[i] == null || !envelope.Peaks[i].Active)
                {
                    continue;
                }
                ret.NumberOfMatchedIsotopePeaks++;

                //if (isotopeList[i].Ratio > RelativeIntesnityThresholdForRankSum)
                //{
                var localIndex = envelope.Peaks[i].IndexInSpectrum - peakStartIndex;
                if (localIndex >= rankings.Length || localIndex < 0)
                {
                    continue;
                }
                ranksum += rankings[localIndex];
                nRankSum++;
                //}
            }

            var pvalue = FitScoreCalculator.GetRankSumPvalue(ret.NumberOfLocalPeaks, nRankSum, ranksum);

            ret.RankSumScore = (pvalue > 0) ? -Math.Log(pvalue, 2) : 50;

            // calculate poisson test score
            var n  = ret.NumberOfPossiblePeaks;
            var k  = ret.NumberOfIsotopePeaks;        // # of theretical isotope ions of the mass within the local window
            var n1 = ret.NumberOfLocalPeaks;          // # of detected ions within the local window
            var k1 = ret.NumberOfMatchedIsotopePeaks; // # of matched ions generating isotope envelope profile

            var lambda = ((double)n1 / (double)n) * k;

            pvalue           = 1 - Poisson.CDF(lambda, k1);
            ret.PoissonScore = (pvalue > 0) ? -Math.Log(pvalue, 2) : 50;
            return(ret);
        }