mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-18 16:27:02 +00:00
add the dna algorithm (#6323)
* adding the dna algorithm * following bot recommendations following bot recommendations for the indentation * following bot recommendations following bot recommendations regarding indentation [ again ] * following bot recommendations following bot recommendations regarding indentation [ again. ] * following bot recommendations following bot recommendations.
This commit is contained in:
parent
b1818af517
commit
cbf3c6140a
26
strings/dna.py
Normal file
26
strings/dna.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
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")
|
||||||
|
'Invalid Strand'
|
||||||
|
"""
|
||||||
|
|
||||||
|
r = len(re.findall("[ATCG]", dna)) != len(dna)
|
||||||
|
val = dna.translate(dna.maketrans("ATCG", "TAGC"))
|
||||||
|
return "Invalid Strand" if r else val
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
__import__("doctest").testmod()
|
Loading…
Reference in New Issue
Block a user