Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Import a string in Newick format
| ResourceFunction["ImportNewickString"][newickString] reads a String in Newick format and outputs a nested structure suitable for further analysis. | 
Import a basic Newick string:
| In[1]:= | ![ResourceFunction["ImportNewickString"]["(a:3, b:2)c:0"]](https://www.wolframcloud.com/obj/resourcesystem/images/4c5/4c5ddf48-69da-463c-b292-4f53ebc6bf8b/4abdc1f252dcb72b.png) | 
| 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"]](https://www.wolframcloud.com/obj/resourcesystem/images/4c5/4c5ddf48-69da-463c-b292-4f53ebc6bf8b/3b4bf5bba65851b8.png) | 
| Out[2]= |  | 
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"]](https://www.wolframcloud.com/obj/resourcesystem/images/4c5/4c5ddf48-69da-463c-b292-4f53ebc6bf8b/114ddb66b5ef7d41.png) | 
| 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"]](https://www.wolframcloud.com/obj/resourcesystem/images/4c5/4c5ddf48-69da-463c-b292-4f53ebc6bf8b/7b736bbf037afea5.png) | 
| 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)"]](https://www.wolframcloud.com/obj/resourcesystem/images/4c5/4c5ddf48-69da-463c-b292-4f53ebc6bf8b/7b9095be04ef2a94.png) | 
| Out[5]= |  | 
This work is licensed under a Creative Commons Attribution 4.0 International License