Skip to content

Instantly share code, notes, and snippets.

@satta
Created June 1, 2015 20:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satta/432035142884804566a8 to your computer and use it in GitHub Desktop.
Save satta/432035142884804566a8 to your computer and use it in GitHub Desktop.
add_mrna.lua
#!/usr/bin/env gt
function usage()
io.stderr:write(string.format("Usage: %s <GFF annotation>\n" , arg[0]))
os.exit(1)
end
if #arg < 1 then
usage()
end
visitor = gt.custom_visitor_new()
function visitor:visit_feature(fn)
if fn:get_type() == "gene" then
new_mrna = gt.feature_node_new(fn:get_seqid(), "mRNA",
fn:get_range():get_start(),
fn:get_range():get_end(),
fn:get_strand())
fn:add_child(new_mrna)
new_mrna:set_source(fn:get_source())
new_mrna:add_attribute("ID", fn:get_attribute("ID") .. ".1")
for node in fn:children() do
if node:get_type() == "CDS" then
fn:remove_leaf(node)
new_mrna:add_child(node)
end
end
end
return 0
end
-- make simple visitor stream, just applies given visitor to every node
visitor_stream = gt.custom_stream_new_unsorted()
function visitor_stream:next_tree()
local node = self.instream:next_tree()
if node then
node:accept(self.vis)
end
return node
end
visitor_stream.instream = gt.gff3_in_stream_new_sorted(arg[1])
visitor_stream.vis = visitor
outstream = gt.gff3_out_stream_new(visitor_stream)
local gn = outstream:next_tree()
while (gn) do
gn = outstream:next_tree()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment