BACKGROUND
comparative methods in biology have been an active area of scientific software development since the wider availability of computing resources made such large-scale quantitative analyses feasible  <cit> .
in recent years, the number and range of tools for working with phylogenetic information alone has expanded dramatically, creating new opportunities as well as challenges in data integration  <cit> .
at the same time, we have seen new efforts to create standards for data exchange and storage  <cit> .
there is thus a growing need for modular software toolkits that can integrate cleanly into workflows for bioinformatics analyses that include phylogenetic data, as well as facilitate tool development by providing a high-level application programming interface  independent of data storage formats.
freely available, open-source software libraries now play a major role in integrating software components for bioinformatics analyses.
generalized toolkits for working with phylogenetic information are already available and in wide use, including the ape package for the r statistical programming language  <cit> , bioperl  <cit>  and bio::phylo  <cit>  for perl, and mesquite  <cit>  for java.
the open bioinformatics foundation in particular supports an ecosystem of broadly aimed bioinformatics libraries, collectively referred to as the bio* or “bio-star” projects.
these include bioperl  <cit> , biopython  <cit> , biojava  <cit> , bioruby  <cit> , biolib  <cit>  and biosql  <cit> .
all of these libraries provide common functionality to each of their target programming languages or environments: read and write a variety of file formats used in bioinformatics, communicate with public web services such as ncbi entrez  <cit> , access widely used stand-alone programs such as blast  <cit> , and define fundamental data types for storing biological information, such as annotated sequence records, protein structures and phylogenetic trees.
we chose python as the implementation language for our library due to its increasing usage in scientific work  <cit> .
it allows for particularly concise, easy-to-read code, has extensive library support, and enables the same code to be run on all major operating systems.
in addition to biopython, several other high-quality python libraries are available for phylogenetics: pycogent  <cit> , dendropy  <cit> , ete  <cit>  and p <dig>  <cit>  each serve specific problem domains well.
however, they focus specificially on phylogenetics and are not intended to be general-purpose frameworks for processing biological data.
in this article we present a framework for phylogenetics in the python programming language, fully integrated with the biopython toolkit.
we supplemented existing support for the nexus  <cit>  and newick  <cit>  standards in biopython with a full-featured phylogenetic module, bio.phylo, incorporating new input/output support for the phyloxml standard  <cit> .
we then integrated the new i/o infrastructure with related code in biopython and added more features that would be useful for researchers, with a focus on easy interoperability and rapid script development.
our contributions include an i/o framework with parsers and serializers for the standard newick, nexus and phyloxml formats for phylogenetic trees, integrated through a consistent and simple api that is familiar to users of biopython and bioperl, as well as a set of common functions to perform on trees independently of the source data format.
this framework includes comprehensive class definitions for the rich annotation types which can be serialized in the standard phyloxml format.
we also provide several options for visualizing trees, and convenient integration with popular third-party tools.
implementation
bio.phylo is written as a sub-package within the biopython code base, and is installed along with the biopython distribution.
it has been available as part of the biopython library since version  <dig> , released in may  <dig>
the library can be used in python versions  <dig>  through  <dig>  and  <dig>  or later, without any external libraries required at the time of installation.
functions that rely on external libraries are written within a separate module of the code base, and import their dependencies at run-time.
this design makes it possible to install biopython and use the rest of bio.phylo without having installed the dependencies for these specific functions.
because bio.phylo is written entirely in python, it also runs on alternative implementations of python: jython  <dig>  and pypy  <dig>  through  <dig>  in particular pass the module’s unit testing suite.
i/o functions for standard file formats
a unified api for input and output is provided for the newick, nexus and phyloxml formats with the same underlying object structures.
the simple api style is shared with bio.seqio, alignio, motif and other modules within biopython; the api also resembles that of bioperl.
the read and write functions accept a filename or handle, so they also work with unix pipes, network handles or other file-like objects.
as in biopython’s seqio and alignio, a convert function is available to convert between any two of the supported formats with a single call.
the i/o code is designed for simple addition of other file formats without disturbing the existing code for newick, nexus and phyloxml.
parsing and serialization code is separated from the internal tree object representation.
all parsers return a common object type, the tree, independently of the source data format, and the parsed tree objects all support a common set of operations.
common tree representation
a phylogeny is represented by a tree object which contains global information about the phylogeny, such as whether it is rooted, and a reference to the root clade.
each clade contains a reference to its child clades, a simple python list of further clade objects, nested recursively.
the clade object also contains information about the node occuring at the split or tip it represents, such as the length of the branch leading to it and the name of the node.
there is no additional complex data structure operating “under the hood”, and trees are not required to be bifurcating, although the functions in bio.phylo currently assume that each clade has a single parent, i.e., the topology of the tree is indeed a tree and not a network.
this straightforward design is conducive to implementing algorithms in a form that is easy to read and understand, with minimal need for management of the object’s internal data representation.
the basic tree and clade objects store the intersection of the information that can be represented in the newick and phyloxml formats.
to store additional format-specific attributes, we defined separate newick and phyloxml sub-classes which inherit from the basic tree and clade classes.
classes for each element type defined in the phyloxml specification have been implemented in the bio.phylo.phyloxml module, allowing richer annotation types to be attached to tree objects.
for convenience in adding graphical cues, the clade class also has attributes for the displayed color and width of a branch.
the properties of the branch color and width attributes follow the phyloxml specification, and are available on the common clade class due to their usefulness, particularly during interactive work.
in accordance with the phyloxml specification, these attributes apply in a cascading manner down the clade: for example, if the root clade object is assigned the color blue, the entire tree will be displayed as blue unless a child clade overrides this attribute.
methods for tree inspection and manipulation
the tree and clade objects also implement common methods for tree manipulation and simple analyses that might be used routinely in bioinformatics workflows.
these include methods for tree search and traversal, extracting basic information, and modifying or manipulating the tree.
a listing of these methods and other functions available in bio.phylo is given in table  <dig>
public methods and functions provided in the bio.phylo module and sub-modules.
an up-to-date version of this information is available at http://biopython.org/dist/docs/api/.
both the tree and clade classes inherit from a third class, treemixin, which implements these common tree methods.
therefore, most of the same methods are available on both the tree object and any of the clade objects it contains; in practice, one can usually ignore the distinction between the global tree object and the root clade.
visualization
we implemented several mechanisms for displaying trees.
the draw function displays a rooted phylogram , in the style of phylip’s drawgram program, while draw_graphviz displays an unrooted cladogram using the graphviz programs  <cit>  for layout and the networkx library  <cit>  as an intermediate graph representation.
the generated plots can be further modified using the built-in functions of matplotlib or pylab  <cit> .
in case no visualization libraries are available on a system, plain-text representations of a tree are also possible.
the function draw_ascii draws an “ascii-art” tree to standard output or a given file handle.
using the built-in python print statement on a tree object shows the nested object hierarchy, including class names and the values of attributes such as branch length.
since the complete phyloxml specification is implemented, files can be saved by bio.phylo with graphical annotations and then rendered with popular visualization tools such as archaeopteryx  <cit> .
the cascading behavior of clade colors and branch widths is shared by archaeopteryx and other tree visualization software that implements phyloxml.
wrappers for third-party programs
biopython includes a common framework for building wrappers for external programs.
this framework allows us to leverage the functionality of widely used third-party programs from within biopython, rather than reimplement those functions.
for example, biopython supports the phylip suite of programs via emboss  <cit> , with wrappers implemented in the bio.emboss.applications module.
we follow this rationale in bio.phylo.
within the sub-module bio.phylo.applications, we currently provide wrappers for the tree inference programs phyml  <cit>  and raxml  <cit> .
the code scaffolding is in place to add more, using the same common bio.application framework.
paml integration
bio.phylo also includes wrappers for the paml suite of programs  <cit> , specifically the analysis programs yn <dig>  baseml, and codeml.
additionally, we created a pure-python re-implementation of the program chi <dig> as a simple means to perform likelihood ratio tests.
since the analysis programs are operated through the use of configuration files rather than command-line arguments, a different approach was required than what bio.application enables.
we therefore provide wrappers for these programs in a separate sub-module, bio.phylo.paml.
for each of the three analysis programs, the wrapper defines a corresponding class that the user instantiates to store the configuration state.
the programs’ standard configuration options are set through the set_options method and are automatically written to a configuration file when the run method is invoked or through the write_ctl_file method.
existing configuration files may be parsed via the method read_ctl_file.
finally, each module of bio.phylo.paml provides a read method, which parses the output files of the respective programs.
the results of an analysis are stored hierarchically in a set of nested dictionary objects, allowing quick access by keywords.
biopython integration
bio.phylo integrates cleanly with other parts of the biopython toolkit.
we reuse existing biopython api conventions, including classes for exceptions and warnings, as well as the packaging and installation mechanisms and the testing framework.
as mentioned above, the wrappers for running external programs use a common biopython framework, bio.application.
nexus and newick support were obtained through a refactoring of the bio.nexus module, originally written by frank kauff and cymon j. cox  <cit> .
where appropriate, classes in the phyloxml module support methods for conversion to and from instances of the general-purpose biopython classes for molecular sequences, annotated sequence regions and multiple sequence alignments.
for example, phyloxml defines a proteindomain element type which represents a functional domain within a protein sequence that appears in the tree; our implementation of the proteindomain class includes a to_seqfeature method to convert a proteindomain instance to an instance of the biopython class seqfeature, a generalized representation of an annotated sequence region.
these seqfeature objects could then be used with the biopython’s genomediagram module  <cit>  to create a diagram of the protein domain architecture of each sequence appearing in the phyloxml tree.
the proteindomain class also provides a complementary method, from_seqfeature, which could be used to add domain architecture annotations to the sequences in a phyloxml record, given the corresponding genbank files.
validation
a complete suite of unit tests to verify correct functioning of each module is included with the biopython distribution.
this includes the round-trip parsing and serialization of example files in each supported file format; conversion between formats; proper construction, behavior and serialization of all phyloxml element types; methods for tree inspection, traversal and manipulation; and succesful loading of optional third-party libraries, if available.
RESULTS
use of bio.phylo in published studies
since the bio.phylo module has been made available to the community throughout its development, researchers have had the opportunity to use it in studies that have since been published.
a recent study of microbial phylogenomics used bio.phylo for large-scale processing of microbial gene trees, generating permutations of tree topologies by rerooting over  <dig>  gene trees at each internal and external node  <cit> .
additional file  <dig> shows a simplified example of how such rerooting could be performed.
in another study of the eukaryotic protein kinase superfamily in the protozoan phylum apicomplexa, bio.phylo was used to identify putative lineage-specific ortholog groups by selecting clades with significant bootstrap support from gene trees  <cit> .
the corresponding sequences were then automatically extracted from a matching fasta file, using biopython’s seqio module, for further analysis in a computational pipeline.
performance
despite the stark simplification of the underlying data structures, the majority of the built-in tree methods have a run time that is theoretically linear or constant in proportion to the number of nodes in the tree.
the tree traversal methods find_clades and find_elements are python generator functions which evaluate and emit values incrementally, as needed by the caller; this “lazy evaluation” approach uses computer memory more efficiently and avoids performing more computation than necessary; for example, the method find_any uses this property to stop traversal after finding the first element matching the user’s query and thus avoid traversing the remainder of the tree structure or evaluating any further comparisons.
we timed several benchmark operations on large tree files to evaluate the speed of bio.phylo on several different tasks .
on more modestly sized trees and input files, these operations typically complete in a small fraction of a second.
performance of bio.phylo functions and tree methods under different python versions on several benchmark tasks.
reported execution times are the median of  <dig> replications of each task, in seconds .
benchmarks were evaluated with python versions  <dig> .
<dig> and  <dig> .
<dig> and pypy version  <dig>  on an intel xeon e <dig>  <dig>  ghz processor with  <dig> gb memory, running under 64-bit ubuntu linux  <dig>  with biopython  <dig>  installed.
cookbook and additional documentation
in keeping the bio.phylo module general-purpose and simple to begin using, we have chosen not to include niche functions, or approaches that are still the topic of active research, in the biopython distribution.
however, we nonetheless anticipate that other users of the bio.phylo module will want to use these features, and there is a benefit to sharing this code.
we resolve this by maintaining an online “cookbook” on the biopython wiki .
this cookbook contains working code samples for common usage patterns, as well as exporting to object types of other libraries.
in particular, we provide functions to convert a bio.phylo tree object to a distance or adjacency matrix using the numpy module for python, and to export a bio.phylo tree to the native tree objects used by the r package ape  <cit> , via the rpy <dig> module, and the python package pycogent  <cit> .
the main biopython tutorial, included with the biopython distribution and available online at http://biopython.org/, contains a chapter on the bio.phylo module describing its use in detail.
discussion
bio.phylo organizes phylogenetic trees as a primary data type, filling a previously underserved area of data handling within biopython.
the module directly implements tree parsing and serialization in three standard formats, as well as navigation, visualization and manipulation of phylogenetic trees, and conversion of tree data to other data types.
other important aspects of phylogenetics, including phylogenetic tree reconstruction and analysis of rate variation and ancestral character states, exist as optimized stand-alone programs by other authors; raxml and paml are examples of such programs that are already well accepted by the phylogenetics community.
rather than re-implement the functionality of these established third-party programs ourselves, we have opted to provide wrappers for these, and focus on providing “glue” utilities to ease the process of assembling computational workflows that involve phylogenetic data.
by building our work into an existing, popular library, we were able to take advantage of both the software infrastructure and the community of developers and users associated with biopython.
by reusing core objects and maintaining common api conventions for file parsing, the resulting software package has a familiar feel to new users who have prior experience with biopython or bioperl.
to ensure code correctness and minimize errors introduced during additional development, we reuse the existing test framework and packaging mechanisms in biopython.
a continuous integration server http://testing.open-bio.org/biopython/ runs an automated test suite nightly on all supported python versions, operating systems and implementations, including the jython java-based port of python.
our work also provides an example of the short- and long-term benefits of building a community of developers and users around a shared open-source project.
by integrating with biopython from the beginning, we gained access to an existing community of developers and users who have continually tested the software under a variety of environments and use cases, reported bugs, requested new features, and provided new code.
a notable example of a contribution from the biopython user community is bio.phylo.paml, which began as an independent project, pypaml.
we successfully integrated the pypaml source code into biopython, with further enhancements based on feedback from biopython developers and users.
the permissive open-source license that governs both biopython and bio.phylo allows this code to be reused freely in other software, which could help overcome the pervasive problem of incompatible software support for widely used file formats.
future development
in future releases we intend to provide support for another recently standardized xml-based format, nexml, an xml-based successor to nexus  <cit> .
since the core classes for phylogenies have already been defined and implemented in bio.phylo, the implementation of nexml i/o is expected to be straightforward.
another area for future growth is the addition of wrappers for other third-party applications in bio.phylo.applications.
using the existing bio.application framework, it is straightforward to add other tools that can be run with a standard command-line interface.
other widely used programs that require specialized input, notably mrbayes and phylobayes, may be implemented with an approach similar to bio.phylo.paml, providing a module containing both the functions to generate the configuration file and to run the program itself with the generated configuration.
smaller features may appear first on the cookbook wiki page, implemented as stand-alone functions, and may later be added to the official biopython distribution.
CONCLUSIONS
bio.phylo meets a growing need in bioinformatics for working with heterogeneous types of biological and phylogenetic data.
by supporting interoperability with multiple file formats and leveraging existing biopython features, this library simplifies the construction of phylogenetic workflows and computational pipelines, addressing practical issues of data integration and exchange in the bioinformatics community.
availability and requirements
project name: biopythonproject home page:http://biopython.org/operating system: platform independentprogramming language: pythonother requirements: python  <dig>  or higher; optional libraries matplotlib, graphviz, networkxlicense: biopython licenseany restrictions to use by non-academics: none
competing interests
the authors declare that they have no competing interests.
authors’ contributions
et wrote the code for bio.phylo.
bi wrote the code for bio.phylo.paml.
bac and pjac mentored and supervised the development of bio.phylo and contributed enhancements and bug fixes.
et, bi, pjac and bac wrote the manuscript.
all authors read and approved the final manuscript.
supplementary material
additional file 1
tree rerooting.
example code to read a tree from a file and write copies of the tree rerooted at every internal and external node.
the method find_clades produces an iterator over the tree rather than a new list, in order to make more efficient use of memory in general.
in this case, because the method root_with_outgroup modifies the tree in-place, which could change the ordering of nodes during traversal, list is used to create an unchanging copy of references to the original nodes in the tree.
click here for file
additional file 2
performance benchmark script.
python script to time the execution of the benchmark tasks shown in table  <dig>
click here for file
acknowledgements
we acknowledge the role of google summer of code  <dig> and the national evolutionary synthesis center  phyloinformatics program in sponsoring and initiating this project.
we also thank the biopython community and open bioinformatics foundation for ongoing advice and support.
several individuals made direct contributions to bio.phylo: aaron gallagher, connor mccoy, joel berendzen, robert beiko and tanya golubchik provided bug fixes, test cases, feature requests and example code; frank kauff wrote most of the tree parsing code in the bio.nexus module, which bio.phylo builds upon, and gave helpful comments on a draft of the manuscript; cymon j. cox gave advice on the port of bio.nexus code; and christian m. zmasek co-mentored the original google summer of code project with brad a. chapman, guiding the implementation of phyloxml.
we also thank the peer reviewers for helpful suggestions on this manuscript.
bi is supported by a fi-dgr from agaur .
harvard bioinformatics core provided for publication costs and moral support.

 comparative methods in biology have been an active area of scientific software development since the wider availability of computing resources made such large-scale quantitative analyses feasible. in recent years, the number and range of tools for working with phylogenetic information alone has expanded dramatically, creating new opportunities as well as challenges in data integration. at the same time, we have seen new efforts to create standards for data exchange and storage. there is thus a growing need for modular software toolkits that can integrate cleanly into workflows for bioinformatics analyses that include phylogenetic data, as well as facilitate tool development by providing a high-level application programming interface independent of data storage formats. freely available, open-source software libraries now play a major role in integrating software components for bioinformatics analyses. generalized toolkits for working with phylogenetic information are already available and in wide use, including the ape package for the r statistical programming language, bioperl and bio::phylo for perl, and mesquite for java. the open bioinformatics foundation in particular supports an ecosystem of broadly aimed bioinformatics libraries, collectively referred to as the bio* or “bio-star” projects. these include bioperl, biopython, biojava, bioruby, biolib and biosql. all of these libraries provide common functionality to each of their target programming languages or environments: read and write a variety of file formats used in bioinformatics, communicate with public web services such as ncbi entrez, access widely used stand-alone programs such as blast, and define fundamental data types for storing biological information, such as annotated sequence records, protein structures and phylogenetic trees. we chose python as the implementation language for our library due to its increasing usage in scientific work. it allows for particularly concise, easy-to-read code, has extensive library support, and enables the same code to be run on all major operating systems. in addition to biopython, several other high-quality python libraries are available for phylogenetics: pycogent, dendropy, ete and p each serve specific problem domains well. however, they focus specificially on phylogenetics and are not intended to be general-purpose frameworks for processing biological data. in this article we present a framework for phylogenetics in the python programming language, fully integrated with the biopython toolkit. we supplemented existing support for the nexus and newick standards in biopython with a full-featured phylogenetic module, bio.phylo, incorporating new input/output support for the phyloxml standard. we then integrated the new i/o infrastructure with related code in biopython and added more features that would be useful for researchers, with a focus on easy interoperability and rapid script development. our contributions include an i/o framework with parsers and serializers for the standard newick, nexus and phyloxml formats for phylogenetic trees, integrated through a consistent and simple api that is familiar to users of biopython and bioperl, as well as a set of common functions to perform on trees independently of the source data format. this framework includes comprehensive class definitions for the rich annotation types which can be serialized in the standard phyloxml format. we also provide several options for visualizing trees, and convenient integration with popular third-party tools. implementation bio.phylo is written as a sub-package within the biopython code base, and is installed along with the biopython distribution. it has been available as part of the biopython library since version, released in may the library can be used in python versions through and or later, without any external libraries required at the time of installation. functions that rely on external libraries are written within a separate module of the code base, and import their dependencies at run-time. this design makes it possible to install biopython and use the rest of bio.phylo without having installed the dependencies for these specific functions. because bio.phylo is written entirely in python, it also runs on alternative implementations of python: jython and pypy through in particular pass the module’s unit testing suite. i/o functions for standard file formats a unified api for input and output is provided for the newick, nexus and phyloxml formats with the same underlying object structures. the simple api style is shared with bio.seqio, alignio, motif and other modules within biopython; the api also resembles that of bioperl. the read and write functions accept a filename or handle, so they also work with unix pipes, network handles or other file-like objects. as in biopython’s seqio and alignio, a convert function is available to convert between any two of the supported formats with a single call. the i/o code is designed for simple addition of other file formats without disturbing the existing code for newick, nexus and phyloxml. parsing and serialization code is separated from the internal tree object representation. all parsers return a common object type, the tree, independently of the source data format, and the parsed tree objects all support a common set of operations. common tree representation a phylogeny is represented by a tree object which contains global information about the phylogeny, such as whether it is rooted, and a reference to the root clade. each clade contains a reference to its child clades, a simple python list of further clade objects, nested recursively. the clade object also contains information about the node occuring at the split or tip it represents, such as the length of the branch leading to it and the name of the node. there is no additional complex data structure operating “under the hood”, and trees are not required to be bifurcating, although the functions in bio.phylo currently assume that each clade has a single parent, i.e., the topology of the tree is indeed a tree and not a network. this straightforward design is conducive to implementing algorithms in a form that is easy to read and understand, with minimal need for management of the object’s internal data representation. the basic tree and clade objects store the intersection of the information that can be represented in the newick and phyloxml formats. to store additional format-specific attributes, we defined separate newick and phyloxml sub-classes which inherit from the basic tree and clade classes. classes for each element type defined in the phyloxml specification have been implemented in the bio.phylo.phyloxml module, allowing richer annotation types to be attached to tree objects. for convenience in adding graphical cues, the clade class also has attributes for the displayed color and width of a branch. the properties of the branch color and width attributes follow the phyloxml specification, and are available on the common clade class due to their usefulness, particularly during interactive work. in accordance with the phyloxml specification, these attributes apply in a cascading manner down the clade: for example, if the root clade object is assigned the color blue, the entire tree will be displayed as blue unless a child clade overrides this attribute. methods for tree inspection and manipulation the tree and clade objects also implement common methods for tree manipulation and simple analyses that might be used routinely in bioinformatics workflows. these include methods for tree search and traversal, extracting basic information, and modifying or manipulating the tree. a listing of these methods and other functions available in bio.phylo is given in table public methods and functions provided in the bio.phylo module and sub-modules. an up-to-date version of this information is available at http://biopython.org/dist/docs/api/. both the tree and clade classes inherit from a third class, treemixin, which implements these common tree methods. therefore, most of the same methods are available on both the tree object and any of the clade objects it contains; in practice, one can usually ignore the distinction between the global tree object and the root clade. visualization we implemented several mechanisms for displaying trees. the draw function displays a rooted phylogram, in the style of phylip’s drawgram program, while draw_graphviz displays an unrooted cladogram using the graphviz programs for layout and the networkx library as an intermediate graph representation. the generated plots can be further modified using the built-in functions of matplotlib or pylab. in case no visualization libraries are available on a system, plain-text representations of a tree are also possible. the function draw_ascii draws an “ascii-art” tree to standard output or a given file handle. using the built-in python print statement on a tree object shows the nested object hierarchy, including class names and the values of attributes such as branch length. since the complete phyloxml specification is implemented, files can be saved by bio.phylo with graphical annotations and then rendered with popular visualization tools such as archaeopteryx. the cascading behavior of clade colors and branch widths is shared by archaeopteryx and other tree visualization software that implements phyloxml. wrappers for third-party programs biopython includes a common framework for building wrappers for external programs. this framework allows us to leverage the functionality of widely used third-party programs from within biopython, rather than reimplement those functions. for example, biopython supports the phylip suite of programs via emboss, with wrappers implemented in the bio.emboss.applications module. we follow this rationale in bio.phylo. within the sub-module bio.phylo.applications, we currently provide wrappers for the tree inference programs phyml and raxml. the code scaffolding is in place to add more, using the same common bio.application framework. paml integration bio.phylo also includes wrappers for the paml suite of programs, specifically the analysis programs yn baseml, and codeml. additionally, we created a pure-python re-implementation of the program chi as a simple means to perform likelihood ratio tests. since the analysis programs are operated through the use of configuration files rather than command-line arguments, a different approach was required than what bio.application enables. we therefore provide wrappers for these programs in a separate sub-module, bio.phylo.paml. for each of the three analysis programs, the wrapper defines a corresponding class that the user instantiates to store the configuration state. the programs’ standard configuration options are set through the set_options method and are automatically written to a configuration file when the run method is invoked or through the write_ctl_file method. existing configuration files may be parsed via the method read_ctl_file. finally, each module of bio.phylo.paml provides a read method, which parses the output files of the respective programs. the results of an analysis are stored hierarchically in a set of nested dictionary objects, allowing quick access by keywords. biopython integration bio.phylo integrates cleanly with other parts of the biopython toolkit. we reuse existing biopython api conventions, including classes for exceptions and warnings, as well as the packaging and installation mechanisms and the testing framework. as mentioned above, the wrappers for running external programs use a common biopython framework, bio.application. nexus and newick support were obtained through a refactoring of the bio.nexus module, originally written by frank kauff and cymon j. cox. where appropriate, classes in the phyloxml module support methods for conversion to and from instances of the general-purpose biopython classes for molecular sequences, annotated sequence regions and multiple sequence alignments. for example, phyloxml defines a proteindomain element type which represents a functional domain within a protein sequence that appears in the tree; our implementation of the proteindomain class includes a to_seqfeature method to convert a proteindomain instance to an instance of the biopython class seqfeature, a generalized representation of an annotated sequence region. these seqfeature objects could then be used with the biopython’s genomediagram module to create a diagram of the protein domain architecture of each sequence appearing in the phyloxml tree. the proteindomain class also provides a complementary method, from_seqfeature, which could be used to add domain architecture annotations to the sequences in a phyloxml record, given the corresponding genbank files. validation a complete suite of unit tests to verify correct functioning of each module is included with the biopython distribution. this includes the round-trip parsing and serialization of example files in each supported file format; conversion between formats; proper construction, behavior and serialization of all phyloxml element types; methods for tree inspection, traversal and manipulation; and succesful loading of optional third-party libraries, if available.  use of bio.phylo in published studies since the bio.phylo module has been made available to the community throughout its development, researchers have had the opportunity to use it in studies that have since been published. a recent study of microbial phylogenomics used bio.phylo for large-scale processing of microbial gene trees, generating permutations of tree topologies by rerooting over gene trees at each internal and external node. additional file shows a simplified example of how such rerooting could be performed. in another study of the eukaryotic protein kinase superfamily in the protozoan phylum apicomplexa, bio.phylo was used to identify putative lineage-specific ortholog groups by selecting clades with significant bootstrap support from gene trees. the corresponding sequences were then automatically extracted from a matching fasta file, using biopython’s seqio module, for further analysis in a computational pipeline. performance despite the stark simplification of the underlying data structures, the majority of the built-in tree methods have a run time that is theoretically linear or constant in proportion to the number of nodes in the tree. the tree traversal methods find_clades and find_elements are python generator functions which evaluate and emit values incrementally, as needed by the caller; this “lazy evaluation” approach uses computer memory more efficiently and avoids performing more computation than necessary; for example, the method find_any uses this property to stop traversal after finding the first element matching the user’s query and thus avoid traversing the remainder of the tree structure or evaluating any further comparisons. we timed several benchmark operations on large tree files to evaluate the speed of bio.phylo on several different tasks. on more modestly sized trees and input files, these operations typically complete in a small fraction of a second. performance of bio.phylo functions and tree methods under different python versions on several benchmark tasks. reported execution times are the median of replications of each task, in seconds. benchmarks were evaluated with python versions. and. and pypy version on an intel xeon e ghz processor with gb memory, running under 64-bit ubuntu linux with biopython installed. cookbook and additional documentation in keeping the bio.phylo module general-purpose and simple to begin using, we have chosen not to include niche functions, or approaches that are still the topic of active research, in the biopython distribution. however, we nonetheless anticipate that other users of the bio.phylo module will want to use these features, and there is a benefit to sharing this code. we resolve this by maintaining an online “cookbook” on the biopython wiki. this cookbook contains working code samples for common usage patterns, as well as exporting to object types of other libraries. in particular, we provide functions to convert a bio.phylo tree object to a distance or adjacency matrix using the numpy module for python, and to export a bio.phylo tree to the native tree objects used by the r package ape, via the rpy module, and the python package pycogent. the main biopython tutorial, included with the biopython distribution and available online at http://biopython.org/, contains a chapter on the bio.phylo module describing its use in detail. discussion bio.phylo organizes phylogenetic trees as a primary data type, filling a previously underserved area of data handling within biopython. the module directly implements tree parsing and serialization in three standard formats, as well as navigation, visualization and manipulation of phylogenetic trees, and conversion of tree data to other data types. other important aspects of phylogenetics, including phylogenetic tree reconstruction and analysis of rate variation and ancestral character states, exist as optimized stand-alone programs by other authors; raxml and paml are examples of such programs that are already well accepted by the phylogenetics community. rather than re-implement the functionality of these established third-party programs ourselves, we have opted to provide wrappers for these, and focus on providing “glue” utilities to ease the process of assembling computational workflows that involve phylogenetic data. by building our work into an existing, popular library, we were able to take advantage of both the software infrastructure and the community of developers and users associated with biopython. by reusing core objects and maintaining common api conventions for file parsing, the resulting software package has a familiar feel to new users who have prior experience with biopython or bioperl. to ensure code correctness and minimize errors introduced during additional development, we reuse the existing test framework and packaging mechanisms in biopython. a continuous integration server http://testing.open-bio.org/biopython/ runs an automated test suite nightly on all supported python versions, operating systems and implementations, including the jython java-based port of python. our work also provides an example of the short- and long-term benefits of building a community of developers and users around a shared open-source project. by integrating with biopython from the beginning, we gained access to an existing community of developers and users who have continually tested the software under a variety of environments and use cases, reported bugs, requested new features, and provided new code. a notable example of a contribution from the biopython user community is bio.phylo.paml, which began as an independent project, pypaml. we successfully integrated the pypaml source code into biopython, with further enhancements based on feedback from biopython developers and users. the permissive open-source license that governs both biopython and bio.phylo allows this code to be reused freely in other software, which could help overcome the pervasive problem of incompatible software support for widely used file formats. future development in future releases we intend to provide support for another recently standardized xml-based format, nexml, an xml-based successor to nexus. since the core classes for phylogenies have already been defined and implemented in bio.phylo, the implementation of nexml i/o is expected to be straightforward. another area for future growth is the addition of wrappers for other third-party applications in bio.phylo.applications. using the existing bio.application framework, it is straightforward to add other tools that can be run with a standard command-line interface. other widely used programs that require specialized input, notably mrbayes and phylobayes, may be implemented with an approach similar to bio.phylo.paml, providing a module containing both the functions to generate the configuration file and to run the program itself with the generated configuration. smaller features may appear first on the cookbook wiki page, implemented as stand-alone functions, and may later be added to the official biopython distribution.  bio.phylo meets a growing need in bioinformatics for working with heterogeneous types of biological and phylogenetic data. by supporting interoperability with multiple file formats and leveraging existing biopython features, this library simplifies the construction of phylogenetic workflows and computational pipelines, addressing practical issues of data integration and exchange in the bioinformatics community. availability and requirements project name: biopythonproject home page:http://biopython.org/operating system: platform independentprogramming language: pythonother requirements: python or higher; optional libraries matplotlib, graphviz, networkxlicense: biopython licenseany restrictions to use by non-academics: none competing interests the authors declare that they have no competing interests. authors’ contributions et wrote the code for bio.phylo. bi wrote the code for bio.phylo.paml. bac and pjac mentored and supervised the development of bio.phylo and contributed enhancements and bug fixes. et, bi, pjac and bac wrote the manuscript. all authors read and approved the final manuscript. supplementary material additional file 1 tree rerooting. example code to read a tree from a file and write copies of the tree rerooted at every internal and external node. the method find_clades produces an iterator over the tree rather than a new list, in order to make more efficient use of memory in general. in this case, because the method root_with_outgroup modifies the tree in-place, which could change the ordering of nodes during traversal, list is used to create an unchanging copy of references to the original nodes in the tree. click here for file additional file 2 performance benchmark script. python script to time the execution of the benchmark tasks shown in table click here for file acknowledgements we acknowledge the role of google summer of code and the national evolutionary synthesis center phyloinformatics program in sponsoring and initiating this project. we also thank the biopython community and open bioinformatics foundation for ongoing advice and support. several individuals made direct contributions to bio.phylo: aaron gallagher, connor mccoy, joel berendzen, robert beiko and tanya golubchik provided bug fixes, test cases, feature requests and example code; frank kauff wrote most of the tree parsing code in the bio.nexus module, which bio.phylo builds upon, and gave helpful comments on a draft of the manuscript; cymon j. cox gave advice on the port of bio.nexus code; and christian m. zmasek co-mentored the original google summer of code project with brad a. chapman, guiding the implementation of phyloxml. we also thank the peer reviewers for helpful suggestions on this manuscript. bi is supported by a fi-dgr from agaur. harvard bioinformatics core provided for publication costs and moral support.
