Skip to content

Commit 77d7d7c

Browse files
committed
Contig stitcher: do no re-draw same contigs
Make sure that every contig, including once composed of root-level contigs, is displayed at most once.
1 parent 135ef59 commit 77d7d7c

File tree

2 files changed

+21
-30
lines changed

2 files changed

+21
-30
lines changed

micall/core/plot_contigs.py

+18-7
Original file line numberDiff line numberDiff line change
@@ -839,12 +839,15 @@ def get_contig_coordinates(contig):
839839
a_r_ei = f_r_ei
840840
return (a_r_st, a_r_ei, f_r_st, f_r_ei)
841841

842-
def get_tracks(group_ref, contig_name):
842+
def get_tracks(repeatset, group_ref, contig_name):
843843
parts = final_parent_mapping[contig_name]
844844
for part_name in parts:
845845
part = contig_map[part_name]
846846

847-
if part_name in bad_contigs:
847+
if part.name in repeatset:
848+
continue
849+
850+
if part.name in bad_contigs:
848851
continue
849852

850853
if not isinstance(part, AlignedContig):
@@ -853,16 +856,20 @@ def get_tracks(group_ref, contig_name):
853856
if part.group_ref != group_ref:
854857
continue
855858

859+
repeatset.add(part.name)
856860
indexes = name_mappings[part.name]
857861
(a_r_st, a_r_ei, f_r_st, f_r_ei) = get_contig_coordinates(part)
858862
yield Track(f_r_st, f_r_ei, label=f"{indexes}")
859863

860-
def get_arrows(group_ref, contig_name, labels):
864+
def get_arrows(repeatset, group_ref, contig_name, labels):
861865
parts = final_parent_mapping[contig_name]
862866
for part_name in parts:
863867
part = contig_map[part_name]
864868

865-
if part_name in bad_contigs:
869+
if part.name in repeatset:
870+
continue
871+
872+
if part.name in bad_contigs:
866873
continue
867874

868875
if not isinstance(part, AlignedContig):
@@ -871,6 +878,7 @@ def get_arrows(group_ref, contig_name, labels):
871878
if part.group_ref != group_ref:
872879
continue
873880

881+
repeatset.add(part.name)
874882
indexes = name_mappings[part.name] if labels else None
875883
height = 20 if labels else 1
876884
elevation = 1 if labels else -20
@@ -881,8 +889,9 @@ def get_arrows(group_ref, contig_name, labels):
881889
label=indexes)
882890

883891
def get_all_arrows(group_ref, labels):
892+
repeatset = set()
884893
for parent_name in sorted_roots:
885-
yield from get_arrows(group_ref, parent_name, labels)
894+
yield from get_arrows(repeatset, group_ref, parent_name, labels)
886895

887896
################
888897
# Drawing part #
@@ -955,11 +964,13 @@ def get_all_arrows(group_ref, labels):
955964
# Contigs #
956965
###########
957966

967+
repeatset1 = set()
968+
repeatset2 = set()
958969
for parent_name in sorted_roots:
959-
arrows = list(get_arrows(group_ref, parent_name, labels=False))
970+
arrows = list(get_arrows(repeatset1, group_ref, parent_name, labels=False))
960971
if arrows:
961972
figure.add(ArrowGroup(arrows))
962-
parts = list(get_tracks(group_ref, parent_name))
973+
parts = list(get_tracks(repeatset2, group_ref, parent_name))
963974
if parts:
964975
figure.add(Multitrack(parts))
965976

micall/tests/data/stitcher_plots/test_partial_align_consensus_multiple_sequences.svg

+3-23
Loading

0 commit comments

Comments
 (0)