Ejemplo n.º 1
0
        /**
         * Method to generate decoy sequence according to a given input sequence and other options like
         * decoy type and whether to exclude N-terminus.
         **/

        private static string GenerateDecoySequence(string sequence, DecoyDatabaseMethod decoyType, bool excludeNTerminus, bool onlyIfNTerminusIsMethionine)
        {
            char[] temp          = new char[sequence.Length];
            bool   keepNTerminus = excludeNTerminus && (!onlyIfNTerminusIsMethionine || sequence[0] == 'M');

            switch (decoyType)
            {
            case DecoyDatabaseMethod.Reverse:

                temp = sequence.ToCharArray();
                if (keepNTerminus)
                {
                    Array.Reverse(temp, 1, temp.Length - 1);
                }
                else
                {
                    Array.Reverse(temp);
                }

                break;

            case DecoyDatabaseMethod.Shuffle:

                temp = sequence.ToCharArray();
                if (keepNTerminus)
                {
                    Shuffle(temp, 1, temp.Length - 1);
                }
                else
                {
                    Shuffle(temp);
                }

                break;

            case DecoyDatabaseMethod.Random:

                int index = 0;
                if (keepNTerminus)
                {
                    temp[index++] = sequence[0];
                }

                // Generate Random Characters
                while (index < sequence.Length)
                {
                    temp[index++] = AminoAcids[Random.Next(AminoAcids.Count)];
                }

                break;

            case DecoyDatabaseMethod.None:
                break;
            }

            // Create decoy sequence string from temporary char array.
            return(new string(temp));
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Generate a decoy version of the given fasta
 /// </summary>
 /// <param name="preText">The pretext to add to the description to indicated this is a decoy fasta</param>
 /// <param name="method">The decoy generation type</param>
 /// <param name="excludeNTerminus">Exclude the n-terminal amino acid</param>
 /// <param name="onlyIfNTerminusIsMethionine">Exclude the n-terminal amino aicd only if it is a Methionine</param>
 /// <returns>The generated decoy fasta</returns>
 public Fasta ToDecoy(string preText = "DECOY_", DecoyDatabaseMethod method = DecoyDatabaseMethod.Reverse, bool excludeNTerminus = true, bool onlyIfNTerminusIsMethionine = true)
 {
     return(new Fasta(GenerateDecoySequence(Sequence, method, excludeNTerminus, onlyIfNTerminusIsMethionine), preText + Description));
 }