phylotree 1.0.20 → 1.2.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.
Files changed (40) hide show
  1. package/bin/phylotree-neighbor-join.js +28 -0
  2. package/bin/phylotree-validate.js +33 -0
  3. package/bin/phylotree.js +1 -0
  4. package/dist/phylotree.js +268 -22
  5. package/dist/phylotree.min.js +1 -1
  6. package/package.json +4 -3
  7. package/src/branches.js +0 -156
  8. package/src/clustering/cluster-picker.js +0 -115
  9. package/src/clustering/phylopart.js +0 -238
  10. package/src/export.js +0 -25
  11. package/src/extract-dates.js +0 -69
  12. package/src/formats/beast.js +0 -29
  13. package/src/formats/newick.js +0 -271
  14. package/src/formats/nexml.js +0 -42
  15. package/src/formats/nexus.js +0 -96
  16. package/src/formats/phyloxml.js +0 -80
  17. package/src/formats/registry.js +0 -20
  18. package/src/index.js +0 -22
  19. package/src/main.js +0 -311
  20. package/src/max-parsimony.js +0 -81
  21. package/src/metrics/center-of-tree.js +0 -138
  22. package/src/metrics/compute-midpoint.js +0 -81
  23. package/src/metrics/pairwise-distances.js +0 -119
  24. package/src/metrics/root-to-tip.js +0 -220
  25. package/src/metrics/sackins.js +0 -21
  26. package/src/nodes.js +0 -215
  27. package/src/render/cartesian.js +0 -23
  28. package/src/render/clades.js +0 -116
  29. package/src/render/coordinates.js +0 -7
  30. package/src/render/draw.js +0 -1365
  31. package/src/render/edges.js +0 -134
  32. package/src/render/events.js +0 -166
  33. package/src/render/helpers.js +0 -7
  34. package/src/render/menus.js +0 -452
  35. package/src/render/nodes.js +0 -355
  36. package/src/render/options.js +0 -141
  37. package/src/render/radial.js +0 -79
  38. package/src/rooting.js +0 -183
  39. package/src/transformations.js +0 -20
  40. package/src/traversal.js +0 -114
