Example #1
0
        /// <summary>
        /// Calculate scores for targets and decoys.  A transition is selected from each transition group using the
        /// scoring weights, and then its score is calculated using the calculator weights applied to each feature.
        /// </summary>
        /// <param name="scoringParams">Parameters to choose the best peak</param>
        /// <param name="calculatorParams">Parameters to calculate the score of the best peak.</param>
        /// <param name="targetScores">Output list of target scores.</param>
        /// <param name="decoyScores">Output list of decoy scores.</param>
        /// <param name="secondBestScores">Output list of false target scores.</param>
        /// <param name="invert">If true, select minimum rather than maximum scores</param>
        public void GetScores(LinearModelParams scoringParams, LinearModelParams calculatorParams, out List <double> targetScores, out List <double> decoyScores,
                              out List <double> secondBestScores, bool invert = false)
        {
            targetScores     = new List <double>();
            decoyScores      = new List <double>();
            secondBestScores = new List <double>();
            int invertSign = invert ? -1 : 1;

            foreach (var peakTransitionGroupFeatures in _peakTransitionGroupFeaturesList)
            {
                PeakGroupFeatures maxFeatures  = null;
                PeakGroupFeatures nextFeatures = null;
                double            maxScore     = Double.MinValue;
                double            nextScore    = Double.MinValue;

                // No peaks in this transition group record
                if (peakTransitionGroupFeatures.PeakGroupFeatures.Count == 0)
                {
                    continue;
                }

                // Find the highest and second highest scores among the transitions in this group.
                foreach (var peakGroupFeatures in peakTransitionGroupFeatures.PeakGroupFeatures)
                {
                    double score = invertSign * GetScore(scoringParams, peakGroupFeatures);
                    if (nextScore < score)
                    {
                        if (maxScore < score)
                        {
                            nextScore    = maxScore;
                            maxScore     = score;
                            nextFeatures = maxFeatures;
                            maxFeatures  = peakGroupFeatures;
                        }
                        else
                        {
                            nextScore    = score;
                            nextFeatures = peakGroupFeatures;
                        }
                    }
                }

                double currentScore = maxFeatures == null ? Double.NaN : GetScore(calculatorParams, maxFeatures);
                if (peakTransitionGroupFeatures.Id.NodePep.IsDecoy)
                {
                    decoyScores.Add(currentScore);
                }
                else
                {
                    targetScores.Add(currentScore);
                    // Skip if only one peak
                    if (peakTransitionGroupFeatures.PeakGroupFeatures.Count == 1)
                    {
                        continue;
                    }
                    double secondBestScore = nextFeatures == null ? Double.NaN : GetScore(calculatorParams, nextFeatures);
                    secondBestScores.Add(secondBestScore);
                }
            }
        }
Example #2
0
 private static double GetScore(LinearModelParams parameters, PeakGroupFeatures peakGroupFeatures)
 {
     return(GetScore(parameters.Weights, peakGroupFeatures, parameters.Bias));
 }
Example #3
0
 /// <summary>
 /// Calculate the score of a set of features given an array of weighting coefficients.
 /// </summary>
 private static double GetScore(IList <double> weights, PeakGroupFeatures peakGroupFeatures, double bias)
 {
     return(LinearModelParams.Score(peakGroupFeatures.Features, weights, bias));
 }