Skip to content

How to use custom annotation parsers and writer with readNewick and writeNewick

PhyloJS provides flexibility in handling custom annotations in Newick format trees through custom parser and writer functions. This example demonstrates how to read a Newick string with custom annotations and write it back with custom formatting.

Let's say we have a Newick tree with some custom annotation format with key value pairs separated by ';'. This is a terrible idea in practice because ';' signifies the end of a Newick string, but for the sake of an example, let's run with it.

NOTE: As of 17-05-2025, custom parsers still expect annotations to be enclosed in square brackets. This is a limitation of the current implementation and will be fixed in future releases.

```javascript

See the Pen Custom Annotation Parsing and Writing by Leo Featherstone (@LeoFeatherstone) on CodePen.