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

Returns tree from the Clustal .dnd file format and equivalent

The tree is made of skbio.core.tree.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:


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

  / \
 *   \
/ \   \
a b   c

 \__|___ c

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


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.


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.



The root of the parsed tree



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.

See also





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