Skip to content

fix(featurecounts): select and pair records like Subread - #206

Merged
ewels merged 1 commit into
seqeralabs:mainfrom
rhassaine:fix/featurecounts-read-selection-v3
Nov 27, 2026
Merged

ewels merged 1 commit into
seqeralabs:mainfrom
rhassaine:fix/featurecounts-read-selection-v3

Conversation

@rhassaine

@rhassaine rhassaine commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Makes featureCounts-style counting and dupRadar's paired-end counting select and pair records like Subread:

  • supplementary (0x800) and QC-fail (0x200) records are counted, since Subread has no filter on those flags;
  • records are paired by Subread's key (read name cut at /, unmapped self or mate as -1/0), whatever their direction;
  • a fragment is a duplicate or multi-mapper if either record is;
  • cross-chromosome pairs are paired in BAM order, so the output is the same for any --threads.

Unit tests built from hand-written SAM records cover supplementary, QC-fail, secondary with NH, and split vs sequential pairing. No nf-core RNA test BAM has supplementary or QC-fail records, so there's no new test data (see the note in the test module).

Checked against featureCounts 2.1.1 and Rsubread 2.20.0 / dupRadar 1.38.0 on a copy of the chr6 test BAM with secondary, supplementary and QC-fail records added: 0 differences in counts and summary at --threads 1, 2 and 6. Outputs on 8 public datasets are unchanged.

One known gap, documented on the featureCounts page: for a fragment whose records come in the order R2, other, R1, R1-supplementary, Rsubread pairs each record with the one just before it, so dupRadar's duplication matrix can shift by one for that fragment's gene. It doesn't occur in STAR output or the nf-core test data.

🤖 Generated with Claude Code

Make featureCounts-style counting and the dupRadar paired-end counting
follow Subread's readSummary.c and the Rsubread pairer instead of
RustQC's own rules.

Read selection:
- supplementary (0x800) and QC-fail (0x200) records are counted: Subread
  has no filter on those flags, so neither did we need one;
- records are paired by featureCounts' pairer key regardless of
  direction: the read name cut at '/', and an unmapped self or mate
  recorded as -1/0; unmapped reads placed next to their mate are included;
- a fragment is evaluated as Rsubread's process_line_buffer does: the later
  record first, Unmapped only if it and its mate are both unmapped, and
  duplicate / multi-mapped if either record is.

Cross-chromosome pairs are paired in BAM order, so the sequential and the
parallel path (any --threads) give the same pairs and the same gene counts.

Known gap, documented in the featureCounts page: for supplementary records ordered
R2, other, R1, R1-supplementary Rsubread pairs by the previous record, so dupRadar's
duplication matrix can differ by +-1 for that gene. Counts and summary are unaffected.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@rhassaine
rhassaine force-pushed the fix/featurecounts-read-selection-v3 branch from 9352289 to e6a0e01 Compare November 27, 2026 15:04

@ewels ewels left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ewels
ewels merged commit 5e9ab4e into seqeralabs:main Nov 27, 2026
7 checks passed
@rhassaine
rhassaine deleted the fix/featurecounts-read-selection-v3 branch November 27, 2026 15:52
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.

2 participants