Biopython: non-standard Newick formating

Created on 20 Feb 2017  路  4Comments  路  Source: biopython/biopython

Hi,

I wish to mention that the string returned by NewickIO.Writer.write() has a format not compliant to Newick standard, when the default option of writing both branch length and branch supports is chosen. Two semi-colons are written: a regular one before the branch length, but also a wrong one before the branch support, e.g. (as highlighted by RAxML when trying to read the file outputed by Bio.Phylo):

ERROR: Expecting ',' in tree; found: character ':'
CITFR2:0.00015):1.00:0.00042,CITFR5:0.00
^

It seem the code line 330 of NewickIO.py is to blame:

                    return (':' + format_confidence + ':' + format_branch_length

should be:

                    return (format_confidence + ':' + format_branch_length

can you please fix that?

all the best,

Florent

Most helpful comment

I can see why someone would want to have the full information on the node, i.e. "(labelA, labelB)labelC:confval:branchlenght" retained in the Newick string.

Unfortunately, most Newick parser will fail on that formatting, because the semicolon is expected only once per node, to signal the branch length field. As said in the issue #488 the usual way is to replace internal labels with confidence values when there are (not really to concatenate them, as then the float confidence value will be considered part of the label).

I would suggest that if someone wants to have the three node attributes retained in the Newick string (label, confidence value, branch length), he could specify an non-default option to get the 2-semicolon decorator "label:confval:branchlenght", but that by default, or when the internal node has no label, that the 1-semicolon decorator "confval:branchlenght" be used.

Maybe a tuple argument could be passed to the writer() function specifying what one wants, e.g.:

("confidence_value", "name")

All 4 comments

We've gone back and forth on this, see: #488

Newick has only a vague spec, and I'm not an expert in how current tools prefer to parse it.

I can see why someone would want to have the full information on the node, i.e. "(labelA, labelB)labelC:confval:branchlenght" retained in the Newick string.

Unfortunately, most Newick parser will fail on that formatting, because the semicolon is expected only once per node, to signal the branch length field. As said in the issue #488 the usual way is to replace internal labels with confidence values when there are (not really to concatenate them, as then the float confidence value will be considered part of the label).

I would suggest that if someone wants to have the three node attributes retained in the Newick string (label, confidence value, branch length), he could specify an non-default option to get the 2-semicolon decorator "label:confval:branchlenght", but that by default, or when the internal node has no label, that the 1-semicolon decorator "confval:branchlenght" be used.

Maybe a tuple argument could be passed to the writer() function specifying what one wants, e.g.:

("confidence_value", "name")

this seems to have been solved with commit a0352e16d5208cbdab76e1fffb7c334ea1e34c74.

Thanks - that was done in pull request #1276.

Was this page helpful?
0 / 5 - 0 ratings