Skip to content

Commit

Permalink
Contig stitcher: always rename children
Browse files Browse the repository at this point in the history
  • Loading branch information
Donaim committed Jan 20, 2024
1 parent 7c90109 commit f21caaf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
6 changes: 1 addition & 5 deletions micall/core/contig_stitcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,11 +248,7 @@ def align_to_reference(contig) -> Iterable[GenotypedContig]:
contig = new_contig

for i, single_hit in enumerate(connected):
if len(connected) == 1:
query = contig
else:
query = replace(contig, name=generate_new_name())

query = replace(contig, name=generate_new_name())
part = AlignedContig.make(query, single_hit, strand)

logger.info("Part %r of contig %r aligned as %r at [%s, %s]->[%s, %s]%s.",
Expand Down
20 changes: 13 additions & 7 deletions micall/core/plot_contigs.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ def build_stitcher_figure(logs) -> None:
discarded: List[str] = []
unknown: List[str] = []
anomaly: List[str] = []
overlaps_list: List[str] = []
overlap_leftparent_map: Dict[str, str] = {}
overlap_rightparent_map: Dict[str, str] = {}
overlap_lefttake_map: Dict[str, str] = {}
Expand Down Expand Up @@ -561,12 +562,8 @@ def record_morphism(contig: Contig, original: Contig):
record_contig(event.result, [event.original])
record_morphism(event.result, event.original)
elif event.action == "overlap":
temporary.add(event.left_take.name)
temporary.add(event.right_take.name)
temporary.add(event.left_overlap.name)
temporary.add(event.right_overlap.name)
temporary.add(event.left.name)
temporary.add(event.right.name)
overlaps_list.append(event.left_overlap.name)
overlaps_list.append(event.right_overlap.name)
overlap_leftparent_map[event.left_remainder.name] = event.left.name
overlap_rightparent_map[event.right_remainder.name] = event.right.name
overlap_lefttake_map[event.left_remainder.name] = event.left_take.name
Expand Down Expand Up @@ -611,6 +608,11 @@ def record_morphism(contig: Contig, original: Contig):
eqv_morphism_graph = reflexive_closure(symmetric_closure(transitive_closure(morphism_graph)))
reduced_morphism_graph = reduced_closure(morphism_graph)

for contig in overlaps_list:
temporary.add(contig)
for child in transitive_children_graph.get(contig, []):
temporary.add(child)

for contig, parents in parent_graph.items():
if len(parents) > 2:
children_join_points.append(contig)
Expand Down Expand Up @@ -689,7 +691,11 @@ def copy_takes_one_side(edge_table, overlap_xtake_map, overlap_xparent_map):

# for join in last_join_points + sorted_sinks:
for join in last_join_points + sorted_sinks:
for contig in parent_graph.get(join, [join]):
parents = parent_graph.get(join, [join])
if not any(isinstance(parent, AlignedContig) for parent in parents):
parents = [join]

for contig in parents:
for contig in reduced_morphism_graph.get(contig, [contig]):
if any(contig in transitive_parent_graph.get(bad, []) for bad in bad_contigs):
continue
Expand Down

0 comments on commit f21caaf

Please sign in to comment.