Skip to content

Commit

Permalink
Add two options to gff.bed()
Browse files Browse the repository at this point in the history
  • Loading branch information
Haibao Tang committed Oct 5, 2023
1 parent 7e4c5e5 commit b4cfc67
Showing 1 changed file with 21 additions and 5 deletions.
26 changes: 21 additions & 5 deletions jcvi/formats/gff.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,6 @@ def to_range(obj, score=None, id=None, strand=None):


def main():

actions = (
("addparent", "merge sister features and infer their parent"),
("bed", "parse gff and produce bed file for particular feature type"),
Expand Down Expand Up @@ -3022,6 +3021,18 @@ def bed(args):
default="Parent",
help="Parent gene key to group with --primary_only",
)
p.add_option(
"--add_chr",
default=False,
action="store_true",
help="Add `chr` prefix to seqid",
)
p.add_option(
"--ensembl_cds",
default=False,
action="store_true",
help="Use transcript_name.exon_number as accn",
)
p.set_outfile()

opts, args = p.parse_args(args)
Expand All @@ -3036,6 +3047,8 @@ def bed(args):
span = opts.span
primary_only = opts.primary_only
parent_key = opts.parent_key
add_chr = opts.add_chr
ensembl_cds = opts.ensembl_cds

if opts.type:
type = set(x.strip() for x in opts.type.split(","))
Expand Down Expand Up @@ -3072,6 +3085,13 @@ def bed(args):
bl.accn = accn
if span:
bl.score = bl.span
if add_chr:
bl.seqid = "chr" + bl.seqid
if ensembl_cds:
bl.accn = "{0}.{1}".format(
g.get_attr("transcript_name"), g.get_attr("exon_number")
)

b.append(bl)

sorted = not opts.nosort
Expand Down Expand Up @@ -3134,7 +3154,6 @@ def children(args):
parents = set(opts.parents.split(","))

for feat in get_parents(gff_file, parents):

cc = [c.id for c in g.children(feat.id, 1)]
if len(cc) <= 1:
continue
Expand Down Expand Up @@ -3513,7 +3532,6 @@ def get_coords(feature, site, fLen, seqlen, feat, children_list, gffdb):
elif site in ["TrSS", "TrES"]:
children = []
for c in gffdb.children(feat.id, 1):

if c.featuretype not in children_list:
continue
children.append((c.start, c.stop))
Expand Down Expand Up @@ -3686,7 +3704,6 @@ def bed12(args):
fw = must_open(outfile, "w")

for f in g.features_of_type(parent):

chrom = f.chrom
chromStart = f.start - 1
chromEnd = f.stop
Expand All @@ -3701,7 +3718,6 @@ def bed12(args):
blocks = []

for c in g.children(name, 1):

cstart, cend = c.start - 1, c.stop

if c.featuretype == block:
Expand Down

0 comments on commit b4cfc67

Please sign in to comment.