Exemplo n.º 1
0
        internal static void ConvertElementTableToFormula(
            ref clsElementIsotopes elemental_isotope_composition,
            Hashtable elementCounts, out DeconToolsV2.MolecularFormula formula)
        {
            var elements = elementCounts.Keys.GetEnumerator();

            formula = new DeconToolsV2.MolecularFormula();

            while (elements.MoveNext())
            {
                // Get the next element symbol in the table
                var element = (string)elements.Current;
                // Put it in a character array
                var count = (int)elementCounts[element];

                // find the index of the element in the AtomicInformation
                var index = elemental_isotope_composition.GetElementIndex(element);
                if (index == -1)
                {
                    throw new ApplicationException(string.Concat("Unknown element ", element));
                }
                var atomic_count = new DeconToolsV2.AtomicCount(index, count);
                var mono_mass    =
                    elemental_isotope_composition.ElementalIsotopesList[index].Isotopes[0].Mass * count;
                var avg_mass = elemental_isotope_composition.ElementalIsotopesList[index].AverageMass *
                               count;
                formula.AddAtomicCount(atomic_count, mono_mass, avg_mass);
            }
        }
Exemplo n.º 2
0
 public MolecularFormula(MolecularFormula formula)
 {
     Formula          = formula.Formula;
     TotalAtomCount   = formula.TotalAtomCount;
     MonoisotopicMass = formula.MonoisotopicMass;
     ElementalComposition.Clear();
     ElementalComposition.AddRange(formula.ElementalComposition);
 }
Exemplo n.º 3
0
        public void CalculateMasses(DeconToolsV2.MolecularFormula formula)
        {
            MonoMw    = 0;
            AverageMw = 0;
            var numElementsFound = formula.NumElements;

            for (var j = 0; j < numElementsFound; j++)
            {
                var elementIndex = formula.ElementalComposition[j].Index;
                var atomicity    = (int)formula.ElementalComposition[j].NumCopies;

                if (atomicity == 0)
                {
                    continue;
                }
                //int numIsotopes = ElementalIsotopeComposition.ElementalIsotopesList[elementIndex].NumberOfIsotopes;
                var monoMw = ElementalIsotopeComposition.ElementalIsotopesList[elementIndex].Isotopes[0].Mass;
                var avgMw  = ElementalIsotopeComposition.ElementalIsotopesList[elementIndex].AverageMass;
                MonoMw    += atomicity * monoMw;
                AverageMw += atomicity * avgMw;
            }
        }
Exemplo n.º 4
0
        private void CalcVariancesAndMassRange(int charge, DeconToolsV2.MolecularFormula formula)
        {
            MassVariance = 0;
            var numElementsFound = formula.NumElements;

            for (var elementNum = 0; elementNum < numElementsFound; elementNum++)
            {
                var elementIndex      = formula.ElementalComposition[elementNum].Index;
                var atomicity         = (int)formula.ElementalComposition[elementNum].NumCopies;
                var elementalVariance = ElementalIsotopeComposition.ElementalIsotopesList[elementIndex].MassVariance;
                MassVariance += elementalVariance * atomicity;
            }

            if (charge == 0)
            {
                _massRange = (int)(Math.Sqrt(1 + MassVariance) * 10);
            }
            else
            {
                _massRange = (int)(Math.Sqrt(1 + MassVariance) * 10.0 / charge);
            }
            /* +/- 5 sd's : Multiply charged */

            /* Set to nearest (upper) power of 2 */
            for (var i = 1024; i > 0; i /= 2)
            {
                if (i < _massRange)
                {
                    _massRange = i * 2;
                    i          = 0;
                }
            }
            if (_massRange <= 0)
            {
                _massRange = 1;
            }
        }
