Bedtools CRAM support
Closed this issue · 0 comments
eugenegardner commented
It appears that pybedtools does not support cram at the moment since it was added to bedtools in version 2.28 this past May. This mainly appears due to:
- Some bedtools requiring the
-ibam
flag instead of the-i
flag and - pybedtools checking only for the bam magic number when deciding whether to use the
-ibam
flag or not.
This can be seen in the code snippet of helpers.py
:
def isBAM(fn):
"""
Returns True if the file is both BGZIPed and the compressed contents have
start with the magic number `BAM\\x01`.
"""
# Note: previously we were catching ValueError when trying to open
# a non-BAM with pysam.Samfile. That started segfaulting, so now do it the
# right way with magic number.
if isBGZIP(fn) and (gzip.open(fn, 'rb').read(4).decode() == 'BAM\x01'):
return True
You can backdoor this functionality by doing something like:
bt = bedtools.BedTool(self.input_bam)
bt._isbam = True
bg_file = bt.genome_coverage(bg=True)
But this feels like bad coding practice. Figured it's reasonably quick fix to check for the CRAM magic number as well?