@@ -1418,17 +1418,19 @@ def is_candidate_out_node(x:TVGNode, y:TVGNode):
14181418 # the input node itself.
14191419 return node , set ()
14201420
1421- visited :Set [ TVGNode ] = {node }
1421+ visited :Dict [ str , TVGNode ] = {node . id : node }
14221422 # When a new farthest node is found, the downstream nodes of the old
14231423 # farthest node are put into this `exceptions` container, so they
14241424 # can be visited again.
14251425 exceptions :Set [TVGNode ] = set ()
1426+ non_members :Set [str ] = set ()
14261427 while queue :
14271428 cur :TVGNode = queue .popleft ()
14281429 if cur is None :
14291430 continue
14301431
14311432 if cur .reading_frame_index != node .reading_frame_index :
1433+ non_members .add (cur .id )
14321434 continue
14331435
14341436 if subgraph_checker :
@@ -1437,7 +1439,7 @@ def is_candidate_out_node(x:TVGNode, y:TVGNode):
14371439 subgraph_checker = False
14381440
14391441 visited_len_before = len (visited )
1440- visited . add ( cur )
1442+ visited [ cur . id ] = cur
14411443 visited_len_after = len (visited )
14421444 if visited_len_before == visited_len_after :
14431445 if cur is farthest and cur is not node :
@@ -1497,7 +1499,8 @@ def is_candidate_out_node(x:TVGNode, y:TVGNode):
14971499 queue .append (farthest )
14981500 exceptions .add (cur )
14991501 continue
1500- return farthest , visited
1502+ members = {v for k ,v in visited .items () if k not in non_members }
1503+ return farthest , members
15011504
15021505 def first_node_is_smaller (self , first :TVGNode , second :TVGNode ) -> bool :
15031506 """ Check if the first node is larger """
@@ -1628,6 +1631,11 @@ def align_variants(self, node:TVGNode) -> Tuple[TVGNode, TVGNode]:
16281631 new_bridge = bridge_in .copy ()
16291632 for edge in bridge_in .out_edges :
16301633 self .add_edge (new_bridge , edge .out_node , edge .type )
1634+ # Here we want to limit the process within the variant bubble.
1635+ # In-bridge nodes should not be merged with their outgoing nodes
1636+ # that do not belong to the bubble.
1637+ if edge .out_node not in members :
1638+ end_nodes .add (edge .out_node )
16311639 bridge_map [new_bridge ] = bridge_in
16321640 trash .add (bridge_in )
16331641
@@ -1670,7 +1678,7 @@ def align_variants(self, node:TVGNode) -> Tuple[TVGNode, TVGNode]:
16701678 for out_edge in copy .copy (cur .out_edges ):
16711679 out_node :TVGNode = out_edge .out_node
16721680
1673- # So this is the case that some of the end_nodes are in end_nodes
1681+ # So this is the case that some of the out_nodes are in end_nodes
16741682 # but not the others.
16751683 if out_node in end_nodes :
16761684 new_node = cur .copy ()
0 commit comments