UNPKG

phylotree

Version:

A JavaScript library for developing applications and interactive visualizations involving [phylogenetic trees](https://en.wikipedia.org/wiki/Phylogenetic_tree), written as an extension of the [D3](http://d3js.org) [hierarchy layout](https://github.com/d3/

36 lines (29 loc) 848 B
#!/usr/bin/env node const fs = require("fs"); const phylotree = require("../dist/phylotree.js"); const { program } = require("commander"); const _ = require("underscore"); /* * phylotree reroot * * Usage: * phylotree reroot ./test/data/CD2-relax.new -n Horse * */ program .arguments("<newick>", "Input newick file") .requiredOption("-n --node <node>", "Node to reroot on") .parse(process.argv); const options = program.opts(); if (!program.args[0]){ throw "ERROR: Newick file is required... exiting!"; } fs.readFile(program.args[0], (err, newickData) => { const tree = new phylotree.phylotree(newickData.toString()); const node = tree.getNodeByName(options.node); if(_.isUndefined(node)) { throw new Error("Could not find node with name " + options.node); } tree.reroot(node); console.log(tree.getNewick()); });