This is the Rosalind problem that I am working on:
A DNA string is a reverse palindrome if it is equal to its reverse complement. For instance, GCATGC is a reverse palindrome because its reverse complement is GCATGC. See Figure 2.
Given: A DNA string of length at most 1 kbp in FASTA format.
Return: The position and length of every reverse palindrome in the string having length between 4 and 12. You may return these pairs in any order.
This is the code that I have so far:
DNAstrand = "TCAATGCATGCGGGTCTATATGCAT"
def reverseComplement(DNAstrand): x = {"A":"T", "T":"A", "C":"G", "G":"C"} return''.join([x[nuc] for nuc in DNAstrand])[::-1]
substrings = [DNAstrand[x:y] for x in range (len(DNAstrand)) for y in range((x + 1), ((len(DNAstrand)) + 1))]
def string_Length(substrings): """Given a string, return all substrings between 4 and 12 characters in length""" return[string for string in substrings if 4 <= len(string) <= 12]
list = (string_Length(substrings))
for substring in list: if substring == reverseComplement(substring): print(DNAstrand.find(substring))
The output that I should be getting is 4 6 5 4 6 6 7 4 17 4 18 4 20 6 21 4
This is the output I am getting 4 5 6 7 17 18 4 5
Does anyone have suggestions for finding the length of the substrings and printing the position of the substrings at positions 20 and 21?