Exemple #1
0
        public static Modification MakeModification(string unmodifiedSequence, ExplicitMod explicitMod)
        {
            var staticMod = explicitMod.Modification;
            int i         = explicitMod.IndexAA;
            var monoMass  = staticMod.MonoisotopicMass ??
                            SrmSettings.MonoisotopicMassCalc.GetAAModMass(unmodifiedSequence[i], i,
                                                                          unmodifiedSequence.Length);
            var avgMass = staticMod.AverageMass ??
                          SrmSettings.AverageMassCalc.GetAAModMass(unmodifiedSequence[i], i,
                                                                   unmodifiedSequence.Length);

            if (monoMass == 0 && avgMass == 0)
            {
                char aa = unmodifiedSequence[i];
                if ((staticMod.LabelAtoms & LabelAtoms.LabelsAA) != LabelAtoms.None && AminoAcid.IsAA(aa))
                {
                    string heavyFormula = SequenceMassCalc.GetHeavyFormula(aa, staticMod.LabelAtoms);
                    monoMass = SequenceMassCalc.FormulaMass(BioMassCalc.MONOISOTOPIC, heavyFormula,
                                                            SequenceMassCalc.MassPrecision);
                    avgMass = SequenceMassCalc.FormulaMass(BioMassCalc.AVERAGE, heavyFormula,
                                                           SequenceMassCalc.MassPrecision);
                }
            }
            return(new Modification(explicitMod, monoMass, avgMass));
        }
Exemple #2
0
 public void TestGetHeavyFormula()
 {
     Assert.AreEqual("C'O2", SequenceMassCalc.GetHeavyFormula("CO2", LabelAtoms.C13));
     Assert.AreEqual("C'O2", SequenceMassCalc.GetHeavyFormula("C'O2", LabelAtoms.C13));
     Assert.AreEqual("C'", SequenceMassCalc.GetHeavyFormula("C", LabelAtoms.C13));
     Assert.AreEqual("N'", SequenceMassCalc.GetHeavyFormula("N", LabelAtoms.N15));
     Assert.AreEqual("O'", SequenceMassCalc.GetHeavyFormula("O", LabelAtoms.O18));
     Assert.AreEqual("H'", SequenceMassCalc.GetHeavyFormula("H", LabelAtoms.H2));
     Assert.AreEqual("Cl'", SequenceMassCalc.GetHeavyFormula("Cl", LabelAtoms.Cl37));
     Assert.AreEqual("Br'", SequenceMassCalc.GetHeavyFormula("Br", LabelAtoms.Br81));
     Assert.AreEqual("P'", SequenceMassCalc.GetHeavyFormula("P", LabelAtoms.P32));
     Assert.AreEqual("S\"", SequenceMassCalc.GetHeavyFormula("S", LabelAtoms.S33));
     Assert.AreEqual("S'", SequenceMassCalc.GetHeavyFormula("S", LabelAtoms.S34));
 }
