/// <summary>
        /// Compute the mass of the peptide sequence; uses the information in modifiedResidues() to determine modification masses
        /// </summary>
        /// <remarks>Looks for and removes prefix and suffix letters if .RemovePrefixAndSuffixIfPresent = True</remarks>
        /// <param name="sequence">One letter amino acid symbols (no modification symbols or numbers)</param>
        /// <param name="modifiedResidues">List of modified residues</param>
        /// <returns>The computed mass, or -1 if an error</returns>
        public double ComputeSequenceMass(string sequence, List <PeptideSequenceModInfo> modifiedResidues)
        {
            // Note that this call to ComputeSequenceMass will reset mErrorMessage
            var mass = ComputeSequenceMass(sequence);

            if (mass < 0 || modifiedResidues == null || modifiedResidues.Count == 0)
            {
                return(mass);
            }

            var empiricalFormula = new EmpiricalFormula();

            foreach (var modifiedResidue in modifiedResidues)
            {
                // Note: do not use string.IsNullOrWhiteSpace(modifiedResidue.AffectedAtom) since that does not work on a char

                if (modifiedResidue.AffectedAtom is default(char) or NO_AFFECTED_ATOM_SYMBOL)
                {
                    // Positional modification (static or dynamic mod)
                    // Simply add the modification mass to mass
                    mass += modifiedResidue.ModificationMass;
                    continue;
                }

                // Isotopic modification
                if (empiricalFormula.ElementCounts.Count == 0)
                {
                    // Initialize empiricalFormula using the amino acid sequence
                    var empiricalFormulaToAdd = ConvertAminoAcidSequenceToEmpiricalFormula(sequence);
                    empiricalFormula.AddElements(empiricalFormulaToAdd);
                }

                if (!mElementMonoMasses.ContainsKey(modifiedResidue.AffectedAtom.ToString()))
                {
                    ErrorMessage = "Unknown Affected Atom '" + modifiedResidue.AffectedAtom + "'";
                    mass         = -1;
                    break;
                }

                var elementCount = empiricalFormula.GetElementCount(modifiedResidue.AffectedAtom);
                if (elementCount == 0)
                {
                    Console.WriteLine("Warning: no amino acids in {0} contain element {1}", sequence, modifiedResidue.AffectedAtom);
                }
                else
                {
                    mass += elementCount * modifiedResidue.ModificationMass;
                }
            }

            return(mass);
        }
Beispiel #2
0
        public void TestGetAminoAcidMass(char aminoAcidSymbol, double expectedMass)
        {
            var computedMass = mPeptideMassCalculator.GetAminoAcidMass(aminoAcidSymbol);

            var empiricalFormula = new EmpiricalFormula();

            empiricalFormula.AddElements(mPeptideMassCalculator.GetAminoAcidEmpiricalFormula(aminoAcidSymbol));

            var computedMassAlt = PeptideMassCalculator.ComputeMonoisotopicMass(empiricalFormula);

            Assert.AreEqual(expectedMass, computedMass, 0.0001, "Amino acid does not match the expected value");

            Assert.AreEqual(computedMass, computedMassAlt, 1E-05, "GetAminoAcidMass and ComputeMonoisotopicMass do not agree on the mass for the amino acid");
        }