예제 #1
0
        public void TestNullArguments()
        {
            ChemicalFormula     formulaA = new ChemicalFormula("CO");
            IHasChemicalFormula ok       = null;

            Assert.AreEqual("item", Assert.Throws <ArgumentNullException>(() => { formulaA.Add(ok); }).ParamName);
            ChemicalFormula ok2 = null;

            Assert.AreEqual("formula", Assert.Throws <ArgumentNullException>(() => { formulaA.Add(ok2); }).ParamName);
            Assert.AreEqual("other", Assert.Throws <ArgumentNullException>(() => { new ChemicalFormula(ok2); }).ParamName);
            Element ok3 = null;

            Assert.AreEqual("element", Assert.Throws <ArgumentNullException>(() => { formulaA.AddPrincipalIsotopesOf(ok3, 0); }).ParamName);
            Assert.AreEqual("item", Assert.Throws <ArgumentNullException>(() => { formulaA.Remove(ok); }).ParamName);
            Assert.AreEqual("formula", Assert.Throws <ArgumentNullException>(() => { formulaA.Remove(ok2); }).ParamName);
            Assert.AreEqual("formula", Assert.Throws <ArgumentNullException>(() => { formulaA.IsSubsetOf(ok2); }).ParamName);
            Assert.AreEqual("formula", Assert.Throws <ArgumentNullException>(() => { formulaA.IsSupersetOf(ok2); }).ParamName);
            Assert.AreEqual("element", Assert.Throws <ArgumentNullException>(() => { formulaA.CountWithIsotopes(ok3); }).ParamName);
            Assert.AreEqual("element", Assert.Throws <ArgumentNullException>(() => { formulaA.CountSpecificIsotopes(ok3, 0); }).ParamName);
            Assert.IsFalse(formulaA.Equals(ok2));
            IEnumerable <IHasChemicalFormula> ok4 = null;

            Assert.AreEqual("formulas", Assert.Throws <ArgumentNullException>(() => { ChemicalFormula.Combine(ok4); }).ParamName);
            Assert.AreEqual("element", Assert.Throws <ArgumentNullException>(() => { PeriodicTable.Add(ok3); }).ParamName);

            Assert.AreEqual("formula", Assert.Throws <ArgumentNullException>(() => { new IsotopicDistribution(ok2); }).ParamName);

            IHasMass ok5 = null;

            Assert.AreEqual("objectWithMass", Assert.Throws <ArgumentNullException>(() => { ok5.ToMZ(0); }).ParamName);

            var ok7 = new PhysicalObjectWithChemicalFormula("C");
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="argCompond"></param>
        /// <param name="argTheoreticalMonoIdx"></param>
        /// <param name="argIntensities"></param>
        /// <returns></returns>
        public static double IntensityNormalizationFactorByIsotope(COL.GlycoLib.GlycanCompound argCompond, int argNumOfLabelingSite, double[] argIntensities, float argPurity)
        {
            ChemicalFormula MonoChemFormula = new ChemicalFormula();

            MonoChemFormula.Add("C", argCompond.Carbon + argCompond.Carbon13);
            MonoChemFormula.Add("H", argCompond.Hydrogen + argCompond.Deuterium);
            MonoChemFormula.Add("O", argCompond.Oxygen);
            //if (argCompond.Carbon13 != 0)
            //{
            //    MonoChemFormula.Add("C{13}", argCompond.Carbon13);
            //}
            //if (argCompond.Deuterium != 0)
            //{
            //    MonoChemFormula.Add("D", argCompond.Deuterium);
            //}
            if (argCompond.Sodium != 0)
            {
                MonoChemFormula.Add("Na", argCompond.Sodium);
            }
            if (argCompond.Nitrogen != 0)
            {
                MonoChemFormula.Add("N", argCompond.Nitrogen);
            }
            IsotopicDistribution ID = new IsotopicDistribution();

            MZPeak[] Peaks        = ID.CalculateDistribuition(MonoChemFormula, 7, IsotopicDistribution.Normalization.BasePeak).GetPeaks().ToArray();
            double[] isotopeRatio = new double[7];
            for (int i = 0; i < 7; i++)
            {
                isotopeRatio[i] = Peaks[i].Intensity;
            }
            double[] CorrectedIntensities = (double[] )argIntensities.Clone();

            //Isotope Correction
            for (int i = 0; i <= 2; i++)
            {
                double Ratio = CorrectedIntensities[i] / isotopeRatio[0];
                for (int j = i; j < 7; j++)
                {
                    CorrectedIntensities[j] = CorrectedIntensities[j] - (isotopeRatio[j - i] * Ratio);
                }
            }


            double isotopeCorrectionFactor = CorrectedIntensities[3] / argIntensities[3];

            // Purity Correction
            //double PurityCorrection = Math.Pow(argPurity, argNumOfLabelingSite);

            return(isotopeCorrectionFactor);
        }
예제 #3
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="argCompond"></param>
        /// <param name="argTheoreticalMonoIdx"></param>
        /// <param name="argIntensities"></param>
        /// <returns></returns>
        public static double IntensityNormalizationFactorByIsotope(COL.GlycoLib.GlycanCompound argCompond, int argNumOfLabelingSite, double[] argIntensities, float argPurity)
        {
            ChemicalFormula MonoChemFormula = new ChemicalFormula();
            MonoChemFormula.Add("C", argCompond.Carbon+argCompond.Carbon13);
            MonoChemFormula.Add("H", argCompond.Hydrogen+argCompond.Deuterium);
            MonoChemFormula.Add("O", argCompond.Oxygen);
            //if (argCompond.Carbon13 != 0)
            //{
            //    MonoChemFormula.Add("C{13}", argCompond.Carbon13);
            //}
            //if (argCompond.Deuterium != 0)
            //{
            //    MonoChemFormula.Add("D", argCompond.Deuterium);
            //}
            if (argCompond.Sodium != 0)
            {
                MonoChemFormula.Add("Na", argCompond.Sodium);
            }
            if (argCompond.Nitrogen != 0)
            {
                MonoChemFormula.Add("N", argCompond.Nitrogen);
            }
            IsotopicDistribution ID = new IsotopicDistribution();
            MZPeak[] Peaks=  ID.CalculateDistribuition(MonoChemFormula,7, IsotopicDistribution.Normalization.BasePeak).GetPeaks().ToArray();
            double[] isotopeRatio = new double[7];
            for (int i = 0; i < 7; i++)
            {
                isotopeRatio[i] = Peaks[i].Intensity;
            }
            double[] CorrectedIntensities = (double[] )argIntensities.Clone();

            //Isotope Correction
            for (int i = 0; i <= 2; i++)
            {
                double Ratio = CorrectedIntensities[i]/ isotopeRatio[0];
                for (int j = i; j < 7; j++)
                {
                    CorrectedIntensities[j] = CorrectedIntensities[j] - (isotopeRatio[j-i] * Ratio );
                }
            }

            double isotopeCorrectionFactor = CorrectedIntensities[3] / argIntensities[3];

            // Purity Correction
            //double PurityCorrection = Math.Pow(argPurity, argNumOfLabelingSite);

            return isotopeCorrectionFactor;
        }
예제 #4
0
        public void ChemicalForulaMyTest()
        {
            ChemicalFormula formula = new ChemicalFormula();

            formula.Add(new ChemicalFormula("C3H5NO"));
            Assert.AreEqual(PeriodicTable.GetElement("C").PrincipalIsotope.AtomicMass * 3 + PeriodicTable.GetElement("H").PrincipalIsotope.AtomicMass * 5 + PeriodicTable.GetElement("N").PrincipalIsotope.AtomicMass + PeriodicTable.GetElement("O").PrincipalIsotope.AtomicMass, formula.MonoisotopicMass);
        }
예제 #5
0
        public void TestAddChemicalFormula()
        {
            ChemicalFormula formulaB = new ChemicalFormula("C");
            ChemicalFormula formulaA = new ChemicalFormula("C{12}");

            formulaB.Add(formulaA);
            Assert.AreEqual("CC{12}", formulaB.Formula);
        }
예제 #6
0
        /// <summary>
        /// Combine isotope pattern
        /// </summary>
        /// <param name="argNumberPermethlationSite"></param>
        /// <param name="argStartPurity"></param>
        /// <param name="argIntensities"></param>
        /// <returns></returns>
        public static float Estimater3(COL.GlycoLib.GlycanCompound argCompond, int argTheoreticalMonoIdx, float[] argIntensities)
        {
            double[] isotopeRatio = new double[argIntensities.Length];
            for (int i = 0; i < isotopeRatio.Length; i++)
            {
                isotopeRatio[i] = 0;
            }
            ChemicalFormula MonoChemFormula = new ChemicalFormula();

            MonoChemFormula.Add("C", argCompond.Carbon);
            MonoChemFormula.Add("H", argCompond.Hydrogen);
            MonoChemFormula.Add("O", argCompond.Oxygen);
            if (argCompond.Carbon13 != 0)
            {
                MonoChemFormula.Add("C{13}", argCompond.Carbon13);
            }
            if (argCompond.Deuterium != 0)
            {
                MonoChemFormula.Add("D", argCompond.Deuterium);
            }
            if (argCompond.Sodium != 0)
            {
                MonoChemFormula.Add("Na", argCompond.Sodium);
            }
            if (argCompond.Nitrogen != 0)
            {
                MonoChemFormula.Add("N", argCompond.Nitrogen);
            }
            double[] IsotopeDist = MonoChemFormula.GetIsotopicDistribution(10);


            return(0.0f);
        }
        public void AddZeroSymbolToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2H3NO");

            formulaA.Add("H", 0);

            Assert.AreEqual(formulaA, formulaB);
        }
        public void AddNullIChemicalFormulaToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2H3NO");

            formulaA.Add(NullIChemicalFormula);

            Assert.AreEqual(formulaA, formulaB);
        }
