-
Notifications
You must be signed in to change notification settings - Fork 22
/
rosalind_revp.py
42 lines (36 loc) · 1.13 KB
/
rosalind_revp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# ^_^ coding:utf-8 ^_^
"""
Locating Restriction Sites
url: http://rosalind.info/problems/revp/
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.
"""
from Bio import SeqIO
def switch(s):
s = s[::-1]
# print s
switch_s = ''
for i in range(len(s)):
if s[i] == 'A':
switch_s += 'T'
elif s[i] == 'T':
switch_s += 'A'
elif s[i] == 'G':
switch_s += 'C'
elif s[i] == 'C':
switch_s += 'G'
return switch_s
def palindrome(s):
for i in range(len(s)):
for j in range(4,13,1):
if s[i:i+j] == switch(s[i:i+j]) and (i+j <= len(s)):
print(i+1, j)
if __name__ == "__main__":
# load data
seq_name, seq_string = [], []
with open ("../data/rosalind_revp.txt",'r') as fa:
for seq_record in SeqIO.parse(fa,'fasta'):
seq_name.append(str(seq_record.name))
seq_string.append(str(seq_record.seq))
s = seq_string[0]
palindrome(s)