Skip to content

Commit 6bd0bfe

Browse files
committed
Contig stitcher: simplify some visualizer code
1 parent 0238f04 commit 6bd0bfe

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

micall/core/plot_contigs.py

+13-17
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,6 @@ def build_stitcher_figure(logs: Iterable[events.EventType]) -> Figure:
424424
temporary: Set[str] = set()
425425
children_join_points: List[str] = []
426426
children_meet_points: List[str] = []
427-
last_active: List[str] = []
428427
query_position_map: Dict[str, int] = {}
429428

430429
def get_oldest_ancestors(recur, graph, ancestor_name):
@@ -442,30 +441,27 @@ def get_oldest_ancestors(recur, graph, ancestor_name):
442441
yield ancestor_name
443442
return
444443

445-
def reduced_closure(graph):
444+
def remove_intermediate_edges(graph):
446445
ret = {}
447446
for parent, children in graph.items():
448447
lst = []
449448
for child in children:
450-
for anc in get_oldest_ancestors(set(), graph, child):
451-
if anc not in lst:
452-
lst.append(anc)
449+
if all(other not in graph.get(child, []) for other in children):
450+
lst.append(child)
453451
ret[parent] = lst
454452
return ret
455453

456454
def get_all_ancestors(recur, lst, graph, ancestor_name):
457-
if ancestor_name in recur:
458-
assert RuntimeError(f"Recursion in graph {graph!r}")
459-
else:
455+
if ancestor_name not in recur:
460456
recur = recur.copy()
461457
recur.add(ancestor_name)
462458

463-
if ancestor_name not in lst:
464-
lst.append(ancestor_name)
459+
if ancestor_name not in lst:
460+
lst.append(ancestor_name)
465461

466-
existing_ancestors = graph.get(ancestor_name, [])
467-
for existing in existing_ancestors:
468-
get_all_ancestors(recur, lst, graph, existing)
462+
existing_ancestors = graph.get(ancestor_name, [])
463+
for existing in existing_ancestors:
464+
get_all_ancestors(recur, lst, graph, existing)
469465

470466
def transitive_closure(graph):
471467
ret = {}
@@ -593,10 +589,9 @@ def record_bad_contig(contig: GenotypedContig, lst: List[str]):
593589

594590
group_refs = {contig.group_ref: len(contig.ref_seq) for contig in contig_map.values() if contig.ref_seq}
595591
children_graph = inverse_graph(parent_graph)
596-
reduced_parent_graph = reduced_closure(parent_graph)
597-
reduced_children_graph = reduced_closure(children_graph)
598592
transitive_parent_graph = transitive_closure(parent_graph)
599593
transitive_children_graph = transitive_closure(children_graph)
594+
reduced_parent_graph = remove_intermediate_edges(transitive_parent_graph)
600595
eqv_parent_graph = reflexive_closure(symmetric_closure(transitive_parent_graph))
601596
sorted_roots = list(sorted(parent_name for
602597
parent_name in contig_map
@@ -606,8 +601,9 @@ def record_bad_contig(contig: GenotypedContig, lst: List[str]):
606601
if child_name not in children_graph))
607602
bad_contigs = anomaly + discarded + unknown
608603

609-
eqv_morphism_graph = reflexive_closure(symmetric_closure(transitive_closure(morphism_graph)))
610-
reduced_morphism_graph = reduced_closure(morphism_graph)
604+
transitive_morphism_graph = transitive_closure(morphism_graph)
605+
reduced_morphism_graph = remove_intermediate_edges(transitive_morphism_graph)
606+
eqv_morphism_graph = reflexive_closure(symmetric_closure(transitive_morphism_graph))
611607

612608
for contig_name in overlaps_list:
613609
temporary.add(contig_name)

0 commit comments

Comments
 (0)