Created
January 24, 2018 07:59
-
-
Save audy/7e3cee62897b1eac13dbd4c6c34e3759 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DNA: | |
def __init__(self, sequence: str) -> None: | |
self.sequence = str(sequence).lower() | |
@property | |
def reverse(self) -> 'DNA': | |
return DNA(self.sequence[::-1]) | |
@property | |
def complement(self: 'DNA') -> 'DNA': | |
t = { a: b for a, b in zip('gatc', 'ctag') } | |
return DNA(''.join(t[i] for i in self.sequence)) | |
def __repr__(self) -> str: | |
return '<DNA sequence="{}">'.format(self.sequence) | |
def __contains__(self, other: 'DNA') -> bool: | |
return other.sequence in self.sequence | |
def __eq__(self, other: 'DNA') -> object: | |
return self.sequence == other.sequence | |
template = DNA('ATGC') | |
assert template == template | |
assert template.sequence == DNA('atgc') | |
assert template.reverse == DNA('cgta') | |
assert template.reverse.complement == DNA('gcat') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment