Skip to content

Store PNEXT and TLEN as differences from what the record predicts - #113

Merged
mvassilev merged 1 commit into
developfrom
feature/mate-fields
Oct 17, 2026
Merged

mvassilev merged 1 commit into
developfrom
feature/mate-fields

Conversation

@mvassilev

Copy link
Copy Markdown
Collaborator

PNEXT and TLEN were stored as SAM has them, although most of what they
hold is in other columns: the mate is usually a few hundred bases from
POS, and TLEN follows from the two positions, the strands and the
spans. On chr20 of NA12878 at 30x, 17.7 million records, they took 57
of the 563 MB of the file.

The record now stores pnext_delta, PNEXT minus POS when the mate is on
the record's reference and PNEXT otherwise, and tlen_delta, TLEN minus
PredictTLEN(). The prediction is the distance between the 5' ends of
the pair as BWA and Picard compute it, with the mate's span taken to be
the record's own, so it needs no tag. Both are differences modulo 2^32,
so every value comes back exactly. RAMMateOnSameRef() decides whether
the mate is on the same reference for the converters and for
RAMFile::MateOnSameRef(), so writing and reading cannot disagree.
SetMate() replaces SetPNEXT() and SetTLEN(), and GetPNEXT() and
GetTLEN() take that answer. The columns are renamed, so a program that
reads them directly does not mistake them for the SAM values;
CONTRIBUTING says how to get those. The format version becomes 6.

On that chr20 tlen_delta is 0 for 95% of the records. The file goes
from 563.1 to 531.0 MB (-5.7%) from SAM and from 562.9 to 530.7 MB
from BAM, and ramdump -h gives the same bytes as before for both.
Full and region dumps, and conversion from SAM on 4 threads and from
BAM on 2 million records, take the same time within the noise of
alternating runs. flagstat and idxstats are unchanged.

PNEXT and TLEN were stored as SAM has them, although most of what they
hold is in other columns: the mate is usually a few hundred bases from
POS, and TLEN follows from the two positions, the strands and the
spans. On chr20 of NA12878 at 30x, 17.7 million records, they took 57
of the 563 MB of the file.

The record now stores pnext_delta, PNEXT minus POS when the mate is on
the record's reference and PNEXT otherwise, and tlen_delta, TLEN minus
PredictTLEN(). The prediction is the distance between the 5' ends of
the pair as BWA and Picard compute it, with the mate's span taken to be
the record's own, so it needs no tag. Both are differences modulo 2^32,
so every value comes back exactly. RAMMateOnSameRef() decides whether
the mate is on the same reference for the converters and for
RAMFile::MateOnSameRef(), so writing and reading cannot disagree.
SetMate() replaces SetPNEXT() and SetTLEN(), and GetPNEXT() and
GetTLEN() take that answer. The columns are renamed, so a program that
reads them directly does not mistake them for the SAM values;
CONTRIBUTING says how to get those. The format version becomes 6.

On that chr20 tlen_delta is 0 for 95% of the records. The file goes
from 563.1 to 531.0 MB (-5.7%) from SAM and from 562.9 to 530.7 MB
from BAM, and `ramdump -h` gives the same bytes as before for both.
Full and region dumps, and conversion from SAM on 4 threads and from
BAM on 2 million records, take the same time within the noise of
alternating runs. flagstat and idxstats are unchanged.
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.46835% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.64%. Comparing base (5a963cd) to head (5014ac8).

Files with missing lines Patch % Lines
src/rntuple/RAMNTupleRecord.cxx 95.65% 0 Missing and 1 partial ⚠️
test/bam_conversion.cxx 91.66% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #113      +/-   ##
===========================================
+ Coverage    88.47%   88.64%   +0.16%     
===========================================
  Files           25       25              
  Lines         2968     3029      +61     
  Branches       980     1004      +24     
===========================================
+ Hits          2626     2685      +59     
  Misses         185      185              
- Partials       157      159       +2     
Flag Coverage Δ
unittests 88.64% <97.46%> (+0.16%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
inc/rntuple/RAMFile.h 100.00% <100.00%> (ø)
inc/rntuple/RAMNTupleRecord.h 100.00% <100.00%> (ø)
src/ramcore/BamtoNTuple.cxx 88.35% <100.00%> (ø)
src/ramcore/SamToNTuple.cxx 89.50% <100.00%> (-0.03%) ⬇️
test/parallel_conversion_test.cxx 98.67% <100.00%> (+<0.01%) ⬆️
test/ramcoretests.cxx 100.00% <100.00%> (ø)
test/ramdump_test.cxx 99.13% <100.00%> (+0.15%) ⬆️
tools/ramdump.cxx 85.71% <100.00%> (+0.07%) ⬆️
src/rntuple/RAMNTupleRecord.cxx 78.97% <95.65%> (+1.76%) ⬆️
test/bam_conversion.cxx 88.02% <91.66%> (+0.28%) ⬆️
Files with missing lines Coverage Δ
inc/rntuple/RAMFile.h 100.00% <100.00%> (ø)
inc/rntuple/RAMNTupleRecord.h 100.00% <100.00%> (ø)
src/ramcore/BamtoNTuple.cxx 88.35% <100.00%> (ø)
src/ramcore/SamToNTuple.cxx 89.50% <100.00%> (-0.03%) ⬇️
test/parallel_conversion_test.cxx 98.67% <100.00%> (+<0.01%) ⬆️
test/ramcoretests.cxx 100.00% <100.00%> (ø)
test/ramdump_test.cxx 99.13% <100.00%> (+0.15%) ⬆️
tools/ramdump.cxx 85.71% <100.00%> (+0.07%) ⬆️
src/rntuple/RAMNTupleRecord.cxx 78.97% <95.65%> (+1.76%) ⬆️
test/bam_conversion.cxx 88.02% <91.66%> (+0.28%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown

clang-tidy review says "All clean, LGTM! 👍"

@mvassilev
mvassilev merged commit a03b3e8 into develop Oct 17, 2026
4 checks passed
@mvassilev
mvassilev deleted the feature/mate-fields branch October 17, 2026 16:44
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