phylotree 1.0.17 → 1.0.19
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 +2 -2
- package/dist/phylotree.min.js +1 -1
- package/package.json +3 -2
- package/src/branches.js +156 -0
- package/src/clustering/cluster-picker.js +115 -0
- package/src/clustering/phylopart.js +238 -0
- package/src/export.js +25 -0
- package/src/extract-dates.js +68 -0
- package/src/formats/beast.js +29 -0
- package/src/formats/newick.js +271 -0
- package/src/formats/nexml.js +42 -0
- package/src/formats/nexus.js +96 -0
- package/src/formats/phyloxml.js +80 -0
- package/src/formats/registry.js +20 -0
- package/src/index.js +22 -0
- package/src/main.js +311 -0
- package/src/max-parsimony.js +81 -0
- package/src/metrics/center-of-tree.js +138 -0
- package/src/metrics/compute-midpoint.js +81 -0
- package/src/metrics/pairwise-distances.js +119 -0
- package/src/metrics/root-to-tip.js +220 -0
- package/src/metrics/sackins.js +21 -0
- package/src/nodes.js +215 -0
- package/src/render/cartesian.js +23 -0
- package/src/render/clades.js +116 -0
- package/src/render/coordinates.js +7 -0
- package/src/render/draw.js +1365 -0
- package/src/render/edges.js +134 -0
- package/src/render/events.js +166 -0
- package/src/render/helpers.js +7 -0
- package/src/render/menus.js +452 -0
- package/src/render/nodes.js +355 -0
- package/src/render/options.js +141 -0
- package/src/render/radial.js +79 -0
- package/src/rooting.js +183 -0
- package/src/transformations.js +20 -0
- package/src/traversal.js +114 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import * as d3 from "d3";
|
|
2
|
+
import { itemTagged, itemSelected } from "./helpers";
|
|
3
|
+
import { css_classes } from "./options";
|
|
4
|
+
|
|
5
|
+
export function drawEdge(container, edge, transition) {
|
|
6
|
+
|
|
7
|
+
container = d3.select(container);
|
|
8
|
+
|
|
9
|
+
container = container
|
|
10
|
+
.attr("class", d => {
|
|
11
|
+
return this.reclassEdge(d);
|
|
12
|
+
})
|
|
13
|
+
.on("click", d => {
|
|
14
|
+
this.modifySelection([edge.target], this.selection_attribute_name);
|
|
15
|
+
this.update();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
let new_branch_path = this.draw_branch([edge.source, edge.target]);
|
|
19
|
+
|
|
20
|
+
if (transition) {
|
|
21
|
+
|
|
22
|
+
if (container.datum().existing_path) {
|
|
23
|
+
container = container.attr("d", function(d) {
|
|
24
|
+
return d.existing_path;
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
container = container.attr("d", new_branch_path);
|
|
29
|
+
|
|
30
|
+
} else {
|
|
31
|
+
container = container.attr("d", new_branch_path);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
edge.existing_path = new_branch_path;
|
|
35
|
+
|
|
36
|
+
var bl = this.phylotree.branch_length_accessor(edge.target);
|
|
37
|
+
|
|
38
|
+
if (bl !== undefined) {
|
|
39
|
+
var haz_title = container.selectAll("title");
|
|
40
|
+
|
|
41
|
+
if (haz_title.empty()) {
|
|
42
|
+
haz_title = container.append("title");
|
|
43
|
+
}
|
|
44
|
+
haz_title.text("Length = " + bl);
|
|
45
|
+
} else {
|
|
46
|
+
container.selectAll("title").remove();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (this.edge_styler) {
|
|
50
|
+
this.edge_styler(container, edge, transition);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return this.phylotree;
|
|
54
|
+
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function reclassEdge(edge) {
|
|
58
|
+
|
|
59
|
+
let class_var = css_classes["branch"];
|
|
60
|
+
|
|
61
|
+
if (itemTagged(edge)) {
|
|
62
|
+
class_var += " " + css_classes["tagged-branch"];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (itemSelected(edge, this.selection_attribute_name)) {
|
|
66
|
+
class_var += " " + css_classes["selected-branch"];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return class_var;
|
|
70
|
+
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function initializeEdgeLabels() {
|
|
74
|
+
|
|
75
|
+
this.links.forEach(d => {
|
|
76
|
+
|
|
77
|
+
// TODO: Move away from storing attribute data as root (BREAKS occasionally with d3>3)
|
|
78
|
+
if(d.target.data.annotation) {
|
|
79
|
+
d.target[d.target.data.annotation] = d.target.data.annotation;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
export function syncEdgeLabels() {
|
|
88
|
+
|
|
89
|
+
this.links.forEach(d => {
|
|
90
|
+
|
|
91
|
+
// TODO: Move away from storing attribute data as root (BREAKS occasionally with d3>3)
|
|
92
|
+
d[this.selection_attribute_name] =
|
|
93
|
+
d.target[this.selection_attribute_name] || false;
|
|
94
|
+
d.tag = d.target.tag || false;
|
|
95
|
+
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
if (this.countHandler()) {
|
|
99
|
+
|
|
100
|
+
let counts = {};
|
|
101
|
+
|
|
102
|
+
counts[
|
|
103
|
+
this.selection_attribute_name
|
|
104
|
+
] = this.links.reduce((p, c) => {
|
|
105
|
+
return p + (c[this.selection_attribute_name] ? 1 : 0);
|
|
106
|
+
}, 0);
|
|
107
|
+
|
|
108
|
+
counts["tagged"] = this.links.reduce(function(p, c) {
|
|
109
|
+
return p + (itemTagged(c) ? 1 : 0);
|
|
110
|
+
}, 0);
|
|
111
|
+
|
|
112
|
+
this.countUpdate(this, counts, this.countHandler());
|
|
113
|
+
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function edgeVisible(edge) {
|
|
119
|
+
return !(edge.target.hidden || edge.target.notshown || false);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export function edgeCssSelectors(css_classes) {
|
|
123
|
+
return [
|
|
124
|
+
css_classes["branch"],
|
|
125
|
+
css_classes["selected-branch"],
|
|
126
|
+
css_classes["tagged-branch"]
|
|
127
|
+
].reduce(function(p, c, i, a) {
|
|
128
|
+
return (p += "path." + c + (i < a.length - 1 ? "," : ""));
|
|
129
|
+
}, "");
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export function placeAlongAnEdge (e, where) {
|
|
133
|
+
return this.edge_placer (e, where);
|
|
134
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { isLeafNode } from "../nodes";
|
|
2
|
+
import { css_classes } from "./options";
|
|
3
|
+
|
|
4
|
+
let d3_layout_phylotree_event_id = "phylotree.event";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Toggle collapsed view of a given node. Either collapses a clade into
|
|
8
|
+
* a smaller blob for viewing large trees, or expands a node that was
|
|
9
|
+
* previously collapsed.
|
|
10
|
+
*
|
|
11
|
+
* @param {Node} node The node to toggle.
|
|
12
|
+
* @returns {Phylotree} The current ``phylotree``.
|
|
13
|
+
*/
|
|
14
|
+
export function toggleCollapse(node) {
|
|
15
|
+
if (node.collapsed) {
|
|
16
|
+
node.collapsed = false;
|
|
17
|
+
|
|
18
|
+
let unhide = function(n) {
|
|
19
|
+
if (!isLeafNode(n)) {
|
|
20
|
+
if (!n.collapsed) {
|
|
21
|
+
n.children.forEach(unhide);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
n.hidden = false;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
unhide(node);
|
|
28
|
+
} else {
|
|
29
|
+
node.collapsed = true;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.placenodes();
|
|
33
|
+
return this;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function resizeSvg(tree, svg, tr) {
|
|
37
|
+
|
|
38
|
+
let sizes = this.size;
|
|
39
|
+
|
|
40
|
+
if (this.radial()) {
|
|
41
|
+
let pad_radius = this.pad_width(),
|
|
42
|
+
vertical_offset =
|
|
43
|
+
this.options["top-bottom-spacing"] != "fit-to-size"
|
|
44
|
+
? this.pad_height()
|
|
45
|
+
: 0;
|
|
46
|
+
|
|
47
|
+
sizes = [
|
|
48
|
+
sizes[1] + 2 * pad_radius,
|
|
49
|
+
sizes[0] + 2 * pad_radius + vertical_offset
|
|
50
|
+
];
|
|
51
|
+
|
|
52
|
+
if (svg) {
|
|
53
|
+
svg
|
|
54
|
+
.selectAll("." + css_classes["tree-container"])
|
|
55
|
+
.attr(
|
|
56
|
+
"transform",
|
|
57
|
+
"translate (" +
|
|
58
|
+
pad_radius +
|
|
59
|
+
"," +
|
|
60
|
+
(pad_radius + vertical_offset) +
|
|
61
|
+
")"
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
|
|
66
|
+
sizes = [
|
|
67
|
+
sizes[0] +
|
|
68
|
+
(this.options["top-bottom-spacing"] != "fit-to-size"
|
|
69
|
+
? this.pad_height()
|
|
70
|
+
: 0),
|
|
71
|
+
sizes[1] +
|
|
72
|
+
(this.options["left-right-spacing"] != "fit-to-size"
|
|
73
|
+
? this.pad_width()
|
|
74
|
+
: 0)
|
|
75
|
+
];
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (svg) {
|
|
80
|
+
|
|
81
|
+
if (tr) {
|
|
82
|
+
svg = svg.transition(100);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
svg.attr("height", sizes[0]).attr("width", sizes[1]);
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
this.size = sizes;
|
|
90
|
+
|
|
91
|
+
return sizes;
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function rescale(scale, attr_name) {
|
|
96
|
+
attr_name = attr_name || "y_scaled";
|
|
97
|
+
if (attr_name in this) {
|
|
98
|
+
this[attr_name] *= scale;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function triggerRefresh(tree) {
|
|
103
|
+
|
|
104
|
+
var event = new CustomEvent(d3_layout_phylotree_event_id, {
|
|
105
|
+
detail: ["refresh", tree]
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
document.dispatchEvent(event);
|
|
109
|
+
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function countUpdate(tree, counts) {
|
|
113
|
+
var event = new CustomEvent(d3_layout_phylotree_event_id, {
|
|
114
|
+
detail: ["countUpdate", counts, tree.countHandler()]
|
|
115
|
+
});
|
|
116
|
+
document.dispatchEvent(event);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function d3PhylotreeTriggerLayout(tree) {
|
|
120
|
+
var event = new CustomEvent(d3_layout_phylotree_event_id, {
|
|
121
|
+
detail: ["layout", tree, tree.layoutHandler()]
|
|
122
|
+
});
|
|
123
|
+
document.dispatchEvent(event);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export function d3PhylotreeEventListener(event) {
|
|
127
|
+
switch (event.detail[0]) {
|
|
128
|
+
case "refresh":
|
|
129
|
+
event.detail[1].refresh();
|
|
130
|
+
break;
|
|
131
|
+
case "countUpdate":
|
|
132
|
+
event.detail[2](event.detail[1]);
|
|
133
|
+
break;
|
|
134
|
+
case "layout":
|
|
135
|
+
event.detail[2](event.detail[1]);
|
|
136
|
+
}
|
|
137
|
+
return true;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function d3PhylotreeAddEventListener() {
|
|
141
|
+
document.addEventListener(
|
|
142
|
+
d3_layout_phylotree_event_id,
|
|
143
|
+
d3PhylotreeEventListener,
|
|
144
|
+
false
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function d3PhylotreeSvgTranslate(x) {
|
|
149
|
+
if (x && (x[0] !== null || x[1] !== null))
|
|
150
|
+
return (
|
|
151
|
+
"translate (" +
|
|
152
|
+
(x[0] !== null ? x[0] : 0) +
|
|
153
|
+
"," +
|
|
154
|
+
(x[1] !== null ? x[1] : 0) +
|
|
155
|
+
") "
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
return "";
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export function d3PhylotreeSvgRotate(a) {
|
|
162
|
+
if (a !== null) {
|
|
163
|
+
return "rotate (" + a + ") ";
|
|
164
|
+
}
|
|
165
|
+
return "";
|
|
166
|
+
}
|