package/src/nodes.js DELETED
@@ -1,215 +0,0 @@
1
- import * as _ from "underscore";
2
-
3
- // These methods are part of the Phylotree object
4
-
5
- export function graftANode(graft_at, new_child, new_parent, lengths) {
6
-
7
- let nodes = this.nodes.descendants();
8
-
9
- if (graft_at.parent) {
10
- let node_index = nodes.indexOf(graft_at);
11
-
12
- if (node_index >= 0) {
13
- let parent_index = graft_at.parent.children.indexOf(graft_at);
14
-
15
- let new_split = {
16
- name: new_parent,
17
- parent: graft_at.parent,
18
- attribute: lengths ? lengths[2] : null,
19
- original_child_order: graft_at["original_child_order"]
20
- },
21
- new_node = {
22
- name: new_child,
23
- parent: new_split,
24
- attribute: lengths ? lengths[1] : null,
25
- original_child_order: 2
26
- };
27
-
28
- new_split["children"] = [graft_at, new_node];
29
- graft_at["parent"].children[parent_index] = new_split;
30
- graft_at.parent = new_split;
31
- graft_at["attribute"] = lengths ? lengths[0] : null;
32
- graft_at["original_child_order"] = 1;
33
- }
34
- }
35
-
36
- return this;
37
-
38
- }
39
-
40
- /**
41
- * Delete a given node.
42
- *
43
- * @param {Node} The node to be deleted, or the index of such a node.
44
- * @returns The current ``phylotree``.
45
- */
46
- export function deleteANode(index) {
47
- let nodes = this.nodes.descendants();
48
-
49
- if (typeof index != "number") {
50
- return this.deleteANode(nodes.indexOf(index));
51
- }
52
-
53
- if (index > 0 && index < nodes.length) {
54
- let node = nodes[index];
55
-
56
- if (node.parent) {
57
- // can only delete nodes that are not the root
58
- let delete_me_idx = node.parent.children.indexOf(node);
59
-
60
- if (delete_me_idx >= 0) {
61
- nodes.splice(index, 1);
62
-
63
- if (node.children) {
64
- node.children.forEach(function(d) {
65
- d["original_child_order"] = node.parent.children.length;
66
- node.parent.children.push(d);
67
- d.parent = node.parent;
68
- });
69
- }
70
-
71
- if (node.parent.children.length > 2) {
72
- node.parent.children.splice(delete_me_idx, 1);
73
- } else {
74
- if (node.parent.parent) {
75
- node.parent.parent.children[
76
- node.parent.parent.children.indexOf(node.parent)
77
- ] =
78
- node.parent.children[1 - delete_me_idx];
79
- node.parent.children[1 - delete_me_idx].parent = node.parent.parent;
80
- nodes.splice(nodes.indexOf(node.parent), 1);
81
- } else {
82
- nodes.splice(0, 1);
83
- nodes.parent = null;
84
- delete nodes.data["attribute"];
85
- delete nodes.data["annotation"];
86
- delete nodes.data["original_child_order"];
87
- nodes.name = "root";
88
- nodes.data.name = "root";
89
- }
90
- }
91
- }
92
- }
93
- }
94
-
95
- return this;
96
- }
97
-
98
- /**
99
- * Get the tips of the tree
100
- * @returns {Array} Nodes in the current ``phylotree``.
101
- */
102
- export function getTips() {
103
- // get all nodes that have no nodes
104
- return _.filter(this.nodes.descendants(), n => {
105
- return !_.has(n, "children");
106
- });
107
- }
108
-
109
- /**
110
- * Get the internal nodes of the tree
111
- * @returns {Array} Nodes in the current ``phylotree``.
112
- */
113
- export function getInternals() {
114
- // get all nodes that have no nodes
115
- return _.filter(this.nodes.descendants(), n => {
116
- return _.has(n, "children");
117
- });
118
- }
119
-
120
-
121
- /**
122
- * Get the root node.
123
- *
124
- * @returns the current root node of the ``phylotree``.
125
- */
126
- export function getRootNode() {
127
- return this.nodes;
128
- }
129
-
130
- /**
131
- * Get an array of all nodes.
132
- * @returns {Array} Nodes in the current ``phylotree``.
133
- */
134
- export function getNodes() {
135
- return this.nodes;
136
- }
137
-
138
- /**
139
- * Get a node by name.
140
- *
141
- * @param {String} name Name of the desired node.
142
- * @returns {Node} Desired node.
143
- */
144
- export function getNodeByName(name) {
145
- return _.filter(this.nodes.descendants(), d => {
146
- return d.data.name == name;
147
- })[0];
148
- }
149
-
150
- /**
151
- * Add attributes to nodes. New attributes will be placed in the
152
- * ``annotations`` key of any nodes that are matched.
153
- *
154
- * @param {Object} attributes An object whose keys are the names of nodes
155
- * to modify, and whose values are the new attributes to add.
156
- */
157
- export function assignAttributes(attributes) {
158
- //return nodes;
159
- // add annotations to each matching node
160
- _.each(this.nodes, function(d) {
161
- if (_.indexOf(_.keys(attributes), d.name) >= 0) {
162
- d["annotations"] = attributes[d.name];
163
- }
164
- });
165
- }
166
-
167
- /**
168
- * Determine if a given node is a leaf node.
169
- *
170
- * @param {Node} A node in a tree.
171
- * @returns {Bool} Whether or not the node is a leaf node.
172
- */
173
- export function isLeafNode(node) {
174
- return !_.has(node, "children")
175
- }
176
-
177
- /**
178
- * Update a given key name in each node.
179
- *
180
- * @param {String} old_key The old key name.
181
- * @param {String} new_key The new key name.
182
- * @returns The current ``this``.
183
- */
184
- export function updateKeyName(old_key, new_key) {
185
- this.nodes.each(function(n) {
186
- if (old_key in n) {
187
- if (new_key) {
188
- n[new_key] = n[old_key];
189
- }
190
- delete n[old_key];
191
- }
192
- });
193
-
194
- return this;
195
- }
196
-
197
- export function clearInternalNodes(respect) {
198
- if (!respect) {
199
- this.nodes.each(d => {
200
- if (!isLeafNode(d)) {
201
-
202
- // TODO: Move away from storing attribute data as root (BREAKS occasionally with d3>3)
203
- d[this.selection_attribute_name] = false;
204
-
205
- if(!d.data.traits) {
206
- d.data.traits = {};
207
- }
208
- d.data.traits[this.selection_attribute_name] = d[this.selection_attribute_name];
209
-
210
- }
211
- });
212
- }
213
- }
214
-
215
-
@@ -1,23 +0,0 @@
1
- import * as d3 from "d3";
2
- import { xCoord, yCoord } from "./coordinates";
3
-
4
- export var draw_line = d3
5
- .line()
6
- .x(function(d) {
7
- return xCoord(d);
8
- })
9
- .y(function(d) {
10
- return yCoord(d);
11
- })
12
- .curve(d3.curveStepBefore);
13
-
14
- export function lineSegmentPlacer(edge, where) {
15
- return {
16
- x:
17
- xCoord(edge.target) +
18
- (xCoord(edge.source) - xCoord(edge.target)) * where,
19
- y: yCoord(edge.target)
20
- };
21
- }
22
-
23
- export default draw_line;
@@ -1,116 +0,0 @@
1
- import * as d3 from "d3";
2
- import * as _ from "underscore";
3
- import { isNodeCollapsed } from "./nodes";
4
-
5
- export function cladeCssSelectors(css_classes) {
6
- return [css_classes["clade"]].reduce(function(p, c, i, a) {
7
- return (p += "path." + c + (i < a.length - 1 ? "," : ""));
8
- }, "");
9
- }
10
-
11
- export function updateCollapsedClades(transitions) {
12
-
13
- let enclosure = this.svg.selectAll("." + this.css_classes["tree-container"]);
14
- var node_id = 0;
15
-
16
- let collapsed_clades = enclosure
17
- .selectAll(cladeCssSelectors(this.css_classes))
18
- .data(
19
- this.phylotree.nodes.descendants().filter(isNodeCollapsed),
20
- function(d) {
21
- return d.id || (d.id = ++node_id);
22
- }
23
- );
24
-
25
- let spline = function() {};
26
- let spline_f = _.noop();
27
-
28
- // Collapse radial differently
29
- if (this.radial()) {
30
- spline = d3
31
- .line()
32
- .curve(d3.curveBasis)
33
- .y(function(d) {
34
- return d[0];
35
- })
36
- .x(function(d) {
37
- return d[1];
38
- });
39
-
40
- spline_f = function(coord, i, d, init_0, init_1) {
41
- if (i) {
42
- return [
43
- d.screen_y + (coord[0] - init_0) / 50,
44
- d.screen_x + (coord[1] - init_1) / 50
45
- ];
46
- } else {
47
- return [d.screen_y, d.screen_x];
48
- }
49
- };
50
- } else {
51
- spline = d3
52
- .line()
53
- .y(function(d) {
54
- return d[0];
55
- })
56
- .x(function(d) {
57
- return d[1];
58
- }).curve(d3.curveBasis);
59
-
60
- spline_f = function(coord, i, d, init_0, init_1) {
61
- if (i) {
62
- return [
63
- d.screen_y + (coord[0] - init_0) / 50 ,
64
- d.screen_x + (coord[1] - init_1) / 50,
65
- ];
66
- } else {
67
- return [d.screen_y, d.screen_x];
68
- }
69
- };
70
- }
71
-
72
- collapsed_clades
73
- .exit()
74
- .each(function(d) {
75
- d.collapsed_clade = null;
76
- })
77
- .remove();
78
-
79
- if (transitions) {
80
- collapsed_clades
81
- .enter()
82
- .insert("path", ":first-child")
83
- .attr("class", this.css_classes["clade"])
84
- .merge(collapsed_clades)
85
- .attr("d", function(d) {
86
- if (d.collapsed_clade) {
87
- return d.collapsed_clade;
88
- }
89
-
90
- //console.log (d.collapsed);
91
- let init_0 = d.collapsed[0][0];
92
- let init_1 = d.collapsed[0][1];
93
-
94
-
95
-
96
- // #1 return spline(d.collapsed.map(spline_f, d, init_0, init_1));
97
- return spline(
98
- d.collapsed.map(function(coord, i) {
99
- return spline_f(coord, i, d, init_0, init_1);
100
- })
101
- );
102
- })
103
- .attr("d", function(d) {
104
- return (d.collapsed_clade = spline(d.collapsed));
105
- });
106
- } else {
107
- collapsed_clades
108
- .enter()
109
- .insert("path", ":first-child")
110
- .attr("class", this.css_classes["clade"])
111
- .merge(collapsed_clades)
112
- .attr("d", function(d) {
113
- return (d.collapsed_clade ? d.collapsed_clade : d.collapsed_clade = spline(d.collapsed));
114
- });
115
- }
116
- }
@@ -1,7 +0,0 @@
1
- export function xCoord(d) {
2
- return d.y;
3
- }
4
-
5
- export function yCoord(d) {
6
- return d.x;
7
- }