-
Notifications
You must be signed in to change notification settings - Fork 0
/
DNATranslator.py
79 lines (52 loc) · 1.93 KB
/
DNATranslator.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
class sequnce_class():
def __init__(self,s="..."):
self.seq=s
def translate(self):
com=''
for i in self.seq.upper():
if i not in "ATGC":
print("invalid input!Enter:>>ATGC")
break
else:
for i in self.seq.upper():
if i == 'A':
com+='T'
if i == 'T':
com+='A'
if i == 'G':
com+='C'
if i == 'G':
com+='G'
print(f'>>Complement: {com}')
rna=com.replace('T','U')
print(f'>>RNA: {rna}')
if rna.startswith("AUG"):
print('>>ORF: {rna}')
else:
print('>>ORF not found!')
def read_seq(input_seq):
dna_seq = sequnce_class(input_seq)
dna_seq.translate()
input_file="rat.fasta"
with open (input_file,'r')as obj:
header=None
seq=''
sequence_list=[]
for line in obj:
line=line.strip()
if line.startswith('>'):
if header is not None:
sequence_list.append((header,seq))
header=line
seq=''
else:
seq+=line
if header is not None:
sequence_list.append((header,seq))
for i ,(header,seq) in enumerate(sequence_list):
print(f'Sequence: {i+1}\n>>Header: {header}')
print(f'>>DNA: {seq}')
read_seq(seq)
print('\n')
o1=sequnce_class("ATGCATGC")
o1.translate()