Esempio n. 1
0
        public IsotopicProfile GetIsotopePattern(string empiricalFormula, double[][] aafIsoLocal)
        {
            var elementTable = _peptideUtils.ParseEmpiricalFormulaString(empiricalFormula);

            var formulaArray = new int[5];

            formulaArray[0] = getAtomCount(elementTable, "C");
            formulaArray[1] = getAtomCount(elementTable, "H");
            formulaArray[2] = getAtomCount(elementTable, "N");
            formulaArray[3] = getAtomCount(elementTable, "O");
            formulaArray[4] = getAtomCount(elementTable, "S");

            double EPS = 0.001f;

            var afIonIntensity = new double[100]; // store structure here
            var aafIons        = new double[5, 100];

            double fLogTotalLast = 0;
            var    maxIndices    = new int[5];

            for (var i0 = 0; i0 < 5; i0++)
            { // iterate thru elements
                var fLogAmtLight = Math.Log10(aafIsoLocal[i0][0]);
                var fLogAmtHeavy = Math.Log10(aafIsoLocal[i0][1]);
                for (var i1 = 0; i1 <= formulaArray[i0]; i1++)
                {
                    var fLogTotal = fLogAmtLight * (formulaArray[i0] - i1) + fLogAmtHeavy * i1;
                    fLogTotal      += IsotopicDistributionCalculator.LogAChooseB(formulaArray[i0], i1);
                    aafIons[i0, i1] = System.Math.Pow(10, fLogTotal);
                    maxIndices[i0]  = i1;
                    if (i1 > 1 && fLogTotalLast > fLogTotal && aafIons[i0, i1] < EPS)
                    {
                        break;
                    }
                    fLogTotalLast = fLogTotal;
                }
            }

            var maxOffset = 1;

            for (var i = 0; i <= maxIndices[0]; i++)
            {
                for (var j = 0; j <= maxIndices[1]; j++)
                {
                    for (var k = 0; k <= maxIndices[2]; k++)
                    {
                        for (var l = 0; l <= maxIndices[3]; l++)
                        {
                            for (var m = 0; m <= maxIndices[4]; m++)
                            {
                                var offset  = i + j + k + 2 * l + 2 * m; // O and S are +2
                                var fIntTmp = aafIons[0, i] * aafIons[1, j] *
                                              aafIons[2, k] * aafIons[3, l] * aafIons[4, m];
                                if (offset > maxOffset)
                                {
                                    maxOffset = offset;
                                }
                                afIonIntensity[offset] += fIntTmp;
                            }
                        }
                    }
                }
            }
            // normalize
            double max = 0;

            for (var j1 = 0; j1 <= maxOffset; j1++)
            {
                if (afIonIntensity[j1] > max)
                {
                    max = afIonIntensity[j1];
                }
            }
            for (var j1 = 0; j1 <= maxOffset; j1++)
            {
                afIonIntensity[j1] /= max;
            }
            var isoCluster = new IsotopicProfile();

            for (var j1 = 0; j1 < afIonIntensity.Length && j1 <= maxOffset; j1++)
            {
                isoCluster.Peaklist.Add(new MSPeak(0.0f, (float)afIonIntensity[j1], 0.0f, 0.0f));
            }
            return(isoCluster);
        }