예제 #9
0
        public void AddFormulaToItself()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C4H6N2O2");

            formulaA.Add(new ChemicalFormula(formulaA));

            Assert.AreEqual(formulaA, formulaB);
        }
예제 #10
0
        public void AddELementByAtomicNumber()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H2NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2HNO");

            formulaB.Add(1, 1);

            Assert.AreEqual(formulaA, formulaB);
        }
예제 #11
0
        public void AddFormulaToItself()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C4H6N2O2");

            formulaA.Add(formulaA);

            Assert.AreEqual(formulaA, formulaB);
        }
예제 #12
0
        public static void TestAddLargeNegative()
        {
            ChemicalFormula f = ChemicalFormula.ParseFormula("CO");

            f.Add("O", -10);
            Assert.That(f.Formula == "C");
            Assert.That(f.NumberOfUniqueElementsByAtomicNumber == 1);
            Assert.That(f.MonoisotopicMass == 12);
        }
예제 #13
0
        public void AddIChemicalFormulaToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            IChemicalFormula formulaB = new ChemicalFormula("H2O");
            ChemicalFormula formulaC = new ChemicalFormula("C2H5NO2");

            formulaA.Add(formulaB);

            Assert.AreEqual(formulaA, formulaC);
        }
예제 #14
0
        public void AddIChemicalFormulaToFormula()
        {
            ChemicalFormula     formulaA = new ChemicalFormula("C2H3NO");
            IHasChemicalFormula formulaB = new PhysicalObjectWithChemicalFormula("H2O");
            ChemicalFormula     formulaC = new ChemicalFormula("C2H5NO2");

            formulaA.Add(formulaB);

            Assert.AreEqual(formulaA, formulaC);
        }
