コード例 #1
0
        private double ComputeProbability(TracerFormulaEnumerator tracerFormulaEnumerator, TracerPercentFormula tracerPercents)
        {
            var tracerFormula      = tracerFormulaEnumerator.Current;
            var tracerSymbolCounts = tracerFormulaEnumerator.GetTracerSymbolCounts();

            var traceePercents = tracerSymbolCounts.Keys.ToDictionary(s => s, s => 1.0);
            var result         = 1.0;

            foreach (var tracerDef in _tracerDefs.Values)
            {
                int    tracerTraceeCount = tracerSymbolCounts[tracerDef.TraceeSymbol];
                int    tracerCount       = tracerFormula.GetElementCount(tracerDef.Name);
                double probability       = Math.Pow(tracerPercents.GetElementCount(tracerDef.Name) / 100, tracerCount)
                                           * Choose(tracerTraceeCount, tracerCount);
                result *= probability;
                tracerSymbolCounts[tracerDef.TraceeSymbol] = tracerTraceeCount - tracerCount;
                traceePercents[tracerDef.TraceeSymbol]     = traceePercents[tracerDef.TraceeSymbol] -
                                                             tracerPercents.GetElementCount(tracerDef.Name) / 100;
            }
            foreach (var entry in tracerSymbolCounts)
            {
                result *= Math.Pow(traceePercents[entry.Key], entry.Value);
            }
            return(result);
        }
コード例 #2
0
        public TurnoverCalculator(Workspace workspace, String sequence)
        {
            Sequence = sequence;
            _errOnSideOfLowerAbundance = workspace.GetErrOnSideOfLowerAbundance();
            _aminoAcidFormulas         = workspace.GetAminoAcidFormulasWithTracers();
            _tracerDefs    = new Dictionary <String, TracerDef>();
            _traceeSymbols = new HashSet <String>();
            foreach (var tracerDef in workspace.GetTracerDefs())
            {
                if (!_traceeSymbols.Contains(tracerDef.TraceeSymbol))
                {
                    if (tracerDef.GetMaximumTracerCount(sequence) == 0)
                    {
                        continue;
                    }
                    _traceeSymbols.Add(tracerDef.TraceeSymbol);
                }
                _tracerDefs.Add(tracerDef.Name, tracerDef);
            }
            _maxTracerCount = workspace.GetMaxTracerCount(sequence);
            _masses         = new ReadOnlyCollection <MzRange>(GetMasses());
            var tracerFormulae = new List <TracerFormula>();

            _tracerFormulaIndexes = new Dictionary <TracerFormula, int>();
            var enumerator = new TracerFormulaEnumerator(Sequence, _tracerDefs.Values);

            while (enumerator.MoveNext())
            {
                _tracerFormulaIndexes.Add(enumerator.Current, tracerFormulae.Count);
                tracerFormulae.Add(enumerator.Current);
            }
            _tracerFormulae = ImmutableList.ValueOf(tracerFormulae);
        }
コード例 #3
0
        public Dictionary <TracerFormula, double> GetDistribution(TracerPercentFormula tracerPercents)
        {
            var tracerFormulaEnumerator = new TracerFormulaEnumerator(Sequence, _tracerDefs.Values);
            var result = new Dictionary <TracerFormula, double>();

            while (tracerFormulaEnumerator.MoveNext())
            {
                result.Add(tracerFormulaEnumerator.Current, ComputeProbability(tracerFormulaEnumerator, tracerPercents));
            }
            return(result);
        }
コード例 #4
0
        private List <MzRange> GetMasses()
        {
            var massesAndFrequency      = new Dictionary <double, double>();
            var tracerFormulaEnumerator = new TracerFormulaEnumerator(Sequence, _tracerDefs.Values);

            while (tracerFormulaEnumerator.MoveNext())
            {
                MassDistribution massDistribution = _aminoAcidFormulas.GetMassDistribution(
                    MoleculeFromTracerFormula(tracerFormulaEnumerator.Current), 0);
                massDistribution = massDistribution.OffsetAndDivide(_aminoAcidFormulas.GetMassShift(Sequence), 1);
                foreach (var entry in massDistribution)
                {
                    if (entry.Value < MinAbundance)
                    {
                        continue;
                    }
                    double currentAbundance;
                    massesAndFrequency.TryGetValue(entry.Key, out currentAbundance);
                    if (currentAbundance >= entry.Value)
                    {
                        continue;
                    }
                    massesAndFrequency[entry.Key] = entry.Value;
                }
            }
            var allMasses = new List <double>(massesAndFrequency.Keys);

            allMasses.Sort();
            var result = new List <MzRange>();

            foreach (var mass in allMasses)
            {
                if (result.Count == 0)
                {
                    result.Add(new MzRange(mass));
                    continue;
                }
                var lastMass = result[result.Count - 1];
                if (lastMass.Distance(mass) > MassResolution)
                {
                    result.Add(new MzRange(mass));
                    continue;
                }
                result[result.Count - 1] = lastMass.Union(mass);
            }
            return(result);
        }