bug fix handle NoneType when writing to newick with branch_length_only=True

added test for phyloxml -> newick with branch_length_only=True

Peter: This is a rebased version of pull request #552.
This commit is contained in:
Alan Medlar
2015-05-29 16:36:27 +03:00
committed by Peter J. A. Cock
parent aea4f9988e
commit b6f74f2f71
2 changed files with 13 additions and 1 deletions

View File

@ -357,7 +357,7 @@ class Writer:
# write only branchlengths, ignore support
def make_info_string(clade, terminal=False):
return (
":" + format_branch_length % clade.branch_length
":" + format_branch_length % (clade.branch_length or 0.0)
) + _get_comment(clade)
else:

View File

@ -164,6 +164,18 @@ class IOTests(unittest.TestCase):
os.remove(tmp_filename)
self.assertEqual(14, count)
def test_convert_phyloxml_to_newick_branch_length_only(self):
"""Write phyloxml with bootstrap values to newick format using branch_length_only=True"""
trees = Phylo.parse(EX_APAF, "phyloxml")
tmp_filename = tempfile.mktemp()
try:
Phylo.write(trees, tmp_filename, "newick", branch_length_only=True)
os.remove(tmp_filename)
except TypeError:
self.fail()
def test_int_labels(self):
"""Read newick formatted tree with numeric labels."""
tree = Phylo.read(