Exemplo n.º 5
0
        private void CalcFrequencies(int charge, int numPoints, DeconToolsV2.MolecularFormula formula)
        {
            int    i;
            int    j, k;
            double real, imag, freq, x, theta, r, tempr;

            var numElementsInEntity = formula.NumElements;

            /* Calculate first half of Frequency Domain (+)masses */
            for (i = 1; i <= numPoints / 2; i++)
            {
                freq  = (double)(i - 1) / _massRange;
                r     = 1;
                theta = 0;
                for (j = 0; j < numElementsInEntity; j++)
                {
                    var elementIndex = formula.ElementalComposition[j].Index;
                    var atomicity    = (int)formula.ElementalComposition[j].NumCopies;
                    var numIsotopes  = ElementalIsotopeComposition.ElementalIsotopesList[elementIndex].NumberOfIsotopes;
                    var averageMass  = ElementalIsotopeComposition.ElementalIsotopesList[elementIndex].AverageMass;
                    real = imag = 0.0;
                    for (k = 0; k < numIsotopes; k++)
                    {
                        double wrapFreq         = 0;
                        var    isotopeAbundance =
                            ElementalIsotopeComposition.ElementalIsotopesList[elementIndex].Isotopes[k].Probability;
                        if (numIsotopes > 1)
                        {
                            wrapFreq =
                                ElementalIsotopeComposition.ElementalIsotopesList[elementIndex].Isotopes[k].Mass /
                                charge - averageMass / charge;
                            if (wrapFreq < 0)
                            {
                                wrapFreq += _massRange;
                            }
                        }
                        x     = 2 * Pi * wrapFreq * freq;
                        real += isotopeAbundance * Math.Cos(x);
                        imag += isotopeAbundance * Math.Sin(x);
                    }
                    /* Convert to polar coordinates, r then theta */
                    tempr = Math.Sqrt(real * real + imag * imag);
                    r    *= Math.Pow(tempr, atomicity);
                    if (real > 0)
                    {
                        theta += atomicity * Math.Atan(imag / real);
                    }
                    else if (real < 0)
                    {
                        theta += atomicity * (Math.Atan(imag / real) + Pi);
                    }
                    else if (imag > 0)
                    {
                        theta += atomicity * Pi / 2;
                    }
                    else
                    {
                        theta += atomicity * -Pi / 2;
                    }
                }
                /* Convert back to real:imag coordinates and store */
                _frequencyData[i - 1] = new Complex(r * Math.Cos(theta), r * Math.Sin(theta));
            } /* end for(i) */

            /* Calculate second half of Frequency Domain (-)masses */
            for (i = numPoints / 2 + 1; i <= numPoints; i++)
            {
                freq  = (double)(i - numPoints - 1) / _massRange;
                r     = 1;
                theta = 0;

                for (j = 0; j < numElementsInEntity; j++)
                {
                    var elementIndex = formula.ElementalComposition[j].Index;
                    var atomicity    = (int)formula.ElementalComposition[j].NumCopies;
                    var numIsotopes  = ElementalIsotopeComposition.ElementalIsotopesList[elementIndex].NumberOfIsotopes;
                    var averageMass  = ElementalIsotopeComposition.ElementalIsotopesList[elementIndex].AverageMass;

                    real = imag = 0;
                    for (k = 0; k < numIsotopes; k++)
                    {
                        double wrapFreq         = 0;
                        var    isotopeAbundance =
                            ElementalIsotopeComposition.ElementalIsotopesList[elementIndex].Isotopes[k].Probability;
                        if (numIsotopes > 1)
                        {
                            wrapFreq =
                                ElementalIsotopeComposition.ElementalIsotopesList[elementIndex].Isotopes[k].Mass /
                                charge - averageMass / charge;
                            if (wrapFreq < 0)
                            {
                                wrapFreq += _massRange;
                            }
                        }

                        x     = 2 * Pi * wrapFreq * freq;
                        real += isotopeAbundance * Math.Cos(x);
                        imag += isotopeAbundance * Math.Sin(x);
                    }

                    /* Convert to polar coordinates, r then theta */
                    tempr = Math.Sqrt(real * real + imag * imag);
                    r    *= Math.Pow(tempr, atomicity);
                    if (real > 0)
                    {
                        theta += atomicity * Math.Atan(imag / real);
                    }
                    else if (real < 0)
                    {
                        theta += atomicity * (Math.Atan(imag / real) + Pi);
                    }
                    else if (imag > 0)
                    {
                        theta += atomicity * Pi / 2;
                    }
                    else
                    {
                        theta -= atomicity * Pi / 2;
                    }
                } /* end for(j) */

                /* Convert back to real:imag coordinates and store */
                _frequencyData[i - 1] = new Complex(r * Math.Cos(theta), r * Math.Sin(theta));
            } /* end of for(i) */
        }
