-
-
Notifications
You must be signed in to change notification settings - Fork 50.1k
Expand file tree
/
Copy pathdna.py
More file actions
30 lines (22 loc) · 555 Bytes
/
dna.py
File metadata and controls
30 lines (22 loc) · 555 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
import re
def dna(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
"""
if len(re.findall("[ATCG]", dna)) != len(dna):
raise ValueError("Invalid Strand")
return dna.translate(dna.maketrans("ATCG", "TAGC"))
if __name__ == "__main__":
import doctest
doctest.testmod()