Skip to content

feat: add --tools to run only selected tools - #222

Merged
ewels merged 2 commits into
mainfrom
feat/tools-selection
Dec 4, 2026
Merged

ewels merged 2 commits into
mainfrom
feat/tools-selection

Conversation

@ewels

@ewels ewels commented Dec 4, 2026

Copy link
Copy Markdown
Member

Closes #173.

Adds --tools to rustqc rna, so you can run only the analyses you need. The issue's example, samtools stats on a large BAM, becomes:

rustqc rna sample.bam --tools samtools_stats,flagstat,idxstats

No GTF is needed for that, and the deselected tools do no work.

Design

  • The flag
    • --tools a,b, comma-separated, repeatable, or both (--tools samtools_stats --tools flagstat). Also RUSTQC_TOOLS.
    • Names are the YAML config section names, so the CLI and the config read the same: dupradar, featurecounts, qualimap, bam_stat, infer_experiment, read_duplication, read_distribution, junction_annotation, junction_saturation, inner_distance, tin, gene_body_coverage, read_gc, split_bam, preseq, flagstat, idxstats, samtools_stats, bigwig.
    • The names are a clap ValueEnum (config::Tool), so an unknown name fails at parse time with the full list of valid names and a "similar value" hint (samtools-stats suggests samtools_stats).
  • Config
    • rna.tools: [samtools_stats, flagstat] does the same in the YAML config. It is a serde enum, so a bad name fails with the list of valid names.
  • Precedence
    • --tools replaces a config tools: list.
    • A tool list turns on exactly the listed tools. The per-tool enabled toggles are ignored (CLI and list win over enabled: false).
    • --skip-* flags apply last and still remove tools: --tools flagstat,read_gc --skip-read-gc runs flagstat only.
    • dupRadar and featureCounts have no enabled toggle. When deselected, all their output files are switched off. When selected, their per-file toggles are kept.
    • Errors: a selection that leaves nothing to run, and split_bam selected without a BED (--split-bam-bed or split_bam.bed).
  • GTF rules (checked in code, not assumed)
    • Need the GTF: dupradar, featurecounts, qualimap, infer_experiment, read_distribution, junction_annotation, junction_saturation, inner_distance, tin, gene_body_coverage. Each one builds its index from the parsed genes.
    • Do not: bam_stat, read_duplication (positions and sequences only), read_gc, split_bam (BED only), preseq, flagstat, idxstats, samtools_stats, bigwig (header lengths only).
    • Without --gtf, if a selected tool needs it: --gtf is required by: tin. plus the list of tools that need no annotation. With no --tools, the default run of everything still requires --gtf.
    • If --gtf is given but no selected tool needs it, the GTF is not parsed.

What deselected tools cost

  • Per-read accumulators
    • Every RSeQC, preseq, Qualimap and bigWig accumulator was already None when disabled, and the dispatch skips it. Selection only sets the existing toggles, so this holds.
  • Shared counting pass
    • count_reads has a new count_genes switch, false when neither dupradar nor featurecounts is selected. It then skips building the gene interval index, the per-read gene-overlap query, featureCounts / biotype / dupRadar counting and paired-end mate buffering. The loop only decodes records and feeds the selected accumulators.
  • samtools stats counters
    • The bam_stat accumulator serves bam_stat, flagstat, idxstats and samtools stats. The expensive part (CHK checksums, per-cycle histograms, GC-depth, coverage pileup) now only runs when samtools_stats is selected. --tools flagstat is about 1.7x faster than --tools samtools_stats because of this.
  • Duplicate check
    • The "no duplicate-flagged reads" check now runs only when dupRadar runs, because only dupRadar needs duplicate-marked input. --tools featurecounts,flagstat on an unmarked BAM works.
  • CRAM NM/MD
    • cram.decode_md: auto already followed samtools_stats.enabled, so --tools flagstat on CRAM regenerates no tags and --tools samtools_stats regenerates NM only.
  • What still runs
    • BAM decoding of every record (the floor), the progress counter, the unmapped-segment sweep in the parallel path, and a header read per BAM. With count_genes off, the console summary box shows total reads only, and the JSON summary omits the counting block.

Timing

Benchmark BAM (RustQC-benchmarks/test-data/rna/small/test.bam, 52.8K reads) with chr6.gtf.gz and the flags from modules/local/rustqc_rna.nf (--paired --stranded reverse --threads 2 --preseq-seed 408 --preseq-seg-len 100000000 --tin-seed 1 --junction-saturation-seed 1). Wall time in seconds, median of 5 after one warm-up run, Apple M-series laptop:

