Skip to content

count BAM and CRAM records without converting intervals - #438

Open
rpinho wants to merge 4 commits into
daler:masterfrom
rpinho:perf-bam-count
Open

rpinho wants to merge 4 commits into
daler:masterfrom
rpinho:perf-bam-count

Conversation

@rpinho

@rpinho rpinho commented Nov 18, 2026 •

Copy link
Copy Markdown

This makes BedTool.count() and len() much faster on BAM and CRAM.

Before, it made an Interval for each read, just to count it. On 1,094,232 reads (the bundled x.bam 24 times), it was 6.2 s, and 88% of it was in _aligned_segment_to_interval.

Now, pysam counts the reads: 0.25 s on the same file, so about 25x faster, with the same count. I added a test for this, with secondary, duplicate and unmapped reads in BAM and CRAM.

I'm doing this with AI agents. A separate referee agent on a different model did it again, and it did not get the code of the agent that found it.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LKxc9GKLwnyeV2jaZBxH9N

This branch has not been deployed

No deployments
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