Exemple #1
0
        public void SequenceMassCalcTest()
        {
            // Test case that caused unexpected exception when O- was not parsed correctly.
            SequenceMassCalc.ParseModCounts(BioMassCalc.MONOISOTOPIC, "OO-HNHN", new Dictionary <string, int>());

            // Test normal function
            var sequence = "VEDELK";
            var calc     = new SequenceMassCalc(MassType.Monoisotopic);
            var expected = new List <KeyValuePair <double, double> >
            {
                new KeyValuePair <double, double>(366.69232575, 0.668595429107379),
                new KeyValuePair <double, double>(367.194009631186, 0.230439133647163),
                new KeyValuePair <double, double>(367.69569373213, 0.0384590257505838),
                new KeyValuePair <double, double>(367.694446060561, 0.017949871952498),
                new KeyValuePair <double, double>(367.19084355, 0.017192511410608),
                new KeyValuePair <double, double>(368.196128166749, 0.00616111554527541),
                new KeyValuePair <double, double>(367.692527431186, 0.00592559754703795),
                new KeyValuePair <double, double>(367.1954645, 0.00513890101333714),
                new KeyValuePair <double, double>(368.197384928765, 0.00425230800778248),
                new KeyValuePair <double, double>(367.697148381186, 0.00177118156340514),
                new KeyValuePair <double, double>(368.697813900475, 0.00101646716687999),
                new KeyValuePair <double, double>(368.19421153213, 0.00098894968507418),
                new KeyValuePair <double, double>(368.1929673, 0.000458171690211896),
                new KeyValuePair <double, double>(368.699089317816, 0.000360958912487784),
                new KeyValuePair <double, double>(368.19883248213, 0.000295600474962106),
                new KeyValuePair <double, double>(368.69657325, 0.000202295887934749),
                new KeyValuePair <double, double>(367.68936135, 0.000189469126984509),
                new KeyValuePair <double, double>(368.694649407319, 0.000157258059028779),
                new KeyValuePair <double, double>(369.199499540822, 0.000109802223366965),
                new KeyValuePair <double, double>(368.695902738459, 0.000109341412261551),
                new KeyValuePair <double, double>(369.198241127809, 7.04324061939316E-05),
                new KeyValuePair <double, double>(368.191045231186, 6.53027220564238E-05),
                new KeyValuePair <double, double>(368.700518794653, 3.19123118597943E-05),
                new KeyValuePair <double, double>(369.19633171026, 2.61321131972594E-05),
                new KeyValuePair <double, double>(369.699928636691, 1.13012567237636E-05),
                new KeyValuePair <double, double>(368.69272933213, 1.08986656450318E-05),
                new KeyValuePair <double, double>(367.69860325, 1.06303400612337E-05),
            };
            var actual = calc.GetMzDistribution(sequence, 2, IsotopeAbundances.Default).MassesSortedByAbundance();

            for (var i = 0; i < expected.Count; i++)
            {
                Assert.AreEqual(expected[i].Key, actual[i].Key, .0001);
                Assert.AreEqual(expected[i].Value, actual[i].Value, .0001);
            }
        }
