iham-parsers
Version:
orthoxml, phyloxml and newick parsers for the iHam widget
23 lines (21 loc) • 1.29 kB
JavaScript
var hogvis = require("../index.js");
var chai = require('chai'), assert = chai.assert, expect = chai.expect;
const withData = require('mocha-each');
var fs = require('fs');
var parse_newick = hogvis.parse_newick, parse_phyloxml = hogvis.parse_phyloxml, tree_tool = hogvis.tree_tool;
describe('consistencey of newick and phyloxml parse trees', () => {
let files = fs.readdirSync(__dirname + '/speciestree_data');
let cases = files.filter(x => x.endsWith('.nwk')).map(x => [x.substr(0, x.indexOf('.')), x]);
withData(cases)
.it('run test on %s', (tcase, fname, done) => {
var nwk = fs.readFileSync(__dirname + "/speciestree_data/" + tcase + ".nwk").toString();
var xml = fs.readFileSync(__dirname + "/speciestree_data/" + tcase + ".phyloxml").toString();
var xml_tree = parse_phyloxml.phyloXml.parse(xml);
var nwk_tree = parse_newick.parse(nwk);
xml_tree = hogvis.tree_tool.add_nodenames_from_taxonomy_if_needed(hogvis.tree_tool.extractTree(xml_tree));
xml_tree = hogvis.tree_tool.ladderize(xml_tree);
nwk_tree = hogvis.tree_tool.ladderize(nwk_tree);
assert.isOk(hogvis.tree_tool.same_trees(xml_tree, nwk_tree), "tree topologies differ.");
done();
});
});