Skip to content

Dna enhancement #6713

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions strings/dna.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import re


def dna(dna: str) -> str:
def dna_matching_strand(dna: str) -> str:

"""
https://en.wikipedia.org/wiki/DNA
Returns the second side of a DNA strand

>>> dna("GCTA")
>>> dna_matching_strand("GCTA")
'CGAT'
>>> dna("ATGC")
>>> dna_matching_strand("ATGC")
'TACG'
>>> dna("CTGA")
>>> dna_matching_strand("CTGA")
'GACT'
>>> dna("GFGG")
'Invalid Strand'
>>> dna_matching_strand("GFGG")
Traceback (most recent call last):
Exception: Invalid Strand
"""

r = len(re.findall("[ATCG]", dna)) != len(dna)
val = dna.translate(dna.maketrans("ATCG", "TAGC"))
return "Invalid Strand" if r else val
is_invalid_strand = len(re.findall("[ATCG]", dna)) != len(dna)
strand = dna.translate(dna.maketrans("ATCG", "TAGC"))
if is_invalid_strand:
raise Exception("Invalid Strand")
else:
return strand


if __name__ == "__main__":
Expand Down