Skip to content

feat(simulate): support different R1 and R2 read lengths - #28

Open
tfenne wants to merge 1 commit into
mainfrom
tf/asymmetric-read-lengths
Open

tfenne wants to merge 1 commit into
mainfrom
tf/asymmetric-read-lengths

Conversation

@tfenne

@tfenne tfenne commented Oct 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

simulate --read-length now takes one or two values. One value sets both reads, as before; two values (--read-length 150 100) set R1 and R2 separately. Two values are rejected with --single-end, and three values (or repeating the flag) are rejected by clap.

With different lengths:

  • The Illumina error model ramps each read over its own length (the ramp starts at 70% of that read's length), and builds per-cycle tables of each read's length.
  • The number of pairs simulated for --coverage uses R1 + R2 bases per pair.
  • The golden BAM soft-clips each mate's own adapter run, and the --cpg-truth-bedgraph tally counts each mate over its own genomic span. Both now take the mate's reference positions from one helper, read::mate_ref_positions, which replaces three copies of that slicing.

Reproducibility

A single value, or two equal values, keeps the legacy seed string and produces the same reads as main: I compared release builds of main (ac66f99) and this branch with -l 100 and -l 100 100, and the R1/R2 FASTQs and golden BAM records are byte-identical. When the lengths differ, the R2 length is appended to the seed string as a trailing suffix, so swapped lengths get different seeds.

Library API

IlluminaErrorModel::new / with_r2_multiplier take an R1 and an R2 length, generate_read_pair takes r1_length and r2_length, and Simulate::read_length is a Vec<usize>.

Testing

  • cargo ci-fmt, cargo ci-lint, cargo ci-test.
  • Unit tests: per-read error ramps and table lengths; read pairs with different lengths on forward and reverse fragments, with per-mate adapter soft-clips and with indels; mate_ref_positions; the seed for equal, different and swapped lengths; coverage maths; validation.
  • Integration tests: FASTQ base and quality lengths per read; golden BAM soft-clips per mate for fragments between the two lengths; -l 100 and -l 100 100 produce identical FASTQs; CLI rejection of three values and of two values with --single-end; with -l 30 90, every CpG truth bedGraph site has at most the calls rebuilt from the golden BAM's YM:Z tags, and the totals nearly match. I checked that this test fails if the tally swaps the two lengths, flips a mate's strand, or tallies R2 over R1's length.

Summary by CodeRabbit

  • New Features
    • Paired-end simulations can now use different read lengths for R1 and R2. A single length still applies to both reads, and equal lengths preserve previous output and seed behavior.
    • Each read’s error profile, adapter clipping, and coverage calculations now reflect its own length.
  • Documentation
    • Updated simulation options and read-name guidance to explain separate read lengths and their use with single-end mode.

--read-length now takes one or two values. One value sets both reads as
before; two values (R1 R2) set each read's length. The error model ramps
each read over its own length, coverage accounts for both lengths, and
the golden BAM and CpG truth tally use each mate's own genomic span.
Two values are rejected with --single-end. Single-value runs (or two
equal values) keep the legacy seed and produce identical output.
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ede3ed02-b908-4614-a490-b197e9c9190e
📥 Commits

Reviewing files that changed from the base of the PR and between ac66f99 and a8610f7.

📒 Files selected for processing: 7
  • CHANGELOG.md
  • README.md
  • src/commands/simulate.rs
  • src/error_model/illumina.rs
  • src/read.rs
  • tests/test_simulate.rs
  • tests/test_simulate_meth.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

Simulation now accepts separate R1 and R2 lengths for paired-end reads. The lengths apply to error ramps, read generation, adapter clipping, coverage counts, and CpG position tallying. A single length still applies to both mates, and two lengths are rejected in single-end mode.

Changes: Paired Read Lengths

Layer / File(s) Summary
Read-length CLI and run configuration
src/commands/simulate.rs, README.md, CHANGELOG.md
The CLI accepts one or two positive lengths. Two lengths are rejected in single-end mode. Seed derivation preserves the existing value when lengths match, and paired-end coverage counts use the sum of both lengths.
Mate-specific error ramps
src/error_model/illumina.rs, src/commands/simulate.rs
The error model stores R1 and R2 lengths and computes each mate’s ramp and parameter table for its own length.
Mate-specific read generation
src/read.rs, README.md
Read generation uses each mate’s requested length for base extraction, reference positions, adapter padding, and alignment details.
Simulation outputs and integration checks
src/commands/simulate.rs, tests/test_simulate.rs, tests/test_simulate_meth.rs
Simulation passes separate lengths to read generation and CpG tallying. Tests check FASTQ and BAM lengths, CLI validation, equal-length output consistency, and CpG counts.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Sequence Diagram(s)

sequenceDiagram
  participant SimulateCLI
  participant Simulate
  participant IlluminaErrorModel
  participant generate_read_pair
  participant SimulationOutputs
  SimulateCLI->>Simulate: Provide one or two read lengths
  Simulate->>IlluminaErrorModel: Initialize with resolved R1 and R2 lengths
  Simulate->>generate_read_pair: Generate mates with separate lengths
  generate_read_pair->>SimulationOutputs: Return mate reads and alignment details
  Simulate->>SimulationOutputs: Tally CpG positions using each mate length
Loading

Suggested reviewers: nh13

Merge Risk: ⚪ Minimal · up to a8610

This change lets simulate accept separate R1 and R2 read lengths while preserving behavior for single and equal lengths. Tests cover the main paths, and no merge-blocking risk is evident.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: support for different R1 and R2 read lengths in simulation.
Docstring Coverage Passed Docstring coverage is 97.30% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 74 functions across 5 files. (2 skipped: 2 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 97.30% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 74 functions across 5 files. (2 skipped: 2 unsupported.)

✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checks each read-length run,
With R1 and R2 hopping in the sun.
Two ramps rise to fit each read,
Soft clips match the bases they need.
FASTQ and BAM keep counts in view,
Then off goes the rabbit, pleased and true.

Comment @coderabbitai help to get the list of available commands.

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