예제 #15
0
        public void AddNegativeFormulaToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C-1H-2");
            ChemicalFormula formulaC = new ChemicalFormula("CHNO");

            formulaA.Add(formulaB);

            Assert.AreEqual(formulaA, formulaC);
        }
예제 #16
0
        public void TestChemicalFormula()
        {
            Residue.GetResidue('A');

            Peptide A = new Peptide("A");

            Residue.GetResidue('A');

            ChemicalFormula ok = new ChemicalFormula(Residue.GetResidue('A').ThisChemicalFormula);

            ok.Add(new ChemicalFormulaTerminus(ChemicalFormula.ParseFormula("OH")));
            ok.Add(new ChemicalFormulaTerminus(ChemicalFormula.ParseFormula("H")));

            Residue.GetResidue('A');

            Residue.GetResidue('A');

            Assert.AreEqual(ok, A.GetChemicalFormula());
        }
예제 #17
0
        public static void AddFormulaToFormula()
        {
            ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C2H3NO");
            ChemicalFormula formulaB = ChemicalFormula.ParseFormula("H2O");
            ChemicalFormula formulaC = ChemicalFormula.ParseFormula("C2H5NO2");

            formulaA.Add(formulaB);

            Assert.AreEqual(formulaA, formulaC);
        }
예제 #18
0
        public void AddFormulaToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("H2O");
            ChemicalFormula formulaC = new ChemicalFormula("C2H5NO2");

            formulaA.Add(formulaB);

            Assert.AreEqual(formulaA, formulaC);
        }
예제 #19
0
        public void AddNegativeIsotopeToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2HH{1}2NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2HNO");

            Isotope h1 = PeriodicTable.GetElement("H")[1];

            formulaA.Add(h1, -2);

            Assert.AreEqual(formulaA, formulaB);
        }