Exemple #2
0
        public void EquivalentTest()
        {
            var dictHiddenIsotopeModNames    = UniMod.DictHiddenIsotopeModNames;
            var dictHiddenStructuralModNames = UniMod.DictHiddenStructuralModNames;
            var dictIsotopeModNames          = UniMod.DictIsotopeModNames;
            var dictStructuralModNames       = UniMod.DictStructuralModNames;

            var compareDict = new SortedDictionary <string, int>();
            var massCalc    = new SequenceMassCalc(MassType.Monoisotopic);

            foreach (var dict in new[]
            {
                dictStructuralModNames,
                dictIsotopeModNames,
                dictHiddenStructuralModNames,
                dictHiddenIsotopeModNames
            })
            {
                var unimodArray = dict.ToArray();
                var actualDict  = new SortedDictionary <string, int>();
                int actualCount = EquivalentValues(actualDict, unimodArray);

                int count, totalCount = 0;
                // Check that modifications are identified with improper name.
                StaticMod modToMatch;
                for (int i = 0; i < unimodArray.Length; i++)
                {
                    var original = unimodArray[i].Value;

                    modToMatch = (StaticMod)original.ChangeName("Test");

                    count = CountEquivalent(unimodArray, modToMatch, compareDict, i);
                    Assert.IsTrue(count >= 1);
                    totalCount += count;
                }

                Assert.AreEqual(actualCount, totalCount);
                Assert.IsTrue(ArrayUtil.EqualsDeep(actualDict.ToArray(), compareDict.ToArray()));

                compareDict.Clear();
                totalCount = 0;

                // Modify arrangement of formula.
                // Should still be able to identify correct modification.
                for (int i = 0; i < unimodArray.Length; i++)
                {
                    var original = unimodArray[i].Value;
                    modToMatch = (StaticMod)original.ChangeName("Test");
                    var formula = original.Formula;
                    if (formula != null)
                    {
                        var dictCounts = new Dictionary <string, int>();
                        massCalc.ParseModCounts(formula, dictCounts);

                        string newFormula = GetFormula(formula, dictCounts);

                        modToMatch = modToMatch.ChangeFormula(newFormula);
                    }

                    count = CountEquivalent(unimodArray, modToMatch, compareDict, i);
                    Assert.IsTrue(count >= 1);
                    totalCount += count;
                }
                Assert.IsTrue(actualCount == totalCount);
                Assert.IsTrue(ArrayUtil.EqualsDeep(actualDict.ToArray(), compareDict.ToArray()));

                compareDict.Clear();
                totalCount = 0;


                // Add and substract 5 hydrogen atoms to test complex formulas.
                for (int i = 0; i < unimodArray.Length; i++)
                {
                    var original = unimodArray[i].Value;

                    var formula = original.Formula;

                    modToMatch = (StaticMod)original.ChangeName("Test");
                    if (formula != null)
                    {
                        var dictCounts = new Dictionary <string, int>();
                        massCalc.ParseModCounts(formula, dictCounts);

                        if (dictCounts.TryGetValue("H", out count))
                        {
                            dictCounts["H"] = count + 5;
                        }
                        else
                        {
                            dictCounts["H"] = 5;
                        }

                        string newFormula = GetFormula(formula, dictCounts);
                        if (newFormula.Contains("-"))
                        {
                            newFormula = newFormula + "H5";
                        }
                        else
                        {
                            newFormula = newFormula + " - H5";
                        }
                        modToMatch = modToMatch.ChangeFormula(newFormula);
                    }

                    count = CountEquivalent(unimodArray, modToMatch, compareDict, i);
                    Assert.IsTrue(count >= 1);
                    totalCount += count;
                }
                Assert.IsTrue(actualCount == totalCount);
                Assert.IsTrue(ArrayUtil.EqualsDeep(actualDict.ToArray(), compareDict.ToArray()));

                compareDict.Clear();
                totalCount = 0;

                // Change label.
                for (int i = 0; i < unimodArray.Length; i++)
                {
                    var original = unimodArray[i].Value;

                    var labelAtoms = original.LabelAtoms;

                    modToMatch = (StaticMod)original.ChangeName("Test");
                    if (labelAtoms != LabelAtoms.None && original.AAs != null && original.AAs.Length == 1)
                    {
                        double unexplainedMass;
                        string newFormula = massCalc.GetModFormula(original.AAs[0], original, out unexplainedMass);
                        Assert.AreEqual(0, unexplainedMass);
                        modToMatch = modToMatch.ChangeFormula(newFormula).ChangeLabelAtoms(LabelAtoms.None);
                    }

                    count = CountEquivalent(unimodArray, modToMatch, compareDict, i);
                    Assert.IsTrue(count >= 1);
                    totalCount += count;
                }
                Assert.IsTrue(actualCount == totalCount);
                Assert.IsTrue(ArrayUtil.EqualsDeep(actualDict.ToArray(), compareDict.ToArray()));

                // Nonexisting formulas.
                foreach (StaticMod original in dict.Values)
                {
                    modToMatch = (StaticMod)original.ChangeName("Test");
                    if (original.Formula != null || original.Losses != null)
                    {
                        modToMatch = modToMatch.ChangeFormula("H2OCl");
                    }
                    else if (original.LabelAtoms != LabelAtoms.None)
                    {
                        modToMatch = modToMatch.ChangeFormula("H2OCl").ChangeLabelAtoms(LabelAtoms.None);
                    }

                    count = CountEquivalent(unimodArray, modToMatch, compareDict, -1);
                    Assert.AreEqual(0, count);
                }
                compareDict.Clear();
            }
        }
