Skip to content

Commit

Permalink
⚡ raising error if an accession already exists when added to seqtree
Browse files Browse the repository at this point in the history
  • Loading branch information
rbturnbull committed Oct 15, 2023
1 parent 2b0a828 commit a2c152b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion corgi/seqtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ def __setstate__(self, state):
self.partition, self.node_id = state
self.node = None

class AlreadyExists(Exception):
pass


class SeqTree(UserDict):
def __init__(self, classification_tree=None):
Expand All @@ -26,7 +29,11 @@ def __init__(self, classification_tree=None):

def add(self, accession:str, node:SoftmaxNode, partition:int):
assert node.root == self.classification_tree
assert accession not in self, f"Accession {accession} already exists in SeqTree"
if accession in self:
old_node = self.node(accession)
if not node == old_node:
raise AlreadyExists(f"Accession {accession} already exists in SeqTree at node {self.node(accession)}. Cannot change to {node}")

detail = SeqDetail(
partition=partition,
node=node,
Expand Down

0 comments on commit a2c152b

Please sign in to comment.