NeXML and RDF API for BioRuby
The following document discusses the implementation of an NeXML parser and serializer and an RDF API for BioRuby. Note that this document is not final yet.
Parse an NeXML file.
doc = Bio::NeXML::Parser.new( "trees.xml" ) nexml = doc.parse nexml.class #Bio::NeXML::Nexml
Read taxa blocks by calling
otus method on an
nexml object. This returns an array of
nexml.otus.each do |taxa| puts taxa.id puts taxa.label end
An array of
otu objects can be obtained by calling
otu method on an
taxa1 = nexml.otus.first taxa1.class #Bio::NeXML::Otus taxa1.otu.each do |taxon| puts taxon.id puts taxon.label end
Trees are accessible by calling
trees method on an
nexml object, which returns an array of
nexml.trees.each do |trees| puts trees.id end
The taxa block to which a
trees object is linked to can be obtained.
trees1 = nexml.trees.first trees1.class #Bio::NeXML::Trees trees1.otus
tree objects under a
trees element are obtainable.
trees1.tree.each do |tree| puts tree.id end
All the available instance methods from
Bio::Tree class can be called on a
tree1 = trees1.tree.first tree1.class #Bio::NeXML::IntTree or Bio::NeXML::FloatTree node1 = tree.get_node_by_name "n3" #note name is same as id tree1.parents node1