forked from TheAlgorithms/Python
- Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdna.py
30 lines (22 loc) · 555 Bytes
/
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
importre
defdna(dna: str) ->str:
"""
https://en.wikipedia.org/wiki/DNA
Returns the second side of a DNA strand
>>> dna("GCTA")
'CGAT'
>>> dna("ATGC")
'TACG'
>>> dna("CTGA")
'GACT'
>>> dna("GFGG")
Traceback (most recent call last):
...
ValueError: Invalid Strand
"""
iflen(re.findall("[ATCG]", dna)) !=len(dna):
raiseValueError("Invalid Strand")
returndna.translate(dna.maketrans("ATCG", "TAGC"))
if__name__=="__main__":
importdoctest
doctest.testmod()