Example #1
0
 public ExplicitSequenceMassCalc(ExplicitMods mods, SequenceMassCalc massCalcBase, IsotopeLabelType labelType)
 {
     _massCalcBase = massCalcBase;
     _mods = new ExplicitSequenceMods
         { 
             Mods = mods.GetModifications(labelType),
             StaticBaseMods = mods.GetStaticBaseMods(labelType),
             ModMasses = mods.GetModMasses(_massCalcBase.MassType, labelType),
             RequiresAllCalcMods = mods.IsVariableStaticMods
         };
 }
Example #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();
            }
        }
Example #3
0
 public TypedMassCalc(IsotopeLabelType labelType, SequenceMassCalc massCalc)
 {
     LabelType = labelType;
     MassCalc = massCalc;
 }