forked from china-testing/python-api-tesing
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdna.py
More file actions
executable file
·36 lines (30 loc) · 792 Bytes
/
dna.py
File metadata and controls
executable file
·36 lines (30 loc) · 792 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
# dna.py
from random import choice
def complementary_base(base):
"""Return complement of single base."""
if base == "A":
return "T"
elif base == "T":
return "A"
elif base == "C":
return "G"
elif base == "G":
return "C"
return base # leave anything else
def complement(dna):
"""Return complement of dna strand."""
result = ""
for base in dna:
result += complementary_base(base)
return result
def random_dna(length=30):
"""Return random strand of dna of given length."""
fragment = ""
for _ in range(length):
fragment += choice("ACGT")
return fragment
def main():
dna = random_dna()
print("Sequence :", dna)
print("Complement:", complement(dna))
main()