Skip to content

Commit 2a5318c

Browse files
tomwardiocopybara-github
authored andcommitted
Fix IndexError when plotting annotations without labels.
This resolves #25. PiperOrigin-RevId: 877278759 Change-Id: Ie975689d36b700593b09baa5cb4f0ce809771bff
1 parent 442d5a9 commit 2a5318c

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/alphagenome/visualization/plot_components.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,16 +176,18 @@ def plot(
176176
axes_to_annotate_idx = (
177177
range(1, len(axes)) if add_label_axis else range(len(axes))
178178
)
179-
for i, annotation in enumerate(annotations):
180-
for j in axes_to_annotate_idx:
181-
if not annotation.is_variant and j in transcript_axes_idx:
179+
label_index = 0
180+
for annotation in annotations:
181+
for annotate_index in axes_to_annotate_idx:
182+
if not annotation.is_variant and annotate_index in transcript_axes_idx:
182183
# Do not add interval annotations to axes that involves transcripts.
183184
continue
184-
annotation.plot_ax(axes[j], interval, hspace)
185+
annotation.plot_ax(axes[annotate_index], interval, hspace)
185186
if annotation.has_labels:
186187
# Add labels to the empty axis at the top. All labels are added to
187188
# the top axis, in the order they are supplied in annotations list.
188-
annotation.plot_labels(axes[0], interval, height_offsets[i])
189+
annotation.plot_labels(axes[0], interval, height_offsets[label_index])
190+
label_index += 1
189191

190192
# Enable default tick locator for the final subplot.
191193
axes[-1].xaxis.set_major_locator(matplotlib.ticker.AutoLocator())

src/alphagenome/visualization/plot_components_test.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,10 @@ def test_track_component(self, subinterval, logo_ylim):
230230
colors='darkgray',
231231
),
232232
plot_components.VariantAnnotation(
233-
annotated_variants, use_default_labels=True, colors='purple'
233+
annotated_variants, use_default_labels=False, colors='purple'
234+
),
235+
plot_components.VariantAnnotation(
236+
annotated_variants, use_default_labels=True, colors='orange'
234237
),
235238
],
236239
)

0 commit comments

Comments
 (0)