Exemplo n.º 6
0
        /// <summary>
        ///     Calculate the isotope distribution
        /// </summary>
        /// <param name="charge"></param>
        /// <param name="resolution"></param>
        /// <param name="formula"></param>
        /// <param name="x">mz values of isotopic profile that are above the threshold</param>
        /// <param name="y">intensity values of isotopic profile that are above the threshold</param>
        /// <param name="threshold"></param>
        /// <param name="isotopeMzs">peak top mz's for the peaks of the isotopic profile</param>
        /// <param name="isotopeIntensities">peak top intensities's for the peaks of the isotopic profile</param>
        /// <param name="debug"></param>
        public void CalculateDistribution(int charge, double resolution, DeconToolsV2.MolecularFormula formula, out List <double> x,
                                          out List <double> y, double threshold, out List <double> isotopeMzs, out List <double> isotopeIntensities,
                                          bool debug = false)
        {
            /* Calculate mono and average mass */
            CalculateMasses(formula);
            if (debug)
            {
                Console.Error.WriteLine("MonoMW =" + MonoMw + " AverageMW =" + AverageMw);
            }

            /* Calculate mass range to use based on molecular variance */
            CalcVariancesAndMassRange(charge, formula);
            if (debug)
            {
                Console.Error.WriteLine("Variance =" + MassVariance + " Mass Range =" + _massRange);
            }

            _minMz       = AverageMw / charge + (ChargeCarrierMass - MercuryCache.ElectronMass) - _massRange * 1.0 / 2;
            _maxMz       = _minMz + _massRange;
            PointsPerAmu = MercurySize / _massRange; /* Use maximum of 2048 real, 2048 imag points */

            // calculate Ap_subscript to from requested Res
            double aPSubscript;

            if (charge == 0)
            {
                aPSubscript = AverageMw / resolution * MercurySize * 2.0 / _massRange;
            }
            else
            {
                aPSubscript = AverageMw / (resolution * Math.Abs(charge)) * MercurySize * 2.0 / _massRange;
            }

            /* Allocate memory for Axis arrays */
            var numPoints = _massRange * PointsPerAmu;

            _frequencyData = new Complex[numPoints];

            if (charge == 0)
            {
                charge = 1;
            }

            if (debug)
            {
                Console.Error.WriteLine("MINMZ = " + _minMz + " MAXMZ = " + _maxMz);
                Console.Error.WriteLine("Num Points per AMU = " + PointsPerAmu);
            }

            CalcFrequencies(charge, numPoints, formula);

            /* Apodize data */
            double apResolution = 1; /* Resolution used in apodization. Not used yet */

            Apodize(numPoints, apResolution, aPSubscript);

            Fourier.Inverse(_frequencyData, FourierOptions.NumericalRecipes);
            // myers changes this line to Realft(FreqData,NumPoints,-1);

            /*
             *  [gord] 'OutputData' fills 'x', 'y'
             *  [gord] x = mz values of isotopic profile that are above the threshold
             *  [gord] y = intensity values of isotopic profile that are above the threshold
             *  [gord] isotopeMzs = peak top mz's for the peaks of the isotopic profile
             *  [gord] isotopeIntensities = peak top intensities's for the peaks of the isotopic profile
             */
            OutputData(numPoints, charge, out x, out y, threshold, out isotopeMzs, out isotopeIntensities);

            //NormalizeToPercentIons(vect_y);
        }