phylotree 2.1.2 → 2.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/phylotree.js +8548 -58
- package/dist/phylotree.min.js +2 -1
- package/package.json +6 -3
- package/src/formats/nexml.js +2 -2
- package/src/formats/phyloxml.js +24 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phylotree",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.4",
|
|
4
4
|
"main": "dist/phylotree.js",
|
|
5
5
|
"unpkg": "dist/phylotree.js",
|
|
6
6
|
"jsdelivr": "dist/phylotree.js",
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
"commander": "^6.2.1",
|
|
26
26
|
"csv-stringify": "^5.3.6",
|
|
27
27
|
"d3": "^7.9.0",
|
|
28
|
+
"fast-xml-parser": "^5.2.5",
|
|
28
29
|
"jquery": "3",
|
|
29
30
|
"lodash": "^4.17.11",
|
|
30
31
|
"moment": "^2.29.4",
|
|
@@ -35,16 +36,18 @@
|
|
|
35
36
|
"xml2js": "^0.6.2"
|
|
36
37
|
},
|
|
37
38
|
"devDependencies": {
|
|
39
|
+
"@rollup/plugin-commonjs": "^28.0.6",
|
|
40
|
+
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
38
41
|
"concurrently": "^6.2.0",
|
|
39
42
|
"eslint": "^7.32.0",
|
|
40
|
-
"http-server": "^
|
|
43
|
+
"http-server": "^14.1.1",
|
|
41
44
|
"jsdoc-to-markdown": "^7.0.1",
|
|
42
45
|
"prettier": "^2.3.2",
|
|
43
46
|
"rollup": "^2.50.6",
|
|
44
47
|
"rollup-plugin-copy": "^3.3.0",
|
|
45
48
|
"rollup-plugin-execute": "^1.1.1",
|
|
46
49
|
"rollup-plugin-terser": "^7.0.2",
|
|
47
|
-
"rollup-watch": "^
|
|
50
|
+
"rollup-watch": "^3.2.2",
|
|
48
51
|
"tape": "5.2.2",
|
|
49
52
|
"tape-watch": "^2.3.0",
|
|
50
53
|
"yarn": "^1.22.11"
|
package/src/formats/nexml.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as _ from "underscore";
|
|
2
|
-
import
|
|
2
|
+
import * as xml2js from "xml2js";
|
|
3
3
|
|
|
4
4
|
var nexml_parser = function(xml_string, options) {
|
|
5
5
|
var trees;
|
|
6
|
-
parseString(xml_string, function(error, xml) {
|
|
6
|
+
xml2js.parseString(xml_string, function(error, xml) {
|
|
7
7
|
trees = xml["nex:nexml"].trees[0].tree.map(function(nexml_tree) {
|
|
8
8
|
var node_list = nexml_tree.node.map(d => d.$),
|
|
9
9
|
node_hash = node_list.reduce(function(a, b) {
|
package/src/formats/phyloxml.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { XMLParser } from 'fast-xml-parser';
|
|
2
|
+
|
|
1
3
|
// Changes XML to JSON
|
|
2
4
|
// Modified version from here: http://davidwalsh.name/convert-xml-json
|
|
3
5
|
function xmlToJson(xml) {
|
|
@@ -46,15 +48,18 @@ var phyloxml_parser = function(xml, options) {
|
|
|
46
48
|
|
|
47
49
|
function parsePhyloxml(node, index) {
|
|
48
50
|
if (node.clade) {
|
|
51
|
+
if (!Array.isArray(node.clade)) {
|
|
52
|
+
node.clade = [node.clade];
|
|
53
|
+
}
|
|
49
54
|
node.clade.forEach(parsePhyloxml);
|
|
50
55
|
node.children = node.clade;
|
|
51
56
|
delete node.clade;
|
|
52
57
|
}
|
|
53
58
|
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
node.annotation = 1;
|
|
60
|
+
node.attribute = "0.01";
|
|
56
61
|
if (node.branch_length) {
|
|
57
|
-
|
|
62
|
+
node.attribute = node.branch_length;
|
|
58
63
|
}
|
|
59
64
|
if (node.taxonomy) {
|
|
60
65
|
node.name = node.taxonomy.scientific_name;
|
|
@@ -66,8 +71,23 @@ var phyloxml_parser = function(xml, options) {
|
|
|
66
71
|
|
|
67
72
|
var tree_json;
|
|
68
73
|
|
|
74
|
+
if (typeof xml === "string") {
|
|
75
|
+
if (DOMParser) {
|
|
76
|
+
const parser = new DOMParser();
|
|
77
|
+
xml = parser.parseFromString(xml, "text/xml");
|
|
78
|
+
} else {
|
|
79
|
+
const parser = new XMLParser();
|
|
80
|
+
xml = parser.parse(xml);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
69
84
|
xml = xmlToJson(xml);
|
|
70
|
-
|
|
85
|
+
var phylogeny = xml.phyloxml.phylogeny;
|
|
86
|
+
if (Array.isArray(phylogeny)) {
|
|
87
|
+
phylogeny = phylogeny[0];
|
|
88
|
+
console.warn('PhyloXML files with multiple phylogenies are not currently supported. Only the first phylogeny will be loaded.')
|
|
89
|
+
}
|
|
90
|
+
tree_json = phylogeny.clade;
|
|
71
91
|
tree_json.name = "root";
|
|
72
92
|
parsePhyloxml(tree_json, 0);
|
|
73
93
|
|