A DNA sequence can be represented by a string that consists solely of the letters A, C, G and T. The inverse complement of a DNA sequence is reached by reversing the order of the letters in the string and changing every A into a T (and the other way around) and changing every G into a C (and the other way around). The inverse complement of the DNA sequence AGCTGCT, for example, turns into AGCAGCT. A palindromic sequence is a DNA sequence that reads exactly the same on the complementary string. The inverse complement of the DNA sequence AATGCATT, for example, equals the original DNA sequence. This is a palindromic sequence.

Assignment

  1. Write a function DNAPalindrome to which a DNA sequence should be given as an argument. As a result, the function should print the value True if the DNA sequence is a palindromic sequence. Otherwise, the value False should be printed. For example, the function should print True for the DNA sequence GAATTC.

  2. Use the function DNAPalindrome to write the function longestPalindrome, to which a DNA sequence should be given as an argument. As a result, the function should give the longest palindromic partial sequence of the sequence given. To find the longest palindromic partial sequence, you can go through every partial sequence possible and test whether or not you are dealing with a palindromic sequence and eventually be left with the longest palindrome. In order to run through all partial sequences of a given DNA sequence, you can run through all starting positions possible and for every starting position, go through the possible ending positions. This way, you will find every partial sequence as the sequence between every combination of possible starting and ending positions.

Example

>>> DNAPalindrome('GAATTC')
True
>>> DNAPalindrome('AGACTCT')
False
>>> longestPalindrome('CCCCCCCCGAATTCTTTTATTTT')
'GAATTC'
>>> longestPalindrome('')
''