Summary: When a BAM contains alignment records with both the SECONDARY (0x100) and SUPPLEMENTARY (0x800) flags set, RustQC's flagstat module counts those records in both the secondary and supplementary totals, inflating the supplementary count and breaking primary + secondary + supplementary == total. Real samtools flagstat gives the SECONDARY flag priority and counts such dual-flagged records only as secondary.
Environment:
- RustQC 0.2.1 (
c868466, built 2026-04-09), Docker image seqinfomics/rustqc:0.2.1, run via Apptainer 1.4.5
- Input: paired-end STAR-aligned BAM (
--paired), single contig, 156,370 total records
Steps to reproduce:
rustqc rna sample.bam --gtf annotation.gtf --paired --stranded reverse --skip-dup-check --outdir out/
Flag breakdown of the input BAM (via samtools view | awk bitwise check):
| category |
count |
| primary (neither flag) |
154,662 |
| secondary-only |
309 |
| supplementary-only |
587 |
| both secondary+supplementary |
812 |
| total |
156,370 |
Expected (matches real samtools flagstat 1.21):
154662 + 0 primary
1121 + 0 secondary (309 + 812)
587 + 0 supplementary (587-only)
Actual (RustQC's flagstat output):
154662 + 0 primary
1121 + 0 secondary (matches, 309 + 812)
1399 + 0 supplementary (587 + 812 <- the 812 dual-flagged reads are counted again here)
Note 154662 + 1121 + 1399 = 157182, which exceeds the true total of 156370 — the sum invariant that samtools flagstat maintains is violated.
Fix suggestion: In the flagstat counting logic, categorize each record by flag priority (secondary > supplementary > primary) rather than checking the supplementary bit independently of the secondary bit.
Summary: When a BAM contains alignment records with both the
SECONDARY(0x100) andSUPPLEMENTARY(0x800) flags set, RustQC'sflagstatmodule counts those records in both thesecondaryandsupplementarytotals, inflating the supplementary count and breakingprimary + secondary + supplementary == total. Realsamtools flagstatgives theSECONDARYflag priority and counts such dual-flagged records only as secondary.Environment:
c868466, built 2026-04-09), Docker imageseqinfomics/rustqc:0.2.1, run via Apptainer 1.4.5--paired), single contig, 156,370 total recordsSteps to reproduce:
Flag breakdown of the input BAM (via
samtools view | awkbitwise check):Expected (matches real
samtools flagstat 1.21):Actual (RustQC's
flagstatoutput):Note
154662 + 1121 + 1399 = 157182, which exceeds the true total of156370— the sum invariant thatsamtools flagstatmaintains is violated.Fix suggestion: In the flagstat counting logic, categorize each record by flag priority (secondary > supplementary > primary) rather than checking the supplementary bit independently of the secondary bit.