Skip to content

Fix ONT bam file ML/MM parsing for h and m modifications - #112

Open
kpalin wants to merge 2 commits into
nloyfer:masterfrom
kpalin:master
Open

Fix ONT bam file ML/MM parsing for h and m modifications#112
kpalin wants to merge 2 commits into
nloyfer:masterfrom
kpalin:master

Conversation

@kpalin

@kpalin kpalin commented Mar 26, 2026

Copy link
Copy Markdown
  1. Added missing "#import " as suggested by g++ 15.2.
  2. Used claude code to test and fix the error in parsing ONT bam file with C+m and C+h calls.

Works for me. Claude hallusinated the new build target in setup.py (which is not modified)

kpalin and others added 2 commits March 26, 2026 07:19
When a read carries both 5hmC (C+h) and 5mC (C+m) modifications with
different position counts, the ML probability array was sliced using
MM_pos * nr_MM_vals as the offset — implicitly assuming equal block sizes.
This caused the guard condition to fail (e.g. 611 >= 956 is false for
real ONT reads with ~133 C+h and ~478 C+m positions), leaving ML_str
un-trimmed and triggering a size-mismatch throw in parse_np_fields_by_mod.

Fix: compute ml_offset as the cumulative sum of position counts from all
prior MM sections before overwriting MM_str. Matches the SAM spec that
ML values are ordered identically to MM positions across all sections.

Add test_ont_ml.cpp with 5 unit tests covering unequal counts (both
orderings), equal counts, and only-m cases.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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