-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmotif_in_dna.py
More file actions
44 lines (37 loc) · 1020 Bytes
/
motif_in_dna.py
File metadata and controls
44 lines (37 loc) · 1020 Bytes
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
# -*- coding: utf-8 -*-
"""
Created on Sat Jun 23 11:07:09 2018
@author: taoyan
"""
def read_file():
try:
data=open("rosalind_subs.txt", "r")
seq=data.readline().strip()
target=data.readline().strip()
except FileExistsError or FileNotFoundError:
print("Could not open file!")
finally:
data.close()
return seq,target
def motif_find_position(seq,target):
n=[]
for i in range(0,len(seq)):
if seq[i:len(target)+i]==target:
n.append(i)
return n
def save_file(result):
try:
output=open("motif_in_seq.txt","w")
for i in result:
i=str(i)
output.write(i+" ")
except FileExistsError or FileNotFoundError:
print("Could not save the result file!")
finally:
output.close()
def main():
seq,target=read_file()
result=motif_find_position(seq,target)
save_file(result)
if __name__=="__main__":
main()