Skip to content
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

Add support for octal and comma separated samtools exclude flags #113

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CRISPResso2/CRISPRessoPooledCORE.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,17 @@ def calculate_aligned_samtools_exclude_flags(samtools_exclude_flags):
by filtering 0x900 (not primary alignment and supplementary alignment)
and also including any other user specified filters.
"""
samtools_exclude_flags = int(samtools_exclude_flags, base=16)
if ',' in samtools_exclude_flags:
return f'{samtools_exclude_flags},{hex(0x900)}'
elif samtools_exclude_flags.startswith('0x'):
samtools_exclude_flags = int(samtools_exclude_flags, base=16)
elif samtools_exclude_flags.startswith('0'):
samtools_exclude_flags = int(samtools_exclude_flags, base=8)
else:
samtools_exclude_flags = int(samtools_exclude_flags)
return hex(0x900 | samtools_exclude_flags)


def get_n_aligned_bam(bam_filename, samtools_exclude_flags):
p = sb.Popen(f"samtools view -F {calculate_aligned_samtools_exclude_flags(samtools_exclude_flags)} -c {bam_filename}", shell=True, stdout=sb.PIPE)
return int(p.communicate()[0])
Expand Down
10 changes: 10 additions & 0 deletions tests/unit_tests/test_CRISPRessoPooledCORE.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,13 @@ def test_calculate_aligned_samtools_exclude_flags_9():

def test_calculate_aligned_samtools_exclude_flags_0x100():
assert CRISPRessoPooledCORE.calculate_aligned_samtools_exclude_flags('0x100') == hex(0x900)


def test_calculate_aligned_samtools_exclude_flags_010():
"""This tests for proper handling of octal numbers."""
assert CRISPRessoPooledCORE.calculate_aligned_samtools_exclude_flags('010') == hex(0x908)


def test_calculate_aligned_samtools_exclude_flags_comma():
"""This tests for proper handling of commas."""
assert CRISPRessoPooledCORE.calculate_aligned_samtools_exclude_flags('0,4') == f'0,4,{hex(0x900)}'
Loading