Example #1
0
        public void TestGetIonFormula()
        {
            SequenceMassCalc sequenceMassCalc = new SequenceMassCalc(MassType.Monoisotopic);

            Assert.AreEqual(147.11, sequenceMassCalc.GetPrecursorMass("K"), .1);
            Assert.AreEqual("C6H14N2O2", sequenceMassCalc.GetMolecularFormula("K"));

            var label13C6K = new StaticMod("label13C6K", "K", null, LabelAtoms.C13);

            sequenceMassCalc.AddStaticModifications(new [] { label13C6K });
            Assert.AreEqual(153.11, sequenceMassCalc.GetPrecursorMass("K"), .1);
            Assert.AreEqual("C'6H14N2O2", sequenceMassCalc.GetMolecularFormula("K"));

            var label15N2K = new StaticMod("label15N2K", "K", null, LabelAtoms.N15);

            sequenceMassCalc.AddStaticModifications(new[] { label15N2K });
            Assert.AreEqual(155.11, sequenceMassCalc.GetPrecursorMass("K"), .1);
            Assert.AreEqual("C'6H14N'2O2", sequenceMassCalc.GetMolecularFormula("K"));

            var labelLaK = new StaticMod("labelLaK", "K", null, "La");

            sequenceMassCalc.AddStaticModifications(new[] { labelLaK });
            Assert.AreEqual(294.033, sequenceMassCalc.GetPrecursorMass("K"), .1);
            Assert.AreEqual("C'6H14LaN'2O2", sequenceMassCalc.GetMolecularFormula("K"));

            // Check our ability to handle strangely constructed chemical formulas
            Assert.AreEqual(Molecule.Parse("C12H9S2P0").ToString(), Molecule.Parse("C12H9S2").ToString());  // P0 is weird
            Assert.AreEqual(Molecule.Parse("C12H9S2P1").ToString(), Molecule.Parse("C12H9S2P").ToString()); // P1 is weird
            Assert.AreEqual(Molecule.Parse("C12H9S0P").ToString(), Molecule.Parse("C12H9P").ToString());    // S0 is weird, and not at end
        }
        public void TestGetPrecursorFormula()
        {
            var modifiedSequence   = new ModifiedSequence("PEPTIDE", new ModifiedSequence.Modification[0], MassType.Monoisotopic);
            var fragmentedMolecule = FragmentedMolecule.EMPTY.ChangeModifiedSequence(modifiedSequence);
            var precursorFormula   = fragmentedMolecule.PrecursorFormula;

            Assert.AreEqual(0, fragmentedMolecule.PrecursorMassShift);
            var sequenceMassCalc = new SequenceMassCalc(MassType.Monoisotopic);
            var expectedFormula  = Molecule.Parse(sequenceMassCalc.GetMolecularFormula(modifiedSequence.GetUnmodifiedSequence()));

            Assert.AreEqual(expectedFormula.Count, precursorFormula.Count);
            foreach (var entry in expectedFormula)
            {
                Assert.AreEqual(entry.Value, precursorFormula.GetElementCount(entry.Key));
            }
        }