phylotree 2.3.0 → 2.5.0
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/README.md +93 -17
- package/bin/phylotree-distance.js +12 -10
- package/bin/phylotree-mrca.js +9 -7
- package/bin/phylotree-neighbor-join.js +9 -10
- package/bin/phylotree-reroot.js +13 -13
- package/bin/phylotree-shuffle.js +5 -5
- package/bin/phylotree-tag.js +13 -11
- package/bin/phylotree-tips.js +8 -6
- package/bin/phylotree-validate.js +5 -5
- package/bin/root-to-tip.js +11 -10
- package/bin/tip-date-extractor.js +17 -15
- package/dist/phylotree.d.ts +123 -0
- package/dist/phylotree.js +150 -176
- package/dist/phylotree.min.js +1 -1
- package/package.json +24 -25
- package/src/formats/phyloxml.js +48 -48
- package/src/index.js +2 -0
- package/src/render/nodes.js +1 -1
- package/src/render/selection-sets.js +10 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "phylotree",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"main": "dist/phylotree.js",
|
|
5
5
|
"types": "dist/phylotree.d.ts",
|
|
6
6
|
"unpkg": "dist/phylotree.js",
|
|
@@ -23,38 +23,37 @@
|
|
|
23
23
|
"index.html"
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"commander": "^
|
|
27
|
-
"csv-stringify": "^
|
|
26
|
+
"commander": "^14.0.0",
|
|
27
|
+
"csv-stringify": "^6.6.0",
|
|
28
28
|
"d3": "^7.9.0",
|
|
29
|
-
"fast-xml-parser": "^5.
|
|
30
|
-
"jquery": "3",
|
|
31
|
-
"lodash": "^4.17.
|
|
32
|
-
"moment": "^2.
|
|
29
|
+
"fast-xml-parser": "^5.3.4",
|
|
30
|
+
"jquery": "^3.7.1",
|
|
31
|
+
"lodash": "^4.17.23",
|
|
32
|
+
"moment": "^2.30.1",
|
|
33
33
|
"pretty-data": "^0.40.0",
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"winston": "^3.2.1"
|
|
34
|
+
"underscore": "^1.13.7",
|
|
35
|
+
"winston": "^3.17.0"
|
|
37
36
|
},
|
|
38
37
|
"devDependencies": {
|
|
39
|
-
"@rollup/plugin-commonjs": "^
|
|
38
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
40
39
|
"@rollup/plugin-node-resolve": "^16.0.1",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
40
|
+
"@rollup/plugin-terser": "^0.4.4",
|
|
41
|
+
"concurrently": "^9.2.0",
|
|
42
|
+
"@eslint/js": "^9.39.0",
|
|
43
|
+
"eslint": "^9.39.0",
|
|
44
|
+
"globals": "^16.2.0",
|
|
43
45
|
"http-server": "^14.1.1",
|
|
44
|
-
"jsdoc-to-markdown": "^
|
|
45
|
-
"prettier": "^
|
|
46
|
-
"rollup": "^
|
|
47
|
-
"rollup-plugin-copy": "^3.
|
|
48
|
-
"
|
|
49
|
-
"rollup-plugin-terser": "^7.0.2",
|
|
50
|
-
"tape": "5.2.2",
|
|
51
|
-
"yarn": "^1.22.11"
|
|
46
|
+
"jsdoc-to-markdown": "^9.1.0",
|
|
47
|
+
"prettier": "^3.7.0",
|
|
48
|
+
"rollup": "^4.40.0",
|
|
49
|
+
"rollup-plugin-copy": "^3.5.0",
|
|
50
|
+
"tape": "^5.9.0"
|
|
52
51
|
},
|
|
53
52
|
"scripts": {
|
|
54
|
-
"lint": "eslint
|
|
55
|
-
"dev": "rollup -w -c rollup.config.
|
|
56
|
-
"serve": "concurrently 'rollup -w -c rollup.config.
|
|
57
|
-
"build": "rollup -c rollup.config.
|
|
53
|
+
"lint": "eslint .",
|
|
54
|
+
"dev": "rollup -w -c rollup.config.mjs",
|
|
55
|
+
"serve": "concurrently 'rollup -w -c rollup.config.mjs' 'http-server'",
|
|
56
|
+
"build": "rollup -c rollup.config.mjs",
|
|
58
57
|
"test": "tape -r source-map-support/register 'test/*-test.js'",
|
|
59
58
|
"docs:generate": "jsdoc2md 'src/**/*.js' > API.md",
|
|
60
59
|
"docs:validate": "jsdoc2md 'src/**/*.js' --no-cache --partial 'partials/**/*.hbs'",
|
package/src/formats/phyloxml.js
CHANGED
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
import { XMLParser } from
|
|
1
|
+
import { XMLParser } from "fast-xml-parser";
|
|
2
2
|
|
|
3
3
|
// Changes XML to JSON
|
|
4
4
|
// Modified version from here: http://davidwalsh.name/convert-xml-json
|
|
5
5
|
function xmlToJson(xml) {
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
// Create the return object
|
|
8
|
+
var obj = {};
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
if (xml.nodeType == 1) { // element
|
|
11
|
+
// do attributes
|
|
12
|
+
if (xml.attributes.length > 0) {
|
|
13
|
+
obj["@attributes"] = {};
|
|
14
|
+
for (var j = 0; j < xml.attributes.length; j++) {
|
|
15
|
+
var attribute = xml.attributes.item(j);
|
|
16
|
+
obj["@attributes"][attribute.nodeName] = attribute.nodeValue;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
} else if (xml.nodeType == 3) { // text
|
|
20
|
+
obj = xml.nodeValue;
|
|
21
|
+
}
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
23
|
+
// do children
|
|
24
|
+
// If just one text node inside
|
|
25
|
+
if (xml.hasChildNodes() && xml.childNodes.length === 1 && xml.childNodes[0].nodeType === 3) {
|
|
26
|
+
obj = xml.childNodes[0].nodeValue;
|
|
27
|
+
}
|
|
28
|
+
else if (xml.hasChildNodes()) {
|
|
29
|
+
for(var i = 0; i < xml.childNodes.length; i++) {
|
|
30
|
+
var item = xml.childNodes.item(i);
|
|
31
|
+
var nodeName = item.nodeName;
|
|
32
|
+
if (typeof(obj[nodeName]) == "undefined") {
|
|
33
|
+
obj[nodeName] = xmlToJson(item);
|
|
34
|
+
} else {
|
|
35
|
+
if (typeof(obj[nodeName].push) == "undefined") {
|
|
36
|
+
var old = obj[nodeName];
|
|
37
|
+
obj[nodeName] = [];
|
|
38
|
+
obj[nodeName].push(old);
|
|
39
|
+
}
|
|
40
|
+
obj[nodeName].push(xmlToJson(item));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return obj;
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
var phyloxml_parser = function(xml, options) {
|
|
@@ -49,8 +49,8 @@ var phyloxml_parser = function(xml, options) {
|
|
|
49
49
|
function parsePhyloxml(node, index) {
|
|
50
50
|
if (node.clade) {
|
|
51
51
|
if (!Array.isArray(node.clade)) {
|
|
52
|
-
|
|
53
|
-
}
|
|
52
|
+
node.clade = [node.clade];
|
|
53
|
+
}
|
|
54
54
|
node.clade.forEach(parsePhyloxml);
|
|
55
55
|
node.children = node.clade;
|
|
56
56
|
delete node.clade;
|
|
@@ -72,20 +72,20 @@ var phyloxml_parser = function(xml, options) {
|
|
|
72
72
|
var tree_json;
|
|
73
73
|
|
|
74
74
|
if (typeof xml === "string") {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
82
|
}
|
|
83
83
|
|
|
84
84
|
xml = xmlToJson(xml);
|
|
85
85
|
var phylogeny = xml.phyloxml.phylogeny;
|
|
86
86
|
if (Array.isArray(phylogeny)) {
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
phylogeny = phylogeny[0];
|
|
88
|
+
console.warn("PhyloXML files with multiple phylogenies are not currently supported. Only the first phylogeny will be loaded.")
|
|
89
89
|
}
|
|
90
90
|
tree_json = phylogeny.clade;
|
|
91
91
|
tree_json.name = "root";
|
package/src/index.js
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
export { default as phylotree } from "./main.js";
|
|
2
2
|
|
|
3
3
|
export { default as pairwise_distances } from "./metrics/pairwise-distances";
|
|
4
|
+
export { default as pairwiseDistances } from "./metrics/pairwise-distances";
|
|
4
5
|
export { default as sackin } from "./metrics/sackins";
|
|
5
6
|
export { centerOfTree } from "./metrics/center-of-tree";
|
|
6
7
|
export { computeMidpoint } from "./metrics/compute-midpoint";
|
|
7
8
|
export { default as rootToTip, fitRootToTip } from "./metrics/root-to-tip";
|
|
8
9
|
|
|
9
10
|
export { default as extract_dates } from "./extract-dates";
|
|
11
|
+
export { default as extractDates } from "./extract-dates";
|
|
10
12
|
export { default as clusterPicker } from "./clustering/cluster-picker";
|
|
11
13
|
export { default as phylopart } from "./clustering/phylopart";
|
|
12
14
|
|
package/src/render/nodes.js
CHANGED
|
@@ -38,11 +38,11 @@ export function initializeSelectionSets(sets) {
|
|
|
38
38
|
* @private
|
|
39
39
|
*/
|
|
40
40
|
export function _injectSetStyles(sets) {
|
|
41
|
-
const styleId =
|
|
41
|
+
const styleId = "phylotree-selection-set-styles";
|
|
42
42
|
let styleEl = document.getElementById(styleId);
|
|
43
43
|
|
|
44
44
|
if (!styleEl) {
|
|
45
|
-
styleEl = document.createElement(
|
|
45
|
+
styleEl = document.createElement("style");
|
|
46
46
|
styleEl.id = styleId;
|
|
47
47
|
document.head.appendChild(styleEl);
|
|
48
48
|
}
|
|
@@ -127,8 +127,8 @@ export function addToSet(node, setName) {
|
|
|
127
127
|
return this;
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
const nodeName = typeof node ===
|
|
131
|
-
const nodeObj = typeof node ===
|
|
130
|
+
const nodeName = typeof node === "string" ? node : node.data.name;
|
|
131
|
+
const nodeObj = typeof node === "string"
|
|
132
132
|
? this.phylotree.getNodeByName(node)
|
|
133
133
|
: node;
|
|
134
134
|
|
|
@@ -141,8 +141,8 @@ export function addToSet(node, setName) {
|
|
|
141
141
|
this._selectionSets[setName].members.add(nodeName);
|
|
142
142
|
nodeObj._selectionSet = setName;
|
|
143
143
|
|
|
144
|
-
this.emit(
|
|
145
|
-
action:
|
|
144
|
+
this.emit("setChange", {
|
|
145
|
+
action: "add",
|
|
146
146
|
set: setName,
|
|
147
147
|
node: nodeObj,
|
|
148
148
|
allSets: this._getSetsSummary()
|
|
@@ -169,8 +169,8 @@ export function removeFromSet(node, setName) {
|
|
|
169
169
|
return this;
|
|
170
170
|
}
|
|
171
171
|
|
|
172
|
-
const nodeName = typeof node ===
|
|
173
|
-
const nodeObj = typeof node ===
|
|
172
|
+
const nodeName = typeof node === "string" ? node : node.data.name;
|
|
173
|
+
const nodeObj = typeof node === "string"
|
|
174
174
|
? this.phylotree.getNodeByName(node)
|
|
175
175
|
: node;
|
|
176
176
|
|
|
@@ -180,8 +180,8 @@ export function removeFromSet(node, setName) {
|
|
|
180
180
|
delete nodeObj._selectionSet;
|
|
181
181
|
}
|
|
182
182
|
|
|
183
|
-
this.emit(
|
|
184
|
-
action:
|
|
183
|
+
this.emit("setChange", {
|
|
184
|
+
action: "remove",
|
|
185
185
|
set: setName,
|
|
186
186
|
node: nodeObj,
|
|
187
187
|
allSets: this._getSetsSummary()
|