Skip to content

Fix crashes: sklearn n_neighbors=0, NameError in mcluster, argparse types#6

Open
rec3141 wants to merge 4 commits into
LorMeBioAI:mainfrom
rec3141:fix/sklearn-n-neighbors-zero
Open

Fix crashes: sklearn n_neighbors=0, NameError in mcluster, argparse types#6
rec3141 wants to merge 4 commits into
LorMeBioAI:mainfrom
rec3141:fix/sklearn-n-neighbors-zero

Conversation

@rec3141

@rec3141 rec3141 commented Feb 12, 2026

Copy link
Copy Markdown

Summary

This PR fixes several runtime crashes in LorBin:

  • Fix kneighbors_graph crash with scikit-learn >= 1.2 — When latent.shape[0] is 0 or 1 (e.g., very few contigs), n_neighbors is computed as 0 or negative, which raises InvalidParameterError in scikit-learn >= 1.2. Added early-return guards at both kneighbors_graph call sites in bin_cluster().

  • Fix NameError in mcluster() (multi-sample mode) — Two variable name mismatches: samplenamesamplenames (to match msample() return value) and outputoutdir (to match the function parameter). Both cause NameError at runtime when using --multi.

  • Fix argparse type= coercion for all numeric arguments — 10 arguments across bin_mode, cluster, and train subparsers were missing type=int or type=float, causing TypeError when values are provided via CLI (argparse defaults to str). Also corrects misleading help text (wrong defaults, "batchseteps" typo).

Arguments fixed

Subcommand Argument Fix
shared (bin_mode, generate_data, cluster) --bin_length Added type=int
shared (bin_mode, cluster) --akeep Added type=float
cluster --batch_size Added type=int
cluster --epoch Added type=int
cluster --lrate Added type=float
cluster --batchsteps Added type=int
train --batch_size Added type=int
train --epoch Added type=int
train --lrate Added type=float
train --batchsteps Added type=int

Related issues

  • Addresses Argparser issues #2 (Argparser issues) — completes the remaining type annotations
  • Addresses the sklearn >= 1.2 incompatibility

Test plan

  • Run lorbin bin with a small dataset to confirm normal operation
  • Run lorbin cluster with explicit --epoch 100 --batch_size 64 to verify type coercion
  • Run lorbin bin --multi with multi-sample input to verify mcluster path
  • Run with a single-contig assembly to trigger the n_neighbors guard

🤖 Generated with Claude Code

rec3141 and others added 4 commits February 11, 2026 15:52
kneighbors_graph raises InvalidParameterError when n_neighbors=0 in
scikit-learn >= 1.2. This happens when latent.shape[0] is 1 (first
clustering pass) or when all contigs are assigned in the first pass
leaving 0-1 unclustered contigs for the recluster phase.

Guard both kneighbors_graph call sites with an early return when
min_k < 1 instead of passing an invalid parameter.

Traceback without fix (sklearn 1.8.0):
  sklearn.utils._param_validation.InvalidParameterError:
  The 'n_neighbors' parameter of kneighbors_graph must be an int
  in the range [1, inf). Got 0 instead.
The mcluster() function (multi-sample mode) referenced `samplename`
(a local variable inside msample()) instead of the returned `samplenames`.
Also fixed `output` → `outdir` to match the function parameter name.

Both bugs cause NameError when running LorBin with --multi flag.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Both arguments were missing `type=` in add_argument(), causing
command-line values to arrive as strings instead of int/float.
This causes TypeError on comparisons like `bin_length <= 0`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add missing type= annotations to 8 arguments across the cluster and
train subparsers: --batch_size (type=int), --epoch (type=int),
--lrate (type=float), and --batchsteps (type=int) in both.

Without type=, argparse treats CLI-provided values as strings, causing
TypeError on numeric comparisons in train_vae() (e.g. nepochs < 1)
and DataLoader(batch_size=...).

Also fix help text: correct "default: 64" → "default: 128" to match
the actual default, and fix "batchseteps" typo.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
rec3141 added a commit to rec3141/danaSeq that referenced this pull request Feb 22, 2026
Idempotent script that applies four open PRs not yet merged upstream:
- LorMeBioAI/LorBin#6: Fix sklearn n_neighbors=0 crash, NameError in
  mcluster, missing argparse type= annotations
- LorMeBioAI/LorBin#7: Pass --cuda flag to train_vae in bin subcommand
- LottePronk/whokaryote#13: Fix GFF3 parsing for Bakta/PGAP output
- oschwengers/bakta#429: Make AMRFinderPlus failure non-fatal (warn + return)

Run once after install.sh. Safe to re-run.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

1 participant