示例#1
0
        public static IEnumerable <Peptide> GenerateIsoforms(Peptide peptide, Modification modification, long ptms)
        {
            // Get all the possible modified-residues' indices (zero-based)
            List <int> sites = modification.GetModifiableSites(peptide).ToList();

            // Total number of PTM sites
            int ptmsites = sites.Count;

            // Exact number of possible isoforms
            long isoforms = Combinatorics.BinomCoefficient(ptmsites, ptms);

            // For each possible isoform
            for (long isoform = 0; isoform < isoforms; isoform++)
            {
                // Create a new peptide based on the one passed in
                Peptide pep = new Peptide(peptide);

                long x = isoforms - isoform - 1;
                long a = ptmsites;
                long b = ptms;

                // For each ptm
                for (int i = 0; i < ptms; i++)
                {
                    long ans   = Combinatorics.LargestV(a, b, x);
                    int  index = sites[(int)(ptmsites - ans - 1)];
                    if (index == 0)
                    {
                        pep.AddModification(modification, Terminus.N);
                    }
                    else if (index > pep.Length)
                    {
                        pep.AddModification(modification, Terminus.C);
                    }
                    else
                    {
                        pep.AddModification(modification, index);
                    }
                    x -= Combinatorics.BinomCoefficient(ans, b);
                    a  = ans;
                    b--;
                }

                yield return(pep);
            }
        }
示例#2
0
        public IEnumerable <Peptide> GenerateIsotopologues()
        {
            // Get all the modifications that are isotopologues
            var isotopologues = GetUniqueModifications <IIsotopologue>().ToArray();

            // Base condition, no more isotopologues to make, so just return
            if (isotopologues.Length < 1)
            {
                yield break;
            }

            // Grab the the first isotopologue
            IIsotopologue isotopologue = isotopologues[0];

            // Loop over each modification in the isotopologue
            foreach (Modification mod in isotopologue)
            {
                // Create a clone of the peptide, cloning modifications as well.
                Peptide peptide = new Peptide(this);

                // Replace the base isotopologue mod with the specific version
                peptide.ReplaceModification(isotopologue, mod);

                // There were more than one isotopologue, so we must go deeper
                if (isotopologues.Length > 1)
                {
                    // Call the same rotuine on the newly generate peptide that has one less isotopologue
                    foreach (var subpeptide in peptide.GenerateIsotopologues())
                    {
                        yield return(subpeptide);
                    }
                }
                else
                {
                    // Return this peptide
                    yield return(peptide);
                }
            }
        }
示例#3
0
文件: PSM.cs 项目: trishorts/Compass
 public void SetSequenceAndMods(string sequence, IList <Modification> fixedMods, string variableMods)
 {
     Peptide = new CSMSL.Proteomics.Peptide(sequence);
     Peptide.SetModifications(fixedMods);
     Modificationstring = variableMods;
     foreach (Tuple <Modification, int> modTuple in OmssaModification.ParseModificationLine(variableMods))
     {
         Modification mod  = modTuple.Item1;
         int          site = modTuple.Item2;
         if (site == 1 && mod.Sites.HasFlag(ModificationSites.NPep))
         {
             Peptide.AddModification(mod, Terminus.N);
         }
         else if (site == Peptide.Length && mod.Sites.HasFlag(ModificationSites.PepC))
         {
             Peptide.AddModification(mod, Terminus.C);
         }
         else
         {
             Peptide.AddModification(mod, site);
         }
     }
 }
示例#4
0
        public static IEnumerable <Peptide> GenerateIsoforms(Peptide peptide, bool keepBaseModifications, params Modification[] modifications)
        {
            // Get the number of modifications to this peptide
            int numberOfModifications = modifications.Length;

            if (numberOfModifications < 1)
            {
                // No modifications, return the base peptide
                yield return(peptide);
            }
            else if (numberOfModifications == 1)
            {
                // Only one modification, use the faster algorithm
                foreach (Peptide pep in GenerateIsoforms(peptide, modifications[0], 1))
                {
                    yield return(pep);
                }
            }
            else
            {
                // More than one ptm case

                // Get all the unique modified sites for all the mods
                Dictionary <Modification, List <int> > allowedSites = new Dictionary <Modification, List <int> >();
                foreach (Modification mod in modifications)
                {
                    List <int> sites;
                    if (!allowedSites.TryGetValue(mod, out sites))
                    {
                        allowedSites.Add(mod, mod.GetModifiableSites(peptide).ToList());
                    }
                }

                // Only one type of mod, use the faster algorithm
                if (allowedSites.Count == 1)
                {
                    foreach (Peptide pep in GenerateIsoforms(peptide, modifications[0], numberOfModifications))
                    {
                        yield return(pep);
                    }
                    yield break;
                }

                HashSet <Modification[]> results = new HashSet <Modification[]>(new ModificationArrayComparer());

                // Call out to the recursive helper method, starting with mod 0 and site 0
                GenIsoHelper(results, new Modification[peptide.Length + 2], modifications, allowedSites, 0, 0);

                // Create correct peptide mappings
                foreach (Modification[] modArray in results)
                {
                    Peptide pep = new Peptide(peptide, keepBaseModifications);
                    for (int i = 0; i < modArray.Length; i++)
                    {
                        var mod = modArray[i];
                        if (mod == null)
                        {
                            continue;
                        }

                        if (i == 0)
                        {
                            pep.AddModification(mod, Terminus.N);
                        }
                        else if (i > peptide.Length)
                        {
                            pep.AddModification(mod, Terminus.C);
                        }
                        else
                        {
                            pep.AddModification(mod, i);
                        }
                    }
                    yield return(pep);
                }
            }
        }