Skip to content

fix(writer): guard per-gene thresholding against degenerate similarities#59

Open
EliHei2 wants to merge 1 commit into
mainfrom
bugfix/threshold-degenerate
Open

fix(writer): guard per-gene thresholding against degenerate similarities#59
EliHei2 wants to merge 1 commit into
mainfrom
bugfix/threshold-degenerate

Conversation

@EliHei2

@EliHei2 EliHei2 commented Jun 1, 2026

Copy link
Copy Markdown
Collaborator

threshold_yen / threshold_li_custom crash (or return garbage) on degenerate per-gene similarity arrays. Before thresholding, drop null / non-finite values and short-circuit the two degenerate cases: no finite values -> treat as failed-to-converge (backfilled with the global quantile); a single or constant value -> use that value directly. Prevents crashes on sparse genes.

What to review: the few guard lines added before the existing try/except in the per-gene threshold loop. No change for genes with a normal spread of values.

threshold_yen / threshold_li_custom crash (or return garbage) on degenerate
per-gene similarity arrays. Before thresholding, drop null / non-finite values
and short-circuit the two degenerate cases: no finite values -> treat as
failed-to-converge (backfilled with the global quantile); a single or constant
value -> use that value directly. Prevents crashes on sparse genes.

What to review: the few guard lines added before the existing try/except in the
per-gene threshold loop. No change for genes with a normal spread of values.
@EliHei2 EliHei2 requested a review from Tobiaspk June 1, 2026 13:05
@Tobiaspk

Tobiaspk commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

I wasn't aware that segger similarities could be null or infinite. Do you have a way to reproduce, or know why this happens?

Also, when arr.size == 1 or np.allclose(arr, arr[0]) it still sets "converged" to true and sets a threshold. Does that make sense? Should these transcripts actually be included in the final anndata and assignments?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants