Skip to content

Conversation

althonos
Copy link
Contributor

Hi!

This PR adds a filter method to AlignmentFile to support reading flags that have given flags set or unset. This is faster than doing this test in a for loop in the Python code because it avoids a useless copy of reads that are discarded.

For instance, on a BAM file with 6,369,435 reads with only 315,068 of them being mapped, iterating with

for read in AlignmentFile("reads.bam").filter(flag_filter=FUNMAP):
    pass

is about 2x faster than:

for read in AlignmentFile("reads.bam"):
    if read.is_mapped:
        pass

I added some tests and type hints as well.

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