@figtreejs/core 0.0.1-beta.0 → 0.0.1-beta.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.
- package/dist/index.cjs +2 -2
- package/dist/index.d.ts +450 -233
- package/dist/index.mjs +611 -597
- package/package.json +1 -1
- package/src/evo/tree/normalized-tree/immutable-tree.ts +1 -3
- package/src/evo/tree/parsers/annotation-parser.ts +6 -0
- package/src/evo/tree/parsers/newick-character-parser.ts +8 -0
- package/src/evo/tree/parsers/newick-parsing.ts +6 -0
- package/src/evo/tree/parsers/nexus-parsing.ts +8 -3
- package/src/evo/tree/parsers/stream-reader/nexus-importer.ts +8 -1
- package/src/evo/tree/parsers/stream-reader/nexus-tokenizer.ts +5 -0
- package/src/evo/tree/taxa/helper-functions.ts +14 -0
- package/src/evo/tree/taxa/taxon.ts +40 -1
- package/src/evo/tree/traversals/preorder-traversal.ts +5 -0
- package/src/evo/tree/traversals/traversal-types.ts +3 -0
- package/src/evo/tree/tree-types.ts +259 -20
- package/src/layouts/functional/radial-layout.ts +14 -10
- package/src/layouts/functional/rectangular-layout.ts +7 -0
- package/src/layouts/layout-interface.ts +0 -73
package/package.json
CHANGED
|
@@ -143,9 +143,7 @@ export class ImmutableTree implements Tree, TaxonSetInterface {
|
|
|
143
143
|
nexus: string,
|
|
144
144
|
options?: newickParsingOptions,
|
|
145
145
|
): ImmutableTree {
|
|
146
|
-
|
|
147
|
-
return parseNexus(tree, nexus, options);
|
|
148
|
-
// throw new Error("Nexus parsing not implemented")
|
|
146
|
+
return parseNexus(nexus, options);
|
|
149
147
|
}
|
|
150
148
|
static fromString(
|
|
151
149
|
string: string,
|
|
@@ -130,6 +130,12 @@ export function parseAnnotation(annotationString: string): ParsedAnnotationRaw {
|
|
|
130
130
|
return annotations;
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
/**
|
|
134
|
+
* Process an annotation value and return the possibly transformed value and
|
|
135
|
+
* figtreejs annotation type
|
|
136
|
+
* @param values RawAnnotationValue
|
|
137
|
+
* @returns ClassifiedValue {type: BaseAnnotationType, value: ValueOf<BaseAnnotationType>};
|
|
138
|
+
*/
|
|
133
139
|
export function processAnnotationValue(
|
|
134
140
|
values: RawAnnotationValue,
|
|
135
141
|
): ClassifiedValue {
|
|
@@ -4,6 +4,10 @@ import type { NodeRef } from "../tree-types";
|
|
|
4
4
|
import { ImmutableTree } from "../normalized-tree/immutable-tree";
|
|
5
5
|
import { parseAnnotation } from "./annotation-parser";
|
|
6
6
|
import { notNull, unNullify } from "../../../utils/maybe";
|
|
7
|
+
/**
|
|
8
|
+
* A class that contains the logic for parsing newick strings.
|
|
9
|
+
* It the tokens of the string should be split as in
|
|
10
|
+
* /\s*('[^']+'|"[^"]+"|\[&[^[]+]|,|:|\)|\(|;)\s\*/
|
|
7
11
|
|
|
8
12
|
export class NewickCharacterParser {
|
|
9
13
|
done: boolean;
|
|
@@ -52,6 +56,10 @@ export class NewickCharacterParser {
|
|
|
52
56
|
return this.tree;
|
|
53
57
|
}
|
|
54
58
|
|
|
59
|
+
/**
|
|
60
|
+
* Parse the next token
|
|
61
|
+
* @param t token
|
|
62
|
+
*/
|
|
55
63
|
parseCharacter(t: string): void {
|
|
56
64
|
if (this.done) {
|
|
57
65
|
throw new Error("Parsing is done. We have seen a ';'");
|
|
@@ -2,6 +2,12 @@ import { NewickCharacterParser } from "./newick-character-parser";
|
|
|
2
2
|
import type { ImmutableTree, newickParsingOptions } from "..";
|
|
3
3
|
import { TaxonSet } from "..";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* An internal function to parse a newick string.
|
|
7
|
+
* @param newick
|
|
8
|
+
* @param options
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
5
11
|
export function parseNewick(
|
|
6
12
|
newick: string,
|
|
7
13
|
options: newickParsingOptions = {},
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
import { ImmutableTree } from "../normalized-tree/immutable-tree";
|
|
3
|
+
import { newickParsingOptions } from "../tree-types";
|
|
3
4
|
import { parseNewick } from "./newick-parsing";
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
/**
|
|
7
|
+
* An internal helper function that parses the first tree in a nexus string
|
|
8
|
+
* @param nexus - The nexus string to be parsed.
|
|
9
|
+
* @param options - newickParsingOptions - parseAnnotations is set to true
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
6
12
|
export function parseNexus(
|
|
7
|
-
_tree: ImmutableTree,
|
|
8
13
|
nexus: string,
|
|
9
|
-
options = {},
|
|
14
|
+
options: newickParsingOptions = {},
|
|
10
15
|
): ImmutableTree {
|
|
11
16
|
// odd parts ensure we're not in a taxon label
|
|
12
17
|
//TODO make this parsing more robust
|
|
@@ -5,6 +5,10 @@ import { TaxonSet } from "../../taxa/taxon";
|
|
|
5
5
|
import { NewickCharacterParser } from "../newick-character-parser";
|
|
6
6
|
import { newickDeliminators, nexusTokenizer } from "./nexus-tokenizer";
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* A nexus importing class that parses a stream and into an asynchronous
|
|
10
|
+
* iterator over trees.
|
|
11
|
+
*/
|
|
8
12
|
export class NexusImporter {
|
|
9
13
|
reader: ReadableStreamDefaultReader<string>;
|
|
10
14
|
taxonSet: TaxonSet;
|
|
@@ -27,7 +31,10 @@ export class NexusImporter {
|
|
|
27
31
|
this.currentBlock = undefined;
|
|
28
32
|
this.options = options;
|
|
29
33
|
}
|
|
30
|
-
|
|
34
|
+
/**
|
|
35
|
+
* The main public api.
|
|
36
|
+
* an asynchronous iterator over the trees provided by the stream
|
|
37
|
+
*/
|
|
31
38
|
async *getTrees(): AsyncIterableIterator<ImmutableTree> {
|
|
32
39
|
while (this.currentBlock !== "trees") {
|
|
33
40
|
await this.parseNextBlock();
|
|
@@ -7,6 +7,11 @@ export enum STATUS {
|
|
|
7
7
|
IN_COMMENT = "in comment",
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* A helper function that converts an incoming stream into tokens in
|
|
12
|
+
* a nexus file.
|
|
13
|
+
* @returns A pipe string tokenizer for use in a transform stream.
|
|
14
|
+
*/
|
|
10
15
|
export function nexusTokenizer() {
|
|
11
16
|
return {
|
|
12
17
|
lastChunk: "",
|
|
@@ -2,6 +2,13 @@ import type { Maybe, Undefinable } from "../../../utils";
|
|
|
2
2
|
import { Nothing, Some, MaybeType } from "../../../utils";
|
|
3
3
|
import type { Taxon, TaxonSetData } from "./taxon";
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* An internal maybe safe helper function for getting a taxon's name
|
|
7
|
+
* @param data - the underlying taxon set data.
|
|
8
|
+
* @param id
|
|
9
|
+
* @returns Maybe(name)
|
|
10
|
+
*/
|
|
11
|
+
|
|
5
12
|
export function maybeGetNameFromIndex(
|
|
6
13
|
data: TaxonSetData,
|
|
7
14
|
id: Maybe<number> | number,
|
|
@@ -23,6 +30,13 @@ export function maybeGetNameFromIndex(
|
|
|
23
30
|
return Some(name);
|
|
24
31
|
}
|
|
25
32
|
|
|
33
|
+
/**
|
|
34
|
+
* An internal maybe safe helper function for getting a taxon by it's name
|
|
35
|
+
* @param data - the underlying taxon set data.
|
|
36
|
+
* @param id
|
|
37
|
+
* @returns Maybe(taxon)
|
|
38
|
+
*/
|
|
39
|
+
|
|
26
40
|
export function maybeGetTaxonByName(
|
|
27
41
|
data: TaxonSetData,
|
|
28
42
|
id: Maybe<string> | string,
|
|
@@ -1,12 +1,23 @@
|
|
|
1
1
|
import { MaybeType } from "../../../utils";
|
|
2
2
|
import { maybeGetNameFromIndex, maybeGetTaxonByName } from "./helper-functions";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* A interface for taxon.
|
|
6
|
+
* There should only be one taxon per individual sampled.
|
|
7
|
+
* The taxon is meant to be synonymous with the individual and may be shared across multiple trees.
|
|
8
|
+
*/
|
|
4
9
|
export interface Taxon {
|
|
5
10
|
name: string;
|
|
6
11
|
number: number;
|
|
7
12
|
annotations: { [annotation: string]: string | string[] | number | number[] };
|
|
8
13
|
}
|
|
9
14
|
|
|
15
|
+
/**
|
|
16
|
+
* An internal helper function for constructing a new taxon.
|
|
17
|
+
* @param name - taxon name
|
|
18
|
+
* @param number - taxon number
|
|
19
|
+
* @returns
|
|
20
|
+
*/
|
|
10
21
|
function newTaxon(name: string, number: number): Taxon {
|
|
11
22
|
return {
|
|
12
23
|
name,
|
|
@@ -15,19 +26,47 @@ function newTaxon(name: string, number: number): Taxon {
|
|
|
15
26
|
};
|
|
16
27
|
}
|
|
17
28
|
|
|
29
|
+
/**
|
|
30
|
+
* An interface for a taxon set - a group of taxa in a tree.
|
|
31
|
+
*/
|
|
18
32
|
export interface TaxonSetInterface {
|
|
33
|
+
/**
|
|
34
|
+
* Add a taxon the the set
|
|
35
|
+
* @param name - Add a new taxon with this name
|
|
36
|
+
*/
|
|
19
37
|
addTaxon(name: string): TaxonSetInterface;
|
|
20
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Get a taxon by it's number
|
|
40
|
+
* @param id -taxon number
|
|
41
|
+
*/
|
|
42
|
+
getTaxon(id: number): Taxon | undefined; // remove this undefined?
|
|
43
|
+
/**
|
|
44
|
+
* Get a taxon object by it's name.
|
|
45
|
+
* @param name -the taxon name
|
|
46
|
+
*/
|
|
21
47
|
getTaxonByName(name: string): Taxon;
|
|
48
|
+
/**
|
|
49
|
+
* Return the number of taxa in the set.
|
|
50
|
+
*/
|
|
22
51
|
getTaxonCount(): number;
|
|
52
|
+
/**
|
|
53
|
+
* Lock the taxa set. No taxa can be added or removed at this point. The population is fixed.
|
|
54
|
+
*/
|
|
23
55
|
lockTaxa(): TaxonSetInterface;
|
|
24
56
|
}
|
|
25
57
|
|
|
58
|
+
/**
|
|
59
|
+
* The interface for a taxon set internal data structure.
|
|
60
|
+
*/
|
|
26
61
|
export interface TaxonSetData {
|
|
27
62
|
allNames: string[];
|
|
28
63
|
byName: { [taxon: string]: Taxon };
|
|
29
64
|
finalized: boolean;
|
|
30
65
|
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* A concrete implementation of the taxonset interface
|
|
69
|
+
*/
|
|
31
70
|
export class TaxonSet implements TaxonSetInterface {
|
|
32
71
|
_data: TaxonSetData;
|
|
33
72
|
constructor(taxonSetData?: TaxonSetData) {
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { Tree, NodeRef } from "../tree-types";
|
|
2
2
|
import type { TreeTraversal } from "./traversal-types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* A class for a cached pre-order traversal.
|
|
6
|
+
* This needs to be revisited before it can be used.
|
|
7
|
+
*/
|
|
3
8
|
export class PreOrderTraversalCache implements TreeTraversal {
|
|
4
9
|
_forwardCache: Map<NodeRef, NodeRef>;
|
|
5
10
|
_reverseCache: Map<NodeRef, NodeRef>;
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import type { Taxon, TaxonSet } from "./taxa/taxon";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* The base interface for a node.
|
|
5
|
+
* Information about the node will be provided by the tree.
|
|
6
|
+
*/
|
|
3
7
|
export interface NodeRef {
|
|
4
8
|
number: number;
|
|
5
9
|
_id: string;
|
|
6
10
|
}
|
|
11
|
+
/**
|
|
12
|
+
* Types of annotations that can exist on nodes in a tree.
|
|
13
|
+
* Each type corresponds to a value type.
|
|
14
|
+
*/
|
|
7
15
|
export enum BaseAnnotationType {
|
|
8
16
|
DISCRETE = "DISCRETE", // string could also be stringy numbers
|
|
9
17
|
BOOLEAN = "BOOLEAN", // true false
|
|
@@ -17,6 +25,8 @@ export enum BaseAnnotationType {
|
|
|
17
25
|
}
|
|
18
26
|
export type MarkovJumpValue = { from: string; to: string; time?: number };
|
|
19
27
|
|
|
28
|
+
// A helper type function that returns the value type of an annotation given its
|
|
29
|
+
// figtree type.
|
|
20
30
|
export type ValueOf<T extends BaseAnnotationType> =
|
|
21
31
|
T extends BaseAnnotationType.DISCRETE
|
|
22
32
|
? string
|
|
@@ -34,6 +44,9 @@ export type ValueOf<T extends BaseAnnotationType> =
|
|
|
34
44
|
? Record<string, number>
|
|
35
45
|
: never;
|
|
36
46
|
|
|
47
|
+
// A helper function that returns the raw value type that corresponds to a figtreejs annotation type.
|
|
48
|
+
// This generally is the same as the value type, but some annotations such as markov jumps are transformed
|
|
49
|
+
// between being read from a nexus file and stored in the tree.
|
|
37
50
|
export type RawValueOf<T extends BaseAnnotationType> =
|
|
38
51
|
T extends BaseAnnotationType.DISCRETE
|
|
39
52
|
? string
|
|
@@ -51,6 +64,10 @@ export type RawValueOf<T extends BaseAnnotationType> =
|
|
|
51
64
|
? Record<string, number>
|
|
52
65
|
: never;
|
|
53
66
|
|
|
67
|
+
/**
|
|
68
|
+
* A helper type function that returns the domain of an annotation based on the
|
|
69
|
+
* type of an annotation.
|
|
70
|
+
*/
|
|
54
71
|
export type DomainOf<T extends BaseAnnotationType> =
|
|
55
72
|
T extends BaseAnnotationType.DISCRETE
|
|
56
73
|
? string[]
|
|
@@ -79,25 +96,42 @@ export type Annotation = {
|
|
|
79
96
|
[K in BaseAnnotationType]: AbstractAnnotation<K>;
|
|
80
97
|
}[BaseAnnotationType];
|
|
81
98
|
|
|
99
|
+
/**
|
|
100
|
+
* The type of summary information that can be provided by a tree.
|
|
101
|
+
*/
|
|
82
102
|
export interface AbstractAnnotationSummary<T extends BaseAnnotationType> {
|
|
83
103
|
id: string;
|
|
84
104
|
type: T;
|
|
85
105
|
domain: DomainOf<T>;
|
|
86
106
|
}
|
|
87
107
|
|
|
108
|
+
/**
|
|
109
|
+
* unions across all types of annotations.
|
|
110
|
+
*/
|
|
88
111
|
export type AnnotationDomain = {
|
|
89
112
|
[K in BaseAnnotationType]: DomainOf<K>;
|
|
90
113
|
}[BaseAnnotationType];
|
|
114
|
+
|
|
91
115
|
export type AnnotationValue = {
|
|
92
116
|
[K in BaseAnnotationType]: ValueOf<K>;
|
|
93
117
|
}[BaseAnnotationType];
|
|
118
|
+
|
|
94
119
|
export type AnnotationSummary = {
|
|
95
120
|
[K in BaseAnnotationType]: AbstractAnnotationSummary<K>;
|
|
96
121
|
}[BaseAnnotationType];
|
|
122
|
+
|
|
97
123
|
export type RawAnnotationValue = {
|
|
98
124
|
[K in BaseAnnotationType]: RawValueOf<K>;
|
|
99
125
|
}[BaseAnnotationType];
|
|
100
126
|
|
|
127
|
+
/**
|
|
128
|
+
* A object for the parsing options available for importing a newick string.
|
|
129
|
+
* dateFormat : string if provided with date prefix the data will be parsed from the taxon label and stored in an annotation called 'date'
|
|
130
|
+
* datePrefix : string The character immediately preceding the date assuming the date is at the end of the taxon label
|
|
131
|
+
* labelName : If there are node labels they will be parsed as annotations and stored with this annotation name
|
|
132
|
+
* tipNameMap : If taxon are present as number or some other encoding this map will be used to insert the full taxon name.
|
|
133
|
+
* taxonSet : If provided this taxon set will be used to link taxa across trees.
|
|
134
|
+
*/
|
|
101
135
|
export interface newickParsingOptions {
|
|
102
136
|
dateFormat?: string;
|
|
103
137
|
datePrefix?: string;
|
|
@@ -106,92 +140,297 @@ export interface newickParsingOptions {
|
|
|
106
140
|
tipNameMap?: Map<string, string>;
|
|
107
141
|
taxonSet?: TaxonSet;
|
|
108
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* A representation of a phylogenetic tree.
|
|
145
|
+
* Trees may represent unrooted tree, but all trees nominally have a root node.
|
|
146
|
+
* Functions do not return 'undefined' or 'null'.
|
|
147
|
+
* If a value that does not exist is accessed the tree will throw an error.
|
|
148
|
+
* Helper functions are provided to check if a value exists.
|
|
149
|
+
*/
|
|
109
150
|
export interface Tree {
|
|
151
|
+
/**
|
|
152
|
+
* Return the root of the tree.
|
|
153
|
+
*/
|
|
110
154
|
getRoot(): NodeRef;
|
|
111
|
-
isRooted(): boolean;
|
|
155
|
+
// isRooted(): boolean;
|
|
156
|
+
/**
|
|
157
|
+
* Return the number of nodes in the tree.
|
|
158
|
+
*/
|
|
112
159
|
getNodeCount(): number;
|
|
160
|
+
/**
|
|
161
|
+
* Return the number of internal nodes.
|
|
162
|
+
*/
|
|
113
163
|
getInternalNodeCount(): number;
|
|
164
|
+
/**
|
|
165
|
+
* Return the number of tips / external nodes
|
|
166
|
+
*/
|
|
114
167
|
getExternalNodeCount(): number;
|
|
168
|
+
/**
|
|
169
|
+
* Get Node by name/label, taxon, or index (in full node list)
|
|
170
|
+
* @param i: string | Taxon | number
|
|
171
|
+
*/
|
|
115
172
|
getNode(i: string | Taxon | number): NodeRef;
|
|
173
|
+
/**
|
|
174
|
+
* Get an array of internal nodes
|
|
175
|
+
*/
|
|
116
176
|
getInternalNodes(): NodeRef[];
|
|
177
|
+
/**
|
|
178
|
+
* Get an array of external nodes
|
|
179
|
+
*/
|
|
117
180
|
getExternalNodes(): NodeRef[];
|
|
181
|
+
/**
|
|
182
|
+
* Get an array of all nodes.
|
|
183
|
+
*/
|
|
118
184
|
getNodes(): NodeRef[];
|
|
185
|
+
/**
|
|
186
|
+
* Get the taxon affiliated with a node or by it's index
|
|
187
|
+
* @param id: number | NodeRef
|
|
188
|
+
*/
|
|
119
189
|
getTaxon(id: number | NodeRef): Taxon;
|
|
120
|
-
|
|
190
|
+
/**
|
|
191
|
+
* Helper to function to determine if a node in an external node
|
|
192
|
+
* @param node
|
|
193
|
+
*/
|
|
121
194
|
isExternal(node: NodeRef): boolean;
|
|
195
|
+
/**
|
|
196
|
+
* A helper function to determine if an node is an internal node
|
|
197
|
+
* @param node
|
|
198
|
+
*/
|
|
122
199
|
isInternal(node: NodeRef): boolean;
|
|
200
|
+
/**
|
|
201
|
+
* A helper function to determine if a node is the root node.
|
|
202
|
+
* @param node
|
|
203
|
+
*/
|
|
123
204
|
isRoot(node: NodeRef): boolean;
|
|
124
|
-
|
|
205
|
+
/**
|
|
206
|
+
* Return the number of children an given node has.
|
|
207
|
+
* @param node
|
|
208
|
+
*/
|
|
125
209
|
getChildCount(node: NodeRef): number;
|
|
210
|
+
/**
|
|
211
|
+
* Access the ith child of a node
|
|
212
|
+
* @param node - NodeRef
|
|
213
|
+
* @param i - index of the child
|
|
214
|
+
*/
|
|
126
215
|
getChild(node: NodeRef, i: number): NodeRef;
|
|
127
|
-
|
|
216
|
+
/**
|
|
217
|
+
* An explicit function to get a node by it's Taxon
|
|
218
|
+
* @param taxon
|
|
219
|
+
*/
|
|
128
220
|
getNodeByTaxon(taxon: Taxon): NodeRef;
|
|
221
|
+
/**
|
|
222
|
+
* An explicit function to access a node by it's label
|
|
223
|
+
* @param label - string
|
|
224
|
+
*/
|
|
129
225
|
getNodeByLabel(label: string): NodeRef;
|
|
130
226
|
// getLevel(node:NodeRef):number;
|
|
131
|
-
|
|
227
|
+
/**
|
|
228
|
+
* Return the distance from this node to the root.
|
|
229
|
+
* @param node -NodeRef
|
|
230
|
+
*/
|
|
132
231
|
getDivergence(node: NodeRef): number;
|
|
232
|
+
/**
|
|
233
|
+
* Return the distance between a node and the node furthest from the root
|
|
234
|
+
* @param node -NodeRef
|
|
235
|
+
*/
|
|
133
236
|
getHeight(node: NodeRef): number;
|
|
237
|
+
/**
|
|
238
|
+
* Return the length of the branch subtending a node
|
|
239
|
+
* @param node -NodeRef
|
|
240
|
+
*/
|
|
134
241
|
getLength(node: NodeRef): number;
|
|
135
|
-
|
|
242
|
+
/**
|
|
243
|
+
* Return a node's parent
|
|
244
|
+
* @param node -NodeRef
|
|
245
|
+
*/
|
|
136
246
|
getParent(node: NodeRef): NodeRef;
|
|
247
|
+
/**
|
|
248
|
+
* Get an array of the node's children
|
|
249
|
+
* @param node -NodeRef
|
|
250
|
+
*/
|
|
137
251
|
getChildren(node: NodeRef): NodeRef[];
|
|
138
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Get the annotation value for a node.
|
|
254
|
+
* If the default value is not provided, and the node is not annotated, the function will throw an error.
|
|
255
|
+
* @param node - NodeRef
|
|
256
|
+
* @param name - string the name of the annotation
|
|
257
|
+
* @param d - AnnotationValue - The default value to return if the node does not have the provided annotation.
|
|
258
|
+
*/
|
|
139
259
|
getAnnotation(
|
|
140
260
|
node: NodeRef,
|
|
141
261
|
name: string,
|
|
142
262
|
d?: AnnotationValue,
|
|
143
263
|
): AnnotationValue; // what about or undefined?
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
264
|
+
/**
|
|
265
|
+
* Annotate a node with a value.
|
|
266
|
+
* @param node - NodeRef
|
|
267
|
+
* @param name -string - Name of the annotation
|
|
268
|
+
* @param value - the annotation value for a node.
|
|
269
|
+
*/
|
|
148
270
|
annotateNode(node: NodeRef, name: string, value: RawAnnotationValue): Tree;
|
|
149
271
|
annotateNode(
|
|
150
272
|
node: NodeRef,
|
|
151
273
|
annotation: Record<string, RawAnnotationValue>,
|
|
152
274
|
): Tree;
|
|
153
|
-
|
|
275
|
+
/**
|
|
276
|
+
* Get the label for a given node
|
|
277
|
+
* @param node
|
|
278
|
+
*/
|
|
154
279
|
getLabel(node: NodeRef): string;
|
|
280
|
+
/**
|
|
281
|
+
* Check if a node has a label
|
|
282
|
+
* @param node
|
|
283
|
+
*/
|
|
155
284
|
hasLabel(node: NodeRef): boolean;
|
|
156
|
-
|
|
285
|
+
/**
|
|
286
|
+
* Get all the names of annotations in the tree
|
|
287
|
+
*/
|
|
157
288
|
getAnnotationKeys(): string[];
|
|
289
|
+
/**
|
|
290
|
+
* Get the type of an annotation found in the tree.
|
|
291
|
+
* @param name string - Name of the annotation
|
|
292
|
+
*/
|
|
158
293
|
getAnnotationType(name: string): BaseAnnotationType;
|
|
159
294
|
|
|
295
|
+
/**
|
|
296
|
+
* Return an array of summary data for all annotations in the tree.
|
|
297
|
+
*/
|
|
160
298
|
getAnnotations(): AnnotationSummary[];
|
|
299
|
+
/**
|
|
300
|
+
* Return a summary of an annotation in the tree
|
|
301
|
+
* @param name - name of the annotation
|
|
302
|
+
*/
|
|
161
303
|
getAnnotationSummary(name: string): AnnotationSummary;
|
|
162
|
-
|
|
304
|
+
/**
|
|
305
|
+
* Add nodes to a tree.
|
|
306
|
+
* The nodes can be accessed by their indices, but have no relationships with other nodes in the tree.
|
|
307
|
+
* Returns an object with {tree: the new tree with nodes,node: An array of the new nodes}
|
|
308
|
+
* @param n - number of nodes to add default 1
|
|
309
|
+
*/
|
|
163
310
|
addNodes(n?: number): { tree: Tree; nodes: NodeRef[] };
|
|
311
|
+
/**
|
|
312
|
+
* Delete a node from a tree.
|
|
313
|
+
* It is not possible to delete the root node.
|
|
314
|
+
* @param n - NodeRef
|
|
315
|
+
*/
|
|
164
316
|
deleteNode(n: NodeRef): Tree;
|
|
317
|
+
/**
|
|
318
|
+
* Remove a child node from a parent node's descendants
|
|
319
|
+
* @param parent - The node whose child will be removed
|
|
320
|
+
* @param child - The child that is removed from the parent.
|
|
321
|
+
*/
|
|
165
322
|
removeChild(parent: NodeRef, child: NodeRef): Tree;
|
|
166
|
-
deleteClade(n: NodeRef): Tree;
|
|
323
|
+
// deleteClade(n: NodeRef): Tree;
|
|
167
324
|
// hasNextSibling(node:Node)
|
|
325
|
+
/**
|
|
326
|
+
* Get the next sibling.
|
|
327
|
+
* This will wrap back to the first sibling if the provided node is the last sibling.
|
|
328
|
+
* @param node - NodeRef
|
|
329
|
+
*/
|
|
168
330
|
getNextSibling(node: NodeRef): NodeRef;
|
|
331
|
+
/**
|
|
332
|
+
* A checker function to determine if a node has a right sibling
|
|
333
|
+
* @param node - NodeRef
|
|
334
|
+
*/
|
|
169
335
|
hasRightSibling(node: NodeRef): boolean;
|
|
336
|
+
/**
|
|
337
|
+
* Return a node's right sibling (if it has one) or error.
|
|
338
|
+
* @param node
|
|
339
|
+
*/
|
|
170
340
|
getRightSibling(node: NodeRef): NodeRef;
|
|
341
|
+
/**
|
|
342
|
+
* Check if a node has a left sibling
|
|
343
|
+
* @param node
|
|
344
|
+
*/
|
|
171
345
|
hasLeftSibling(node: NodeRef): boolean;
|
|
346
|
+
/**
|
|
347
|
+
* Return a node's left sibling (if it has one) or throw an error.
|
|
348
|
+
* @param node
|
|
349
|
+
*/
|
|
172
350
|
getLeftSibling(node: NodeRef): NodeRef;
|
|
173
351
|
|
|
352
|
+
/**
|
|
353
|
+
* Set the distance between a node and the node furthest from the root.
|
|
354
|
+
* @param node
|
|
355
|
+
* @param height number - the new node height
|
|
356
|
+
*/
|
|
174
357
|
setHeight(node: NodeRef, height: number): Tree;
|
|
358
|
+
/**
|
|
359
|
+
* Set the distance between a node and the root node.
|
|
360
|
+
* @param node
|
|
361
|
+
* @param divergence number - new divergence
|
|
362
|
+
*/
|
|
175
363
|
setDivergence(node: NodeRef, divergence: number): Tree;
|
|
364
|
+
/**
|
|
365
|
+
* Set the length of the branch subtending a node
|
|
366
|
+
* @param node NodeRef
|
|
367
|
+
* @param length - number - the new length
|
|
368
|
+
*/
|
|
176
369
|
setLength(node: NodeRef, length: number): Tree;
|
|
370
|
+
/**
|
|
371
|
+
* Assign a taxon to a node.
|
|
372
|
+
* @param node NodRef
|
|
373
|
+
* @param taxon Taxon
|
|
374
|
+
*/
|
|
177
375
|
setTaxon(node: NodeRef, taxon: Taxon): Tree;
|
|
376
|
+
/**
|
|
377
|
+
* Set the label on a node.
|
|
378
|
+
* @param node Noderf
|
|
379
|
+
* @param label string
|
|
380
|
+
*/
|
|
178
381
|
setLabel(node: NodeRef, label: string): Tree;
|
|
179
|
-
|
|
382
|
+
/**
|
|
383
|
+
* Add a child to a node.
|
|
384
|
+
* @param parent the parent that gets a new child
|
|
385
|
+
* @param child The child added to a parent
|
|
386
|
+
*/
|
|
180
387
|
addChild(parent: NodeRef, child: NodeRef): Tree;
|
|
181
388
|
// root(node: NodeRef,portion:number): Tree
|
|
182
|
-
unroot(node: NodeRef): Tree;
|
|
389
|
+
// unroot(node: NodeRef): Tree;
|
|
390
|
+
|
|
391
|
+
/**
|
|
392
|
+
*
|
|
393
|
+
* @param node - An optional node start writing from. If not provided the whole tree will be written.
|
|
394
|
+
* @param options { includeAnnotations: boolean } - include annotations in newick string
|
|
395
|
+
*/
|
|
183
396
|
toNewick(node?: NodeRef, options?: { includeAnnotations: boolean }): string;
|
|
397
|
+
/**
|
|
398
|
+
* Sort children arrays by the number of offspring.
|
|
399
|
+
* @param down Boolean to sort down or up.
|
|
400
|
+
*/
|
|
184
401
|
orderNodesByDensity(down: boolean): Tree;
|
|
402
|
+
/**
|
|
403
|
+
*
|
|
404
|
+
* @param node Node whose children will be sorted
|
|
405
|
+
* @param compare - A function which compares two nodes. Will be used as in an array sort
|
|
406
|
+
*/
|
|
185
407
|
sortChildren(
|
|
186
408
|
node: NodeRef,
|
|
187
409
|
compare: (a: NodeRef, b: NodeRef) => number,
|
|
188
410
|
): Tree;
|
|
189
|
-
|
|
411
|
+
/**
|
|
412
|
+
* Get the most recent common ancestor of two nodes
|
|
413
|
+
* @param node1
|
|
414
|
+
* @param node2
|
|
415
|
+
*/
|
|
190
416
|
getMRCA(node1: NodeRef, node2: NodeRef): NodeRef;
|
|
417
|
+
/**
|
|
418
|
+
* Get the most recent common ancestor of an array of nodes
|
|
419
|
+
* @param nodes
|
|
420
|
+
*/
|
|
191
421
|
getMRCA(nodes: NodeRef[]): NodeRef;
|
|
422
|
+
/**
|
|
423
|
+
* Rotate a node's children
|
|
424
|
+
* @param node
|
|
425
|
+
* @param recursive - rotate the children as well down the tree
|
|
426
|
+
*/
|
|
192
427
|
rotate(node: NodeRef, recursive: boolean): Tree;
|
|
428
|
+
/**
|
|
429
|
+
* Reroot a tree along a branch subtending a new node.
|
|
430
|
+
* @param node The root will be inserted along the branch subtending this node
|
|
431
|
+
* @param proportion - proportion along the branch to place the root.
|
|
432
|
+
*/
|
|
193
433
|
reroot(node: NodeRef, proportion: number): Tree;
|
|
194
434
|
}
|
|
195
|
-
export type TreeListener = (tree: Tree, node: NodeRef) => void;
|
|
196
435
|
|
|
197
|
-
|
|
436
|
+
export type TreeListener = (tree: Tree, node: NodeRef) => void;
|