feat: opt-in base_quality feature channel from dorado per-base Q-scores

Aperta
#478 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, pytorch

Direzione di ricerca

Read src/leech/constants.py, preparation/reader.py, and io/bam_reader.py, then inspect the existing feature-channel and backend-selection paths and the prototype on feat/478-base-quality. First review audit #157, since training is gated on finding per-position, speed-adjusted signal above the control region. Done means the stated acceptance criteria and tests pass, with the paired-seed run-held-out ablation documented; the issue says not to train before the audit gate is met.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement

Summary

Add the basecaller's per-base quality (dorado Q-score, BAM QUAL) as an opt-in feature channel base_quality. leech currently reads no base qualities anywhere; the only basecall-error-adjacent signals are the per-chunk junction_indel / junction_mapped metadata. The channel gives the model the basecaller's own per-base uncertainty, which is defined under both --anchor reference and --anchor basecall and needs no alignment walk.

Status and gate (2026-11-29)

A prototype implementing everything below except predict wiring exists on branch feat/478-base-quality (176 tests pass). Do not train on it yet. The pre-registered gate is an offline audit, rnabioco/2026-aa-trna-models#157 (a related offline question, the CCA-junction error signature, is #158), because the first measurement is negative:

  • Qualities are present on the real ncAA-trio BAMs (results/noncognate-22way/data_noncognate/filtered/MetRS_{met,aha,hpg}_b5/noncognate.bam, 3000/3000 reads), mean Q about 13.5 (RNA004).
  • Per-read mean Q over the K=6/fe=10 window (ref bases motif+8 .. +18) does not separate Met/AHA/HPG: pairwise AUC 0.491 / 0.497 / 0.506 (n=3000 per arm), identical to the AUC of a control region 40..10 bases upstream (0.491 / 0.494 / 0.504). Window Q is lower than the body (10.8 vs 15.5), but equally so in every arm.
  • So at read-mean resolution the channel carries no adduct signal on the project's best-validated benchmark, and its dominant variance is run/speed. Its main risk in this project is being a nuisance channel (the bottleneck there is confounds, not capacity).

Proceed to the training ablation only if the audit finds per-position, speed-adjusted signal above the control region.

Design

base_quality is a new entry in the existing feature-channel system (#358), not a new array:

  • Add "base_quality" to KNOWN_FEATURE_CHANNELS (src/leech/constants.py). Not in DEFAULT_FEATURE_CHANNELS/ALL_FEATURE_CHANNELS defaults: opt in via --feature-channels, so existing recipes keep their input shape.
  • Per-base values are indexed exactly like the dwell and level channels, i.e. one per base of seq_to_sig_map. With --anchor basecall that is one per base of aln.query_sequence (pysam returns query_qualities in the same orientation as query_sequence, so the pairing holds by construction; asserted by a test, not assumed). With --anchor reference (the default) the map is indexed by the reference slice, so the query qualities are carried across the CIGAR with the same make_ref_to_query_mapping interpolation compute_ref_to_signal uses: a reference base that was deleted in the read gets the interpolated quality of its neighbours, and there is no second CIGAR walk.
  • Computed in preparation/reader.py next to compute_signal_features and folded into the signal_features dict, so merge_feature_channels orders and windows it with no new plumbing.
  • ReadInfo (io/bam_reader.py) carries the qualities (as uint8, not a Python list) to the workers.
  • Transform is a flag, --quality-transform {raw,perr} (default raw), recorded in prepare_config.json and the model config so predict reproduces it.
  • Missing qualities (QUAL = *, hard-clipped regions): data prepare raises when the channel is requested and a read has none, naming the read count. No silent zero-fill.

Backend

Python-only extraction, same precedent as --mask-seq-side. _select_prepare_backend and the predict --backend auto path must route to Python when base_quality is requested; --backend rust raises. A Rust port is a non-goal here and gated on the result below.

Acceptance criteria

  1. leech data prepare --feature-channels <default>,base_quality produces a corpus whose feature tensor has one extra row at the position given by the recorded list; prepare_config.json records the channel and transform.
  2. leech model train and leech predict on that corpus build a model with the extra input channel and reproduce the same transform at predict time. Old corpora and checkpoints load unchanged.
  3. A corpus/checkpoint channel-count mismatch raises, naming both counts.
  4. --backend rust with the channel raises; --backend auto falls back to Python with a warning.
  5. Reads without qualities raise at prepare time when the channel is requested.
  6. --standardize-features handles the channel; perr clips Q to [0, 60].
  7. Evaluation protocol documented in the PR: paired seeds (6, per the CRF-port finding that 3 is too few) with and without the channel, on the run-held-out split, reporting cross-run vs within-run metrics. A gain that appears only within-run is a confound, not a result.

Expected tests

  • tests/test_data_prep.py::TestFeatureChannelOrder extended: base_quality position and name validation (validate_feature_channels accepts it, still rejects typos).
  • tests/test_base_quality_feature.py (new): quality-to-base pairing on a forward and a reverse-strand fixture (value at base i belongs to base i); soft-clip and window-edge handling; missing-quality raise; transform round trip through prepare_config.json; predict reproduces training transform.
  • Backend-selection tests: rust raises, auto falls back.

Non-goals

  • No Rust implementation, and no change to tests/test_backend_parity.py fixtures.
  • No binary mismatch / insertion / deletion channels (possible follow-up if quality helps).
  • No change to default channel lists or to any existing checkpoint's input.
  • No use of read-level mean Q or MAPQ.
  • No relabeling or filtering of reads by quality (that is label_quality, #473).

Risks to report in the PR

  • Leakage path: acyl modification may depress basecaller confidence near the 3' end; the model could learn basecaller-version behaviour rather than charging state. Run-held-out split is the test.
  • Dorado per-base Q is a model-confidence output, not calibrated across model versions or flowcells.
Lingua principale
Python
Stelle
0
Fork
0
Merge medio
11h 17m
PR unite (30g)
23

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di rnabioco/leech

Tutte le issue di rnabioco/leech

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.