Back to index

python-biopython  1.60
Functions | Variables
Bio.Phylo._io Namespace Reference

Functions

def parse
def read
def write
def convert

Variables

string __docformat__ = "restructuredtext en"
dictionary supported_formats

Function Documentation

def Bio.Phylo._io.convert (   in_file,
  in_format,
  out_file,
  out_format,
  kwargs 
)
Convert between two tree file formats.

Definition at line 75 of file _io.py.

00075 
00076 def convert(in_file, in_format, out_file, out_format, **kwargs):
00077     """Convert between two tree file formats."""
00078     trees = parse(in_file, in_format)
00079     return write(trees, out_file, out_format, **kwargs)

Here is the call graph for this function:

def Bio.Phylo._io.parse (   file,
  format,
  kwargs 
)
Iteratively parse a file and return each of the trees it contains.

If a file only contains one tree, this still returns an iterable object that
contains one element.

Example
-------

>>> trees = parse('../../Tests/PhyloXML/apaf.xml', 'phyloxml')
>>> for tree in trees:
...     print tree.rooted
True

Definition at line 26 of file _io.py.

00026 
00027 def parse(file, format, **kwargs):
00028     """Iteratively parse a file and return each of the trees it contains.
00029 
00030     If a file only contains one tree, this still returns an iterable object that
00031     contains one element.
00032 
00033     Example
00034     -------
00035 
00036     >>> trees = parse('../../Tests/PhyloXML/apaf.xml', 'phyloxml')
00037     >>> for tree in trees:
00038     ...     print tree.rooted
00039     True
00040     """
00041     with File.as_handle(file, 'r') as fp:
00042         for tree in getattr(supported_formats[format], 'parse')(fp, **kwargs):
00043             yield tree
00044 

Here is the caller graph for this function:

def Bio.Phylo._io.read (   file,
  format,
  kwargs 
)
Parse a file in the given format and return a single tree.

Raises a `ValueError` if there are zero or multiple trees -- if this occurs,
use `parse` instead to get the complete sequence of trees.

Definition at line 45 of file _io.py.

00045 
00046 def read(file, format, **kwargs):
00047     """Parse a file in the given format and return a single tree.
00048 
00049     Raises a `ValueError` if there are zero or multiple trees -- if this occurs,
00050     use `parse` instead to get the complete sequence of trees.
00051     """
00052     try:
00053         tree_gen = parse(file, format, **kwargs)
00054         tree = tree_gen.next()
00055     except StopIteration:
00056         raise ValueError("There are no trees in this file.")
00057     try:
00058         tree_gen.next()
00059     except StopIteration:
00060         return tree
00061     else:
00062         raise ValueError(
00063                 "There are multiple trees in this file; use parse() instead.")
00064 

Here is the call graph for this function:

def Bio.Phylo._io.write (   trees,
  file,
  format,
  kwargs 
)
Write a sequence of trees to file in the given format.

Definition at line 65 of file _io.py.

00065 
00066 def write(trees, file, format, **kwargs):
00067     """Write a sequence of trees to file in the given format."""
00068     if isinstance(trees, BaseTree.Tree) or isinstance(trees, BaseTree.Clade):
00069         # Passed a single tree instead of an iterable -- that's OK
00070         trees = [trees]
00071     with File.as_handle(file, 'w+') as fp:
00072         n = getattr(supported_formats[format], 'write')(trees, fp, **kwargs)
00073     return n
00074 

Here is the caller graph for this function:


Variable Documentation

string Bio.Phylo._io.__docformat__ = "restructuredtext en"

Definition at line 13 of file _io.py.

Initial value:
00001 {
00002         'newick':   NewickIO,
00003         'nexus':    NexusIO,
00004         'phyloxml': PhyloXMLIO,
00005         }

Definition at line 19 of file _io.py.