diff --git a/AGENTS.md b/AGENTS.md index d242085..25cc137 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -14,6 +14,8 @@ > [preseq](https://github.com/smithlabcode/preseq) `lc_extrap`) > - **samtools-compatible** flagstat, idxstats, and full stats output > - **Gene body coverage** profiling with Qualimap-compatible output +> - **bigWig** genome coverage tracks (bedtools `genomecov` + UCSC `bedClip` / +> `bedGraphToBigWig`; nf-core/rnaseq's three files by default) > > Binary crate (`rustqc`), Rust edition 2021. @@ -64,7 +66,7 @@ src/ io.rs — Shared I/O utilities (gzip-transparent file reading) gtf.rs — GTF annotation file parser (with configurable attribute extraction) rna/ - mod.rs — Re-exports all submodules (dupradar, featurecounts, rseqc, bam_flags, preseq, qualimap, rng) + mod.rs — Re-exports all submodules (dupradar, featurecounts, rseqc, bam_flags, preseq, qualimap, rng, bigwig) bam_flags.rs — BAM flag constants dupradar/ mod.rs — Re-exports counting, dupmatrix, fitting, plots @@ -76,6 +78,11 @@ src/ mod.rs — Re-exports output output.rs — featureCounts-format output & biotype counting preseq.rs — preseq lc_extrap library complexity extrapolation + bigwig/ + mod.rs — Re-exports accumulator, output and writer + accumulator.rs — Streaming bedtools genomecov coverage (memory bounded by read span) + output.rs — Per-track bigWig output (file names, bedtools-style scaling) + writer.rs — bigWig writer following UCSC bedGraphToBigWig (trees, zlib sections, zooms) rng.rs — MT19937 + libstdc++ binomial port for preseq bootstrap reproducibility qualimap/ mod.rs — Re-exports all Qualimap modules @@ -121,8 +128,9 @@ dupRadar duplicate rate analysis, featureCounts-compatible gene counting, the RSeQC-equivalent tools (bam_stat, infer_experiment, read_duplication, read_distribution, junction_annotation, junction_saturation, inner_distance, TIN, and split_bam when `--split-bam-bed` is given), preseq library complexity extrapolation, samtools-compatible outputs -(flagstat, idxstats, stats), and gene body coverage profiling with -Qualimap-compatible output. The GTF parser extracts transcript-level +(flagstat, idxstats, stats), gene body coverage profiling with +Qualimap-compatible output, and nf-core/rnaseq-compatible bigWig coverage +tracks. The GTF parser extracts transcript-level structure (exons + CDS features) to derive all data needed by every tool. Individual tools can be disabled via the YAML config file (each has an `enabled` @@ -299,8 +307,19 @@ forwarded to `count_reads()` as the `skip_dup_check: bool` parameter). chromosomes match alignment reference names, not GTF-mapped names. - `split_bam` parity fixtures (`tests/data/split_bam_test.*`, `tests/expected/split_bam/`) are generated by `tests/create_split_bam_test_data.sh` with RSeQC 5.0.4; do not edit by hand. -- Under `rna:`, there are also sections for `preseq:`, `qualimap:`, +- Under `rna:`, there are also sections for `preseq:`, `qualimap:`, `bigwig:`, `flagstat:`, `idxstats:`, and `samtools_stats:`. Each has an `enabled: bool` toggle. + `bigwig:` mirrors `bedtools genomecov` options: `tracks` (`combined`/`forward`/`reverse`; + unset = combined, plus forward/reverse for stranded libraries, labels swapped for + reverse-stranded ones), `split` (`-split`, default true), `du` (`-du`, default true), + `scale`, `bga`, `read_end` (`5p`/`3p`), `fragment_size` (`-fs`); CLI `--bigwig-*` + and `--skip-bigwig`. The defaults must keep producing nf-core/rnaseq's files. +- The bigWig parity fixtures `tests/expected/bigwig/..bedGraph` (and + `tests/data/bigwig_edge.bam`, from `bigwig_edge.sam`) are real bedtools 2.31.1 + `genomecov` output, regenerated by `tests/create_bigwig_test_data.sh`; do not edit + by hand. The bigWig writer's zoom levels follow UCSC `bbiWriteZoomLevels` (f32 + summaries, first level from the average interval size); keep them that way so + `bigWigSummary` and genome browsers give the same answers as for UCSC's files. Preseq has additional parameters: `max_extrap`, `step_size`, `n_bootstraps`, `confidence_level`, `seed`, `max_terms`, `defects`. TIN has `sample_size` and `min_coverage`. diff --git a/CHANGELOG.md b/CHANGELOG.md index b2c3552..93fd0f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ ## [Unreleased] +### Features + +- Add bigWig genome coverage tracks in the existing BAM streaming pass, matching `bedtools genomecov` + UCSC `bedClip` + `bedGraphToBigWig` ([#112](https://github.com/seqeralabs/RustQC/issues/112), [#114](https://github.com/seqeralabs/RustQC/pull/114)) + - By default writes nf-core/rnaseq's files: `{sample}.bigWig` (`-split -bg`), plus `{sample}.forward.bigWig` / `{sample}.reverse.bigWig` (`-split -du -strand +/-`, swapped for reverse-stranded libraries) for stranded libraries + - Options for `-split`, `-du`, `-strand` (track selection), `-scale`, `-bga`, `-5`/`-3` and `-fs`, under `rna.bigwig` in the config and as `--bigwig-*` flags; `--skip-bigwig` turns the tracks off + - Pure-Rust bigWig writer with `bedGraphToBigWig`'s file layout, zoom levels and zoom summaries; no C dependencies + ### Other changes - Migrate BAM/SAM/CRAM I/O from rust-htslib to pure-Rust [noodles](https://crates.io/crates/noodles) (#113) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0ab0f31..b1fcaaf 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -67,8 +67,8 @@ src/ io.rs Shared I/O utilities (gzip-transparent file reading) gtf.rs GTF annotation file parser rna/ - mod.rs Re-exports all submodules (bam_flags, dupradar, featurecounts, - preseq, qualimap, rng, rseqc) + mod.rs Re-exports all submodules (bam_flags, bigwig, dupradar, + featurecounts, preseq, qualimap, rng, rseqc) bam_flags.rs BAM flag constants dupradar/ mod.rs Re-exports counting, dupmatrix, fitting, plots @@ -80,6 +80,11 @@ src/ mod.rs Re-exports output output.rs featureCounts-format output and biotype counting preseq.rs preseq lc_extrap library complexity extrapolation + bigwig/ + mod.rs Re-exports accumulator, output and writer + accumulator.rs bedtools genomecov streaming coverage accumulation + output.rs Per-track bigWig output (file names, scaling) + writer.rs bigWig file writer (bedGraphToBigWig layout and zoom levels) rng.rs MT19937 + libstdc++ binomial port for preseq bootstrap qualimap/ mod.rs Re-exports accumulator, coverage, index, output, plots, report diff --git a/Cargo.toml b/Cargo.toml index fe12b58..047fe91 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.2.1" edition = "2021" rust-version = "1.89" authors = ["Phil Ewels ", "Jon Manning "] -description = "Fast RNA-seq QC in a single pass: dupRadar, featureCounts, 9 RSeQC tools, preseq, samtools stats, and Qualimap — reimplemented in Rust" +description = "Fast RNA-seq QC in a single pass: dupRadar, featureCounts, 9 RSeQC tools, preseq, samtools stats, Qualimap, and bigWig coverage tracks — reimplemented in Rust" license = "GPL-3.0-or-later" repository = "https://github.com/seqeralabs/RustQC" readme = "README.md" @@ -21,6 +21,7 @@ path = "src/lib.rs" name = "rustqc" path = "src/main.rs" + [dependencies] # CLI argument parsing clap = { version = "4", features = ["derive", "env"] } @@ -70,6 +71,7 @@ indicatif = "0.18" number_prefix = "0.4" serde_json = "1" + [profile.release] opt-level = 3 lto = true diff --git a/README.md b/README.md index b941f70..6edc941 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@

- Benchmark: RustQC ~14m 54s vs traditional tools ~15h 34m sequential (dupRadar + featureCounts + 8 RSeQC tools incl. TIN + preseq + samtools + Qualimap) + Benchmark: RustQC ~14m 54s vs traditional tools ~15h 34m sequential (dupRadar + featureCounts + 8 RSeQC tools incl. TIN + preseq + samtools + Qualimap + bigWig)

@@ -53,11 +53,12 @@ It currently includes: | split_bam | [RSeQC](https://rseqc.sourceforge.net/#split-bam-py) `split_bam.py` | BED-region (e.g. rRNA) read classification, needs `--split-bam-bed` | | preseq | [preseq](http://smithlabresearch.org/software/preseq/) `lc_extrap` | Library complexity extrapolation | | Qualimap rnaseq | [Qualimap](http://qualimap.conesalab.org/) `rnaseq` | Gene body coverage, read origin, strand specificity | +| bigWig | [bedtools](https://github.com/arq5x/bedtools2) `genomecov` + UCSC `bedGraphToBigWig` | Genome coverage tracks; by default the nf-core/rnaseq set | | flagstat | [samtools](http://www.htslib.org/) `flagstat` | Alignment flag summary | | idxstats | [samtools](http://www.htslib.org/) `idxstats` | Per-chromosome read counts | | stats | [samtools](http://www.htslib.org/) `stats` | Full samtools stats output including all histogram sections | -All outputs are format- and numerically identical to the upstream tools, and compatible with [MultiQC](https://multiqc.info/) for reporting. +Most outputs are format- and numerically identical to the upstream tools, and compatible with [MultiQC](https://multiqc.info/) for reporting. bigWig coverage matches [bedtools](https://github.com/arq5x/bedtools2) `genomecov` exactly; the `.bigWig` files have the same layout and zoom levels as UCSC `bedGraphToBigWig` output (see [bigWig docs](https://seqeralabs.github.io/RustQC/rna/bigwig/)). ## Quick start @@ -85,7 +86,7 @@ See the [documentation](https://seqeralabs.github.io/RustQC/) for full usage det ## Use as a Rust library -The crate is also published as a library, so the QC analysis modules (GTF parsing, dupRadar, featureCounts, RSeQC, Qualimap, preseq, samtools-style outputs) can be embedded into other Rust programs: +The crate is also published as a library, so the QC analysis modules (GTF parsing, dupRadar, featureCounts, RSeQC, Qualimap, bigWig, preseq, samtools-style outputs) can be embedded into other Rust programs: ```toml [dependencies] diff --git a/docs/astro.config.mjs b/docs/astro.config.mjs index 4e1c2f4..01a7fca 100644 --- a/docs/astro.config.mjs +++ b/docs/astro.config.mjs @@ -68,6 +68,7 @@ export default defineConfig({ { label: "featureCounts", slug: "rna/featurecounts" }, { label: "RSeQC", slug: "rna/rseqc" }, { label: "Qualimap", slug: "rna/qualimap" }, + { label: "bigWig", slug: "rna/bigwig" }, { label: "Preseq", slug: "rna/preseq" }, { label: "Samtools", slug: "rna/samtools" }, ], diff --git a/docs/src/content/docs/about/credits.mdx b/docs/src/content/docs/about/credits.mdx index a5a06c9..a704958 100644 --- a/docs/src/content/docs/about/credits.mdx +++ b/docs/src/content/docs/about/credits.mdx @@ -98,6 +98,24 @@ Qualimap rnaseq report. - Website: [qualimap.conesalab.org](http://qualimap.conesalab.org/) - Publication: [doi.org/10.1093/bioinformatics/bts503](https://doi.org/10.1093/bioinformatics/bts503) +## bigWig coverage tracks + +RustQC writes genome-wide bigWig coverage tracks that match +[bedtools](https://github.com/arq5x/bedtools2) `genomecov` followed by UCSC +`bedClip` and `bedGraphToBigWig`, with nf-core/rnaseq's settings by default. +See the [bigWig](../rna/bigwig/) page for output files, options, and +validation details. + +> Quinlan AR, Hall IM. BEDTools: a flexible suite of utilities for comparing +> genomic features. *Bioinformatics*. 2010;26(6):841-842. + +- bedtools: [github.com/arq5x/bedtools2](https://github.com/arq5x/bedtools2) +- Publication: [doi.org/10.1093/bioinformatics/btq033](https://doi.org/10.1093/bioinformatics/btq033) +- bigWig format (UCSC): Kent WJ, Zweig AS, Barber G, Hinrichs AS, Karolchik D. + BigWig and BigBed: enabling browsing of large distributed datasets. + *Bioinformatics*. 2010;26(17):2204-2207. + [doi.org/10.1093/bioinformatics/btq351](https://doi.org/10.1093/bioinformatics/btq351) + ## Key dependencies RustQC is built with the following open-source Rust libraries: diff --git a/docs/src/content/docs/getting-started/introduction.mdx b/docs/src/content/docs/getting-started/introduction.mdx index e65f65c..63deb95 100644 --- a/docs/src/content/docs/getting-started/introduction.mdx +++ b/docs/src/content/docs/getting-started/introduction.mdx @@ -13,6 +13,7 @@ RustQC is a fast quality control toolkit for sequencing data, written in Rust. I - [preseq](https://github.com/smithlabcode/preseq): library complexity extrapolation (lc_extrap) - [samtools](http://www.htslib.org/): flagstat, idxstats, and full stats output including all histogram sections - [Qualimap](http://qualimap.conesalab.org/): gene body coverage profiling and RNA-seq QC summary +- [nf-core/rnaseq](https://nf-co.re/rnaseq) bigWig: genome-wide coverage tracks (`bedtools genomecov` + UCSC utilities) ## Why RustQC? @@ -41,6 +42,7 @@ Given a duplicate-marked BAM file and a GTF annotation, `rustqc rna` runs all of | dupRadar | [dupRadar](https://bioconductor.org/packages/dupRadar/) | RNA-seq PCR duplicate rate analysis | | featureCounts | [featureCounts](http://subread.sourceforge.net/) | Gene-level read counting and biotypes | | Qualimap rnaseq | [Qualimap](http://qualimap.conesalab.org/) rnaseq | Gene body coverage and RNA-seq QC | +| bigWig | [nf-core/rnaseq](https://nf-co.re/rnaseq) `bedtools genomecov` | Genome-wide coverage tracks | | preseq | [preseq](http://smithlabresearch.org/software/preseq/) `lc_extrap` | Library complexity extrapolation | | flagstat | `samtools flagstat` | Alignment flag statistics | | idxstats | `samtools idxstats` | Per-chromosome read counts | diff --git a/docs/src/content/docs/getting-started/quickstart.md b/docs/src/content/docs/getting-started/quickstart.md index 1f3dd84..99afe7a 100644 --- a/docs/src/content/docs/getting-started/quickstart.md +++ b/docs/src/content/docs/getting-started/quickstart.md @@ -7,7 +7,7 @@ A basic RustQC analysis from install to results. ## RNA-seq duplicate analysis -Run all RNA-seq QC analyses (dupRadar, featureCounts, RSeQC tools including TIN, Qualimap, preseq, and samtools) in a single pass: +Run all RNA-seq QC analyses (dupRadar, featureCounts, RSeQC tools including TIN, Qualimap, bigWig coverage tracks, preseq, and samtools) in a single pass: ```bash rustqc rna sample.markdup.bam --gtf genes.gtf -p -o results/ @@ -27,7 +27,8 @@ This command: ### Output -Output files are organized into subdirectories by tool group. +Output files are organized into subdirectories by tool group +(for example `dupradar/`, `rseqc/`, `qualimap/`, `bigwig/`, `preseq/`, and `samtools/`). Files are generally named the same as their upstream tool equivalents. This means that MultiQC should find them and report them as if they were created by the original tool. diff --git a/docs/src/content/docs/index.mdx b/docs/src/content/docs/index.mdx index b06d9f7..29c3abe 100644 --- a/docs/src/content/docs/index.mdx +++ b/docs/src/content/docs/index.mdx @@ -27,6 +27,7 @@ export const base = import.meta.env.BASE_URL; featureCounts,{" "} RSeQC,{" "} Qualimap,{" "} + nf-core/rnaseq bigWig,{" "} preseq, and{" "} samtools in Rust, delivering matching results much faster. @@ -163,7 +164,8 @@ export const base = import.meta.env.BASE_URL; Produces identical or near-identical output to R's dupRadar and featureCounts, plus faithful reimplementations of 9 RSeQC tools (including TIN and split_bam), preseq, - and samtools. See [benchmark details](./rna/benchmark-details/). + samtools, and nf-core/rnaseq-compatible bigWig coverage tracks. + See [benchmark details](./rna/benchmark-details/). Processes ~186M reads in 14m 54s on AWS vs ~15h 34m of sequential tool @@ -171,7 +173,7 @@ export const base = import.meta.env.BASE_URL; workflow. - Replaces 14+ separate QC tool invocations with a single CLI command. + Replaces 15+ separate QC tool invocations with a single CLI command. One task to stage data for. One pass through the BAM file. Minimal staging and I/O overhead. @@ -183,5 +185,5 @@ export const base = import.meta.env.BASE_URL; ## Credits -RustQC reimplements established tools including dupRadar, featureCounts, RSeQC, preseq, samtools, and Qualimap. +RustQC reimplements established tools including dupRadar, featureCounts, RSeQC, preseq, samtools, Qualimap, and nf-core/rnaseq bigWig coverage tracks. See the [Credits & Citations](./about/credits/) page for the full list and how to cite them. diff --git a/docs/src/content/docs/rna/benchmark-details.mdx b/docs/src/content/docs/rna/benchmark-details.mdx index 8594e00..a3ec3e0 100644 --- a/docs/src/content/docs/rna/benchmark-details.mdx +++ b/docs/src/content/docs/rna/benchmark-details.mdx @@ -45,7 +45,8 @@ across chromosomes. Per-tool comparison tables and known differences are on the individual tool pages: [dupRadar](../dupradar/), [featureCounts](../featurecounts/), [RSeQC](../rseqc/), -[preseq](../preseq/), [Samtools](../samtools/), [Qualimap](../qualimap/). +[preseq](../preseq/), [Samtools](../samtools/), [Qualimap](../qualimap/), +[bigWig](../bigwig/). ## Upstream tool versions @@ -59,6 +60,7 @@ RustQC output was validated against these specific versions: | preseq | 3.2.0 | | samtools | 1.22.1 | | Qualimap | 2.3 | +| bedtools | 2.31.1 | Exact container tags and commands are in the [RustQC-benchmarks](https://github.com/seqeralabs/RustQC-benchmarks) Nextflow pipeline. diff --git a/docs/src/content/docs/rna/bigwig.mdx b/docs/src/content/docs/rna/bigwig.mdx new file mode 100644 index 0000000..edb9ec1 --- /dev/null +++ b/docs/src/content/docs/rna/bigwig.mdx @@ -0,0 +1,214 @@ +--- +title: bigWig Coverage Tracks +description: Genome-wide bigWig coverage tracks matching bedtools genomecov and nf-core/rnaseq, generated in the RustQC streaming pass. +--- + +import { Aside, FileTree } from "@astrojs/starlight/components"; + + + +RustQC writes **bigWig** genome coverage tracks during the `rustqc rna` pass. +Coverage follows `bedtools genomecov` v2.31.1, and the default output set is +the three files that nf-core/rnaseq publishes in its `bigwig/` directory. + +## What it replaces + +For each sample, nf-core/rnaseq runs up to three of these chains, one per +track: + +1. `bedtools genomecov` on the genome BAM, then `sort` → bedGraph +2. `bedClip` with the chromosome sizes → clipped bedGraph +3. `bedGraphToBigWig` → `.bigWig` + +RustQC accumulates the coverage in the read loop that the other tools already +use, clips it to the chromosome ends (what `bedClip` does), and writes the +bigWig itself. The writer follows `bedGraphToBigWig`: the same file layout, +the same zoom levels and the same zoom summaries, so genome browsers and +`bigWigSummary` show the same values as for a `bedGraphToBigWig` file. + +## Output files + +The files go in a `bigwig/` subdirectory of the output directory, or directly +in the output directory with `--flat-output`. The names match nf-core/rnaseq. + + +- bigwig/ + - sample.bigWig All reads (every library) + - sample.forward.bigWig Reads from forward-strand transcripts (stranded libraries) + - sample.reverse.bigWig Reads from reverse-strand transcripts (stranded libraries) + + +`forward` and `reverse` refer to the strand of the transcript, so their +`-strand` filter depends on the library. For a reverse-stranded library (for +example dUTP), read 1 lies on the opposite strand to the transcript, and the +labels swap, as nf-core/rnaseq does: + +| Library (`--stranded`) | `sample.forward.bigWig` | `sample.reverse.bigWig` | +| ---------------------- | ----------------------- | ----------------------- | +| `forward` | `-du -strand +` | `-du -strand -` | +| `reverse` | `-du -strand -` | `-du -strand +` | +| `unstranded` | not written by default | not written by default | + +You can ask for the strand tracks of an unstranded library with +`--bigwig-tracks`. Then `forward` is the `+` genome strand and `reverse` is the +`-` genome strand. + +### Equivalent commands (defaults) + +With the default settings, each file is equal to the output of these commands. +`chrom.sizes` holds the reference names and lengths from the BAM header. + +**`sample.bigWig`** (every library): + +```bash +bedtools genomecov -ibam sample.bam -split -bg | LC_ALL=C sort -k1,1 -k2,2n > sample.bedGraph +bedClip sample.bedGraph chrom.sizes sample.clip.bedGraph +bedGraphToBigWig sample.clip.bedGraph chrom.sizes sample.bigWig +``` + +**`sample.forward.bigWig`** (stranded libraries; use `-strand -` for a +reverse-stranded library): + +```bash +bedtools genomecov -ibam sample.bam -split -du -strand + -bg | LC_ALL=C sort -k1,1 -k2,2n > sample.forward.bedGraph +bedClip sample.forward.bedGraph chrom.sizes sample.clip.forward.bedGraph +bedGraphToBigWig sample.clip.forward.bedGraph chrom.sizes sample.forward.bigWig +``` + +**`sample.reverse.bigWig`** (stranded libraries; use `-strand +` for a +reverse-stranded library): + +```bash +bedtools genomecov -ibam sample.bam -split -du -strand - -bg | LC_ALL=C sort -k1,1 -k2,2n > sample.reverse.bedGraph +bedClip sample.reverse.bedGraph chrom.sizes sample.clip.reverse.bedGraph +bedGraphToBigWig sample.clip.reverse.bedGraph chrom.sizes sample.reverse.bigWig +``` + +## Options + +Every option is available in the [YAML config](../usage/configuration/#bigwig) +under `rna.bigwig`, as a CLI flag, and as an environment variable. CLI flags +take precedence over the config file. The options apply to all tracks of a run. + +| YAML key | CLI flag / env var | Default | `bedtools genomecov` | +| --------------- | -------------------------------------------------------- | ----------- | -------------------- | +| `enabled` | `--skip-bigwig` / `RUSTQC_SKIP_BIGWIG` | `true` | (whole step) | +| `tracks` | `--bigwig-tracks` / `RUSTQC_BIGWIG_TRACKS` | see below | `-strand +/-` | +| `split` | `--bigwig-split[=BOOL]` / `RUSTQC_BIGWIG_SPLIT` | `true` | `-split` | +| `du` | `--bigwig-du[=BOOL]` / `RUSTQC_BIGWIG_DU` | `true` | `-du` | +| `scale` | `--bigwig-scale` / `RUSTQC_BIGWIG_SCALE` | `1.0` | `-scale` | +| `bga` | `--bigwig-bga[=BOOL]` / `RUSTQC_BIGWIG_BGA` | `false` | `-bga` (else `-bg`) | +| `read_end` | `--bigwig-read-end` / `RUSTQC_BIGWIG_READ_END` | unset | `-5` (`5p`), `-3` (`3p`) | +| `fragment_size` | `--bigwig-fragment-size` / `RUSTQC_BIGWIG_FRAGMENT_SIZE` | unset | `-fs` | + +- `tracks` is a list of `combined`, `forward` and `reverse` + (`--bigwig-tracks combined,forward`). If it is not set, RustQC writes + `combined`, plus `forward` and `reverse` for stranded libraries. +- The boolean flags accept `--bigwig-bga` (true) or `--bigwig-bga=false`. +- With `bga`, the bigWig stores zero-coverage spans as `0`. Without it, those + spans are gaps, which bigWig readers report as "no data", not `0`. + +### Equivalent commands (any settings) + +For any settings, a track is equal to this command, followed by the same +`sort`, `bedClip` and `bedGraphToBigWig` steps as above: + +```bash +bedtools genomecov -ibam sample.bam [-split] [-du -strand +|-] [-scale S] [-5|-3] [-fs N] -bg|-bga +``` + +| Setting | Add to the command | +| ------------------------------- | ------------------------------------------------------------ | +| `split: true` | `-split`, but only if `read_end` and `fragment_size` are unset | +| `forward` / `reverse` track | `-strand` as in the table above, and `-du` if `du: true` | +| `scale` other than 1 | `-scale S` | +| `bga: true` | `-bga` instead of `-bg` | +| `read_end: 5p` / `3p` | `-5` / `-3` | +| `fragment_size: N` | `-fs N` | + +Some combinations follow bedtools rules: + +- `fragment_size` has priority over `read_end`, and both have priority over + `split`. bedtools does the same with `-fs`, and it does not accept `-split` + together with `-5` or `-3`. +- `-du` only changes the strand that `-strand` uses. It has no effect on the + combined track, so nf-core/rnaseq omits it there. +- `-5`, `-3` and `-fs` use the strand of the read itself, not the `-du` strand. + +## Which reads are counted + +The tracks use bedtools' rules, which differ from the other RustQC tools: + +- Only unmapped reads are excluded. Duplicates, secondary and supplementary + alignments, QC-failed reads and reads of any MAPQ all add coverage. +- A `D` (deletion) in the CIGAR always splits a read into blocks. An `N` + (intron) splits it only with `split`. Insertions and clips add nothing. +- Each mate of a pair adds its own coverage, so overlapping mates count twice. +- Coverage past the end of a chromosome is clipped, as `bedClip` does. + +## Replacing bedtools in nf-core/rnaseq + +nf-core/rnaseq publishes `{sample}.bigWig` for every sample, and also +`{sample}.forward.bigWig` and `{sample}.reverse.bigWig` for stranded samples. +RustQC writes the same three files with its defaults. Give the library +strandedness and run it on the same BAM that nf-core/rnaseq gives to +`bedtools genomecov` (the coordinate-sorted, duplicate-marked genome BAM): + +```bash +rustqc rna sample.markdup.sorted.bam --gtf genes.gtf --stranded reverse -o results/ +``` + +Use `--stranded forward`, `reverse` or `unstranded` to match the sample's +`strandedness`. The tracks are in `results/bigwig/`. The other bigWig options +must keep their defaults (`split: true`, `du: true`, `scale: 1.0`, +`bga: false`, no `read_end` or `fragment_size`). To make only the bigWig +files, turn the other tools off in the config file. + +## Requirements and limits + +- The input must be coordinate-sorted. If RustQC finds a read out of order, it + writes no bigWig for that file and shows a warning. The other outputs are + not affected. +- If a track has no coverage (for example the reverse track of a library with + reads on one strand only), RustQC does not write that file and shows a + warning. A bigWig cannot hold an empty track. +- Memory: the live state for each track is only the coverage of reads that + overlap the current position. The finished coverage is kept as 8 bytes for + each change in depth until the end of the pass. +- Not available: `-pc` (paired fragment coverage), `-ignoreD`, `-max`, the + `-d`/`-dz` per-base and histogram outputs, and `-trackline`. + `-pc` needs the end of read 1 and the start of its mate, which can be far + apart, so it does not fit the single streaming pass. + +## Validation + +- Each track and option is compared with real bedtools 2.31.1 + `genomecov` output (`tests/expected/bigwig/`, made by + `tests/create_bigwig_test_data.sh`), on the single-threaded and the parallel + code path. There are two test BAMs: the single-end test BAM, and a small BAM + with reads 1 and 2 on both strands with mapped and unmapped mates, `N` and + `D` CIGARs, a read past the chromosome end, and secondary, duplicate, + QC-failed and supplementary records. The tests decode the written bigWig + files, so they check the file format as well as the intervals. +- UCSC `bigWigToBedGraph` decodes RustQC's files to the same intervals as the + bedtools tracks, and `bigWigInfo` and `bigWigSummary` give the same zoom + levels and summary values as for `bedGraphToBigWig` files made from the + same bedGraph. +- The `.bigWig` files are not byte-identical to `bedGraphToBigWig` output: + the zlib compression and some unused index padding differ. + +## References + +- **bedtools:** Quinlan AR, Hall IM. BEDTools: a flexible suite of utilities + for comparing genomic features. *Bioinformatics*. 2010;26(6):841-842. + [bedtools on GitHub](https://github.com/arq5x/bedtools2) +- **bigWig format:** Kent WJ, Zweig AS, Barber G, Hinrichs AS, Karolchik D. + BigWig and BigBed: enabling browsing of large distributed datasets. + *Bioinformatics*. 2010;26(17):2204-2207. diff --git a/docs/src/content/docs/usage/cli-reference.mdx b/docs/src/content/docs/usage/cli-reference.mdx index eb1e5ac..60a763b 100644 --- a/docs/src/content/docs/usage/cli-reference.mdx +++ b/docs/src/content/docs/usage/cli-reference.mdx @@ -13,11 +13,11 @@ one pass over the BAM file. ## `rna` RNA-seq quality control: duplicate rate analysis (dupRadar equivalent), -featureCounts-compatible read counting with biotype summaries, 8 +featureCounts-compatible read counting with biotype summaries, the RSeQC-equivalent tools (bam_stat, infer_experiment, read_duplication, read_distribution, junction_annotation, junction_saturation, inner_distance, -TIN), Qualimap RNA-seq QC, preseq library complexity, and samtools-compatible -outputs. +TIN, split_bam), Qualimap RNA-seq QC, bigWig genome coverage tracks, preseq +library complexity, and samtools-compatible outputs. ### Synopsis @@ -79,6 +79,11 @@ Library strandedness for strand-aware read counting: **Default:** `unstranded` +For **bigWig coverage tracks**, stranded libraries also get +`{sample}.forward.bigWig` and `{sample}.reverse.bigWig`, with the +nf-core/rnaseq strand filters. Unstranded libraries get only `{sample}.bigWig`. +See [bigWig](../rna/bigwig/) for details. +