Function Repository Resource:

ExportNewickString

Source Notebook

Generate the Newick string representation of a tree

Contributed by: Jon McLoone

ResourceFunction["ExportNewickString"][gr]

generates the Newick string representation of the tree Graph gr.

Details

Only the vertex-labeled representation, without distances, is supported.

Examples

Basic Examples (1) 

Generate the Newick string of a simple tree:

In[1]:=
ResourceFunction["ExportNewickString"][
 Graph[{1 \[DirectedEdge] 2, 1 \[DirectedEdge] 3, 2 \[DirectedEdge] 4,
    2 \[DirectedEdge] 5}]]
Out[1]=

Possible Issues (1) 

Because Newick strings use parentheses and commas to represent structure, vertex names whose string representation contains these characters are modified:

In[2]:=
ResourceFunction["ExportNewickString"][
 Graph[{f[a, b] \[DirectedEdge] 2, f[a, b] \[DirectedEdge] 3, 2 \[DirectedEdge] 4, 2 \[DirectedEdge] "t(x)"}]]
Out[2]=

Publisher

Jon McLoone

Version History

  • 1.0.0 – 22 March 2021

Related Resources

License Information