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/README.md
CHANGED
|
@@ -2,10 +2,42 @@
|
|
|
2
2
|
|
|
3
3
|
A JavaScript library for developing applications and interactive visualizations involving [phylogenetic trees](https://en.wikipedia.org/wiki/Phylogenetic_tree), written as an extension of the [D3](http://d3js.org) [hierarchy layout](https://github.com/d3/d3-3.x-api-reference/blob/master/Hierarchy-Layout.md). It generates high quality SVG vector graphics, allows a great degree of customizability (CSS or JavaScript callbacks), and comes with a lot of *built-in* convenience features.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Quick Start
|
|
6
6
|
|
|
7
|
+
### Installation
|
|
7
8
|
|
|
8
|
-
|
|
9
|
+
```bash
|
|
10
|
+
npm install phylotree
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
### Basic Usage
|
|
14
|
+
|
|
15
|
+
```javascript
|
|
16
|
+
import { phylotree } from "phylotree";
|
|
17
|
+
|
|
18
|
+
// Parse a Newick string
|
|
19
|
+
const newick = "((A:0.1,B:0.2):0.3,(C:0.4,D:0.5):0.6);";
|
|
20
|
+
const tree = new phylotree(newick);
|
|
21
|
+
|
|
22
|
+
// Render to an SVG container
|
|
23
|
+
const renderer = tree.render({
|
|
24
|
+
container: "#tree-container",
|
|
25
|
+
width: 800,
|
|
26
|
+
height: 600,
|
|
27
|
+
"align-tips": true,
|
|
28
|
+
zoom: true
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### TypeScript Support
|
|
33
|
+
|
|
34
|
+
phylotree.js includes TypeScript declarations. Import types alongside the main export:
|
|
35
|
+
|
|
36
|
+
```typescript
|
|
37
|
+
import { phylotree, PhylotreeNode, RenderOptions } from "phylotree";
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Standalone Web Application
|
|
9
41
|
|
|
10
42
|
A [full-featured web application](http://phylotree.hyphy.org) based on phylotree.js, implemented in [index.html](index.html).
|
|
11
43
|
|
|
@@ -65,21 +97,7 @@ curly braces directly after identifiers, e.g.:
|
|
|
65
97
|
|
|
66
98
|
## Examples
|
|
67
99
|
|
|
68
|
-
###
|
|
69
|
-
🚀 **[Browse Local Examples](examples/)** - Self-contained HTML/JS examples that you can run locally
|
|
70
|
-
|
|
71
|
-
**Available Examples:**
|
|
72
|
-
* [Basic Tree Visualization](examples/basic/01-basic-tree/) - Learn phylotree.js fundamentals
|
|
73
|
-
* [Cluster Analysis](examples/intermediate/05-cluster-analysis/) - Identify phylogenetic clusters
|
|
74
|
-
|
|
75
|
-
**Coming Soon:**
|
|
76
|
-
* Radial Tree Layout
|
|
77
|
-
* Bootstrap Value Coloring
|
|
78
|
-
* Metadata & Host Coloring
|
|
79
|
-
* Root-to-Tip Analysis
|
|
80
|
-
* Tree Center Computation
|
|
81
|
-
|
|
82
|
-
### Original Observable Notebooks
|
|
100
|
+
### Observable Notebooks
|
|
83
101
|
* [Simple Example](https://observablehq.com/@stevenweaver/phylotree-1-0-0?collection=@stevenweaver/phylotree-utilities)
|
|
84
102
|
* [Unscaled IAV HA colored by host](https://observablehq.com/@stevenweaver/phylotree-1-0-0-unscaled-iav-ha-colored-by-host?collection=@stevenweaver/phylotree-utilities)
|
|
85
103
|
* [HIV RT](https://observablehq.com/@stevenweaver/phylotree-1-0-0-hiv-rt?collection=@stevenweaver/phylotree-utilities)
|
|
@@ -92,6 +110,64 @@ curly braces directly after identifiers, e.g.:
|
|
|
92
110
|
|
|
93
111
|
📚 View the complete [Observable Collection](https://observablehq.com/collection/@stevenweaver/phylotree-utilities)
|
|
94
112
|
|
|
113
|
+
## Utility Functions
|
|
114
|
+
|
|
115
|
+
phylotree.js exports several utility functions for phylogenetic analysis:
|
|
116
|
+
|
|
117
|
+
### Tree Metrics
|
|
118
|
+
|
|
119
|
+
```javascript
|
|
120
|
+
import {
|
|
121
|
+
pairwiseDistances, // Compute pairwise distances between nodes
|
|
122
|
+
sackin, // Sackin's index (tree balance measure)
|
|
123
|
+
centerOfTree, // Find the center node of the tree
|
|
124
|
+
computeMidpoint, // Compute midpoint for rooting
|
|
125
|
+
rootToTip, // Root-to-tip distance regression
|
|
126
|
+
fitRootToTip // Find optimal root by R² maximization
|
|
127
|
+
} from "phylotree";
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Clustering Algorithms
|
|
131
|
+
|
|
132
|
+
```javascript
|
|
133
|
+
import {
|
|
134
|
+
clusterPicker, // Cluster Picker algorithm for transmission cluster identification
|
|
135
|
+
phylopart // PhyloPart clustering algorithm
|
|
136
|
+
} from "phylotree";
|
|
137
|
+
|
|
138
|
+
// Example: Identify clusters
|
|
139
|
+
const clusters = clusterPicker(tree, {
|
|
140
|
+
bootstrap_threshold: 0.9,
|
|
141
|
+
distance_threshold: 0.045
|
|
142
|
+
});
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
### Tree Construction
|
|
146
|
+
|
|
147
|
+
```javascript
|
|
148
|
+
import {
|
|
149
|
+
neighborJoining, // Build tree from distance matrix
|
|
150
|
+
getDistanceMatrix, // Compute distance matrix from sequences
|
|
151
|
+
parseFasta // Parse FASTA format sequences
|
|
152
|
+
} from "phylotree";
|
|
153
|
+
|
|
154
|
+
// Example: Build tree from sequences
|
|
155
|
+
const sequences = parseFasta(fastaString);
|
|
156
|
+
const { matrix, labels } = getDistanceMatrix(sequences);
|
|
157
|
+
const treeJson = neighborJoining(matrix, labels);
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Parsers and Export
|
|
161
|
+
|
|
162
|
+
```javascript
|
|
163
|
+
import {
|
|
164
|
+
newickParser, // Parse Newick format strings
|
|
165
|
+
getNewick, // Export tree to Newick format
|
|
166
|
+
loadAnnotations, // Load annotations from NEXUS files
|
|
167
|
+
extractDates // Extract dates from tip names
|
|
168
|
+
} from "phylotree";
|
|
169
|
+
```
|
|
170
|
+
|
|
95
171
|
## Options
|
|
96
172
|
|
|
97
173
|
phylotree.js supports a variety of options for common features, which can be set using
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require("fs"),
|
|
4
4
|
phylotree = require("../dist/phylotree.js"),
|
|
5
|
-
|
|
5
|
+
{ program } = require("commander"),
|
|
6
6
|
_ = require("underscore");
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
program
|
|
9
9
|
.arguments("<newick>", "Input newick file")
|
|
10
10
|
.requiredOption("-s --source <node>", "Source Node")
|
|
11
11
|
.requiredOption("-t --target <node>", "Target Node")
|
|
@@ -16,32 +16,34 @@ commander
|
|
|
16
16
|
})
|
|
17
17
|
.parse(process.argv);
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
const options = program.opts();
|
|
20
|
+
|
|
21
|
+
fs.readFile(program.args[0], (err, newick_data) => {
|
|
20
22
|
|
|
21
23
|
const tree = new phylotree.phylotree(newick_data.toString());
|
|
22
24
|
phylotree.pairwise_distances(tree);
|
|
23
25
|
|
|
24
26
|
// GET SOURCE NODE
|
|
25
|
-
const sourceNode = tree.getNodeByName(
|
|
27
|
+
const sourceNode = tree.getNodeByName(options.source);
|
|
26
28
|
|
|
27
29
|
if(_.isUndefined(sourceNode)) {
|
|
28
|
-
throw new Error(
|
|
30
|
+
throw new Error("Could not find source node with name " + options.source);
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
// GET LEAF INDEX OF TARGET
|
|
32
|
-
const targetNode = tree.getNodeByName(
|
|
34
|
+
const targetNode = tree.getNodeByName(options.target);
|
|
33
35
|
|
|
34
36
|
if(_.isUndefined(targetNode)) {
|
|
35
|
-
throw new Error(
|
|
37
|
+
throw new Error("Could not find target node with name " + options.target);
|
|
36
38
|
}
|
|
37
39
|
|
|
38
40
|
|
|
39
|
-
const targetIndex = targetNode[
|
|
41
|
+
const targetIndex = targetNode["cot_leaf_index"];
|
|
40
42
|
|
|
41
|
-
let distance = sourceNode[
|
|
43
|
+
let distance = sourceNode["cot_path_to_leaves_above"][targetIndex];
|
|
42
44
|
|
|
43
45
|
// if include source tip length, add it
|
|
44
|
-
if(
|
|
46
|
+
if(options.includeSourceLength) {
|
|
45
47
|
distance+=parseFloat(sourceNode.data.attribute);
|
|
46
48
|
}
|
|
47
49
|
|
package/bin/phylotree-mrca.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require("fs"),
|
|
4
4
|
phylotree = require("../dist/phylotree.js"),
|
|
5
|
-
|
|
5
|
+
{ program } = require("commander"),
|
|
6
6
|
_ = require("underscore");
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
program
|
|
9
9
|
.arguments("<newick>", "Input newick file")
|
|
10
10
|
.requiredOption("-s --source <node>", "Source Node")
|
|
11
11
|
.requiredOption("-t --target <node>", "Target Node")
|
|
@@ -17,20 +17,22 @@ commander
|
|
|
17
17
|
})
|
|
18
18
|
.parse(process.argv);
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
const options = program.opts();
|
|
21
|
+
|
|
22
|
+
fs.readFile(program.args[0], (err, newick_data) => {
|
|
21
23
|
const tree = new phylotree.phylotree(newick_data.toString());
|
|
22
24
|
|
|
23
|
-
const targetNode = tree.getNodeByName(
|
|
25
|
+
const targetNode = tree.getNodeByName(options.target);
|
|
24
26
|
|
|
25
27
|
// GET SOURCE NODE
|
|
26
|
-
const sourceNode = tree.getNodeByName(
|
|
28
|
+
const sourceNode = tree.getNodeByName(options.source);
|
|
27
29
|
|
|
28
30
|
if (_.isUndefined(sourceNode)) {
|
|
29
|
-
throw new Error("Could not find source node with name " +
|
|
31
|
+
throw new Error("Could not find source node with name " + options.source);
|
|
30
32
|
}
|
|
31
33
|
|
|
32
34
|
if (_.isUndefined(targetNode)) {
|
|
33
|
-
throw new Error("Could not find target node with name " +
|
|
35
|
+
throw new Error("Could not find target node with name " + options.target);
|
|
34
36
|
}
|
|
35
37
|
|
|
36
38
|
let mrca = tree.mrca([sourceNode, targetNode]);
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require("fs"),
|
|
4
4
|
phylotree = require("../dist/phylotree.js"),
|
|
5
|
-
|
|
5
|
+
{ program } = require("commander"),
|
|
6
6
|
_ = require("lodash");
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
program
|
|
9
9
|
.arguments("<fasta>", "Input fasta file")
|
|
10
10
|
.usage("./test/data/CD2.fas")
|
|
11
11
|
.on("--help", function() {
|
|
@@ -14,15 +14,14 @@ commander
|
|
|
14
14
|
.parse(process.argv);
|
|
15
15
|
|
|
16
16
|
|
|
17
|
-
fs.readFile(
|
|
17
|
+
fs.readFile(program.args[0], ( err, fastaData ) => {
|
|
18
18
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
let fasta = phylotree.parseFasta(fastaData);
|
|
20
|
+
let nodeList = _.keys(fasta);
|
|
21
|
+
let distanceMatrix = phylotree.getDistanceMatrix(fasta);
|
|
22
|
+
let distanceMatrixArr = _.values(distanceMatrix);
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
let nj = phylotree.neighborJoining(distanceMatrixArr, _.keys(fasta).length, nodeList);
|
|
25
|
+
console.log(nj.getNewick());
|
|
26
26
|
|
|
27
27
|
});
|
|
28
|
-
|
package/bin/phylotree-reroot.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const fs = require(
|
|
4
|
-
const phylotree = require(
|
|
5
|
-
const
|
|
6
|
-
const _ = require(
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const phylotree = require("../dist/phylotree.js");
|
|
5
|
+
const { program } = require("commander");
|
|
6
|
+
const _ = require("underscore");
|
|
7
7
|
|
|
8
8
|
/*
|
|
9
9
|
* phylotree reroot
|
|
10
10
|
*
|
|
11
11
|
* Usage:
|
|
12
|
-
* phylotree reroot ./test/data/CD2-relax.new -n Horse
|
|
12
|
+
* phylotree reroot ./test/data/CD2-relax.new -n Horse
|
|
13
13
|
*
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
program
|
|
17
17
|
.arguments("<newick>", "Input newick file")
|
|
18
18
|
.requiredOption("-n --node <node>", "Node to reroot on")
|
|
19
|
-
.parse(process.argv);
|
|
19
|
+
.parse(process.argv);
|
|
20
20
|
|
|
21
|
+
const options = program.opts();
|
|
21
22
|
|
|
22
|
-
if (!
|
|
23
|
-
throw
|
|
23
|
+
if (!program.args[0]){
|
|
24
|
+
throw "ERROR: Newick file is required... exiting!";
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
fs.readFile(
|
|
27
|
+
fs.readFile(program.args[0], (err, newickData) => {
|
|
27
28
|
const tree = new phylotree.phylotree(newickData.toString());
|
|
28
|
-
const node = tree.getNodeByName(
|
|
29
|
+
const node = tree.getNodeByName(options.node);
|
|
29
30
|
if(_.isUndefined(node)) {
|
|
30
|
-
throw new Error(
|
|
31
|
+
throw new Error("Could not find node with name " + options.node);
|
|
31
32
|
}
|
|
32
33
|
tree.reroot(node);
|
|
33
34
|
console.log(tree.getNewick());
|
|
34
35
|
});
|
|
35
|
-
|
package/bin/phylotree-shuffle.js
CHANGED
|
@@ -2,21 +2,21 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require("fs"),
|
|
4
4
|
phylotree = require("../dist/phylotree.js"),
|
|
5
|
-
|
|
5
|
+
{ program } = require("commander"),
|
|
6
6
|
_ = require("underscore");
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
program
|
|
9
9
|
.arguments("<newick>", "Input newick file")
|
|
10
10
|
.on("--help", function() {
|
|
11
11
|
console.log("");
|
|
12
12
|
console.log("Examples:");
|
|
13
13
|
console.log(
|
|
14
|
-
|
|
14
|
+
"phylotree shuffle test/data/MERS.txt"
|
|
15
15
|
);
|
|
16
16
|
})
|
|
17
17
|
.parse(process.argv);
|
|
18
18
|
|
|
19
|
-
fs.readFile(
|
|
19
|
+
fs.readFile(program.args[0], (err, newickData) => {
|
|
20
20
|
|
|
21
21
|
const tree = new phylotree.phylotree(newickData.toString());
|
|
22
22
|
let tips = tree.getTips();
|
|
@@ -27,7 +27,7 @@ fs.readFile(commander.args[0], (err, newickData) => {
|
|
|
27
27
|
// Shuffle names
|
|
28
28
|
let shuffledNames = _.shuffle(names);
|
|
29
29
|
|
|
30
|
-
_.each(tips, (d,i) => d.data.name = shuffledNames[i])
|
|
30
|
+
_.each(tips, (d,i) => d.data.name = shuffledNames[i]);
|
|
31
31
|
|
|
32
32
|
console.log(tree.getNewick());
|
|
33
33
|
|
package/bin/phylotree-tag.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const phylotree = require("../dist/phylotree.js");
|
|
5
|
-
const
|
|
5
|
+
const { program } = require("commander");
|
|
6
6
|
const _ = require("underscore");
|
|
7
7
|
|
|
8
8
|
// Parse command line arguments
|
|
9
|
-
|
|
9
|
+
program
|
|
10
10
|
.arguments("<newick>", "Input newick file")
|
|
11
11
|
.requiredOption(
|
|
12
12
|
"-p --patterns <patterns>",
|
|
@@ -30,16 +30,18 @@ commander
|
|
|
30
30
|
)
|
|
31
31
|
.parse(process.argv);
|
|
32
32
|
|
|
33
|
+
const options = program.opts();
|
|
34
|
+
|
|
33
35
|
// Input validation
|
|
34
|
-
if (
|
|
36
|
+
if (options.patterns.split(",").length !== options.tags.split(",").length) {
|
|
35
37
|
throw new Error(
|
|
36
38
|
"The number of patterns must match the number of corresponding tags.",
|
|
37
39
|
);
|
|
38
40
|
}
|
|
39
41
|
|
|
40
42
|
// Parse patterns and tags
|
|
41
|
-
const patterns =
|
|
42
|
-
const tags =
|
|
43
|
+
const patterns = options.patterns.split(",");
|
|
44
|
+
const tags = options.tags.split(",");
|
|
43
45
|
|
|
44
46
|
// Function to get annotations for Newick output
|
|
45
47
|
function annotator(node) {
|
|
@@ -47,15 +49,15 @@ function annotator(node) {
|
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
// Main tagging function
|
|
50
|
-
fs.readFile(
|
|
52
|
+
fs.readFile(program.args[0], (err, newick_data) => {
|
|
51
53
|
if (err) throw new Error("Error reading Newick file: " + err.message);
|
|
52
54
|
|
|
53
55
|
// Parse tree
|
|
54
56
|
const tree = new phylotree.phylotree(newick_data.toString());
|
|
55
57
|
|
|
56
58
|
// Reroot if specified
|
|
57
|
-
if (
|
|
58
|
-
const reroot_node = tree.getNodeByName(
|
|
59
|
+
if (options.reroot) {
|
|
60
|
+
const reroot_node = tree.getNodeByName(options.reroot);
|
|
59
61
|
if (reroot_node) {
|
|
60
62
|
tree.reroot(reroot_node);
|
|
61
63
|
}
|
|
@@ -66,7 +68,7 @@ fs.readFile(commander.args[0], (err, newick_data) => {
|
|
|
66
68
|
if (tree.isLeafNode(node)) {
|
|
67
69
|
for (let i = 0; i < patterns.length; i++) {
|
|
68
70
|
const matches = new RegExp(patterns[i]).test(node.data.name);
|
|
69
|
-
if (
|
|
71
|
+
if (options.invert ? !matches : matches) {
|
|
70
72
|
node.data.annotation = tags[i];
|
|
71
73
|
break;
|
|
72
74
|
}
|
|
@@ -75,7 +77,7 @@ fs.readFile(commander.args[0], (err, newick_data) => {
|
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
function applyStrategy() {
|
|
78
|
-
switch (
|
|
80
|
+
switch (options.strategy) {
|
|
79
81
|
case "none":
|
|
80
82
|
// Only leaf nodes are tagged
|
|
81
83
|
break;
|
|
@@ -119,7 +121,7 @@ fs.readFile(commander.args[0], (err, newick_data) => {
|
|
|
119
121
|
}
|
|
120
122
|
|
|
121
123
|
// Apply tagging
|
|
122
|
-
if (!
|
|
124
|
+
if (!options.leafOnly) {
|
|
123
125
|
tree.traverse_and_compute(tagLeafNodes);
|
|
124
126
|
applyStrategy();
|
|
125
127
|
} else {
|
package/bin/phylotree-tips.js
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require("fs");
|
|
4
4
|
const phylotree = require("../dist/phylotree.js");
|
|
5
|
-
const
|
|
5
|
+
const { program } = require("commander");
|
|
6
6
|
const _ = require("underscore");
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
program
|
|
9
9
|
.arguments("<newick>", "Input newick file")
|
|
10
10
|
.requiredOption(
|
|
11
11
|
"-p --patterns <patterns>",
|
|
@@ -24,16 +24,18 @@ commander
|
|
|
24
24
|
})
|
|
25
25
|
.parse(process.argv);
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
const options = program.opts();
|
|
28
|
+
|
|
29
|
+
if (options.patterns.split(",").length !== options.tags.split(",").length) {
|
|
28
30
|
throw new Error(
|
|
29
31
|
"The number of patterns must match the number of corresponding tags."
|
|
30
32
|
);
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
const patterns =
|
|
34
|
-
const tags =
|
|
35
|
+
const patterns = options.patterns.split(",");
|
|
36
|
+
const tags = options.tags.split(",");
|
|
35
37
|
|
|
36
|
-
fs.readFile(
|
|
38
|
+
fs.readFile(program.args[0], (err, newick_data) => {
|
|
37
39
|
if (err) {
|
|
38
40
|
throw new Error("Error reading the Newick file: " + err.message);
|
|
39
41
|
}
|
|
@@ -2,29 +2,29 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require("fs"),
|
|
4
4
|
phylotree = require("../dist/phylotree.js"),
|
|
5
|
-
|
|
5
|
+
{ program } = require("commander"),
|
|
6
6
|
_ = require("underscore");
|
|
7
7
|
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
program
|
|
10
10
|
.arguments("<newick>", "Input newick file")
|
|
11
11
|
.on("--help", function() {
|
|
12
12
|
console.log("");
|
|
13
13
|
console.log("Examples:");
|
|
14
14
|
console.log(
|
|
15
|
-
|
|
15
|
+
"phylotree validate test/data/MERS.txt"
|
|
16
16
|
);
|
|
17
17
|
})
|
|
18
18
|
.parse(process.argv);
|
|
19
19
|
|
|
20
|
-
fs.readFile(
|
|
20
|
+
fs.readFile(program.args[0], (err, newickData) => {
|
|
21
21
|
|
|
22
22
|
const tree = new phylotree.newickParser(newickData.toString());
|
|
23
23
|
|
|
24
24
|
if(!tree.error) {
|
|
25
25
|
console.log("Valid Newick string ");
|
|
26
26
|
} else {
|
|
27
|
-
console.warn("Newick string is not valid!")
|
|
27
|
+
console.warn("Newick string is not valid!");
|
|
28
28
|
console.log(tree.error);
|
|
29
29
|
|
|
30
30
|
}
|
package/bin/root-to-tip.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
|
-
const fs = require(
|
|
4
|
-
const phylotree = require(
|
|
5
|
-
const
|
|
6
|
-
const _ = require(
|
|
3
|
+
const fs = require("fs");
|
|
4
|
+
const phylotree = require("../dist/phylotree.js");
|
|
5
|
+
const { program } = require("commander");
|
|
6
|
+
const _ = require("underscore");
|
|
7
7
|
|
|
8
8
|
/*
|
|
9
9
|
* Computes root-to-tip distance and fits linear regression
|
|
@@ -15,14 +15,15 @@ const _ = require('underscore');
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
program.option(
|
|
19
|
+
"-n --newick <newick>",
|
|
20
|
+
"Input newick file"
|
|
21
21
|
).parse(process.argv);
|
|
22
22
|
|
|
23
|
+
const options = program.opts();
|
|
23
24
|
|
|
24
|
-
if (!
|
|
25
|
-
throw
|
|
25
|
+
if (!options.newick){
|
|
26
|
+
throw "ERROR: Newick file is required... exiting!";
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
// Assumes date formatted like 1984-09-20
|
|
@@ -48,7 +49,7 @@ let date_parser = function(tree, node) {
|
|
|
48
49
|
return null;
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
fs.readFile(
|
|
52
|
+
fs.readFile(options.newick, (err, newick_data) => {
|
|
52
53
|
const tree = new phylotree.phylotree(newick_data.toString());
|
|
53
54
|
let computed_tree = phylotree.rootToTip(tree);
|
|
54
55
|
let tree_with_dates = phylotree.extract_dates(computed_tree, _.partial(date_parser, computed_tree));
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const fs = require("fs"),
|
|
4
4
|
phylotree = require("../dist/phylotree.js"),
|
|
5
|
-
|
|
5
|
+
{ program } = require("commander"),
|
|
6
6
|
_ = require("underscore"),
|
|
7
7
|
moment = require("moment"),
|
|
8
8
|
winston = require("winston"),
|
|
9
|
-
stringify = require("csv-stringify");
|
|
9
|
+
{ stringify } = require("csv-stringify");
|
|
10
10
|
|
|
11
11
|
const logger = winston.createLogger({
|
|
12
12
|
level: "warn",
|
|
@@ -38,7 +38,7 @@ function collect(value, previous) {
|
|
|
38
38
|
return previous.concat([value]);
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
program
|
|
42
42
|
.requiredOption("-n --newick <newick>", "Input newick file")
|
|
43
43
|
.option("-r --regex <regex>", "Regular expression to search date for", collect, [])
|
|
44
44
|
.option(
|
|
@@ -57,7 +57,7 @@ commander
|
|
|
57
57
|
)
|
|
58
58
|
.option("-l --log-level <level>", "Specify log level", default_log);
|
|
59
59
|
|
|
60
|
-
|
|
60
|
+
program
|
|
61
61
|
.on("--help", function() {
|
|
62
62
|
console.log("");
|
|
63
63
|
console.log("Examples:");
|
|
@@ -70,23 +70,25 @@ commander
|
|
|
70
70
|
})
|
|
71
71
|
.parse(process.argv);
|
|
72
72
|
|
|
73
|
-
|
|
73
|
+
const options = program.opts();
|
|
74
|
+
|
|
75
|
+
if (options.regex.length && options.splitOnChar) {
|
|
74
76
|
logger.warn("-r and -s options are mutually exclusive");
|
|
75
77
|
process.exit(1);
|
|
76
78
|
}
|
|
77
79
|
|
|
78
|
-
if (
|
|
79
|
-
regexp = _.map(
|
|
80
|
+
if (options.regex.length) {
|
|
81
|
+
regexp = _.map(options.regex, r => new RegExp(r));
|
|
80
82
|
}
|
|
81
83
|
|
|
82
|
-
if (
|
|
83
|
-
logger.level =
|
|
84
|
+
if (options.logLevel) {
|
|
85
|
+
logger.level = options.logLevel;
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
var date_format = undefined;
|
|
87
89
|
|
|
88
|
-
if (
|
|
89
|
-
date_format =
|
|
90
|
+
if (options.dateFormat) {
|
|
91
|
+
date_format = options.dateFormat;
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
// Assumes date formatted like 1984-09-20
|
|
@@ -163,22 +165,22 @@ let split_date_parser = function(tree, delimiter, pos, format, node) {
|
|
|
163
165
|
return null;
|
|
164
166
|
};
|
|
165
167
|
|
|
166
|
-
fs.readFile(
|
|
168
|
+
fs.readFile(options.newick, (err, newick_data) => {
|
|
167
169
|
const tree = new phylotree.phylotree(newick_data.toString());
|
|
168
170
|
let computed_tree = phylotree.rootToTip(tree);
|
|
169
171
|
|
|
170
172
|
let date_parser = _.partial(default_date_parser, computed_tree);
|
|
171
173
|
|
|
172
174
|
// Set appropriate date parser
|
|
173
|
-
if (
|
|
175
|
+
if (options.splitOnChar) {
|
|
174
176
|
date_parser = _.partial(
|
|
175
177
|
split_date_parser,
|
|
176
178
|
computed_tree,
|
|
177
|
-
|
|
179
|
+
options.splitOnChar,
|
|
178
180
|
"last",
|
|
179
181
|
date_format
|
|
180
182
|
);
|
|
181
|
-
} else if (
|
|
183
|
+
} else if (options.regex.length) {
|
|
182
184
|
date_parser = _.partial(
|
|
183
185
|
regex_date_parser,
|
|
184
186
|
computed_tree,
|