Exemple #1
0
        private static IsotopicDistribution CalculateFineGrain(List <List <Composition> > elementalComposition, double _mwResolution, double _mergeFineResolution, double _fineResolution, double _fineMinProb)
        {
            List <Polynomial> fPolynomial = MultiplyFinePolynomial(elementalComposition, _fineResolution, _mwResolution, _fineMinProb);

            fPolynomial = MergeFinePolynomial(fPolynomial, _mwResolution, _mergeFineResolution);

            // Convert polynomial to spectrum
            int count = fPolynomial.Count;
            IsotopicDistribution dist = new IsotopicDistribution(count);
            double totalProbability   = 0;
            double basePeak           = 0;
            int    i = 0;

            foreach (Polynomial polynomial in fPolynomial)
            {
                totalProbability += polynomial.Probablity;
                if (polynomial.Probablity > basePeak)
                {
                    basePeak = polynomial.Probablity;
                }
                dist.masses[i]      = polynomial.Power * _mwResolution;
                dist.intensities[i] = polynomial.Probablity;
                i++;
            }
            return(dist);
        }
Exemple #2
0
        public static IsotopicDistribution GetDistribution(ChemicalFormula formula, double fineResolution, double minProbability, double molecularWeightResolution)
        {
            var a = GetNewFineAndMergeResolutions(fineResolution);

            fineResolution = a.Item1;
            double _mergeFineResolution = a.Item2;
            List <List <Composition> > elementalComposition = new List <List <Composition> >();

            // Get all the unique elements that might have isotopes
            foreach (var elementAndCount in formula.Elements)
            {
                int count = elementAndCount.Value;
                List <Composition> isotopeComposition = new List <Composition>();
                foreach (Isotope isotope in elementAndCount.Key.Isotopes.OrderBy(iso => iso.AtomicMass))
                {
                    Composition c = new Composition
                    {
                        Atoms           = count,
                        MolecularWeight = isotope.AtomicMass,
                        Power           = isotope.AtomicMass,
                        Probability     = isotope.RelativeAbundance
                    };

                    isotopeComposition.Add(c);
                }
                elementalComposition.Add(isotopeComposition);
            }

            foreach (List <Composition> compositions in elementalComposition)
            {
                double sumProb = compositions.Sum(t => t.Probability);
                foreach (Composition composition in compositions)
                {
                    composition.Probability   /= sumProb;
                    composition.LogProbability = Math.Log(composition.Probability);
                    composition.Power          = Math.Floor(composition.MolecularWeight / molecularWeightResolution + 0.5);
                }
            }
            IsotopicDistribution dist = CalculateFineGrain(elementalComposition, molecularWeightResolution, _mergeFineResolution, fineResolution, minProbability);

            double additionalMass = 0;

            foreach (var isotopeAndCount in formula.Isotopes)
            {
                additionalMass += isotopeAndCount.Key.AtomicMass * isotopeAndCount.Value;
            }

            for (int i = 0; i < dist.masses.Length; i++)
            {
                dist.masses[i] += additionalMass;
            }

            return(dist);
        }