Exemple #3
0
        public void TestGetHeavyFormula()
        {
            Assert.AreEqual("C'O2", SequenceMassCalc.GetHeavyFormula("CO2", LabelAtoms.C13));
            Assert.AreEqual("C'O2", SequenceMassCalc.GetHeavyFormula("C'O2", LabelAtoms.C13));
            Assert.AreEqual("C'", SequenceMassCalc.GetHeavyFormula("C", LabelAtoms.C13));
            Assert.AreEqual("N'", SequenceMassCalc.GetHeavyFormula("N", LabelAtoms.N15));
            Assert.AreEqual("O'", SequenceMassCalc.GetHeavyFormula("O", LabelAtoms.O18));
            Assert.AreEqual("H'", SequenceMassCalc.GetHeavyFormula("H", LabelAtoms.H2));
            Assert.AreEqual("Cl'", SequenceMassCalc.GetHeavyFormula("Cl", LabelAtoms.Cl37));
            Assert.AreEqual("Br'", SequenceMassCalc.GetHeavyFormula("Br", LabelAtoms.Br81));
            Assert.AreEqual("P'", SequenceMassCalc.GetHeavyFormula("P", LabelAtoms.P32));
            Assert.AreEqual("S'", SequenceMassCalc.GetHeavyFormula("S", LabelAtoms.S34));

            // Make sure IUPAC nicknames don't find their way into our list of heavy symbols
            Assume.IsTrue(BioMassCalc.IsSkylineHeavySymbol("H'"));
            Assume.IsFalse(BioMassCalc.IsSkylineHeavySymbol("D"));
            Assume.IsFalse(BioMassCalc.IsSkylineHeavySymbol("T"));
        }
        private static Molecule GetSequenceFormula(ModifiedSequence modifiedSequence, MassType massType, out double unexplainedMassShift)
        {
            unexplainedMassShift = 0;
            var    molecule           = new Dictionary <string, int>();
            string unmodifiedSequence = modifiedSequence.GetUnmodifiedSequence();
            var    modifications      = modifiedSequence.GetModifications().ToLookup(mod => mod.IndexAA);

            for (int i = 0; i < unmodifiedSequence.Length; i++)
            {
                char aminoAcid = unmodifiedSequence[i];
                AddAminoAcidFormula(massType, aminoAcid, molecule, ref unexplainedMassShift);
                foreach (var mod in modifications[i])
                {
                    string formula = mod.Formula;
                    if (formula == null)
                    {
                        var staticMod = mod.StaticMod;
                        var aa        = unmodifiedSequence[i];
                        if ((staticMod.LabelAtoms & LabelAtoms.LabelsAA) != LabelAtoms.None && AminoAcid.IsAA(aa))
                        {
                            formula = SequenceMassCalc.GetHeavyFormula(aa, staticMod.LabelAtoms);
                        }
                    }
                    if (formula != null)
                    {
                        var modFormula = Molecule.ParseExpression(formula);
                        Add(molecule, modFormula);
                    }
                    else
                    {
                        unexplainedMassShift += massType.IsMonoisotopic() ? mod.MonoisotopicMass : mod.AverageMass;
                    }
                }
            }
            return(Molecule.FromDict(molecule));
        }
Exemple #5
0
        private void UpdateMasses()
        {
            string     formula    = null;
            LabelAtoms labelAtoms = LabelAtoms.None;

            if (cbChemicalFormula.Checked)
            {
                formula = Formula;
            }
            else
            {
                labelAtoms = LabelAtoms;
                string aaString = comboAA.Text;
                if (!string.IsNullOrEmpty(aaString) && aaString.Length == 1 &&
                    AminoAcid.IsAA(aaString[0]) && labelAtoms != LabelAtoms.None)
                {
                    formula = SequenceMassCalc.GetHeavyFormula(aaString[0], labelAtoms);
                }
            }

            if (string.IsNullOrEmpty(formula))
            {
                // If the mass edit boxes are already enabled, don't clear what a user
                // may have typed in them.
                if (!_formulaBox.MassEnabled)
                {
                    _formulaBox.MonoMass    = null;
                    _formulaBox.AverageMass = null;
                }
                _formulaBox.MassEnabled = (labelAtoms == LabelAtoms.None);
            }
            else
            {
                _formulaBox.Formula = formula;
            }
        }
