I have to make a function that prints the longest palindrome substring of a piece of DNA. I already wrote a function that checks whether a piece of DNA is a palindrome itself. See the function below.
def make_complement_strand(DNA):
complement=[]
rules_for_complement={"A":"T","T":"A","C":"G","G":"C"}
for letter in DNA:
complement.append(rules_for_complement[letter])
return(complement)
def is_this_a_palindrome(DNA):
DNA=list(DNA)
if DNA!=(make_complement_strand(DNA)[::-1]):
print("false")
return False
else:
print("true")
return True
is_this_a_palindrome("GGGCCC")
But now: how to make a function printing the longest palindrome substring of a DNA string?
The meaning of palindrome in the context of genetics is slightly different from the definition used for words and sentences. Since a double helix is formed by two paired strands of nucleotides that run in opposite directions in the 5’- to-3’ sense, and the nucleotides always pair in the same way (Adenine (A) with Thymine (T) for DNA, with Uracil (U) for RNA; Cytosine (C) with Guanine (G)), a (single-stranded) nucleotide sequence is said to be a palindrome if it is equal to its reverse complement. For example, the DNA sequence ACCTAGGT is palindromic because its nucleotide-by-nucleotide complement is TGGATCCA, and reversing the order of the nucleotides in the complement gives the original sequence.