2022-09-05 01:51:11 +00:00
|
|
|
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")
|
2022-11-06 14:54:44 +00:00
|
|
|
Traceback (most recent call last):
|
|
|
|
...
|
|
|
|
ValueError: Invalid Strand
|
2022-09-05 01:51:11 +00:00
|
|
|
"""
|
|
|
|
|
2022-11-06 14:54:44 +00:00
|
|
|
if len(re.findall("[ATCG]", dna)) != len(dna):
|
|
|
|
raise ValueError("Invalid Strand")
|
|
|
|
|
|
|
|
return dna.translate(dna.maketrans("ATCG", "TAGC"))
|
2022-09-05 01:51:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2022-11-06 14:54:44 +00:00
|
|
|
import doctest
|
|
|
|
|
|
|
|
doctest.testmod()
|