MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / dna

Function dna

strings/dna.py:4–24  ·  view source on GitHub ↗

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

(dna: str)

Source from the content-addressed store, hash-verified

2
3
4def dna(dna: str) -> str:
5 """
6 https://en.wikipedia.org/wiki/DNA
7 Returns the second side of a DNA strand
8
9 >>> dna("GCTA")
10 'CGAT'
11 >>> dna("ATGC")
12 'TACG'
13 >>> dna("CTGA")
14 'GACT'
15 >>> dna("GFGG")
16 Traceback (most recent call last):
17 ...
18 ValueError: Invalid Strand
19 """
20
21 if len(re.findall("[ATCG]", dna)) != len(dna):
22 raise ValueError("Invalid Strand")
23
24 return dna.translate(dna.maketrans("ATCG", "TAGC"))
25
26
27if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected