Advertisement
Razali

DNA Sequence

Nov 13th, 2014
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.27 KB | None | 0 0
  1. /*
  2. * <summary> Matches all of "seq1" concurrently with "seq2" </summary>
  3. * <params> "seq1", "seq2" = Two strings containing the DNA sequence </params>
  4. * <return>
  5. *   "1" : If the entire "seq1" matches with "seq2" concurrently
  6. *   "0" : Otherwise
  7. * </return>
  8. * <precond> Both "seq1" and "seq2" are strings hence should be null-terminated </precond>
  9. */
  10. int match (char seq1[], char seq2[])
  11. {
  12.      char correctSequence[20];
  13.      int i = 0, seq1_length = strlen(seq1);
  14.    
  15.      /* Generate the expected matching sequence of "seq1" and store into "correctSequence" */
  16.      while(i < seq1_length)
  17.      {
  18.           switch(seq1[i])
  19.           {
  20.                case 'A' :
  21.                     correctSequence[i] = 'T';
  22.                     break;
  23.                case 'T' :
  24.                     correctSequence[i] = 'A';
  25.                     break;
  26.                case 'C' :
  27.                     correctSequence[i] = 'G';
  28.                     break;
  29.                case 'G' :
  30.                     correctSequence[i] = 'C';
  31.                     break;
  32.            }//end of switch
  33.      }//end of while
  34.  
  35.      /* Terminate with Null */
  36.      correcttSequence[i] = '\0';
  37.    
  38.      /* Use the substring function to determine a match */
  39.      return strstr(seq2, correctSequence) != NULL ? 1 : 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement