Build Status

bio-phyloxml (the package name on is bioruby-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.


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

  • zlib
  • libiconv
  • libxml

With these installed, libxml-ruby gem should be installed.

gem install libxml-ruby

If you see "ERROR: Failed to build gem native extension", the above C libraries and their headers may be missing. See doc/Tutorial.rd about installation of them in some system.

bio-phyloxml also uses the bio gem. It will automatically be installed during the installation of bio-phyloxml in normal cases.

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


gem install bioruby-phyloxml

Note: Please uninstall old bio-phyloxml gem that have not been maintained since 2012. The old bio-phyloxml gem was created in 2012 as a preliminary trial of splitting bioruby components to separate gems. We tried to contact the author of the old bio-phyloxml gem, but no response.

gem uninstall 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 and BioRuby project. See COPYING or COPYING.ja for further details.

This was first written by Clayton Wheeler.