public static double ComputeMonoisotopicMass(string pepSeqWithMods)
        {
            double mass = Constants.WATER_MONOISOTOPIC_MASS;

            bool   cumulMod = false;
            string strMod   = "";

            for (int i = 0; i < pepSeqWithMods.Length; i++)
            {
                if (pepSeqWithMods[i] == '(')
                {
                    strMod   = "";
                    cumulMod = true;
                }
                else if (pepSeqWithMods[i] == ')')
                {
                    cumulMod = false;
                    mass    += ModificationDictionary.Instance[strMod].MonoisotopicMassShift;
                }
                else if (cumulMod)
                {
                    strMod += pepSeqWithMods[i];
                }
                else
                {
                    mass += AminoAcidMasses.GetMonoisotopicMass(pepSeqWithMods[i]);
                }
            }
            return(mass);
        }
Esempio n. 2
0
        public double[] GetMasses()
        {
            double cumul = Proteomics.Utilities.Constants.WATER_MONOISOTOPIC_MASS;

            double[] array = new double[BaseSequence.Length];
            for (int r = 1; r <= BaseSequence.Length; r++)
            {
                double tmp = 0;
                if (FixedModifications != null && FixedModifications.ContainsKey(r + 1))
                {
                    foreach (Modification mod in FixedModifications[r + 1])
                    {
                        tmp += mod.MonoisotopicMassShift;
                    }
                }
                if (VariableModifications != null && VariableModifications.ContainsKey(r + 1))
                {
                    tmp += VariableModifications[r + 1].MonoisotopicMassShift;
                }

                array[r - 1] = AminoAcidMasses.GetMonoisotopicMass(BaseSequence[r - 1]) + tmp;
                cumul       += array[r - 1];
            }
            return(array);
        }