Exemple #6
0
        public const string UnimodPrefix = "unimod:"; // Not L10N

        /// <summary>
        /// Constructs a ModifiedSequence from SrmSettings and PeptideDocNode.
        /// </summary>
        public static ModifiedSequence GetModifiedSequence(SrmSettings settings, PeptideDocNode docNode, IsotopeLabelType labelType)
        {
            if (docNode.Peptide.IsCustomMolecule)
            {
                return(null);
            }
            var  unmodifiedSequence          = docNode.Peptide.Sequence;
            bool includeStaticMods           = true;
            bool includeStaticHeavyMods      = false;
            List <Modification> explicitMods = new List <Modification>();

            if (null != docNode.ExplicitMods)
            {
                var staticBaseMods    = docNode.ExplicitMods.GetStaticBaseMods(labelType);
                var labelMods         = docNode.ExplicitMods.GetModifications(labelType);
                var explicitLabelType = labelType;
                if (labelMods == null && !labelType.IsLight)
                {
                    labelMods              = docNode.ExplicitMods.GetModifications(IsotopeLabelType.light);
                    explicitLabelType      = IsotopeLabelType.light;
                    includeStaticHeavyMods = true;
                }
                if (labelMods != null || staticBaseMods != null)
                {
                    IEnumerable <ExplicitMod> modsToAdd = (labelMods ?? Enumerable.Empty <ExplicitMod>())
                                                          .Concat(staticBaseMods ?? Enumerable.Empty <ExplicitMod>());
                    var monoMasses = docNode.ExplicitMods.GetModMasses(MassType.Monoisotopic, explicitLabelType);
                    var avgMasses  = docNode.ExplicitMods.GetModMasses(MassType.Average, explicitLabelType);
                    foreach (var mod in modsToAdd)
                    {
                        explicitMods.Add(new Modification(mod, monoMasses[mod.IndexAA], avgMasses[mod.IndexAA]));
                    }
                    includeStaticMods = docNode.ExplicitMods.IsVariableStaticMods && staticBaseMods == null;
                }
            }

            if (includeStaticMods || includeStaticHeavyMods)
            {
                var peptideModifications = settings.PeptideSettings.Modifications;
                for (int i = 0; i < unmodifiedSequence.Length; i++)
                {
                    IEnumerable <StaticMod> staticMods = peptideModifications.GetModifications(labelType);
                    if (!labelType.IsLight && includeStaticMods)
                    {
                        staticMods = peptideModifications.GetModifications(IsotopeLabelType.light).Concat(staticMods);
                    }
                    foreach (var staticMod in staticMods)
                    {
                        if (staticMod.IsExplicit || staticMod.IsVariable)
                        {
                            continue;
                        }
                        if (staticMod.Terminus.HasValue)
                        {
                            if (staticMod.Terminus == ModTerminus.N && i != 0)
                            {
                                continue;
                            }
                            if (staticMod.Terminus == ModTerminus.C && i != unmodifiedSequence.Length - 1)
                            {
                                continue;
                            }
                        }
                        if (!string.IsNullOrEmpty(staticMod.AAs) && !staticMod.AAs.Contains(unmodifiedSequence[i]))
                        {
                            continue;
                        }
                        var monoMass = staticMod.MonoisotopicMass ??
                                       SrmSettings.MonoisotopicMassCalc.GetAAModMass(unmodifiedSequence[i], i,
                                                                                     unmodifiedSequence.Length);
                        var avgMass = staticMod.AverageMass ??
                                      SrmSettings.AverageMassCalc.GetAAModMass(unmodifiedSequence[i], i,
                                                                               unmodifiedSequence.Length);
                        if (monoMass == 0 && avgMass == 0)
                        {
                            char aa = unmodifiedSequence[i];
                            if ((staticMod.LabelAtoms & LabelAtoms.LabelsAA) != LabelAtoms.None && AminoAcid.IsAA(aa))
                            {
                                string heavyFormula = SequenceMassCalc.GetHeavyFormula(aa, staticMod.LabelAtoms);
                                monoMass = SequenceMassCalc.FormulaMass(BioMassCalc.MONOISOTOPIC, heavyFormula,
                                                                        SequenceMassCalc.MassPrecision);
                                avgMass = SequenceMassCalc.FormulaMass(BioMassCalc.AVERAGE, heavyFormula,
                                                                       SequenceMassCalc.MassPrecision);
                            }
                        }
                        explicitMods.Add(new Modification(new ExplicitMod(i, staticMod), monoMass, avgMass));
                    }
                }
            }
            return(new ModifiedSequence(unmodifiedSequence, explicitMods, settings.TransitionSettings.Prediction.PrecursorMassType));
        }