# skbio.tree.TreeNode.from_newick¶

classmethod TreeNode.from_newick(lines, unescape_name=True)[source]

Returns tree from the Clustal .dnd file format and equivalent

Note

Deprecated in scikit-bio 0.2.0-dev from_newick will be removed in scikit-bio 0.3.0. It is replaced by read, which is a more general method for deserializing TreeNode instances. read supports multiple file formats, automatic file format detection, etc. by taking advantage of scikit-bio’s I/O registry system. See skbio.io for more details.

The tree is made of skbio.TreeNode objects, with branch lengths if specified by the format.

More information on the Newick format can be found here [1]. In brief, the format uses parentheses to define nesting. For instance, a three taxon tree can be represented with:

((a,b),c);


Two possible ways to represent this tree drawing it out would be:

   *
/ \
*   \
/ \   \
a b   c

a
\__|___ c
/
b


The Newick format allows for defining branch length as well, for example:

((a:0.1,b:0.2):0.3,c:0.4);


This structure has a the same topology as the first example but the tree now contains more information about how similar or dissimilar nodes are to their parents. In the above example, we can see that tip a has a distance of 0.1 to its parent, and b has a distance of 0.2 to its parent. We can additionally see that the clade that encloses tips a and b has a distance of 0.3 to its parent, or in this case, the root.

Parameters: lines : a str, a list of str, or a file-like object The input newick string to parse unescape_names : bool Remove extraneous quote marks around names. Sometimes other programs are sensitive to the characters used in names, and it is essential (at times) to quote node names for compatibility. TreeNode The root of the parsed tree RecordError The following three conditions will trigger a RecordError: Unbalanced number of left and right parentheses A malformed newick string. For instance, if a semicolon is embedded within the string as opposed to at the end. If a non-newick string is passed.

to_newick

References

Examples

>>> from skbio import TreeNode
>>> TreeNode.from_newick("((a,b)c,(d,e)f)root;")
<TreeNode, name: root, internal node count: 2, tips count: 4>
>>> from six import StringIO
>>> s = StringIO("((a,b),c);")
>>> TreeNode.from_newick(s)
<TreeNode, name: unnamed, internal node count: 1, tips count: 3>