diff --git a/scripts/rename_reads_for_bam.py b/scripts/rename_reads_for_bam.py new file mode 100644 index 0000000000000000000000000000000000000000..432267c5ac7d10f4a5a0971acb82da43d9c8b14f --- /dev/null +++ b/scripts/rename_reads_for_bam.py @@ -0,0 +1,35 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- + +# Author: Xiaofei Zeng +# Email: xiaofei_zeng@whu.edu.cn +# Created Time: 2023-12-18 15:27 + + +import argparse +import os + +def rename_reads(bam): + + n = 0 + with os.popen('samtools view -h {}'.format(bam)) as f: + for line in f: + if not line.strip(): + continue + if line.startswith('@'): + print(line, end='') + elif line.split()[1] != '0': + print('read{}\t{}'.format(n//2, line.split('\t', 1)[-1]), end='') + n += 1 + + +def main(): + parser = argparse.ArgumentParser() + parser.add_argument('bam', help='paired-end bam output by wf-pore-c') + args = parser.parse_args() + + rename_reads(args.bam) + + +if __name__ == '__main__': + main() \ No newline at end of file