Esempio n. 3
0
 public static double[] GetMasses(string sequence)
 {
     double[] proteinMasses = new double[sequence.Length];
     for (int i = 0; i < sequence.Length; i++)
     {
         proteinMasses[i] = AminoAcidMasses.GetMonoisotopicMass(sequence[i]);
     }
     return(proteinMasses);
 }
        private void InitializeProductArrays()
        {
            double mass_shift;

            cumulativeNTerminalMass = new double[Length];

            mass_shift = 0.0;
            // fixed modifications on protein N-terminus
            if (fixedModifications != null)
            {
                List <Modification> prot_n_term_fixed_mods;
                if (fixedModifications.TryGetValue(0, out prot_n_term_fixed_mods))
                {
                    foreach (Modification fixed_modification in prot_n_term_fixed_mods)
                    {
                        mass_shift += fixed_modification.MonoisotopicMassShift;
                    }
                }
            }
            // variable modification on the protein N-terminus
            if (variableModifications != null)
            {
                Modification protein_n_term_variable_mod;
                if (variableModifications.TryGetValue(0, out protein_n_term_variable_mod))
                {
                    mass_shift += protein_n_term_variable_mod.MonoisotopicMassShift;
                }
            }
            // fixed modifications on peptide N-terminus
            if (fixedModifications != null)
            {
                List <Modification> pep_n_term_fixed_mods;
                if (fixedModifications.TryGetValue(1, out pep_n_term_fixed_mods))
                {
                    foreach (Modification fixed_modification in pep_n_term_fixed_mods)
                    {
                        mass_shift += fixed_modification.MonoisotopicMassShift;
                    }
                }
            }
            // variable modification on peptide N-terminus
            if (variableModifications != null)
            {
                Modification pep_n_term_variable_mod;
                if (variableModifications.TryGetValue(1, out pep_n_term_variable_mod))
                {
                    mass_shift += pep_n_term_variable_mod.MonoisotopicMassShift;
                }
            }
            cumulativeNTerminalMass[0] = mass_shift;

            for (int r = 1; r < Length; r++)
            {
                mass_shift = 0.0;
                // fixed modifications on this residue
                if (fixedModifications != null)
                {
                    List <Modification> residue_fixed_mods;
                    if (fixedModifications.TryGetValue(r + 1, out residue_fixed_mods))
                    {
                        foreach (Modification fixed_modification in residue_fixed_mods)
                        {
                            mass_shift += fixed_modification.MonoisotopicMassShift;
                        }
                    }
                }
                // variable modification on this residue
                if (variableModifications != null)
                {
                    Modification residue_variable_mod;
                    if (variableModifications.TryGetValue(r + 1, out residue_variable_mod))
                    {
                        mass_shift += residue_variable_mod.MonoisotopicMassShift;
                    }
                }
                cumulativeNTerminalMass[r] = cumulativeNTerminalMass[r - 1] + (productMassType == MassType.Average ? AminoAcidMasses.GetAverageMass(this[r - 1]) : AminoAcidMasses.GetMonoisotopicMass(this[r - 1])) + mass_shift;
            }

            cumulativeCTerminalMass = new double[Length];

            mass_shift = 0.0;
            // fixed modifications on protein C-terminus
            if (fixedModifications != null)
            {
                List <Modification> prot_c_term_fixed_mods;
                if (fixedModifications.TryGetValue(Length + 3, out prot_c_term_fixed_mods))
                {
                    foreach (Modification fixed_modification in prot_c_term_fixed_mods)
                    {
                        mass_shift += fixed_modification.MonoisotopicMassShift;
                    }
                }
            }
            // variable modification on protein C-terminus
            if (variableModifications != null)
            {
                Modification prot_c_term_variable_mod;
                if (variableModifications.TryGetValue(Length + 3, out prot_c_term_variable_mod))
                {
                    mass_shift += prot_c_term_variable_mod.MonoisotopicMassShift;
                }
            }
            // fixed modifications on peptide C-terminus
            if (fixedModifications != null)
            {
                List <Modification> pep_c_term_fixed_mods;
                if (fixedModifications.TryGetValue(Length + 2, out pep_c_term_fixed_mods))
                {
                    foreach (Modification fixed_modification in pep_c_term_fixed_mods)
                    {
                        mass_shift += fixed_modification.MonoisotopicMassShift;
                    }
                }
            }
            // variable modification on peptide C-terminus
            if (variableModifications != null)
            {
                Modification pep_c_term_variable_mod;
                if (variableModifications.TryGetValue(Length + 2, out pep_c_term_variable_mod))
                {
                    mass_shift += pep_c_term_variable_mod.MonoisotopicMassShift;
                }
            }
            cumulativeCTerminalMass[0] = mass_shift;

            for (int r = 1; r < Length; r++)
            {
                mass_shift = 0.0;
                // fixed modifications on this residue
                if (fixedModifications != null)
                {
                    List <Modification> residue_fixed_mods;
                    if (fixedModifications.TryGetValue(Length - r + 2, out residue_fixed_mods))
                    {
                        foreach (Modification fixed_modification in residue_fixed_mods)
                        {
                            mass_shift += fixed_modification.MonoisotopicMassShift;
                        }
                    }
                }
                // variable modification on this residue
                if (variableModifications != null)
                {
                    Modification residue_variable_mod;
                    if (variableModifications.TryGetValue(Length - r + 2, out residue_variable_mod))
                    {
                        mass_shift += residue_variable_mod.MonoisotopicMassShift;
                    }
                }

                cumulativeCTerminalMass[r] = cumulativeCTerminalMass[r - 1] + (productMassType == MassType.Average ? AminoAcidMasses.GetAverageMass(this[Length - r]) : AminoAcidMasses.GetMonoisotopicMass(this[Length - r])) + mass_shift;
            }

            initializeProductArrays = false;
        }
