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/

35 lines (25 loc) 792 B
#!/usr/bin/env node const fs = require("fs"), phylotree = require("../dist/phylotree.js"), commander = require("commander"), _ = require("underscore"); commander .arguments("<newick>", "Input newick file") .on("--help", function() { console.log(""); console.log("Examples:"); console.log( 'phylotree shuffle test/data/MERS.txt' ); }) .parse(process.argv); fs.readFile(commander.args[0], (err, newickData) => { const tree = new phylotree.phylotree(newickData.toString()); let tips = tree.getTips(); // Get all the names and randomly assign them let names = _.map(tips, d => d.data.name); // Shuffle names let shuffledNames = _.shuffle(names); _.each(tips, (d,i) => d.data.name = shuffledNames[i]) console.log(tree.getNewick()); });