Skip to content


Subversion checkout URL

You can clone with
Download ZIP
PhyloXML gem for BioRuby
Latest commit 96fac1f @csw Cleaned up comments.


Build Status

bio-phyloxml is a phyloXML plugin for BioRuby, an open source bioinformatics library for Ruby.

phyloXML is an XML language for saving, analyzing and exchanging data of annotated phylogenetic trees. The phyloXML parser in BioRuby is implemented in Bio::PhyloXML::Parser, and its writer in Bio::PhyloXML::Writer. More information can be found at

This phyloXML code has historically been part of the core BioRuby gem, but has been split into its own gem as part of an effort to modularize BioRuby. bio-phyloxml and many more plugins are available at

This code was originally written by Diana Jaunzeikare during the Google Summer of Code 2009 for the Implementing phyloXML support in BioRuby project with NESCent, mentored by Christian Zmasek et al. For details of development, see and the BioRuby mailing list archives.

NOTE: this is currently in the repackaging process and is not yet released! Production users should use the phyloXML support provided with BioRuby for the time being.


bio-phyloxml uses libxml-ruby, which requires several C libraries and their headers to be installed:

  • zlib
  • libiconv
  • libxml

With these installed, the bio and libxml-ruby gems should be installed

gem install -r bio libxml-ruby

For more information see the libxml installer page and the BioRuby installation page.


gem install bio-phyloxml


Users who were previously using the phyloXML support in the core BioRuby gem should be able to migrate to using this gem very easily. Simply install the bio-phyloxml gem as described below, and add require 'bio-phyloxml' to the relevant application code.


require 'bio-phyloxml'

Parsing a file

require 'bio-phyloxml'

# Create new phyloxml parser
phyloxml ='example.xml')

# Print the names of all trees in the file
phyloxml.each do |tree|

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

tree = phyloxml[3]

You can use all Bio::Tree methods on the tree, since PhyloXML::Tree inherits from Bio::Tree. For example,

tree.leaves.each do |node|

PhyloXML files can hold additional information besides phylogenies at the end of the file. This info can be accessed through the 'other' array of the parser object.

phyloxml ='example.xml')
while tree = phyloxml.next_tree
  # do stuff with trees

puts phyloxml.other

Writing a file

# Create new phyloxml writer
writer ='tree.xml')

# Write tree to the file tree.xml

# Add another tree to the file

Retrieving data

Here is an example of how to retrieve the scientific name of the clades included in each tree.

require 'bio-phyloxml'

phyloxml ='ncbi_taxonomy_mollusca.xml')
phyloxml.each do |tree|
  tree.each_node do |node|
    print "Scientific name: ", node.taxonomies[0].scientific_name, "\n"

Retrieving 'other' data

require 'bio'

phyloxml ='phyloxml_examples.xml')
while tree = phyloxml.next_tree
 #do something with the trees

p phyloxml.other
puts "\n"
#=> output is an object representation

#Print in a readable way
puts phyloxml.other[0].to_xml, "\n"
#<align:alignment xmlns:align="">
#  <seq name="A">acgtcgcggcccgtggaagtcctctcct</seq>
#  <seq name="B">aggtcgcggcctgtggaagtcctctcct</seq>
#  <seq name="C">taaatcgc--cccgtgg-agtccc-cct</seq>

#Once we know whats there, lets output just sequences
phyloxml.other[0].children.each do |node|
 puts node.value

The API doc is online. (TODO: generate and link) For more code examples see the test files in the source tree.

Project home page

Information on the source tree, documentation, examples, issues and how to contribute, see

The BioRuby community is on IRC server:, channel: #bioruby.


If you use this software, please cite one of

This Biogem is published at #bio-phyloxml


Copyright (c) 2009 Diana Jaunzeikare. See LICENSE.txt for further details.

Something went wrong with that request. Please try again.