Skip to content

Commit

Permalink
add hash for atom wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
noskill committed Apr 21, 2020
1 parent 8fa480b commit 3a19ac9
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions atomwrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@


class CAtom:
pass
def __hash__(self):
return hash(str(self))


class CNode(CAtom):
atom_type = None
def __init__(self, name):
self.name = name
if name == 'HLA-B *57:01:01':
import pdb;pdb.set_trace()

def __str__(self):
return '({0} "{1}")'.format(self.atom_type, self.name.replace('"', '\\"'))
Expand All @@ -22,6 +22,7 @@ def recursive_print(self, result='', indent=''):
return result + indent + str(self)



class CLink(CAtom):
def __init__(self, *atoms):
self.outgoing = atoms
Expand Down Expand Up @@ -60,4 +61,14 @@ class CListLink(CLink):
class CGeneNode(CNode):
atom_type = 'GeneNode'

class CContextLink(CLink):
atom_type = 'ContextLink'


class CSetLink(CLink):
atom_type = 'SetLink'

def __str__(self):
# str is used for hash computation, so need to sort outgoing set for all unordered links
outgoing = '\n'.join(sorted([str(x) for x in self.outgoing]))
return '({0} {1})'.format(self.atom_type, outgoing)

0 comments on commit 3a19ac9

Please sign in to comment.