Exemple #3
0
        public void SequenceMassCalcTest()
        {
            // Test case that caused unexpected exception when O- was not parsed correctly.
            SequenceMassCalc.ParseModCounts(BioMassCalc.MONOISOTOPIC, "OO-HNHN", new Dictionary <string, int>());

            // Test normal function
            var sequence = new Target("VEDELK");
            var calc     = new SequenceMassCalc(MassType.Monoisotopic);
            var expected = new List <KeyValuePair <double, double> >
            {
                new KeyValuePair <double, double>(366.69232575, 0.668595429107379),
                new KeyValuePair <double, double>(367.194009631186, 0.230439133647163),
                new KeyValuePair <double, double>(367.69569373213, 0.0384590257505838),
                new KeyValuePair <double, double>(367.694446060561, 0.017949871952498),
                new KeyValuePair <double, double>(367.19084355, 0.017192511410608),
                new KeyValuePair <double, double>(368.196128166749, 0.00616111554527541),
                new KeyValuePair <double, double>(367.692527431186, 0.00592559754703795),
                new KeyValuePair <double, double>(367.1954645, 0.00513890101333714),
                new KeyValuePair <double, double>(368.197384928765, 0.00425230800778248),
                new KeyValuePair <double, double>(367.697148381186, 0.00177118156340514),
                new KeyValuePair <double, double>(368.697813900475, 0.00101646716687999),
                new KeyValuePair <double, double>(368.19421153213, 0.00098894968507418),
                new KeyValuePair <double, double>(368.1929673, 0.000458171690211896),
                new KeyValuePair <double, double>(368.699089317816, 0.000360958912487784),
                new KeyValuePair <double, double>(368.19883248213, 0.000295600474962106),
                new KeyValuePair <double, double>(368.69657325, 0.000202295887934749),
                new KeyValuePair <double, double>(367.68936135, 0.000189469126984509),
                new KeyValuePair <double, double>(368.694649407319, 0.000157258059028779),
                new KeyValuePair <double, double>(369.199499540822, 0.000109802223366965),
                new KeyValuePair <double, double>(368.695902738459, 0.000109341412261551),
                new KeyValuePair <double, double>(369.198241127809, 7.04324061939316E-05),
                new KeyValuePair <double, double>(368.191045231186, 6.53027220564238E-05),
                new KeyValuePair <double, double>(368.700518794653, 3.19123118597943E-05),
                new KeyValuePair <double, double>(369.19633171026, 2.61321131972594E-05),
                new KeyValuePair <double, double>(369.699928636691, 1.13012567237636E-05),
                new KeyValuePair <double, double>(368.69272933213, 1.08986656450318E-05),
                new KeyValuePair <double, double>(367.69860325, 1.06303400612337E-05),
            };
            var actual = calc.GetMzDistribution(sequence, Adduct.DOUBLY_PROTONATED, IsotopeAbundances.Default).MassesSortedByAbundance();

            for (var i = 0; i < expected.Count; i++)
            {
                Assert.AreEqual(expected[i].Key, actual[i].Key, .0001);
                Assert.AreEqual(expected[i].Value, actual[i].Value, .0001);
            }

            // Now try it with dimer
            actual   = calc.GetMzDistribution(sequence, Adduct.FromStringAssumeProtonated("[2M+H]"), IsotopeAbundances.Default).MassesSortedByAbundance();
            expected = new List <KeyValuePair <double, double> >
            {
                new KeyValuePair <double, double>(1463.74754654509, 0.446952046999841),
                new KeyValuePair <double, double>(1464.75091373569, 0.308094366214783),
                new KeyValuePair <double, double>(1465.75428096509, 0.104502495092047),
                new KeyValuePair <double, double>(1465.75177853495, 0.0241787720728353),
                new KeyValuePair <double, double>(1466.75765484084, 0.0235859617485415),
                new KeyValuePair <double, double>(1464.74458144349, 0.0229861821768609),
                new KeyValuePair <double, double>(1466.75514391842, 0.0166321763672613),
                new KeyValuePair <double, double>(1465.74794863409, 0.0158449061303438),
                new KeyValuePair <double, double>(1464.75382328909, 0.00693546665186705),
                new KeyValuePair <double, double>(1467.75850938071, 0.00562963106050384),
                new KeyValuePair <double, double>(1466.75131586349, 0.00537443201400792),
                new KeyValuePair <double, double>(1465.75719047969, 0.00478077730453152),
                new KeyValuePair <double, double>(1467.76104095438, 0.00404384128691872),
                new KeyValuePair <double, double>(1466.7605577091, 0.00162159134209772),
                new KeyValuePair <double, double>(1468.76187811107, 0.00125712562385447),
                new KeyValuePair <double, double>(1466.74882721349, 0.0012251401424684),
                new KeyValuePair <double, double>(1467.75468976295, 0.00121294105003981),
                new KeyValuePair <double, double>(1467.75219259911, 0.000842727179304581),
                new KeyValuePair <double, double>(1467.75603830967, 0.000586408980257825),
                new KeyValuePair <double, double>(1468.76444202787, 0.000567782385153248),
                new KeyValuePair <double, double>(1465.74161634189, 0.000548855573943895),
                new KeyValuePair <double, double>(1468.75939300441, 0.000398455807475131),
                new KeyValuePair <double, double>(1466.74498353249, 0.000378338820311423),
                new KeyValuePair <double, double>(1467.76392745102, 0.000362303274653099),
                new KeyValuePair <double, double>(1468.75555806299, 0.000285235413419449),
                new KeyValuePair <double, double>(1468.75807595161, 0.000207931538310744),
                new KeyValuePair <double, double>(1469.76526667317, 0.000206771603698575),
                new KeyValuePair <double, double>(1469.76274777416, 0.000133221073579107),
                new KeyValuePair <double, double>(1467.7483507619, 0.00012832870395677),
                new KeyValuePair <double, double>(1469.7678564138, 6.79035524187075E-05),
                new KeyValuePair <double, double>(1469.7589267626, 6.36963686931021E-05),
                new KeyValuePair <double, double>(1468.76730210576, 6.02445600328977E-05),
                new KeyValuePair <double, double>(1465.76010003309, 3.90471536916692E-05),
                new KeyValuePair <double, double>(1470.76607119395, 3.04466596822611E-05),
                new KeyValuePair <double, double>(1468.7530730878, 3.01473461225893E-05),
                new KeyValuePair <double, double>(1467.74586211189, 2.92534441292776E-05),
                new KeyValuePair <double, double>(1469.76147692291, 2.91999633188283E-05),
                new KeyValuePair <double, double>(1468.7517180868, 2.85070807700198E-05),
                new KeyValuePair <double, double>(1470.76865091652, 2.75751131620645E-05),
                new KeyValuePair <double, double>(1466.76346722369, 2.69161046467483E-05),
                new KeyValuePair <double, double>(1469.75642098879, 2.07496271610838E-05),
                new KeyValuePair <double, double>(1468.74922749751, 2.01223285414029E-05),
                new KeyValuePair <double, double>(1465.75598028509, 1.13541999955428E-05),
                new KeyValuePair <double, double>(1470.76230177139, 1.06228647668148E-05)
            };
            for (var i = 0; i < expected.Count; i++)
            {
                Assert.AreEqual(expected[i].Key, actual[i].Key, .0001);
                Assert.AreEqual(expected[i].Value, actual[i].Value, .0001);
            }
        }
Exemple #4
0
 public void SequenceMassCalcTest()
 {
     // Test case that caused unexpected exception when O- was not parsed correctly.
     SequenceMassCalc.ParseModCounts(BioMassCalc.MONOISOTOPIC, "OO-HNHN", new Dictionary <string, int>());
 }