Difference between revisions of "NeXML and RDF API for BioRuby"

From Phyloinformatics
Jump to: navigation, search
(Parsing)
Line 43: Line 43:
 
   end
 
   end
  
All the available instance methods from <code>[http://bioruby.org/rdoc/classes/Bio/Tree.html#M001688 Bio::Tree] class can be called on a <code>tree</code> object.
+
All the available instance methods from <code>[http://bioruby.org/rdoc/classes/Bio/Tree.html#M001688 Bio::Tree]</code> class can be called on a <code>tree</code> object.
 
   tree1 = trees1.tree.first
 
   tree1 = trees1.tree.first
 
   tree1.class #Bio::NeXML::IntTree or Bio::NeXML::FloatTree
 
   tree1.class #Bio::NeXML::IntTree or Bio::NeXML::FloatTree

Revision as of 14:46, 2 June 2010

Preface

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.

Parsing

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 otus objects.

 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 otus object.

 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 trees objects.

 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

All the 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 tree object.

 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