by supporting interoperability with multiple file formats and leveraging existing biopython features, this library simplifies the construction of phylogenetic workflows. we unified the modules for working with the standard file formats newick, nexus and phyloxml behind a consistent and simple api, providing a common set of functionality independent of the data source. we also provide examples of the benefits of building a community around a shared open-source project. this brings with it the challenge of integrating phylogenetic and other related biological data found in a wide variety of formats, and underlines the need for reusable software that can read, manipulate and transform this information into the various forms required to build computational pipelines. our library, bio.phylo, is highly interoperable with existing libraries, tools and standards, and is capable of parsing common file formats for phylogenetic trees, performing basic transformations and manipulations, attaching rich annotations, and visualizing trees. bio.phylo meets a growing need in bioinformatics for working with heterogeneous types of phylogenetic data. we built a python software library for working with phylogenetic data that is tightly integrated with biopython, a broad-ranging toolkit for computational biology.
 ongoing innovation in phylogenetics and evolutionary biology has been accompanied by a proliferation of software tools, data formats, analytical techniques and web servers. this brings with it the challenge of integrating phylogenetic and other related biological data found in a wide variety of formats, and underlines the need for reusable software that can read, manipulate and transform this information into the various forms required to build computational pipelines.  we built a python software library for working with phylogenetic data that is tightly integrated with biopython, a broad-ranging toolkit for computational biology. our library, bio.phylo, is highly interoperable with existing libraries, tools and standards, and is capable of parsing common file formats for phylogenetic trees, performing basic transformations and manipulations, attaching rich annotations, and visualizing trees. we unified the modules for working with the standard file formats newick, nexus and phyloxml behind a consistent and simple api, providing a common set of functionality independent of the data source.  bio.phylo meets a growing need in bioinformatics for working with heterogeneous types of phylogenetic data. by supporting interoperability with multiple file formats and leveraging existing biopython features, this library simplifies the construction of phylogenetic workflows. we also provide examples of the benefits of building a community around a shared open-source project. bio.phylo is included with biopython, available through the biopython website, http://biopython.org. 