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)