예제 #1
0
        public void TestSortAndNormalizedByIntensityIsotopePattern()
        {
            var spExp = new IsotopePattern(new[]
            {
                new IsotopeContainer(157.07503, 0.0002),
                new IsotopeContainer(156.07770, 2),
                new IsotopeContainer(158.08135, 0.004),
                new IsotopeContainer(157.08059, 0.0006),
            });

            spExp.MonoIsotope = spExp.Isotopes[1];
            spExp.Charge      = 1;

            var isoNorma = IsotopePatternManipulator.SortAndNormalizedByIntensity(spExp);
            var listISO  = isoNorma.Isotopes;

            Assert.AreEqual(156.07770, isoNorma.MonoIsotope.Mass, 0.00001);
            Assert.AreEqual(156.07770, listISO[0].Mass, 0.00001);
            Assert.AreEqual(158.08135, listISO[1].Mass, 0.00001);
            Assert.AreEqual(157.08059, listISO[2].Mass, 0.00001);
            Assert.AreEqual(157.07503, listISO[3].Mass, 0.00001);

            Assert.AreEqual(1, isoNorma.MonoIsotope.Intensity, 0.00001);
            Assert.AreEqual(1, listISO[0].Intensity, 0.00001);
            Assert.AreEqual(0.002, listISO[1].Intensity, 0.00001);
            Assert.AreEqual(0.0003, listISO[2].Intensity, 0.00001);
            Assert.AreEqual(0.0001, listISO[3].Intensity, 0.00001);

            Assert.AreEqual(1, isoNorma.Charge, 0.001);
        }
예제 #2
0
        /// <summary>
        /// Get all combinatorial chemical isotopes given a structure.
        /// </summary>
        /// <param name="molFor">The IMolecularFormula to start</param>
        /// <returns>A IsotopePattern object containing the different combinations</returns>
        public IsotopePattern GetIsotopes(IMolecularFormula molFor)
        {
            if (builder == null)
            {
                try
                {
                    isoFactory = CDK.IsotopeFactory;
                    builder    = molFor.Builder;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.StackTrace);
                }
            }
            var mf = MolecularFormulaManipulator.GetString(molFor, true);

            var molecularFormula = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula(mf, builder);

            IsotopePattern abundance_Mass = null;

            foreach (var isos in molecularFormula.Isotopes)
            {
                var elementSymbol = isos.Symbol;
                var atomCount     = molecularFormula.GetCount(isos);

                // Generate possible isotope containers for the current atom's
                // these will then me 'multiplied' with the existing patten
                var additional = new List <IsotopeContainer>();
                foreach (var isotope in isoFactory.GetIsotopes(elementSymbol))
                {
                    double mass      = isotope.ExactMass.Value;
                    double abundance = isotope.Abundance.Value;
                    if (abundance <= 0.000000001)
                    {
                        continue;
                    }
                    IsotopeContainer container = new IsotopeContainer(mass, abundance);
                    if (storeFormula)
                    {
                        container.Formula = AsFormula(isotope);
                    }
                    additional.Add(container);
                }
                for (int i = 0; i < atomCount; i++)
                {
                    abundance_Mass = CalculateAbundanceAndMass(abundance_Mass, additional);
                }
            }

            var isoP = IsotopePatternManipulator.SortAndNormalizedByIntensity(abundance_Mass);

            isoP = CleanAbundance(isoP, minIntensity);
            var isoPattern = IsotopePatternManipulator.SortByMass(isoP);

            return(isoPattern);
        }
        public void TestCompareIsotopePatternIsotopePattern()
        {
            var is_ = new IsotopePatternSimilarity();

            IsotopePattern spExp = new IsotopePattern(new[]
            {
                new IsotopeContainer(156.07770, 1),
                new IsotopeContainer(157.07503, 0.0004),
                new IsotopeContainer(157.08059, 0.0003),
                new IsotopeContainer(158.08135, 0.002),
            });

            spExp.MonoIsotope = spExp.Isotopes[0];

            var formula             = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula("C6H10N3O2", builder);
            var isotopeGe           = new IsotopePatternGenerator(0.1);
            var patternIsoPredicted = isotopeGe.GetIsotopes(formula);
            var patternIsoNormalize = IsotopePatternManipulator.Normalize(patternIsoPredicted);
            var score = is_.Compare(spExp, patternIsoNormalize);

            Assert.AreNotSame(0.0, score);
        }
        public void TestSelectingMF()
        {
            var is_ = new IsotopePatternSimilarity();

            IsotopePattern spExp = new IsotopePattern(new[]
            {
                new IsotopeContainer(156.07770, 1),
                new IsotopeContainer(157.07503, 0.0101),
                new IsotopeContainer(157.08059, 0.074),
                new IsotopeContainer(158.08135, 0.0024),
            });

            spExp.MonoIsotope = spExp.Isotopes[0];
            spExp.Charge      = 1;

            double score    = 0;
            string mfString = "";

            string[] listMF = { "C4H8N6O", "C2H12N4O4", "C3H12N2O5", "C6H10N3O2", "CH10N5O4", "C4H14NO5" };

            for (int i = 0; i < listMF.Length; i++)
            {
                IMolecularFormula       formula             = MolecularFormulaManipulator.GetMajorIsotopeMolecularFormula(listMF[i], builder);
                IsotopePatternGenerator isotopeGe           = new IsotopePatternGenerator(0.01);
                IsotopePattern          patternIsoPredicted = isotopeGe.GetIsotopes(formula);

                IsotopePattern patternIsoNormalize = IsotopePatternManipulator.Normalize(patternIsoPredicted);
                double         tempScore           = is_.Compare(spExp, patternIsoNormalize);
                if (score < tempScore)
                {
                    mfString = MolecularFormulaManipulator.GetString(formula);
                    score    = tempScore;
                }
            }
            Assert.AreEqual("C6H10N3O2", mfString);
        }
