Exemplo n.º 1
0
        public double CalculateSubsetFdr(ScoreDistribution subset, IFalseDiscoveryRateCalculator calc)
        {
            double targetCount = 0;
            double decoyCount  = 0;

            foreach (OptimalResultCondition cond in subset.Keys)
            {
                var subsetOrs = subset[cond];
                var totalOrs  = this[cond];

                var counts =
                    from s in subsetOrs
                    join t in totalOrs on s.Score equals t.Score
                    select new { TargetCount = (int)s.PeptideCountFromTargetDB, DecoyCount = (double)s.PeptideCountFromTargetDB * t.PeptideCountFromDecoyDB / t.PeptideCountFromTargetDB };

                targetCount +=
                    (from c in counts
                     select c.TargetCount).Sum();

                decoyCount +=
                    (from c in counts
                     select c.DecoyCount).Sum();
            }

            return(calc.Calculate((int)decoyCount, (int)targetCount));
        }
        public void Test()
        {
            ScoreDistribution      s  = new ScoreDistribution();
            OptimalResultCondition or = new OptimalResultCondition(1, 1, 1, 1);

            s[or] = new List <OptimalResult>()
            {
                new OptimalResult(1.0, 1.0, 100, 10, 0.1),
                new OptimalResult(2.0, 1.0, 200, 10, 0.05),
                new OptimalResult(3.0, 1.0, 1000, 10, 0.01)
            };

            ScoreDistribution subset = new ScoreDistribution();

            subset[or] = new List <OptimalResult>()
            {
                new OptimalResult(2.0, 1.0, 100, 0, 0),
                new OptimalResult(3.0, 1.0, 900, 0, 0)
            };

            IFalseDiscoveryRateCalculator calc = new TargetFalseDiscoveryRateCalculator();

            double fdr = s.CalculateSubsetFdr(subset, calc);

            Assert.AreEqual(0.014, fdr);
        }