Skip to content

Commit

Permalink
Add --chrprefix
Browse files Browse the repository at this point in the history
  • Loading branch information
tanghaibao committed Aug 9, 2024
1 parent afb7b2d commit 3689e1c
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jcvi/formats/bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand Down

0 comments on commit 3689e1c

Please sign in to comment.