Beispiel #1
0
        public TracerPercentFormula ComputePrecursorEnrichmentAndTurnover(IDictionary <TracerFormula, double> peptideDistribution, out double turnover, out double turnoverScore, out IDictionary <TracerFormula, double> bestMatch)
        {
            if (peptideDistribution.Count < 3)
            {
                turnover      = 0;
                turnoverScore = 0;
                bestMatch     = null;
                return(null);
            }
            var tracerFormulaIndexes = new Dictionary <TracerFormula, int>();
            var observedPercentages  = new DenseVector(peptideDistribution.Count);

            foreach (var entry in peptideDistribution)
            {
                var tracerFormula = entry.Key;
                observedPercentages[tracerFormulaIndexes.Count] = entry.Value;
                tracerFormulaIndexes.Add(tracerFormula, tracerFormulaIndexes.Count);
            }
            var initialVector = DistributionToVector(GetDistribution(GetInitialTracerPercents()), tracerFormulaIndexes);

            bestMatch = null;
            TracerPercentFormula bestFormula = null;
            double bestScore               = 0;
            double bestTurnover            = 0;
            var    tracerPercentEnumerator = new TracerPercentEnumerator(_tracerDefs.Values);

            while (tracerPercentEnumerator.MoveNext())
            {
                var tracerPercents         = tracerPercentEnumerator.Current;
                var distribution           = GetDistribution(tracerPercents);
                var newlySynthesizedVector = DistributionToVector(distribution, tracerFormulaIndexes);
                var combination            = FindBestCombination(observedPercentages, initialVector, newlySynthesizedVector);
                if (combination == null)
                {
                    continue;
                }
                if (combination[0] < 0 || combination[1] < 0 || combination.Sum() <= 0)
                {
                    continue;
                }
                if (combination.Sum() <= 0)
                {
                    continue;
                }
                var resultVector = initialVector.Multiply(combination[0]).Add(newlySynthesizedVector.Multiply(combination[1]));
                var score        = Score(observedPercentages, resultVector);
                if (bestFormula == null || score > bestScore)
                {
                    bestFormula  = tracerPercents;
                    bestScore    = score;
                    bestTurnover = combination[1] / (combination[0] + combination[1]);
                    bestMatch    = tracerFormulaIndexes.ToDictionary(kv => kv.Key, kv => resultVector[kv.Value]);
                }
            }
            turnover      = bestTurnover;
            turnoverScore = bestScore;
            return(bestFormula);
        }
Beispiel #2
0
        public List <TracerPercentFormula> ListTracerPercents(int intermediateLevels)
        {
            var result     = new List <TracerPercentFormula>();
            var enumerator = new TracerPercentEnumerator(_tracerDefs.Values, intermediateLevels);

            while (enumerator.MoveNext())
            {
                result.Add(enumerator.Current);
            }
            return(result);
        }