Function Repository Resource:

ImportNewickString

Source Notebook

Import a string in Newick format

Contributed by: John Cassel (Wolfram|Alpha Team)

ResourceFunction["ImportNewickString"][newickString]

reads a String in Newick format and outputs a nested structure suitable for further analysis.

Details and Options

Newick format is a popular format for representing phylogenetic trees. It uses a nested format capturing the geometric and clustering structure.

Examples

Basic Examples (2) 

Import a basic Newick string:

In[1]:=
ResourceFunction["ImportNewickString"]["(a:3, b:2)c:0"]
Out[1]=

Arbitrary depths of nesting are supported:

In[2]:=
ResourceFunction[
 "ImportNewickString"]["(a:3, (d:4, (e:7, f:20)g:2, h:3), b:2)c:0"]
Out[2]=

Scope (3) 

If the Newick string does not provide labels for any nodes, labels will be automatically generated:

In[3]:=
ResourceFunction["ImportNewickString"]["(a:3, (b:1, d:3):4, c:2):0"]
Out[3]=

In the case labels names are duplicated, indexes will be appended to uniquely identify them:

In[4]:=
ResourceFunction[
 "ImportNewickString"]["(a:3, (b:1, d:3)node:4, c:2)node:0"]
Out[4]=

ImportNewickString also supports multiple trees not linked by a common node:

In[5]:=
ResourceFunction[
 "ImportNewickString"]["((a:3, b:2)node:0, (c:1, d:2)node2:1)"]
Out[5]=

Version History

  • 1.0.0 – 22 April 2020

Related Resources

License Information