phylotree 2.6.0 → 2.7.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 +49 -5
- package/bin/phylotree-neighbor-join.js +4 -5
- package/bin/root-to-tip.js +1 -1
- package/bin/tip-date-extractor.js +26 -18
- package/dist/phylotree-menus.css +93 -0
- package/dist/phylotree.d.ts +509 -241
- package/dist/phylotree.js +5023 -1515
- package/dist/phylotree.min.js +1 -1
- package/package.json +25 -27
- package/src/branches.js +58 -34
- package/src/clustering/cluster-picker.js +18 -2
- package/src/clustering/phylopart.js +14 -6
- package/src/export.js +1 -1
- package/src/extract-dates.js +3 -3
- package/src/formats/beast.js +5 -1
- package/src/formats/newick.js +43 -7
- package/src/formats/nexml.js +87 -30
- package/src/formats/nexus.js +112 -32
- package/src/formats/phyloxml.js +74 -15
- package/src/formats/registry.js +5 -1
- package/src/index.js +1 -0
- package/src/main.js +76 -25
- package/src/metrics/center-of-tree.js +4 -2
- package/src/metrics/compute-midpoint.js +7 -1
- package/src/metrics/pairwise-distances.js +4 -2
- package/src/metrics/root-to-tip.js +43 -10
- package/src/metrics/sackins.js +7 -1
- package/src/msa-parsers/fasta.js +9 -12
- package/src/neighbor-join.js +107 -75
- package/src/nodes.js +43 -31
- package/src/render/clades.js +16 -4
- package/src/render/draw.js +128 -86
- package/src/render/edges.js +17 -8
- package/src/render/events.js +2 -3
- package/src/render/menus.js +110 -10
- package/src/render/nodes.js +42 -16
- package/src/render/options.js +3 -1
- package/src/render/selection-sets.js +30 -14
- package/src/render/unrooted.js +90 -12
- package/src/rooting.js +12 -3
- package/src/traversal.js +4 -3
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ const renderer = tree.render({
|
|
|
31
31
|
|
|
32
32
|
### TypeScript Support
|
|
33
33
|
|
|
34
|
-
phylotree.js includes TypeScript declarations. Import types alongside the main export:
|
|
34
|
+
phylotree.js includes TypeScript declarations. They build on the d3 types, so `@types/d3` is installed with the package as a dependency. Import types alongside the main export:
|
|
35
35
|
|
|
36
36
|
```typescript
|
|
37
37
|
import { phylotree, PhylotreeNode, RenderOptions } from "phylotree";
|
|
@@ -136,10 +136,8 @@ import {
|
|
|
136
136
|
} from "phylotree";
|
|
137
137
|
|
|
138
138
|
// Example: Identify clusters
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
distance_threshold: 0.045
|
|
142
|
-
});
|
|
139
|
+
// clusterPicker(tree, bootstrap_threshold, diameter_threshold)
|
|
140
|
+
const clusters = clusterPicker(tree, 0.9, 0.045);
|
|
143
141
|
```
|
|
144
142
|
|
|
145
143
|
### Tree Construction
|
|
@@ -244,6 +242,52 @@ The following are a list of possible options, along with their types, meanings,
|
|
|
244
242
|
### minimum-per-level-spacing
|
|
245
243
|
`(Number)` Determines minimum node spacing allocated when laying out top to bottom. Defaults to 10.
|
|
246
244
|
|
|
245
|
+
### show-menu
|
|
246
|
+
`(Boolean)` Whether or not the node menu is shown. Defaults to ``true``.
|
|
247
|
+
|
|
248
|
+
### menu-trigger
|
|
249
|
+
`(String)` Which mouse action opens the node menu. Defaults to ``"click"``.
|
|
250
|
+
|
|
251
|
+
* ``"click"`` - Left click.
|
|
252
|
+
* ``"contextmenu"`` - Right-click; the browser's own context menu is suppressed on nodes.
|
|
253
|
+
* ``"both"`` - Either.
|
|
254
|
+
|
|
255
|
+
## Node menu
|
|
256
|
+
|
|
257
|
+
Clicking a node (or right-clicking it, see [menu-trigger](#menu-trigger)) opens a menu with
|
|
258
|
+
the built-in actions enabled by the options above. Add your own items with `addCustomMenu`,
|
|
259
|
+
typically from a node styler:
|
|
260
|
+
|
|
261
|
+
```javascript
|
|
262
|
+
import { phylotree, addCustomMenu } from "phylotree";
|
|
263
|
+
|
|
264
|
+
const tree = new phylotree(newick);
|
|
265
|
+
tree.render({
|
|
266
|
+
container: "#tree",
|
|
267
|
+
"menu-trigger": "contextmenu",
|
|
268
|
+
"node-styler": (element, node) => {
|
|
269
|
+
addCustomMenu(
|
|
270
|
+
node,
|
|
271
|
+
n => "Show details for " + n.data.name, // label
|
|
272
|
+
(n, event) => showDetails(n), // called when clicked
|
|
273
|
+
n => !n.children // optional: only on leaves
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
Just before the menu opens, the tree emits `contextMenu` with `(node, event)`. Call
|
|
280
|
+
`event.preventDefault()` in a listener to show your own menu instead of the built-in one:
|
|
281
|
+
|
|
282
|
+
```javascript
|
|
283
|
+
tree.display.on("contextMenu", (node, event) => {
|
|
284
|
+
event.preventDefault();
|
|
285
|
+
showMyMenu(node, event.clientX, event.clientY);
|
|
286
|
+
});
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
`tree.display.openNodeMenu(node, event)` opens a node's menu from code.
|
|
290
|
+
|
|
247
291
|
## API Reference
|
|
248
292
|
A complete list of available functions can be found at [API.md](API.md)
|
|
249
293
|
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require("fs"),
|
|
4
4
|
phylotree = require("../dist/phylotree.js"),
|
|
5
|
-
{ program } = require("commander")
|
|
6
|
-
_ = require("lodash");
|
|
5
|
+
{ program } = require("commander");
|
|
7
6
|
|
|
8
7
|
program
|
|
9
8
|
.arguments("<fasta>", "Input fasta file")
|
|
@@ -17,11 +16,11 @@ program
|
|
|
17
16
|
fs.readFile(program.args[0], ( err, fastaData ) => {
|
|
18
17
|
|
|
19
18
|
let fasta = phylotree.parseFasta(fastaData);
|
|
20
|
-
let nodeList =
|
|
19
|
+
let nodeList = Object.keys(fasta);
|
|
21
20
|
let distanceMatrix = phylotree.getDistanceMatrix(fasta);
|
|
22
|
-
let distanceMatrixArr =
|
|
21
|
+
let distanceMatrixArr = Object.values(distanceMatrix);
|
|
23
22
|
|
|
24
|
-
let nj = phylotree.neighborJoining(distanceMatrixArr,
|
|
23
|
+
let nj = phylotree.neighborJoining(distanceMatrixArr, Object.keys(fasta).length, nodeList);
|
|
25
24
|
console.log(nj.getNewick());
|
|
26
25
|
|
|
27
26
|
});
|
package/bin/root-to-tip.js
CHANGED
|
@@ -4,19 +4,27 @@ const fs = require("fs"),
|
|
|
4
4
|
phylotree = require("../dist/phylotree.js"),
|
|
5
5
|
{ program } = require("commander"),
|
|
6
6
|
_ = require("underscore"),
|
|
7
|
-
moment = require("moment")
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
moment = require("moment");
|
|
8
|
+
|
|
9
|
+
// Logs go to stderr so they don't end up in the CSV on stdout.
|
|
10
|
+
const log_levels = { error: 0, warn: 1, info: 2, http: 3, verbose: 4, debug: 5, silly: 6 };
|
|
11
|
+
|
|
12
|
+
const logger = { level: "warn" };
|
|
13
|
+
|
|
14
|
+
_.each(_.keys(log_levels), name => {
|
|
15
|
+
logger[name] = message => {
|
|
16
|
+
const threshold = _.has(log_levels, logger.level) ? log_levels[logger.level] : log_levels.warn;
|
|
17
|
+
if (log_levels[name] <= threshold) {
|
|
18
|
+
console.error(name + ": " + message);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
18
21
|
});
|
|
19
22
|
|
|
23
|
+
function csv_field(value) {
|
|
24
|
+
const text = value == null ? "" : String(value);
|
|
25
|
+
return /[",\r\n]/.test(text) ? '"' + text.replace(/"/g, '""') + '"' : text;
|
|
26
|
+
}
|
|
27
|
+
|
|
20
28
|
/*
|
|
21
29
|
* Computes root-to-tip distance and fits linear regression
|
|
22
30
|
* Please see the following notebook for more details
|
|
@@ -95,7 +103,7 @@ if (options.dateFormat) {
|
|
|
95
103
|
let default_date_parser = function(tree, node) {
|
|
96
104
|
const default_regexp = /([0-9]{4})-?([0-9]{2})-?([0-9]{2})$/g;
|
|
97
105
|
|
|
98
|
-
var location
|
|
106
|
+
var location;
|
|
99
107
|
|
|
100
108
|
if (tree.isLeafNode(node)) {
|
|
101
109
|
if ("name" in node.data) {
|
|
@@ -117,7 +125,7 @@ let default_date_parser = function(tree, node) {
|
|
|
117
125
|
|
|
118
126
|
// Example - [0-9]{4}-[0-9]{2}-[0-9]{2}
|
|
119
127
|
let regex_date_parser = function(tree, regex, format, node) {
|
|
120
|
-
var location
|
|
128
|
+
var location;
|
|
121
129
|
|
|
122
130
|
if (tree.isLeafNode(node) && "name" in node.data) {
|
|
123
131
|
|
|
@@ -201,10 +209,10 @@ fs.readFile(options.newick, (err, newick_data) => {
|
|
|
201
209
|
return !_.isNull(d.decimal_date_value);
|
|
202
210
|
});
|
|
203
211
|
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
212
|
+
const rows = _.map(date_and_distances, row => _.map(row, csv_field).join(",") + "\n");
|
|
213
|
+
|
|
214
|
+
// Pretty print table
|
|
215
|
+
console.log("name, date");
|
|
216
|
+
console.log(rows.join(""));
|
|
209
217
|
|
|
210
218
|
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* phylotree-menus.css - Standalone menu styles (no Bootstrap dependency)
|
|
3
|
+
*
|
|
4
|
+
* This file provides native styling for phylotree context menus.
|
|
5
|
+
* Include this CSS file to use menus without Bootstrap.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
.phylotree-context-menu {
|
|
9
|
+
position: absolute;
|
|
10
|
+
display: none;
|
|
11
|
+
min-width: 160px;
|
|
12
|
+
padding: 8px 0;
|
|
13
|
+
margin: 0;
|
|
14
|
+
background-color: #ffffff;
|
|
15
|
+
border: 1px solid rgba(0, 0, 0, 0.15);
|
|
16
|
+
border-radius: 4px;
|
|
17
|
+
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.175);
|
|
18
|
+
z-index: 1000;
|
|
19
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
|
20
|
+
font-size: 14px;
|
|
21
|
+
color: #212529;
|
|
22
|
+
list-style: none;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.phylotree-menu-item {
|
|
26
|
+
display: block;
|
|
27
|
+
padding: 6px 20px;
|
|
28
|
+
color: #212529;
|
|
29
|
+
text-decoration: none;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
white-space: nowrap;
|
|
32
|
+
background-color: transparent;
|
|
33
|
+
border: none;
|
|
34
|
+
width: 100%;
|
|
35
|
+
text-align: left;
|
|
36
|
+
box-sizing: border-box;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.phylotree-menu-item:hover,
|
|
40
|
+
.phylotree-menu-item:focus {
|
|
41
|
+
background-color: #f8f9fa;
|
|
42
|
+
color: #16181b;
|
|
43
|
+
outline: none;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.phylotree-menu-item:active {
|
|
47
|
+
background-color: #e9ecef;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
.phylotree-menu-divider {
|
|
51
|
+
height: 0;
|
|
52
|
+
margin: 8px 0;
|
|
53
|
+
overflow: hidden;
|
|
54
|
+
border-top: 1px solid #e9ecef;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.phylotree-menu-header {
|
|
58
|
+
display: block;
|
|
59
|
+
padding: 6px 20px;
|
|
60
|
+
margin-bottom: 0;
|
|
61
|
+
font-size: 12px;
|
|
62
|
+
font-weight: 600;
|
|
63
|
+
color: #6c757d;
|
|
64
|
+
white-space: nowrap;
|
|
65
|
+
text-transform: uppercase;
|
|
66
|
+
letter-spacing: 0.5px;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/* Selection set color indicators */
|
|
70
|
+
.phylotree-set-indicator {
|
|
71
|
+
display: inline-block;
|
|
72
|
+
width: 10px;
|
|
73
|
+
height: 10px;
|
|
74
|
+
border-radius: 50%;
|
|
75
|
+
margin-right: 8px;
|
|
76
|
+
vertical-align: middle;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/* Animation for menu appearance */
|
|
80
|
+
.phylotree-context-menu[style*="display: block"] {
|
|
81
|
+
animation: phylotree-menu-fade-in 0.15s ease-out;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@keyframes phylotree-menu-fade-in {
|
|
85
|
+
from {
|
|
86
|
+
opacity: 0;
|
|
87
|
+
transform: translateY(-4px);
|
|
88
|
+
}
|
|
89
|
+
to {
|
|
90
|
+
opacity: 1;
|
|
91
|
+
transform: translateY(0);
|
|
92
|
+
}
|
|
93
|
+
}
|