[BioRuby] Bio::Tree::Newick class

Daniel Amelang daniel.amelang at gmail.com
Thu Jul 6 10:11:20 UTC 2006


I'm attaching a zipped tar file with a Bio::Tree::Newick class I wrote
a year and half ago (I hope the attachment goes through). It provides
a newick tree parser, a simple API for manipulating trees, and a
newick tree output generator. It could easily be refactored into a
more general tree library, if the need arose. I've documented the code
quite a bit (although it doesn't have a users manual) and it comes
with a test/unit fixture.

Sense the time I wrote this, I've left the field of bioinformatics and
no longer have any use for it or desire to maintain it. I'm hoping it
might come in handy for someone here. I don't have the time to do the
work to fully integrate it into bioruby, although someone interested
in doing so has contacted me, so hopefully that will happen someday.

- Dan Amelang


Here are some quick examples of it's use:

# parse returns an array of tree objects from a filename or IO object
trees = Bio::Tree::Newick::parse("trees.newick")
tree = trees.first
puts tree.children.size
tree.each_child do |child|
  puts child.distance
end
tree.each_leaf do |leaf|
  ...
end
tree.leaves
node = tree[2][1]
node.is_root?
node.children
node.descendents
node.ancestors[1]
node[3][2].sequence_name

# create a whole new tree
tree = Bio::Tree::Newick.new
tree << Bio::Tree::Newick::LeafNode("turtle")
tree << Bio::Tree::Newick::InnerNode
tree[1].distance = 0.12
tree[1] << Bio::Tree::Newick::LeafNode("panda", nil, 0.02)

# write out the tree (using the to_s method)
puts tree

#produces:

(
  turtle,
  (
    panda:0.02,
  ):0.12
);


More information about the BioRuby mailing list