예제 #20
0
        public void AddZeroIsotopeToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2H3NO");

            Isotope h1 = PeriodicTable.GetElement("H")[1];

            formulaA.Add(h1, 0);

            Assert.AreEqual(formulaA, formulaB);
        }
예제 #21
0
        public static void AddIsotopeToFormula()
        {
            ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C2H3NO");
            ChemicalFormula formulaB = ChemicalFormula.ParseFormula("C2H3H{1}NO");

            Isotope h1 = PeriodicTable.GetElement("H")[1];

            formulaA.Add(h1, 1);

            Assert.AreEqual(formulaA, formulaB);
        }
예제 #22
0
        public static void AddElementToFormula()
        {
            ChemicalFormula formulaA = ChemicalFormula.ParseFormula("C2H3NO");
            ChemicalFormula formulaB = ChemicalFormula.ParseFormula("C2H3N2O");

            Element n = PeriodicTable.GetElement(7);

            formulaA.Add(n, 1);

            Assert.AreEqual(formulaA, formulaB);
        }
예제 #23
0
        public void AddLargeElementToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2H3NOFe");

            Element fe = PeriodicTable.GetElement("Fe");

            formulaA.Add(fe, 1);

            Assert.AreEqual(formulaA, formulaB);
        }
예제 #24
0
        public void AddZeroElementToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2H3NO");

            Element n = PeriodicTable.GetElement("N");

            formulaA.Add(n, 0);

            Assert.AreEqual(formulaA, formulaB);
        }
예제 #25
0
        public void AddIsotopeToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2H4NO");

            Isotope h1 = Element.PeriodicTable["H"][1];

            formulaA.Add(h1, 1);

            Assert.AreEqual(formulaA, formulaB);
        }
예제 #26
0
        public void AddElementToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2H3N2O");

            Element n = Element.PeriodicTable["N"];

            formulaA.Add(n, 1);

            Assert.AreEqual(formulaA, formulaB);
        }
        public void AddLargeIsotopeToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2H3NOFe");

            Isotope fe = PeriodicTable.GetElement("Fe").PrincipalIsotope;

            formulaA.Add(fe, 1);

            Assert.AreEqual(formulaA, formulaB);
        }
예제 #28
0
        /// <summary>
        /// Basic overview of how chemical formulas can be used and modified
        /// </summary>
        private static void ChemicalFormulaExamples()
        {
            Console.WriteLine("**Chemical Formula Examples**");

            // Simple chemical formula creation
            ChemicalFormula formula1 = new ChemicalFormula("C2H3NO");
            WriteFormulaToConsole(formula1);

            // Input order does not matter
            ChemicalFormula formula2 = new ChemicalFormula("NH3C2O");
            WriteFormulaToConsole(formula2);

            // Formulas are identicial if they have the exact same type of elements and count
            Console.WriteLine("Are {0} and {1} equivalent? {2}", formula1, formula2, formula1.Equals(formula2));

            // You can modify exisiting chemical formulas in many ways.
            // You can add a chemical formula to a chemical formula
            formula1.Add(formula2);
            WriteFormulaToConsole(formula1);
            Console.WriteLine("Are {0} and {1} equivalent? {2}", formula1, formula2, formula1.Equals(formula2));

            // You can completely remove an element from a chemical formula
            formula1.Remove("C");
            WriteFormulaToConsole(formula1);

            // Even negative values are possible if not physically possible
            formula1.Remove(formula2);
            WriteFormulaToConsole(formula1);

            // Implicit arithmetic is also possible (supports +, -, and *)
            ChemicalFormula formula3 = formula2 - formula1;
            WriteFormulaToConsole(formula3);
            ChemicalFormula formula4 = formula3 + formula1;
            WriteFormulaToConsole(formula4);
            ChemicalFormula formula5 = formula2*5;
            WriteFormulaToConsole(formula5);

            // Formulas consist of a dictionary of isotopes and count, and by default, the most common (abundant) isotope of an element
            // is included (i.e. Carbon 12 instead of Carbon 13). You can explicitly state that you want another isotope in a chemical formula
            // by this notation: <Element Symbol>{<Mass Number>} (e.g. C{13}, N{15}, etc..)

            formula1 = new ChemicalFormula("C2C{13}2H3NO");
            formula2 = new ChemicalFormula("C4H3NO");

            WriteFormulaToConsole(formula1);
            WriteFormulaToConsole(formula2);

            Console.WriteLine("Are {0} and {1} equivalent? {2}", formula1, formula2, formula1.Equals(formula2));

            // No need to specify the mass number of the most abundant isotope for an element
            formula3 = new ChemicalFormula("C{12}2C2H3NO");
            formula4 = new ChemicalFormula("C4H3NO");
            Console.WriteLine("Are {0} and {1} equivalent? {2}", formula3, formula4, formula3.Equals(formula4));
        }
예제 #29
0
        /// <summary>
        /// Gets the chemical formula of this amino acid polymer.
        /// </summary>
        /// <returns></returns>
        public ChemicalFormula GetChemicalFormula()
        {
            var formula = new ChemicalFormula();

            // Handle Modifications
            if (ContainsModifications())
            {
                for (int i = 0; i < Length + 2; i++)
                {
                    if (_modifications[i] == null)
                    {
                        continue;
                    }

                    IHasChemicalFormula chemMod = _modifications[i] as IHasChemicalFormula;

                    if (chemMod == null)
                    {
                        throw new MzLibException("Modification " + _modifications[i] + " does not have a chemical formula!");
                    }

                    formula.Add(chemMod.ThisChemicalFormula);
                }
            }

            // Handle N-Terminus
            formula.Add(NTerminus.ThisChemicalFormula);

            // Handle C-Terminus
            formula.Add(CTerminus.ThisChemicalFormula);

            // Handle Amino Acid Residues
            for (int i = 0; i < Length; i++)
            {
                formula.Add(residues[i].ThisChemicalFormula);
            }

            return(formula);
        }
예제 #30
0
        static IsoDecon()
        {
            //AVERAGINE
            const double averageC = 4.9384;
            const double averageH = 7.7583;
            const double averageO = 1.4773;
            const double averageN = 1.3577;
            const double averageS = 0.0417;

            const double fineRes = 0.125;
            const double minRes  = 1e-8;

            for (int i = 0; i < numAveraginesToGenerate; i++)
            {
                double averagineMultiplier = (i + 1) / 2.0;
                //Console.Write("numAveragines = " + numAveragines);
                ChemicalFormula chemicalFormula = new ChemicalFormula();
                chemicalFormula.Add("C", Convert.ToInt32(averageC * averagineMultiplier));
                chemicalFormula.Add("H", Convert.ToInt32(averageH * averagineMultiplier));
                chemicalFormula.Add("O", Convert.ToInt32(averageO * averagineMultiplier));
                chemicalFormula.Add("N", Convert.ToInt32(averageN * averagineMultiplier));
                chemicalFormula.Add("S", Convert.ToInt32(averageS * averagineMultiplier));

                {
                    var chemicalFormulaReg  = chemicalFormula;
                    IsotopicDistribution ye = IsotopicDistribution.GetDistribution(chemicalFormulaReg, fineRes, minRes);
                    var masses      = ye.Masses.ToArray();
                    var intensities = ye.Intensities.ToArray();
                    Array.Sort(intensities, masses);
                    Array.Reverse(intensities);
                    Array.Reverse(masses);

                    mostIntenseMasses[i]  = masses[0];
                    diffToMonoisotopic[i] = masses[0] - chemicalFormulaReg.MonoisotopicMass;
                    allMasses[i]          = masses;
                    allIntensities[i]     = intensities;
                }
            }
        }
예제 #31
0
        public ChemicalFormulaModification ToHeavyModification(bool c, bool n)
        {
            var formula = new ChemicalFormula();

            if (c)
            {
                Element carbon   = PeriodicTable.GetElement("C");
                int     carbon12 = ChemicalFormula.Count(carbon[12]);
                formula.Add(carbon[12], -carbon12);
                formula.Add(carbon[13], carbon12);
            }

            if (n)
            {
                Element nitrogen   = PeriodicTable.GetElement("N");
                int     nitrogen14 = ChemicalFormula.Count(nitrogen[14]);
                formula.Add(nitrogen[14], -nitrogen14);
                formula.Add(nitrogen[15], nitrogen14);
            }

            return(new ChemicalFormulaModification(formula, "#", Site));
        }
