def bam_open(fname, mode='r', *args, **kwargs):
    if fname.lower()[-4:] == '.bam':
        return pysam.Samfile(fname, '%sb' % mode, *args, **kwargs)
    return pysam.Samfile(fname, '%s' % mode, *args, **kwargs)
dataset/ETHPy150Open ngsutils/ngsutils/ngsutils/bam/__init__.py/bam_open/original