Back to index

python-biopython  1.60
Public Member Functions
test_Phylo.IOTests Class Reference

List of all members.

Public Member Functions

def test_newick_read_single
def test_newick_read_multiple
def test_newick_write
def test_format_branch_length
def test_convert

Detailed Description

Tests for parsing and writing the supported formats.

Definition at line 26 of file test_Phylo.py.


Member Function Documentation

Convert a tree between all supported formats.

Definition at line 67 of file test_Phylo.py.

00067 
00068     def test_convert(self):
00069         """Convert a tree between all supported formats."""
00070         mem_file_1 = StringIO()
00071         mem_file_3 = StringIO()
00072         if sys.version_info[0] == 3:
00073             from io import BytesIO
00074             mem_file_2 = BytesIO()
00075         else:
00076             mem_file_2 = StringIO()
00077         Phylo.convert(EX_NEWICK, 'newick', mem_file_1, 'nexus')
00078         mem_file_1.seek(0)
00079         Phylo.convert(mem_file_1, 'nexus', mem_file_2, 'phyloxml')
00080         mem_file_2.seek(0)
00081         Phylo.convert(mem_file_2, 'phyloxml', mem_file_3, 'newick')
00082         mem_file_3.seek(0)
00083         tree = Phylo.read(mem_file_3, 'newick')
00084         self.assertEqual(len(tree.get_terminals()), 28)
00085 

Custom format string for Newick branch length serialization.

Definition at line 57 of file test_Phylo.py.

00057 
00058     def test_format_branch_length(self):
00059         """Custom format string for Newick branch length serialization."""
00060         tree = Phylo.read(StringIO('A:0.1;'), 'newick')
00061         mem_file = StringIO()
00062         Phylo.write(tree, mem_file, 'newick', format_branch_length='%.0e')
00063         # Py2.5 compat: Windows with Py2.5- represents this as 1e-001;
00064         # on all other platforms it's 1e-01
00065         self.assertTrue(mem_file.getvalue().strip()
00066                         in ['A:1e-01;', 'A:1e-001;'])

Parse a Nexus file with multiple trees.

Definition at line 34 of file test_Phylo.py.

00034 
00035     def test_newick_read_multiple(self):
00036         """Parse a Nexus file with multiple trees."""
00037         trees = list(Phylo.parse(EX_NEXUS, 'nexus'))
00038         self.assertEqual(len(trees), 3)
00039         for tree in trees:
00040             self.assertEqual(len(tree.get_terminals()), 9)

Read a Newick file with one tree.

Definition at line 29 of file test_Phylo.py.

00029 
00030     def test_newick_read_single(self):
00031         """Read a Newick file with one tree."""
00032         tree = Phylo.read(EX_NEWICK, 'newick')
00033         self.assertEqual(len(tree.get_terminals()), 28)

Parse a Nexus file with multiple trees.

Definition at line 41 of file test_Phylo.py.

00041 
00042     def test_newick_write(self):
00043         """Parse a Nexus file with multiple trees."""
00044         # Tree with internal node labels
00045         mem_file = StringIO()
00046         tree = Phylo.read(StringIO('(A,B,(C,D)E)F;'), 'newick')
00047         Phylo.write(tree, mem_file, 'newick')
00048         mem_file.seek(0)
00049         tree2 = Phylo.read(mem_file, 'newick')
00050         # Sanity check
00051         self.assertEqual(tree2.count_terminals(), 4)
00052         # Check internal node labels were retained
00053         internal_names = set(c.name
00054                 for c in tree2.get_nonterminals()
00055                 if c is not None)
00056         self.assertEqual(internal_names, set(('E', 'F')))


The documentation for this class was generated from the following file: