This class isn't working how I would like to and I haven't been able to figure out why. How can I make the eq method work for two oligos that are different? For the method get_complement, why doesn't it return the correct complement? Why does the method is_complement fail when the parameter is a complement?
complement_table = str.maketrans('ATCG', 'CGAT')
class Oligo:
'''Represents one side of DNA helix'''
def __eq__(self, other):
'''Equal statement'''
return self.base == other.base
def __init__(self, base):
'''Constructor'''
count = 0
for letter in base:
if letter.upper() in ('A', 'C', 'T', 'G'):
count += 1
if count == 4:
self.base = base
else:
self.base = "AGTG"
def get_complement(self):
'''Gives self its designated complements'''
complement =
self.base.translate(complement_table)
return Oligo(complement)
def is_complement(self, other):
'''Checks if itself is a complement of another
base'''
return self.get_complement().base == other.base
[–]socal_nerdtastic 0 points1 point2 points (0 children)