phylotree 1.3.0 → 1.3.1

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.
@@ -10,42 +10,42 @@ commander
10
10
  .requiredOption("-s --source <node>", "Source Node")
11
11
  .requiredOption("-t --target <node>", "Target Node")
12
12
  .usage("./test/data/CD2-relax.new -s Cow -t Cat")
13
- .on("--help", function() {
14
- console.log("\nComputes the distance from the source tip to target tip. Does *not* include the length of the source tip by default.");
13
+ .on("--help", function () {
14
+ console.log(
15
+ "\nComputes the distance from the source tip to target tip. Does *not* include the length of the source tip by default."
16
+ );
15
17
  })
16
18
  .parse(process.argv);
17
19
 
18
20
  fs.readFile(commander.args[0], (err, newick_data) => {
19
-
20
21
  const tree = new phylotree.phylotree(newick_data.toString());
21
22
 
22
23
  const targetNode = tree.getNodeByName(commander.target);
23
24
 
24
25
  // GET SOURCE NODE
25
- const sourceNode = tree.getNodeByName(commander.source)
26
+ const sourceNode = tree.getNodeByName(commander.source);
26
27
 
27
- if(_.isUndefined(sourceNode)) {
28
- throw new Error('Could not find source node with name ' + commander.source)
28
+ if (_.isUndefined(sourceNode)) {
29
+ throw new Error("Could not find source node with name " + commander.source);
29
30
  }
30
31
 
31
- if(_.isUndefined(targetNode)) {
32
- throw new Error('Could not find target node with name ' + commander.target)
32
+ if (_.isUndefined(targetNode)) {
33
+ throw new Error("Could not find target node with name " + commander.target);
33
34
  }
34
35
 
35
36
  let mrca = tree.mrca([sourceNode, targetNode]);
36
37
 
37
38
  // Set all nodeLabel for all descendants of the MRCA
38
- let descendants = tree.selectAllDescendants(mrca, true, true)
39
+ let descendants = tree.selectAllDescendants(mrca, true, true);
39
40
  descendants.push(mrca);
40
41
 
41
- let annotator = function(node) {
42
- if(descendants.includes(node)) {
42
+ let annotator = function (node) {
43
+ if (descendants.includes(node)) {
43
44
  return "{hi}";
44
45
  } else {
45
46
  return "";
46
47
  }
47
- }
48
+ };
48
49
 
49
50
  console.log(tree.getNewick(annotator));
50
-
51
51
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "phylotree",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "main": "dist/phylotree.js",
5
5
  "unpkg": "dist/phylotree.js",
6
6
  "jsdelivr": "dist/phylotree.js",
package/src/main.js CHANGED
@@ -7,7 +7,12 @@ import { default as getTipLengths } from "./export";
7
7
  import * as nexus from "./formats/nexus";
8
8
  import { default as phyloxml_parser } from "./formats/phyloxml";
9
9
  import { default as maxParsimony } from "./max-parsimony";
10
- import { leftChildRightSibling, postOrder, preOrder, default as inOrder } from "./traversal";
10
+ import {
11
+ leftChildRightSibling,
12
+ postOrder,
13
+ preOrder,
14
+ default as inOrder,
15
+ } from "./traversal";
11
16
 
12
17
  import {
13
18
  default as hasBranchLengths,
@@ -16,7 +21,7 @@ import {
16
21
  setBranchLength,
17
22
  branchName,
18
23
  normalize,
19
- scale
24
+ scale,
20
25
  } from "./branches";
21
26
 
22
27
  import * as node_operations from "./nodes";
@@ -26,7 +31,7 @@ import { default as TreeRender } from "./render/draw";
26
31
  function resortChildren(comparator, start_node, filter) {
27
32
  // ascending
28
33
  this.nodes
29
- .sum(function(d) {
34
+ .sum(function (d) {
30
35
  return d.value;
31
36
  })
32
37
  .sort(comparator);
@@ -45,14 +50,13 @@ function resortChildren(comparator, start_node, filter) {
45
50
  * @returns An array of strings, comprising each tag that was read.
46
51
  */
47
52
  function mrca(mrca_nodes) {
48
-
49
53
  var mrca;
50
54
 
51
- mrca_nodes = mrca_nodes.map(function(mrca_node) {
55
+ mrca_nodes = mrca_nodes.map(function (mrca_node) {
52
56
  return typeof mrca_node == "string" ? mrca_node : mrca_node.data.name;
53
57
  });
54
58
 
55
- this.traverse_and_compute(function(node) {
59
+ this.traverse_and_compute(function (node) {
56
60
  if (!node.children) {
57
61
  node.data.mrca = _.intersection([node.data.name], mrca_nodes);
58
62
  } else if (!node.parent) {
@@ -60,7 +64,9 @@ function mrca(mrca_nodes) {
60
64
  mrca = node;
61
65
  }
62
66
  } else {
63
- node.data.mrca = _.union(...node.descendants().map(child => child.data.mrca));
67
+ node.data.mrca = _.union(
68
+ ...node.descendants().map((child) => child.data.mrca)
69
+ );
64
70
  if (!mrca && node.data.mrca.length == mrca_nodes.length) {
65
71
  mrca = node;
66
72
  }
@@ -68,7 +74,6 @@ function mrca(mrca_nodes) {
68
74
  });
69
75
 
70
76
  return mrca;
71
-
72
77
  }
73
78
 
74
79
  /**
@@ -82,9 +87,7 @@ function mrca(mrca_nodes) {
82
87
  * @returns {Phylotree} phylotree - itself, following the builder pattern.
83
88
  */
84
89
  let Phylotree = class {
85
-
86
90
  constructor(nwk, options = {}) {
87
-
88
91
  this.newick_string = "";
89
92
 
90
93
  this.nodes = [];
@@ -138,40 +141,36 @@ let Phylotree = class {
138
141
  this.newick_string = nwk;
139
142
  _node_data = newickParser(nwk, options);
140
143
  }
141
-
142
144
  }
143
145
 
144
146
  if (!_node_data["json"]) {
145
-
146
147
  self.nodes = [];
147
-
148
148
  } else {
149
-
150
149
  self.nodes = d3.hierarchy(_node_data.json);
151
150
 
152
151
  // Parse tags
153
152
  let _parsed_tags = {};
154
153
 
155
- self.nodes.each(node => {
154
+ self.nodes.each((node) => {
156
155
  if (node.data.annotation) {
157
156
  _parsed_tags[node.data.annotation] = true;
158
157
  }
159
158
  });
160
159
 
161
160
  self.parsed_tags = Object.keys(_parsed_tags);
162
-
163
161
  }
164
162
 
165
163
  self.links = self.nodes.links();
166
164
 
167
165
  // If no branch lengths are supplied, set all to 1
168
- if(!this.hasBranchLengths()) {
169
- console.warn("Phylotree User Warning : NO BRANCH LENGTHS DETECTED, SETTING ALL LENGTHS TO 1");
170
- this.setBranchLength(x => 1)
166
+ if (!this.hasBranchLengths()) {
167
+ console.warn(
168
+ "Phylotree User Warning : NO BRANCH LENGTHS DETECTED, SETTING ALL LENGTHS TO 1"
169
+ );
170
+ this.setBranchLength((x) => 1);
171
171
  }
172
172
 
173
173
  return self;
174
-
175
174
  }
176
175
 
177
176
  /*
@@ -182,10 +181,9 @@ let Phylotree = class {
182
181
 
183
182
  */
184
183
  json(traversal_type) {
185
-
186
184
  var index = 0;
187
185
 
188
- this.traverse_and_compute(function(n) {
186
+ this.traverse_and_compute(function (n) {
189
187
  n.json_export_index = index++;
190
188
  }, traversal_type);
191
189
 
@@ -193,7 +191,7 @@ let Phylotree = class {
193
191
 
194
192
  index = 0;
195
193
 
196
- this.traverse_and_compute(function(n) {
194
+ this.traverse_and_compute(function (n) {
197
195
  let node_copy = _.clone(n);
198
196
  delete node_copy.json_export_index;
199
197
 
@@ -202,14 +200,14 @@ let Phylotree = class {
202
200
  }
203
201
 
204
202
  if (n.children) {
205
- node_copy.children = _.map(n.children, function(c) {
203
+ node_copy.children = _.map(n.children, function (c) {
206
204
  return c.json_export_index;
207
205
  });
208
206
  }
209
207
  node_array[index++] = node_copy;
210
208
  }, traversal_type);
211
209
 
212
- this.traverse_and_compute(function(n) {
210
+ this.traverse_and_compute(function (n) {
213
211
  delete n.json_export_index;
214
212
  }, traversal_type);
215
213
 
@@ -235,7 +233,6 @@ let Phylotree = class {
235
233
  }
236
234
 
237
235
  postOrder(node, callback, backtrack);
238
-
239
236
  }
240
237
 
241
238
  function pre_order(node) {
@@ -259,7 +256,6 @@ let Phylotree = class {
259
256
  traversal_type(root_node ? root_node : this.nodes);
260
257
 
261
258
  return this;
262
-
263
259
  }
264
260
 
265
261
  get_parsed_tags() {
@@ -276,7 +272,6 @@ let Phylotree = class {
276
272
  this.display = new TreeRender(this, options);
277
273
  return this.display;
278
274
  }
279
-
280
275
  };
281
276
 
282
277
  Phylotree.prototype.isLeafNode = node_operations.isLeafNode;