예제 #5
0
        /// <summary>
        /// Compare the IMolecularFormula with a isotope
        /// abundance pattern.
        /// </summary>
        /// <param name="isoto1">The Isotope pattern reference (predicted)</param>
        /// <param name="isoto2">The Isotope pattern reference (detected)</param>
        /// <returns>The hit score of similarity</returns>
        public double Compare(IsotopePattern isoto1, IsotopePattern isoto2)
        {
            IsotopePattern iso1 = IsotopePatternManipulator.SortAndNormalizedByIntensity(isoto1);
            IsotopePattern iso2 = IsotopePatternManipulator.SortAndNormalizedByIntensity(isoto2);

            /* charge to add */
            if (isoto1.Charge == 1)
            {
                chargeToAdd = massE;
            }
            else if (isoto1.Charge == -1)
            {
                chargeToAdd = -massE;
            }
            else
            {
                chargeToAdd = 0;
            }

            foreach (var isoC in iso1.Isotopes)
            {
                double mass = isoC.Mass;
                isoC.Mass = mass + chargeToAdd;
            }

            double diffMass, diffAbun, factor, totalFactor = 0d;
            double score = 0d, tempScore;
            // Maximum number of isotopes to be compared according predicted isotope
            // pattern. It is assumed that this will have always more isotopeContainers
            int length = iso1.Isotopes.Count;

            for (int i = 0; i < length; i++)
            {
                var isoContainer = iso1.Isotopes[i];
                factor       = isoContainer.Intensity;
                totalFactor += factor;

                // Search for the closest isotope in the second pattern (detected) to the
                // current isotope (predicted pattern)
                int closestDp = GetClosestDataDiff(isoContainer, iso2);
                if (closestDp == -1)
                {
                    continue;
                }

                diffMass = isoContainer.Mass - iso2.Isotopes[closestDp].Mass;
                diffMass = Math.Abs(diffMass);

                diffAbun = 1.0d - (isoContainer.Intensity / iso2.Isotopes[closestDp].Intensity);
                diffAbun = Math.Abs(diffAbun);

                tempScore = 1 - (diffMass + diffAbun);

                if (tempScore < 0)
                {
                    tempScore = 0;
                }

                score += (tempScore * factor);
            }

            return(score / totalFactor);
        }