Run Median Range
main, full run 0.810 0.799–0.840
this branch, full run 0.803 0.785–0.815
--tools samtools_stats,flagstat,idxstats (no GTF) 0.102 0.102–0.110
--tools samtools_stats (no GTF) 0.100 0.098–0.113
--tools flagstat (no GTF) 0.054 0.052–0.056
--tools featurecounts 0.126 0.123–0.129

That BAM is small, so fixed costs (GTF parse, plots, preseq bootstraps) dominate. To see per-read scaling I also ran the same commands on a 2.1M-read BAM made by writing each benchmark record 40 times with a renamed read (same coordinates, so still sorted):

Run Median Range
main, full run 18.09 17.21–18.68
this branch, full run 19.03 17.17–20.59
--tools samtools_stats,flagstat,idxstats (no GTF) 2.99 2.90–3.18
--tools samtools_stats (no GTF) 2.97 2.96–3.00
--tools flagstat (no GTF) 1.77 1.71–1.80
--tools featurecounts 2.44 2.42–2.49

The full-run difference between main and the branch is within run-to-run noise (overlapping ranges). The synthetic BAM has 40 copies of each read at the same position, which inflates the work of some tools (duplication, junction and TIN accumulators), so the full-run number overstates a real 2M-read BAM. The subset numbers are mostly record decoding plus the selected accumulator.

Byte-identity checks

Outputs compared byte for byte across the whole output tree. Only embedded output paths, the git hash in CITATIONS.md, and Qualimap's "Analysis date" were masked.

  • Default behaviour (no --tools)
    • main vs this branch, all files identical, on tests/data/test.bam + test.gtf (71 files; 72 with --split-bam-bed) and on the benchmark BAM with its flags (79 files; 80 with --split-bam-bed).
  • Subsets vs full run
    • Each of the 19 tools alone, plus samtools_stats,flagstat,idxstats, dupradar,tin, featurecounts,read_distribution and bam_stat,flagstat, on both datasets: every file the subset run writes equals the same file from the full run (50 comparisons). Tools that need no GTF were run without --gtf.
  • Tests in this PR
    • test_tools_subset_outputs_match_full_run: --tools samtools_stats --tools flagstat without --gtf writes only those two files (plus CITATIONS.md) and they match the full run; --tools featurecounts,read_distribution matches too.
    • test_tools_needing_gtf_without_gtf_errors, test_tools_dup_check_only_for_dupradar, test_tools_config_list_and_precedence.
    • CLI unit tests for names, comma and repeated flags, unknown names, and the optional --gtf. Config unit tests for select_tools, enabled_tools, needs_gtf, the YAML list and CRAM tag selection after a selection.

Other changes

  • Citations
    • any_rseqc_output() now includes gene_body_coverage and read_gc, so --tools read_gc still cites RSeQC in CITATIONS.md. Default runs are unaffected.
  • featureCounts header
    • The reconstructed command line in the featureCounts header omits --tools, like it already omits the --skip-* flags. This keeps a subset's counts file byte-identical to a full run's.
  • Library API
    • count_reads gains a count_genes: bool argument, and RseqcConfig a samtools_stats_enabled field. The library is 0.x and documents that minor releases can break the API.
  • Docs
    • CLI reference (new "Tool selection" section with the name / GTF table), configuration page (tools: and RUSTQC_TOOLS), introduction, quick start, samtools page, README, AGENTS.md and CHANGELOG.

🤖 Generated with Claude Code

ewels and others added 2 commits December 4, 2026 09:44
`rustqc rna --tools samtools_stats,flagstat` runs only the named tools.
Names are the config section names; the list can also be set as
`rna.tools` in the config. A tool list overrides the `enabled` toggles,
`--tools` replaces the config list, and `--skip-*` flags still apply.

`--gtf` is now required only when a selected tool uses the annotation.
Without dupRadar and featureCounts the counting pass skips gene overlap,
counting and mate pairing, and the samtools stats counters are only
collected when samtools_stats runs. The duplicate-marking check only runs
for dupRadar.

Default runs are byte-identical to main, and subset outputs are
byte-identical to the same files from a full run.

Closes #173

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ewels ewels added this to the v0.3 milestone Dec 4, 2026
@ewels
ewels merged commit 69a7bca into main Dec 4, 2026
7 checks passed
@ewels
ewels deleted the feat/tools-selection branch December 4, 2026 08:53
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.

Feature request: run a single tool from the command line

1 participant