예제 #32
0
        /// <summary>
        /// Resolve Methods()
        /// if all 'values' are the same this returns the one value otherwise you get a separated list of all values in their original order.
        /// for example:
        /// Notches 1,1,1,1 returns as 1
        /// Notches 1,0,1,0 returns as 1|0|1|0
        /// </summary>
        internal static (string ResolvedString, ChemicalFormula ResolvedValue) Resolve(IEnumerable <IEnumerable <Modification> > enumerable)
        {
            var             list             = enumerable.ToList();
            ChemicalFormula firstChemFormula = new ChemicalFormula();

            foreach (var firstMods in list[0])
            {
                if (firstMods == null || firstMods.ChemicalFormula == null)
                {
                    return("unknown", null);
                }
                firstChemFormula.Add(firstMods.ChemicalFormula);
            }

            bool equals = true;
            List <ChemicalFormula> formulas = new List <ChemicalFormula>();

            foreach (var anEnum in list)
            {
                ChemicalFormula fhere = new ChemicalFormula();
                foreach (var mod in anEnum)
                {
                    if (mod == null || mod.ChemicalFormula == null)
                    {
                        return("unknown", null);
                    }
                    fhere.Add(mod.ChemicalFormula);
                }
                if (!firstChemFormula.Equals(fhere))
                {
                    equals = false;
                }
                formulas.Add(fhere);
            }
            if (!equals)
            {
                var returnString = GlobalVariables.CheckLengthOfOutput(string.Join("|", formulas.Select(b => b.Formula)));
                return(returnString, null);
            }
            else
            {
                return(firstChemFormula.Formula, firstChemFormula);
            }
        }
예제 #33
0
        private static (string, ChemicalFormula) Resolve(IEnumerable <IEnumerable <ModificationWithMassAndCf> > enumerable)
        {
            ChemicalFormula f = new ChemicalFormula();
            {
                var firstEnum = enumerable.First();
                foreach (var mod in firstEnum)
                {
                    if (mod == null)
                    {
                        return("unknown", null);
                    }
                    f.Add(mod.chemicalFormula);
                }
            }
            bool equals = true;
            List <ChemicalFormula> formulas = new List <ChemicalFormula>();

            foreach (var anEnum in enumerable)
            {
                ChemicalFormula fhere = new ChemicalFormula();
                foreach (var mod in anEnum)
                {
                    if (mod == null)
                    {
                        return("unknown", null);
                    }
                    fhere.Add(mod.chemicalFormula);
                }
                if (!f.Equals(fhere))
                {
                    equals = false;
                }
                formulas.Add(fhere);
            }
            if (!equals)
            {
                var returnString = GlobalVariables.CheckLengthOfOutput(string.Join("|", formulas.Select(b => b.Formula)));
                return(returnString, null);
            }
            else
            {
                return(f.Formula, f);
            }
        }
예제 #34
0
        public void AddNullIsotopeToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2H3NO");

            formulaA.Add(NullIsotope, 1);

            Assert.AreEqual(formulaA, formulaB);
        }
예제 #35
0
        public void AddZeroSymbolToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2H3NO");

            formulaA.Add("H", 0);

            Assert.AreEqual(formulaA, formulaB);
        }
예제 #36
0
        public void AddNegativeFormulaToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C-1H-2");
            ChemicalFormula formulaC = new ChemicalFormula("CHNO");

            formulaA.Add(formulaB);

            Assert.AreEqual(formulaA, formulaC);
        }
예제 #37
0
        public void AddNonExistentSymbolToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");

            formulaA.Add("Faa", 1);
        }
        public void AddZeroIsotopeToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2H3NO");

            Isotope h1 = PeriodicTable.GetElement("H")[1];

            formulaA.Add(h1, 0);

            Assert.AreEqual(formulaA, formulaB);
        }
