Skip to content

Add support for filtering rows by flags #1337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

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