-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtext_to_dna.py
62 lines (51 loc) · 1.49 KB
/
text_to_dna.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
"""
textToDNA.py
Dustin Michels
3 March 2017
"""
def text_string_to_dna_string(message_string):
dna_string = ""
for ch in message_string:
"""
# check that number is ascii
try:
message_string.encode('ascii')
except UnicodeEncodeError:
raise ValueError("Perhaps you are entering non-ascii characters? Right now, this tool only deals"
" with ascii (American standard) characters.")
"""
num = ord(ch)
print(num)
print(bin(num))
for i in range(0, 4):
res = (num >> i * 2) & 0b11
print(res)
if res == 0:
dna_string += "A"
elif res == 1:
dna_string += "C"
elif res == 2:
dna_string += "G"
elif res == 3:
dna_string += "T"
else:
raise ValueError(
"Seems like an issue with manipulating the binary representation of your characters."
)
return dna_string
"""
def transcribeDNAtoRNA(seqDNA):
seqRNA = seqDNA[:]
for i in range(0,len(seqDNA)):
if seqDNA[i] == 'T':
seqRNA[i] = 'U'
return seqRNA
"""
def get_dna(message_string):
"""
Main method that will get called by api
:param message_string:
:return: dnaString (message encoded in genetic code.)
"""
dna_string = text_string_to_dna_string(message_string)
return dna_string