khyox / recentrifuge

Recentrifuge: robust comparative analysis and contamination removal for metagenomics
http://www.recentrifuge.org
Other
86 stars 7 forks source link

Update kraken.py to support compressed inputs #21

Closed XiaoJianfeng closed 4 years ago

XiaoJianfeng commented 4 years ago

The output file of kraken might be very large (hundreds Mb or even larger), so I think it might be useful to support compressed files as input.

A wrapper was added to open compressed/uncompressed kraken output file. Both gzip and bzip2 format are supported, as well as uncompressed file.

def open_compressed_and_uncompressed(filename): ext = os.path.splitext(filename)[1] if ext == '.gz': import gzip return gzip.open(filename, mode='rt') elif ext == '.bz2': import bz2 return bz2.open(filename, mode='rt') else: return open(filename, mode='rt')

XiaoJianfeng commented 4 years ago

Thanks. I'm so glad it is accepted.