A DNA sequence can be represented as a string consisting only of the letters (bases) A, G, C and T. The inverse complement of a DNA sequence is obtained by first replacing every occurrence of the base A with the complementary base T (and vice versa), and replacing every occurrence of the base G with the complementary base C (and vice versa), and finally reversing the sequence of characters.

Assignment

  1. Write a function complement which returns the complement for a given base that is passed as a parameter to the function. For example, the function is to return the letter G, if the letter C is passed to the function. Think of how you can best use a dictionary to implement this function.

  2. Use the function complement to write the function inverseComplement, which returns the inverse complement of a given DNA sequence which is to be passed to the function as a parameter. Use a list comprehension to return the inverse complement in a single return statement. Thus, the function must return the string AAGTTATTG for the given DNA sequence CAATAACTT.

Example

>>> complement('A')
'T'
>>> complement('C')
'G'
>>> complement('G')
'C'
>>> complement('T')
'A'
>>> inverseComplement('CAATAACTT')
'AAGTTATTG'
>>> inverseComplement('GAACCTTGT')
'ACAAGGTTC'
>>> inverseComplement('TAACCGAAGGAATC')
'GATTCCTTCGGTTA'
>>> inverseComplement('CTTAGCTGCCCGATTACATACACAC')
'GTGTGTATGTAATCGGGCAGCTAAG'
>>> inverseComplement('TTAATTGGG')
'CCCAATTAA'