diff --git a/CRISPResso2/CRISPRessoPooledCORE.py b/CRISPResso2/CRISPRessoPooledCORE.py index 6cdeea0c..acd101db 100644 --- a/CRISPResso2/CRISPRessoPooledCORE.py +++ b/CRISPResso2/CRISPRessoPooledCORE.py @@ -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]) diff --git a/tests/unit_tests/test_CRISPRessoPooledCORE.py b/tests/unit_tests/test_CRISPRessoPooledCORE.py index c7bc36af..86a02bc1 100644 --- a/tests/unit_tests/test_CRISPRessoPooledCORE.py +++ b/tests/unit_tests/test_CRISPRessoPooledCORE.py @@ -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)}'