Skip to content

Commit

Permalink
add support for bgz suffix
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesli124 committed Jan 6, 2025
1 parent eb28db5 commit 430e726
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/finaletoolkit/utils/_filter_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,14 @@ def filter_file(

if input_file.endswith(".gz"):
suffix = ".gz"
elif input_file.endswith(".bgz"):
suffix = ".bgz"
elif input_file.endswith(".bam"):
suffix = ".bam"
elif input_file.endswith(".cram"):
suffix = ".cram"
else:
raise ValueError('Input file should have suffix .bam, .cram, or .gz')
raise ValueError('Input file should have suffix .bam, .cram, .bgz, or .gz')

# create tempfile to contain filtered output
if output_file is None:
Expand Down Expand Up @@ -195,7 +197,7 @@ def filter_file(
finally:
pysam.set_verbosity(save)

elif input_file.endswith('.gz'):
elif input_file.endswith('.gz') or input_file.endswith('.bgz'):
with gzip.open(input_file, 'r') as infile, open(temp_1, 'w') as outfile:
mapq_column = 0 # 1-index for sanity when comparing with len()
for line in infile:
Expand Down Expand Up @@ -284,5 +286,5 @@ def filter_file(
traceback.print_exc()
exit(1)
else:
raise ValueError("Input file must be a BAM, CRAM, or BED file.")
raise ValueError("Input file must be a BAM, CRAM, or bgzipped BED file.")
return output_file

0 comments on commit 430e726

Please sign in to comment.