phylojs
Version:
A simple typescript library for phylogenetic trees
15 lines (14 loc) • 559 B
JavaScript
import { newickRecurse } from './newick';
/** Writes tree in .nexus format. Undefined branch lengths set to 0.
* @param {tree} tree The tree to write
* @param {boolean} annotate Boolean to include annotations. Default is true.
*/
export function writeNexus(tree, annotationWriter = _annotation => '') {
let nexusStr = '#NEXUS\n\nbegin trees;\n';
if (tree.root !== undefined)
nexusStr +=
`\ttree tree_1 = [&R] ${newickRecurse(tree.root, annotationWriter)};` +
'\n';
nexusStr += 'end;';
return nexusStr;
}