From 7624b051eaef713e3e47ae3647fcd39e37d94882 Mon Sep 17 00:00:00 2001 From: Arslan Tariq <arslan.tariq@hhu.de> Date: Tue, 6 Aug 2024 09:08:53 +0000 Subject: [PATCH] Add new file --- scripts/rename_reads_for_bam.py | 35 +++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 scripts/rename_reads_for_bam.py diff --git a/scripts/rename_reads_for_bam.py b/scripts/rename_reads_for_bam.py new file mode 100644 index 0000000..432267c --- /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 -- GitLab