From 3689e1c994a3c421cc45b402d18f677e8afd64e1 Mon Sep 17 00:00:00 2001 From: Haibao Tang Date: Fri, 9 Aug 2024 12:00:42 -0700 Subject: [PATCH] Add --chrprefix --- jcvi/formats/bed.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/jcvi/formats/bed.py b/jcvi/formats/bed.py index eb6886f5..f949db02 100755 --- a/jcvi/formats/bed.py +++ b/jcvi/formats/bed.py @@ -593,6 +593,7 @@ def format(args): Re-format BED file, e.g. switch sequence ids. """ p = OptionParser(format.__doc__) + p.add_argument("--chrprefix", help="Add prefix to seqid") p.add_argument("--prefix", help="Add prefix to name column (4th)") p.add_argument("--switch", help="Switch seqids based on two-column file") p.set_outfile() @@ -604,11 +605,14 @@ def format(args): (bedfile,) = args switch = DictFile(opts.switch, delimiter="\t") if opts.switch else None prefix = opts.prefix + chrprefix = opts.chrprefix bed = Bed(bedfile) with must_open(opts.outfile, "w") as fw: for b in bed: if prefix: b.accn = prefix + b.accn + if chrprefix: + b.seqid = chrprefix + b.seqid if switch and b.seqid in switch: b.seqid = switch[b.seqid] print(b, file=fw)