예제 #39
0
        internal static IEnumerable <Modification> ReadMods(string unimodLocation)
        {
            var unimodSerializer = new XmlSerializer(typeof(unimod_t));
            var deserialized     = unimodSerializer.Deserialize(new FileStream(unimodLocation, FileMode.Open, FileAccess.Read, FileShare.Read)) as unimod_t;

            Dictionary <string, string> positionConversion = new Dictionary <string, string>()
            {
                { "Anywhere", "Anywhere." },
                { "AnyNterm", "Peptide N-terminal." },
                { "AnyCterm", "Peptide C-terminal." },
                { "ProteinNterm", "N-terminal." },
                { "ProteinCterm", "C-terminal." }
            };

            foreach (var mod in deserialized.modifications)
            {
                var             id = mod.title;
                var             ac = mod.record_id;
                ChemicalFormula cf = new ChemicalFormula();
                foreach (var el in mod.delta.element)
                {
                    try
                    {
                        cf.Add(el.symbol, int.Parse(el.number));
                    }
                    catch
                    {
                        var tempCF = ChemicalFormula.ParseFormula(DictOfElements[el.symbol]);
                        tempCF.Multiply(int.Parse(el.number));
                        cf.Add(tempCF);
                    }
                }

                //TODO Add "on motif" to the ID field
                foreach (var target in mod.specificity)
                {
                    var tg = target.site;
                    if (tg.Length > 1)
                    {
                        tg = "X"; //I think that we should allow motifs here using the trygetmotif
                    }
                    ModificationMotif.TryGetMotif(tg, out ModificationMotif motif);

                    if (positionConversion.TryGetValue(target.position.ToString(), out string pos))
                    {
                        //do nothing, the new string value should be there
                    }
                    else
                    {
                        pos = null;
                    }

                    Dictionary <string, IList <string> > dblinks = new Dictionary <string, IList <string> >
                    {
                        { "Unimod", new List <string> {
                              ac.ToString()
                          } },
                    };

                    if (target.NeutralLoss == null)
                    {
                        yield return(new Modification(_originalId: id, _modificationType: "Unimod", _target: motif, _locationRestriction: pos, _chemicalFormula: cf, _databaseReference: dblinks));
                    }
                    else
                    {
                        Dictionary <MassSpectrometry.DissociationType, List <double> > neutralLosses = null;
                        foreach (var nl in target.NeutralLoss)
                        {
                            ChemicalFormula cfnl = new ChemicalFormula();
                            if (nl.mono_mass == 0)
                            {
                                if (neutralLosses == null)
                                {
                                    neutralLosses = new Dictionary <MassSpectrometry.DissociationType, List <double> >
                                    {
                                        { MassSpectrometry.DissociationType.AnyActivationType, new List <double> {
                                              0
                                          } }
                                    };
                                }
                                else
                                {
                                    if (neutralLosses.ContainsKey(MassSpectrometry.DissociationType.AnyActivationType))
                                    {
                                        if (!neutralLosses[MassSpectrometry.DissociationType.AnyActivationType].Contains(0))
                                        {
                                            neutralLosses[MassSpectrometry.DissociationType.AnyActivationType].Add(0);
                                        }
                                    }//we don't need an else cuz it's already there
                                }
                            }
                            else
                            {
                                foreach (var el in nl.element)
                                {
                                    try
                                    {
                                        cfnl.Add(el.symbol, int.Parse(el.number));
                                    }
                                    catch
                                    {
                                        var tempCF = ChemicalFormula.ParseFormula(DictOfElements[el.symbol]);
                                        tempCF.Multiply(int.Parse(el.number));
                                        cfnl.Add(tempCF);
                                    }
                                }
                                if (neutralLosses == null)
                                {
                                    neutralLosses = new Dictionary <MassSpectrometry.DissociationType, List <double> >
                                    {
                                        { MassSpectrometry.DissociationType.AnyActivationType, new List <double> {
                                              cfnl.MonoisotopicMass
                                          } }
                                    };
                                }
                                else
                                {
                                    if (neutralLosses.ContainsKey(MassSpectrometry.DissociationType.AnyActivationType))
                                    {
                                        if (!neutralLosses[MassSpectrometry.DissociationType.AnyActivationType].Contains(cfnl.MonoisotopicMass))
                                        {
                                            neutralLosses[MassSpectrometry.DissociationType.AnyActivationType].Add(cfnl.MonoisotopicMass);
                                        }
                                    }//we don't need an else cuz it's already there
                                }
                            }
                        }
                        yield return(new Modification(_originalId: id, _target: motif, _locationRestriction: "Anywhere.", _modificationType: "Unimod", _chemicalFormula: cf, _databaseReference: dblinks, _neutralLosses: neutralLosses));
                    }
                }
            }
        }
        public void AddZeroElementToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2H3NO");

            Element n = PeriodicTable.GetElement("N");

            formulaA.Add(n, 0);

            Assert.AreEqual(formulaA, formulaB);
        }
        public void AddNonExistentSymbolToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");

            Assert.Throws<KeyNotFoundException>(() => formulaA.Add("Faa", 1), "The element symbol 'Faa' is not found in the periodic table");
        }
        public void AddNonExistentSymbolToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");

            Assert.Throws <KeyNotFoundException>(() => formulaA.Add("Faa", 1), "The element symbol 'Faa' is not found in the periodic table");
        }
예제 #43
0
        public ChemicalFormulaModification ToHeavyModification(bool c, bool n)
        {
            var formula = new ChemicalFormula();
            if (c)
            {
                Element carbon = PeriodicTable.GetElement("C");
                int carbon12 = ChemicalFormula.Count(carbon[12]);
                formula.Add(carbon[12], -carbon12);
                formula.Add(carbon[13], carbon12);
            }

            if (n)
            {
                Element nitrogen = PeriodicTable.GetElement("N");
                int nitrogen14 = ChemicalFormula.Count(nitrogen[14]);
                formula.Add(nitrogen[14], -nitrogen14);
                formula.Add(nitrogen[15], nitrogen14);
            }

            return new ChemicalFormulaModification(formula, "#", Site);
        }
