-
Notifications
You must be signed in to change notification settings - Fork 0
/
REVP.py
46 lines (36 loc) · 1.12 KB
/
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
43
44
45
46
def read_FASTA(file_path):
sequences_dict = {}
with open(file_path, "r") as f:
lines = f.readlines()
current_label = ""
for index, item in enumerate(lines):
if item[0] == ">":
current_label = item[1:].rstrip()
sequences_dict[current_label] = ""
else:
sequences_dict[current_label] += item.rstrip()
return sequences_dict
def DNA_complement(sequence):
complement = ""
for i in sequence:
if i == "A":
complement += "T"
elif i == "T":
complement += "A"
elif i == "C":
complement += "G"
elif i == "G":
complement += "C"
return complement[::-1]
def main():
data = read_FASTA("data/rosalind_revp.txt")
keys = list(data)
dna_string = data[keys[0]]
for start in range(0, len(dna_string)):
for end in range(start, len(dna_string)):
s = dna_string[start:end+1]
l = len(s)
if l >= 4 and l <= 12 and s == DNA_complement(s):
print(str(start+1)+" "+str(end-start+1))
if __name__ == '__main__':
main()