Esempio n. 5
0
        public IEnumerable <ProductMatch> ComputeFragments(Peptide peptide, int precursorKnownCharge, DBOptions dbOptions)
        {
            int maxCharge;

            if (precursorKnownCharge > 1)
            {
                maxCharge = precursorKnownCharge - 1;
            }
            else
            {
                maxCharge = precursorKnownCharge;
            }

            string       sequence = peptide.BaseSequence;
            ProductMatch match    = new ProductMatch();

            double cumulativeNTerminalMass = 0; // 1.007276 + 15.9949;//TODO Add NTerminal modifications here
            double cumulativeCTerminalMass = 0; // 1.007276;//TODO Add CTerminal modifications here
            string cumulSeq    = "";
            string cumulRevSeq = "";

            for (int r = 1; r <= sequence.Length; r++)
            {
                match.fragmentPos = r;
                //Peptide mods, computed during digestion
                //TODO Only search for modifications that were seen in the spectrum
                double tmp = 0;
                cumulSeq += sequence[r - 1];
                if (peptide.FixedModifications != null && peptide.FixedModifications.ContainsKey(r + 1))
                {
                    foreach (Modification mod in peptide.FixedModifications[r + 1])
                    {
                        tmp += mod.MonoisotopicMassShift;
                    }
                }
                if (peptide.VariableModifications != null && peptide.VariableModifications.ContainsKey(r + 1))
                {
                    tmp += peptide.VariableModifications[r + 1].MonoisotopicMassShift;
                }
                cumulativeNTerminalMass += AminoAcidMasses.GetMonoisotopicMass(sequence[r - 1]) + tmp;

                tmp          = 0;
                cumulRevSeq += sequence[sequence.Length - r];
                if (peptide.FixedModifications != null && peptide.FixedModifications.ContainsKey(sequence.Length + 2 - r))
                {
                    foreach (Modification mod in peptide.FixedModifications[sequence.Length + 2 - r])
                    {
                        tmp += mod.MonoisotopicMassShift;
                    }
                }
                if (peptide.VariableModifications != null && peptide.VariableModifications.ContainsKey(sequence.Length + 2 - r))
                {
                    tmp += peptide.VariableModifications[sequence.Length + 2 - r].MonoisotopicMassShift;
                }
                cumulativeCTerminalMass += AminoAcidMasses.GetMonoisotopicMass(sequence[sequence.Length - r]) + tmp;

                for (int c = maxCharge; c > 0; c--)
                {
                    match.charge = c;
                    foreach (FragmentClass fragment in this)
                    {
                        if (fragment.IsReverse)
                        {
                            match.fragmentPos = 1 + sequence.Length - r;
                        }
                        else
                        {
                            match.fragmentPos = r;
                        }
                        match.Fragment = fragment;

                        foreach (double product_mass in fragment.ComputeFragment(cumulativeCTerminalMass, cumulativeNTerminalMass))
                        {
                            match.weight = fragment.Distribution;//TODO Adjust this value by computing overall impact (times 10?)
                            //ModLess
                            match.theoMz = Numerics.MZFromMass(product_mass, c);
                            yield return(match);

                            //Added mods
                            if (dbOptions.addFragmentMods)
                            {
                                foreach (Modification mod in FragmentDictionary.Fragments.Values)
                                {
                                    if ((fragment.IsReverse ? cumulRevSeq : cumulSeq).Contains(mod.AminoAcid))
                                    {
                                        //!!!!match.Fragment = mod;
                                        match.weight = fragment.Distribution * mod.Probability;
                                        match.theoMz = Numerics.MZFromMass(product_mass + mod.MonoisotopicMassShift, c);
                                        yield return(match);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (dbOptions.addFragmentLoss)
            {
                match.charge   = 1;
                match.Fragment = FragLossObject;
                foreach (Modification mod in FragmentDictionary.AAFragments.Values)
                {
                    if (peptide.BaseSequence.Contains(mod.AminoAcid))
                    {
                        match.fragmentPos = peptide.BaseSequence.IndexOf(mod.AminoAcid);
                        match.theoMz      = mod.MonoisotopicMassShift;// Numerics.MZFromMass(mod.MonoisotopicMassShift, 1);
                        match.weight      = mod.Probability;
                        yield return(match);
                    }
                }
            }
        }