Skip to content

Commit 442d5a9

Browse files
tomwardiocopybara-github
authored andcommitted
Return early if there are no junctions to threshold.
Previously, if there were no junctions after filtering and k_threshold was None, you'd get a `ValueError` when trying to max over an empty array. Instead, return early if there are no junctions after filtering. PiperOrigin-RevId: 875753172 Change-Id: I679ffad56a87ef1864826b9f7c4d1c7129a97015
1 parent ab97343 commit 442d5a9

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

src/alphagenome/data/junction_data.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,14 @@ def get_junctions_to_plot(
244244
raise ValueError(
245245
f'Expected only one ontology term, got {filtered.num_tracks}.'
246246
)
247+
filtered_junctions = []
248+
if filtered.values.size == 0:
249+
return filtered_junctions
250+
247251
if k_threshold is None:
248252
k_threshold = filtered.values.max() * 0.05
253+
249254
# Round k for better visualization.
250-
filtered_junctions = []
251255
for interval, k in zip(filtered.junctions, filtered.values, strict=True):
252256
# Filter by threshold and strand.
253257
if interval.strand != strand:

src/alphagenome/data/junction_data_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,12 @@ def test_intersect_with_interval(self):
223223
genome.Junction('chr2', 10, 11, '+', k=5),
224224
],
225225
),
226+
dict(
227+
name='unknown_track_name',
228+
k_threshold=None,
229+
strand='+',
230+
expected=[],
231+
),
226232
])
227233
def test_get_junctions_to_plot(self, name, k_threshold, strand, expected):
228234
metadata = pd.DataFrame({

0 commit comments

Comments
 (0)