Difference between revisions of "BioRuby PhyloXML HowTo documentation"

From Phyloinformatics
Jump to: navigation, search
(How to parse a file)
(How to parse a file)
Line 27: Line 27:
 
  tree = phyloxml[3]
 
  tree = phyloxml[3]
  
You can use all Bio::Tree methods on the tree. For example,  
+
You can use all Bio::Tree methods on the tree. For example,
+
 
 
  tree.leaves.each do |node|
 
  tree.leaves.each do |node|
 
     puts node.name
 
     puts node.name
 
  end
 
  end
 +
 +
=How to write a file=
 +
 +
# Create new phyloxml writer
 +
writer = Bio::PhyloXML::Writer.new('tree.xml')
 +
 +
# Write tree to the file tree.xml
 +
writer.write(tree1)
 +
 +
# Add another tree to the file
 +
writer.write(tree2)

Revision as of 11:44, 12 August 2009

Intro

PhyloXML is a tree format for saving and exchanging data of annotated phylogenetic trees. PhyloXML parsers and writers are implemented in BioRuby, BioPython and BioPerl. More information at www.phyloxml.org

Requirements

In addition to BioRuby library you need a libxml ruby bindings. To install:

gem install -r libxml-ruby

How to parse a file

require 'bio'
# Create new phyloxml parser
phyloxml = Bio::PhyloXML::Parser.new('example.xml')
# Print the names of all trees in the file
phyloxml.each do |tree|
  puts tree.name
end

If there are several trees in the file, you can access the one you wish by an index

tree = phyloxml[3]

You can use all Bio::Tree methods on the tree. For example,

tree.leaves.each do |node|
   puts node.name
end

How to write a file

# Create new phyloxml writer
writer = Bio::PhyloXML::Writer.new('tree.xml')
# Write tree to the file tree.xml
writer.write(tree1)
# Add another tree to the file
writer.write(tree2)