コード例 #1
0
        public static void DoFilterPeptideFromSameEngineDifferentParameters(List <IIdentifiedSpectrum> peptides, IScoreFunction score, Action <List <IIdentifiedSpectrum> > filter)
        {
            var  dic     = peptides.ToGroupDictionary(m => m.Query.FileScan.Experimental);
            bool changed = false;

            foreach (var v in dic.Values)
            {
                var  vdic           = v.ToGroupDictionary(m => m.Query.FileScan.FirstScan);
                bool currentChanged = false;
                foreach (var peps in vdic.Values)
                {
                    if (peps.Count > 1)
                    {
                        score.SortSpectrum(peps);
                        filter(peps);
                        currentChanged = true;
                    }
                }

                if (currentChanged)
                {
                    changed = true;
                    v.Clear();
                    foreach (var peps in vdic.Values)
                    {
                        v.AddRange(peps);
                    }
                }
            }

            if (changed)
            {
                peptides.Clear();
                foreach (var v in dic.Values)
                {
                    peptides.AddRange(v);
                }
            }
        }
コード例 #2
0
        public void CalculateToleranceScore(IScoreFunction scoreFunc)
        {
            scoreFunc.SortSpectrum(this.Spectra);

            this.Result.Score = this.Spectra.Count > 0 ? scoreFunc.GetScore(this.Spectra.Last()) : 0.0;
        }
コード例 #3
0
        public static void CalculateUniqueQValue(List <IIdentifiedSpectrum> peptides, IScoreFunction scoreFuncs, IFalseDiscoveryRateCalculator fdrCalc)
        {
            if (peptides.Count == 0)
            {
                return;
            }

            scoreFuncs.SortSpectrum(peptides);

            List <IIdentifiedSpectrum> sameScores = new List <IIdentifiedSpectrum>();
            HashSet <string>           targetSeq  = new HashSet <string>();
            HashSet <string>           decoySeq   = new HashSet <string>();

            double lastScore = scoreFuncs.GetScore(peptides[0]);

            for (int i = 0; i < peptides.Count; i++)
            {
                IIdentifiedSpectrum spectrum = peptides[i];
                double score = scoreFuncs.GetScore(peptides[i]);
                if (score == lastScore)
                {
                    sameScores.Add(spectrum);
                    if (spectrum.FromDecoy)
                    {
                        decoySeq.Add(spectrum.Peptide.PureSequence);
                    }
                    else
                    {
                        targetSeq.Add(spectrum.Peptide.PureSequence);
                    }
                    continue;
                }
                else
                {
                    double qValue = fdrCalc.Calculate(decoySeq.Count, targetSeq.Count);
                    foreach (IIdentifiedSpectrum sameScoreSpectrum in sameScores)
                    {
                        sameScoreSpectrum.QValue = qValue;
                    }

                    sameScores.Clear();

                    lastScore = score;
                    sameScores.Add(spectrum);
                    if (spectrum.FromDecoy)
                    {
                        decoySeq.Add(spectrum.Peptide.PureSequence);
                    }
                    else
                    {
                        targetSeq.Add(spectrum.Peptide.PureSequence);
                    }
                    continue;
                }
            }
            double lastQValue = fdrCalc.Calculate(decoySeq.Count, targetSeq.Count);

            foreach (IIdentifiedSpectrum sameScoreSpectrum in sameScores)
            {
                sameScoreSpectrum.QValue = lastQValue;
            }
        }
コード例 #4
0
        /// <summary>
        /// 根据给定分数排序函数以及FDR计算器对鉴定谱图列表计算QValue。
        /// </summary>
        /// <param name="peptides">谱图列表</param>
        /// <param name="scoreFuncs">与分数提取、排序相关类</param>
        /// <param name="fdrCalc">FDR计算器</param>
        public static void CalculateQValue(List <IIdentifiedSpectrum> peptides, IScoreFunction scoreFuncs, IFalseDiscoveryRateCalculator fdrCalc)
        {
            if (peptides.Count == 0)
            {
                return;
            }

            scoreFuncs.SortSpectrum(peptides);

            int totalTarget = 0;
            int totalDecoy  = 0;

            HashSet <string> filenames = new HashSet <string>();

            foreach (IIdentifiedSpectrum spectrum in peptides)
            {
                spectrum.QValue = 0.0;
                if (filenames.Contains(spectrum.Query.FileScan.LongFileName))
                {
                    continue;
                }
                filenames.Add(spectrum.Query.FileScan.LongFileName);

                if (spectrum.FromDecoy)
                {
                    totalDecoy++;
                }
                else
                {
                    totalTarget++;
                }
            }

            double lastScore  = scoreFuncs.GetScore(peptides[peptides.Count - 1]);
            double lastQvalue = fdrCalc.Calculate(totalDecoy, totalTarget);

            for (int i = peptides.Count - 1; i >= 0; i--)
            {
                double score = scoreFuncs.GetScore(peptides[i]);
                if (score != lastScore)
                {
                    lastScore  = score;
                    lastQvalue = fdrCalc.Calculate(totalDecoy, totalTarget);
                    if (lastQvalue == 0.0)
                    {
                        break;
                    }
                    peptides[i].QValue = lastQvalue;
                }
                else
                {
                    peptides[i].QValue = lastQvalue;
                }

                if (peptides[i].FromDecoy)
                {
                    totalDecoy--;
                }
                else
                {
                    totalTarget--;
                }
            }
        }