def filter_length(self, output_filename, threshold_min=0,
threshold_max=np.inf):
"""Select and Write reads within a given range
:param str output_filename: name of output file
:param int threshold_min: minimum length of the reads to keep
:param int threshold_max: maximum length of the reads to keep
"""
assert threshold_min < threshold_max
assert output_filename != self.filename, \
"output filename should be different from the input filename"
self.reset()
with pysam.AlignmentFile(output_filename, "wb", template=self.data) as fh:
for read in self.data:
if ((read.query_length > threshold_min) & (read.query_length < threshold_max)):
fh.write(read)
评论列表
文章目录