def open_asg(in_fn, in_format):
# try to detect kraken and histo formats automatically
if in_format is None:
if '.' in in_fn:
f_ext = in_fn.split('.')[-1]
if f_ext in IN_FMTS:
in_format = f_ext
else:
with open(in_fn, 'rb') as f:
f_start = f.read(2)
if f_start == b'C\t' or f_start == b'U\t':
in_format = 'kraken'
elif f_start == b'#O':
in_format = 'histo'
if in_format == 'sam':
in_f = pysam.AlignmentFile(in_fn, "r")
elif in_format == 'bam':
in_f = pysam.AlignmentFile(in_fn, "rb")
elif in_format == 'cram':
in_f = pysam.AlignmentFile(in_fn, "rc")
elif in_format == 'uncompressed_bam':
in_f = pysam.AlignmentFile(in_fn, "ru")
elif in_format == 'kraken':
in_f = open(in_fn, 'r')
# no need to load assignments if input is a histogram -> go to load_histo
elif in_format == 'histo':
in_f = None
# let pysam assess the format
else:
in_f = pysam.AlignmentFile(in_fn)
return in_f, in_format
评论列表
文章目录