예제 #44
0
        public IEnumerable <Fragment> Fragment(FragmentTypes types, int minIndex, int maxIndex, bool calculateChemicalFormula)
        {
            foreach (FragmentTypes type in types.GetIndividualFragmentTypes())
            {
                bool            isChemicalFormula = calculateChemicalFormula;
                ChemicalFormula capFormula        = type.GetIonCap();
                bool            isCTerminal       = type.GetTerminus() == Terminus.C;

                double          monoMass = capFormula.MonoisotopicMass;
                ChemicalFormula formula  = new ChemicalFormula(capFormula);

                IHasChemicalFormula terminus = isCTerminal ? CTerminus : NTerminus;
                monoMass += terminus.MonoisotopicMass;
                if (isChemicalFormula)
                {
                    formula.Add(terminus);
                }

                bool first  = true;
                bool hasMod = _modifications != null;

                for (int i = 0; i <= maxIndex; i++)
                {
                    int aaIndex = isCTerminal ? Length - i : i - 1;

                    // Handle the terminus mods first in a special case
                    IHasMass mod;
                    if (first)
                    {
                        first = false;
                        if (hasMod)
                        {
                            mod = _modifications[aaIndex + 1];
                            if (mod != null)
                            {
                                monoMass += mod.MonoisotopicMass;
                                if (isChemicalFormula)
                                {
                                    if (mod is IHasChemicalFormula modFormula)
                                    {
                                        formula.Add(modFormula);
                                    }
                                    else
                                    {
                                        isChemicalFormula = false;
                                    }
                                }
                            }
                        }
                        continue;
                    }

                    monoMass += residues[aaIndex].MonoisotopicMass;
                    formula.Add(residues[aaIndex]);

                    if (hasMod)
                    {
                        mod = _modifications[aaIndex + 1];

                        if (mod != null)
                        {
                            monoMass += mod.MonoisotopicMass;
                            if (isChemicalFormula)
                            {
                                if (mod is IHasChemicalFormula modFormula)
                                {
                                    formula.Add(modFormula);
                                }
                                else
                                {
                                    isChemicalFormula = false;
                                }
                            }
                        }
                    }

                    if (i < minIndex)
                    {
                        continue;
                    }

                    if (isChemicalFormula)
                    {
                        yield return(new ChemicalFormulaFragment(type, i, formula, this));
                    }
                    else
                    {
                        yield return(new Fragment(type, i, monoMass, this));
                    }
                }
            }
        }
예제 #45
0
        public void AddLargeIsotopeToFormula()
        {
            ChemicalFormula formulaA = new ChemicalFormula("C2H3NO");
            ChemicalFormula formulaB = new ChemicalFormula("C2H3NOFe");

            Isotope fe = Element.PeriodicTable["Fe"].PrincipalIsotope;

            formulaA.Add(fe, 1);

            Assert.AreEqual(formulaA, formulaB);
        }
예제 #46
0
        /// <summary>
        /// Combine isotope pattern
        /// </summary>
        /// <param name="argNumberPermethlationSite"></param>
        /// <param name="argStartPurity"></param>
        /// <param name="argIntensities"></param>
        /// <returns></returns>
        public static float Estimater3(COL.GlycoLib.GlycanCompound argCompond,int argTheoreticalMonoIdx, float[] argIntensities)
        {
            double[] isotopeRatio = new double[argIntensities.Length];
            for (int i = 0; i < isotopeRatio.Length; i++)
            {
                isotopeRatio[i] = 0;
            }
            ChemicalFormula MonoChemFormula = new ChemicalFormula();
            MonoChemFormula.Add("C", argCompond.Carbon);
            MonoChemFormula.Add("H", argCompond.Hydrogen);
            MonoChemFormula.Add("O", argCompond.Oxygen);
            if (argCompond.Carbon13 != 0)
            {
                MonoChemFormula.Add("C{13}", argCompond.Carbon13);
            }
            if (argCompond.Deuterium != 0)
            {
                MonoChemFormula.Add("D", argCompond.Deuterium);
            }
            if (argCompond.Sodium != 0)
            {
                MonoChemFormula.Add("Na", argCompond.Sodium);
            }
            if (argCompond.Nitrogen != 0)
            {
                MonoChemFormula.Add("N", argCompond.Nitrogen);
            }
            double[] IsotopeDist = MonoChemFormula.GetIsotopicDistribution(10);

            return 0.0f;
        }