@figtreejs/core 0.0.1-alpha.1 → 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 -8874
- package/dist/index.d.ts +461 -233
- package/dist/index.mjs +4432 -6624
- package/package.json +7 -4
- package/src/bauble-makers/set-up-baubles.ts +1 -1
- package/src/components/baubles/clades/highlight.tsx +1 -1
- package/src/components/decorations/axis/polar-axis.tsx +1 -1
- package/src/components/decorations/axis/rectangular-axis.tsx +1 -1
- package/src/components/figtree/figtree.tsx +1 -1
- package/src/components/hoc/with-node.tsx +1 -1
- package/src/evo/tree/normalized-tree/immutable-tree-helpers.ts +2 -2
- package/src/evo/tree/normalized-tree/immutable-tree.test.ts +1 -1
- package/src/evo/tree/normalized-tree/immutable-tree.ts +3 -5
- package/src/evo/tree/parsers/annotation-parser.ts +6 -0
- package/src/evo/tree/parsers/newick-character-parser.ts +9 -1
- 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/parsing.test.ts +1 -1
- package/src/evo/tree/parsers/stream-reader/nexus-importer.ts +9 -2
- package/src/evo/tree/parsers/stream-reader/nexus-tokenizer.ts +6 -1
- package/src/evo/tree/taxa/helper-functions.ts +16 -2
- package/src/evo/tree/taxa/taxon.ts +41 -2
- 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/index.ts +1 -1
- package/src/layouts/functional/radial-layout.ts +15 -11
- package/src/layouts/functional/rectangular-layout.ts +8 -1
- package/src/layouts/layout-interface.ts +0 -73
- package/src/path.helpers.ts +76 -59
- package/src/tests/clades/cartoon.test.tsx +1 -1
- package/src/tests/clades/highlight.test.tsx +1 -1
- package/src/tests/layouts/rectangularlayout.test.ts +1 -1
- package/src/tests/shapes/label.test.tsx +1 -1
- package/src/utils/dateUtils.ts +41 -0
- package/src/utils/index.ts +2 -0
- package/src/utils/maybe.ts +67 -0
- package/CHANGELOG.md +0 -17
- package/eslint.config.js +0 -9
- package/src/utils.ts +0 -57
- package/tsconfig.json +0 -12
- package/vite.config.ts +0 -34
- package/vitetest.config.ts +0 -11
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { immerable } from 'immer';
|
|
2
2
|
import { JSX as JSX_2 } from 'react/jsx-runtime';
|
|
3
|
-
import { Maybe } from '@figtreejs/maybe/maybe';
|
|
4
3
|
import { ScaleContinuousNumeric } from 'd3-scale';
|
|
5
4
|
|
|
6
5
|
/** A single, generic annotation, discriminated by `type`. */
|
|
@@ -10,6 +9,9 @@ export declare type AbstractAnnotation<T extends BaseAnnotationType> = {
|
|
|
10
9
|
value: ValueOf<T>;
|
|
11
10
|
};
|
|
12
11
|
|
|
12
|
+
/**
|
|
13
|
+
* The type of summary information that can be provided by a tree.
|
|
14
|
+
*/
|
|
13
15
|
export declare interface AbstractAnnotationSummary<T extends BaseAnnotationType> {
|
|
14
16
|
id: string;
|
|
15
17
|
type: T;
|
|
@@ -20,6 +22,9 @@ export declare type Annotation = {
|
|
|
20
22
|
[K in BaseAnnotationType]: AbstractAnnotation<K>;
|
|
21
23
|
}[BaseAnnotationType];
|
|
22
24
|
|
|
25
|
+
/**
|
|
26
|
+
* unions across all types of annotations.
|
|
27
|
+
*/
|
|
23
28
|
export declare type AnnotationDomain = {
|
|
24
29
|
[K in BaseAnnotationType]: DomainOf<K>;
|
|
25
30
|
}[BaseAnnotationType];
|
|
@@ -32,35 +37,6 @@ export declare type AnnotationValue = {
|
|
|
32
37
|
[K in BaseAnnotationType]: ValueOf<K>;
|
|
33
38
|
}[BaseAnnotationType];
|
|
34
39
|
|
|
35
|
-
export declare interface ArbitraryVertex {
|
|
36
|
-
hidden: boolean;
|
|
37
|
-
labelHidden: boolean;
|
|
38
|
-
number: number;
|
|
39
|
-
x: number;
|
|
40
|
-
y: number;
|
|
41
|
-
level: number;
|
|
42
|
-
theta?: number;
|
|
43
|
-
pathPoints: {
|
|
44
|
-
x: number;
|
|
45
|
-
y: number;
|
|
46
|
-
}[];
|
|
47
|
-
nodeLabel: {
|
|
48
|
-
dx: number;
|
|
49
|
-
dy: number;
|
|
50
|
-
alignmentBaseline: string;
|
|
51
|
-
textAnchor: string;
|
|
52
|
-
rotation?: number;
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export declare interface ArbitraryVertices {
|
|
57
|
-
vertices: ArbitraryVertex[];
|
|
58
|
-
extent: {
|
|
59
|
-
x: [number, number];
|
|
60
|
-
y: [number, number];
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
|
|
64
40
|
/** Attribute as they are passed internally to possibly animated svg elements */
|
|
65
41
|
declare type Attrs = Record<string, number | string>;
|
|
66
42
|
|
|
@@ -108,6 +84,10 @@ declare type AxisTicksOptions = {
|
|
|
108
84
|
values?: number[];
|
|
109
85
|
};
|
|
110
86
|
|
|
87
|
+
/**
|
|
88
|
+
* Types of annotations that can exist on nodes in a tree.
|
|
89
|
+
* Each type corresponds to a value type.
|
|
90
|
+
*/
|
|
111
91
|
export declare enum BaseAnnotationType {
|
|
112
92
|
DISCRETE = "DISCRETE",// string could also be stringy numbers
|
|
113
93
|
BOOLEAN = "BOOLEAN",// true false
|
|
@@ -176,11 +156,6 @@ declare type CartoonAttrs = ExposedAttrs<PathAttrs>;
|
|
|
176
156
|
|
|
177
157
|
export declare function CartoonClades(options: CartoonOptions): InternalCladeOptions;
|
|
178
158
|
|
|
179
|
-
export declare interface CartoonData {
|
|
180
|
-
cartooned: boolean;
|
|
181
|
-
collapseFactor: number;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
159
|
export declare type CartoonOptions = BaseBaubleOptions<CartoonAttrs>;
|
|
185
160
|
|
|
186
161
|
declare type CircleAttrs = Omit<BaseCircleDOMProps, "cx" | "cy"> & {
|
|
@@ -234,6 +209,10 @@ export declare const defaultInternalLayoutOptions: {
|
|
|
234
209
|
minRadius: number;
|
|
235
210
|
};
|
|
236
211
|
|
|
212
|
+
/**
|
|
213
|
+
* A helper type function that returns the domain of an annotation based on the
|
|
214
|
+
* type of an annotation.
|
|
215
|
+
*/
|
|
237
216
|
export declare type DomainOf<T extends BaseAnnotationType> = T extends BaseAnnotationType.DISCRETE ? string[] : T extends BaseAnnotationType.BOOLEAN ? [boolean, boolean] : T extends BaseAnnotationType.NUMERICAL ? [number, number] : T extends BaseAnnotationType.NUMERICAL_SET ? [number, number] : T extends BaseAnnotationType.DISCRETE_SET ? string[] | number[] : T extends BaseAnnotationType.MARKOV_JUMPS ? string[] : T extends BaseAnnotationType.DENSITIES ? string[] : never;
|
|
238
217
|
|
|
239
218
|
declare type ExposedAttrs<A> = {
|
|
@@ -427,11 +406,6 @@ export declare type InternalLabelOptions = LabelOptions & ({
|
|
|
427
406
|
target: BaubleTarget.BranchLabel;
|
|
428
407
|
});
|
|
429
408
|
|
|
430
|
-
export declare interface internalLayoutOptions extends layoutOptions {
|
|
431
|
-
width?: number;
|
|
432
|
-
height?: number;
|
|
433
|
-
}
|
|
434
|
-
|
|
435
409
|
export declare type InternalNodeOptions = ((CircleNodeOptions & {
|
|
436
410
|
shape: NodeShapes.Circle;
|
|
437
411
|
}) | (RectangleNodeOptions & {
|
|
@@ -440,18 +414,6 @@ export declare type InternalNodeOptions = ((CircleNodeOptions & {
|
|
|
440
414
|
target: BaubleTarget.Node;
|
|
441
415
|
};
|
|
442
416
|
|
|
443
|
-
export declare interface Label {
|
|
444
|
-
x: number;
|
|
445
|
-
y: number;
|
|
446
|
-
alignmentBaseline: string;
|
|
447
|
-
textAnchor: string;
|
|
448
|
-
rotation: number;
|
|
449
|
-
alignedPos?: {
|
|
450
|
-
x: number;
|
|
451
|
-
y: number;
|
|
452
|
-
};
|
|
453
|
-
}
|
|
454
|
-
|
|
455
417
|
declare type LabelAttrs = ExposedAttrs<LabelSpecificTextAttrs>;
|
|
456
418
|
|
|
457
419
|
declare type LabelOptions = BaseBaubleOptions<LabelAttrs> & ExposedAttrs<{
|
|
@@ -501,8 +463,23 @@ export declare type MarkovJumpValue = {
|
|
|
501
463
|
time?: number;
|
|
502
464
|
};
|
|
503
465
|
|
|
466
|
+
declare type Maybe<T> = Some<T> | Nothing;
|
|
467
|
+
|
|
504
468
|
export declare type maybeNodeIndex = Maybe<nodeIndex>;
|
|
505
469
|
|
|
470
|
+
declare enum MaybeType {
|
|
471
|
+
Some = "some",
|
|
472
|
+
Nothing = "nothing"
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
/**
|
|
476
|
+
* A object for the parsing options available for importing a newick string.
|
|
477
|
+
* dateFormat : string if provided with date prefix the data will be parsed from the taxon label and stored in an annotation called 'date'
|
|
478
|
+
* datePrefix : string The character immediately preceding the date assuming the date is at the end of the taxon label
|
|
479
|
+
* labelName : If there are node labels they will be parsed as annotations and stored with this annotation name
|
|
480
|
+
* tipNameMap : If taxon are present as number or some other encoding this map will be used to insert the full taxon name.
|
|
481
|
+
* taxonSet : If provided this taxon set will be used to link taxa across trees.
|
|
482
|
+
*/
|
|
506
483
|
export declare interface newickParsingOptions {
|
|
507
484
|
dateFormat?: string;
|
|
508
485
|
datePrefix?: string;
|
|
@@ -512,6 +489,10 @@ export declare interface newickParsingOptions {
|
|
|
512
489
|
taxonSet?: TaxonSet;
|
|
513
490
|
}
|
|
514
491
|
|
|
492
|
+
/**
|
|
493
|
+
* A nexus importing class that parses a stream and into an asynchronous
|
|
494
|
+
* iterator over trees.
|
|
495
|
+
*/
|
|
515
496
|
export declare class NexusImporter {
|
|
516
497
|
reader: ReadableStreamDefaultReader<string>;
|
|
517
498
|
taxonSet: TaxonSet;
|
|
@@ -524,6 +505,10 @@ export declare class NexusImporter {
|
|
|
524
505
|
constructor(stream: ReadableStream<BufferSource>, options?: {
|
|
525
506
|
labelName?: string;
|
|
526
507
|
});
|
|
508
|
+
/**
|
|
509
|
+
* The main public api.
|
|
510
|
+
* an asynchronous iterator over the trees provided by the stream
|
|
511
|
+
*/
|
|
527
512
|
getTrees(): AsyncIterableIterator<ImmutableTree>;
|
|
528
513
|
private parseNextBlock;
|
|
529
514
|
private nextToken;
|
|
@@ -568,6 +553,10 @@ declare type nodeOption = {
|
|
|
568
553
|
nodes: NodeRef[];
|
|
569
554
|
};
|
|
570
555
|
|
|
556
|
+
/**
|
|
557
|
+
* The base interface for a node.
|
|
558
|
+
* Information about the node will be provided by the tree.
|
|
559
|
+
*/
|
|
571
560
|
export declare interface NodeRef {
|
|
572
561
|
number: number;
|
|
573
562
|
_id: string;
|
|
@@ -578,9 +567,11 @@ declare enum NodeShapes {
|
|
|
578
567
|
Rectangle = 1
|
|
579
568
|
}
|
|
580
569
|
|
|
581
|
-
|
|
570
|
+
declare type Nothing = {
|
|
571
|
+
type: typeof MaybeType.Nothing;
|
|
572
|
+
};
|
|
582
573
|
|
|
583
|
-
|
|
574
|
+
declare const Nothing: () => Nothing;
|
|
584
575
|
|
|
585
576
|
declare type PathAttrs = Omit<BasePathDOMProps, "d">;
|
|
586
577
|
|
|
@@ -597,6 +588,10 @@ export declare function postOrderIterator(tree: Tree, node?: NodeRef | undefined
|
|
|
597
588
|
|
|
598
589
|
export declare function preOrderIterator(tree: Tree, node?: NodeRef | undefined): Generator<NodeRef>;
|
|
599
590
|
|
|
591
|
+
/**
|
|
592
|
+
* A class for a cached pre-order traversal.
|
|
593
|
+
* This needs to be revisited before it can be used.
|
|
594
|
+
*/
|
|
600
595
|
export declare class PreOrderTraversalCache implements TreeTraversal {
|
|
601
596
|
_forwardCache: Map<NodeRef, NodeRef>;
|
|
602
597
|
_reverseCache: Map<NodeRef, NodeRef>;
|
|
@@ -610,182 +605,415 @@ export declare function psuedoRootPostOrderIterator(tree: Tree, node?: NodeRef |
|
|
|
610
605
|
|
|
611
606
|
export declare function psuedoRootPreOrderIterator(tree: Tree, node?: NodeRef | undefined, sort?: (a: NodeRef, b: NodeRef) => number): Generator<NodeRef>;
|
|
612
607
|
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
declare type
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
export declare
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
declare type
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
608
|
+
/**
|
|
609
|
+
* The radial (unrooted) layout
|
|
610
|
+
* @param tree
|
|
611
|
+
* @param options {spread: number} - increases this increases the space between tips
|
|
612
|
+
* @returns (node)=>FunctionalVertex
|
|
613
|
+
*/
|
|
614
|
+
export declare function radialLayout(tree: ImmutableTree, options?: {
|
|
615
|
+
spread?: number;
|
|
616
|
+
}): (node: NodeRef) => FunctionalVertex;
|
|
617
|
+
|
|
618
|
+
export declare type RawAnnotationValue = {
|
|
619
|
+
[K in BaseAnnotationType]: RawValueOf<K>;
|
|
620
|
+
}[BaseAnnotationType];
|
|
621
|
+
|
|
622
|
+
export declare type RawValueOf<T extends BaseAnnotationType> = T extends BaseAnnotationType.DISCRETE ? string : T extends BaseAnnotationType.BOOLEAN ? boolean : T extends BaseAnnotationType.NUMERICAL ? number : T extends BaseAnnotationType.NUMERICAL_SET ? number[] : T extends BaseAnnotationType.DISCRETE_SET ? string[] : T extends BaseAnnotationType.MARKOV_JUMPS ? [number, string, string][] | [string, string, string][] : T extends BaseAnnotationType.DENSITIES ? Record<string, number> : never;
|
|
623
|
+
|
|
624
|
+
declare type RectangleNodeAttrs = ExposedAttrs<RectAttrs>;
|
|
625
|
+
|
|
626
|
+
export declare type RectangleNodeOptions = BaseBaubleOptions<RectangleNodeAttrs>;
|
|
627
|
+
|
|
628
|
+
export declare function RectangleNodes(options: RectangleNodeOptions): InternalNodeOptions;
|
|
629
|
+
|
|
630
|
+
export declare const rectangularLayout: (tree: ImmutableTree) => (node: NodeRef) => FunctionalVertex;
|
|
631
|
+
|
|
632
|
+
declare type RectAttrs = BaseRectangleDOMProps & {
|
|
633
|
+
width: number;
|
|
634
|
+
height: number;
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
export declare interface simplePolarVertex extends simpleVertex {
|
|
638
|
+
theta: number;
|
|
639
|
+
r: number;
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
export declare interface simpleVertex {
|
|
643
|
+
x: number;
|
|
644
|
+
y: number;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
declare type Some<T> = {
|
|
648
|
+
type: typeof MaybeType.Some;
|
|
649
|
+
value: T;
|
|
650
|
+
};
|
|
651
|
+
|
|
652
|
+
declare const Some: <T>(value: T) => Some<T>;
|
|
653
|
+
|
|
654
|
+
/**
|
|
655
|
+
* A interface for taxon.
|
|
656
|
+
* There should only be one taxon per individual sampled.
|
|
657
|
+
* The taxon is meant to be synonymous with the individual and may be shared across multiple trees.
|
|
658
|
+
*/
|
|
659
|
+
export declare interface Taxon {
|
|
660
|
+
name: string;
|
|
661
|
+
number: number;
|
|
662
|
+
annotations: {
|
|
663
|
+
[annotation: string]: string | string[] | number | number[];
|
|
664
|
+
};
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* A concrete implementation of the taxonset interface
|
|
669
|
+
*/
|
|
670
|
+
export declare class TaxonSet implements TaxonSetInterface {
|
|
671
|
+
_data: TaxonSetData;
|
|
672
|
+
constructor(taxonSetData?: TaxonSetData);
|
|
673
|
+
lockTaxa(): TaxonSetInterface;
|
|
674
|
+
addTaxon(taxonOrName: string | Taxon): this;
|
|
675
|
+
getTaxon(id: number): Taxon;
|
|
676
|
+
getTaxonByName(name: string): Taxon;
|
|
677
|
+
hasTaxon(id: string): boolean;
|
|
678
|
+
getTaxonCount(): number;
|
|
679
|
+
get isFinalized(): boolean;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* The interface for a taxon set internal data structure.
|
|
684
|
+
*/
|
|
685
|
+
export declare interface TaxonSetData {
|
|
686
|
+
allNames: string[];
|
|
687
|
+
byName: {
|
|
688
|
+
[taxon: string]: Taxon;
|
|
689
|
+
};
|
|
690
|
+
finalized: boolean;
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
/**
|
|
694
|
+
* An interface for a taxon set - a group of taxa in a tree.
|
|
695
|
+
*/
|
|
696
|
+
export declare interface TaxonSetInterface {
|
|
697
|
+
/**
|
|
698
|
+
* Add a taxon the the set
|
|
699
|
+
* @param name - Add a new taxon with this name
|
|
700
|
+
*/
|
|
701
|
+
addTaxon(name: string): TaxonSetInterface;
|
|
702
|
+
/**
|
|
703
|
+
* Get a taxon by it's number
|
|
704
|
+
* @param id -taxon number
|
|
705
|
+
*/
|
|
706
|
+
getTaxon(id: number): Taxon | undefined;
|
|
707
|
+
/**
|
|
708
|
+
* Get a taxon object by it's name.
|
|
709
|
+
* @param name -the taxon name
|
|
710
|
+
*/
|
|
711
|
+
getTaxonByName(name: string): Taxon;
|
|
712
|
+
/**
|
|
713
|
+
* Return the number of taxa in the set.
|
|
714
|
+
*/
|
|
715
|
+
getTaxonCount(): number;
|
|
716
|
+
/**
|
|
717
|
+
* Lock the taxa set. No taxa can be added or removed at this point. The population is fixed.
|
|
718
|
+
*/
|
|
719
|
+
lockTaxa(): TaxonSetInterface;
|
|
720
|
+
}
|
|
721
|
+
|
|
722
|
+
declare type TextAttrs = BaseTextDOMProps & {
|
|
723
|
+
text: string;
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
export declare function tipIterator(tree: Tree, node?: NodeRef): Generator<NodeRef>;
|
|
727
|
+
|
|
728
|
+
/**
|
|
729
|
+
* A representation of a phylogenetic tree.
|
|
730
|
+
* Trees may represent unrooted tree, but all trees nominally have a root node.
|
|
731
|
+
* Functions do not return 'undefined' or 'null'.
|
|
732
|
+
* If a value that does not exist is accessed the tree will throw an error.
|
|
733
|
+
* Helper functions are provided to check if a value exists.
|
|
734
|
+
*/
|
|
735
|
+
export declare interface Tree {
|
|
736
|
+
/**
|
|
737
|
+
* Return the root of the tree.
|
|
738
|
+
*/
|
|
739
|
+
getRoot(): NodeRef;
|
|
740
|
+
/**
|
|
741
|
+
* Return the number of nodes in the tree.
|
|
742
|
+
*/
|
|
743
|
+
getNodeCount(): number;
|
|
744
|
+
/**
|
|
745
|
+
* Return the number of internal nodes.
|
|
746
|
+
*/
|
|
747
|
+
getInternalNodeCount(): number;
|
|
748
|
+
/**
|
|
749
|
+
* Return the number of tips / external nodes
|
|
750
|
+
*/
|
|
751
|
+
getExternalNodeCount(): number;
|
|
752
|
+
/**
|
|
753
|
+
* Get Node by name/label, taxon, or index (in full node list)
|
|
754
|
+
* @param i: string | Taxon | number
|
|
755
|
+
*/
|
|
756
|
+
getNode(i: string | Taxon | number): NodeRef;
|
|
757
|
+
/**
|
|
758
|
+
* Get an array of internal nodes
|
|
759
|
+
*/
|
|
760
|
+
getInternalNodes(): NodeRef[];
|
|
761
|
+
/**
|
|
762
|
+
* Get an array of external nodes
|
|
763
|
+
*/
|
|
764
|
+
getExternalNodes(): NodeRef[];
|
|
765
|
+
/**
|
|
766
|
+
* Get an array of all nodes.
|
|
767
|
+
*/
|
|
768
|
+
getNodes(): NodeRef[];
|
|
769
|
+
/**
|
|
770
|
+
* Get the taxon affiliated with a node or by it's index
|
|
771
|
+
* @param id: number | NodeRef
|
|
772
|
+
*/
|
|
773
|
+
getTaxon(id: number | NodeRef): Taxon;
|
|
774
|
+
/**
|
|
775
|
+
* Helper to function to determine if a node in an external node
|
|
776
|
+
* @param node
|
|
777
|
+
*/
|
|
778
|
+
isExternal(node: NodeRef): boolean;
|
|
779
|
+
/**
|
|
780
|
+
* A helper function to determine if an node is an internal node
|
|
781
|
+
* @param node
|
|
782
|
+
*/
|
|
783
|
+
isInternal(node: NodeRef): boolean;
|
|
784
|
+
/**
|
|
785
|
+
* A helper function to determine if a node is the root node.
|
|
786
|
+
* @param node
|
|
787
|
+
*/
|
|
788
|
+
isRoot(node: NodeRef): boolean;
|
|
789
|
+
/**
|
|
790
|
+
* Return the number of children an given node has.
|
|
791
|
+
* @param node
|
|
792
|
+
*/
|
|
793
|
+
getChildCount(node: NodeRef): number;
|
|
794
|
+
/**
|
|
795
|
+
* Access the ith child of a node
|
|
796
|
+
* @param node - NodeRef
|
|
797
|
+
* @param i - index of the child
|
|
798
|
+
*/
|
|
799
|
+
getChild(node: NodeRef, i: number): NodeRef;
|
|
800
|
+
/**
|
|
801
|
+
* An explicit function to get a node by it's Taxon
|
|
802
|
+
* @param taxon
|
|
803
|
+
*/
|
|
804
|
+
getNodeByTaxon(taxon: Taxon): NodeRef;
|
|
805
|
+
/**
|
|
806
|
+
* An explicit function to access a node by it's label
|
|
807
|
+
* @param label - string
|
|
808
|
+
*/
|
|
809
|
+
getNodeByLabel(label: string): NodeRef;
|
|
810
|
+
/**
|
|
811
|
+
* Return the distance from this node to the root.
|
|
812
|
+
* @param node -NodeRef
|
|
813
|
+
*/
|
|
814
|
+
getDivergence(node: NodeRef): number;
|
|
815
|
+
/**
|
|
816
|
+
* Return the distance between a node and the node furthest from the root
|
|
817
|
+
* @param node -NodeRef
|
|
818
|
+
*/
|
|
819
|
+
getHeight(node: NodeRef): number;
|
|
820
|
+
/**
|
|
821
|
+
* Return the length of the branch subtending a node
|
|
822
|
+
* @param node -NodeRef
|
|
823
|
+
*/
|
|
824
|
+
getLength(node: NodeRef): number;
|
|
825
|
+
/**
|
|
826
|
+
* Return a node's parent
|
|
827
|
+
* @param node -NodeRef
|
|
828
|
+
*/
|
|
829
|
+
getParent(node: NodeRef): NodeRef;
|
|
830
|
+
/**
|
|
831
|
+
* Get an array of the node's children
|
|
832
|
+
* @param node -NodeRef
|
|
833
|
+
*/
|
|
834
|
+
getChildren(node: NodeRef): NodeRef[];
|
|
835
|
+
/**
|
|
836
|
+
* Get the annotation value for a node.
|
|
837
|
+
* If the default value is not provided, and the node is not annotated, the function will throw an error.
|
|
838
|
+
* @param node - NodeRef
|
|
839
|
+
* @param name - string the name of the annotation
|
|
840
|
+
* @param d - AnnotationValue - The default value to return if the node does not have the provided annotation.
|
|
841
|
+
*/
|
|
842
|
+
getAnnotation(node: NodeRef, name: string, d?: AnnotationValue): AnnotationValue;
|
|
843
|
+
/**
|
|
844
|
+
* Annotate a node with a value.
|
|
845
|
+
* @param node - NodeRef
|
|
846
|
+
* @param name -string - Name of the annotation
|
|
847
|
+
* @param value - the annotation value for a node.
|
|
848
|
+
*/
|
|
849
|
+
annotateNode(node: NodeRef, name: string, value: RawAnnotationValue): Tree;
|
|
850
|
+
annotateNode(node: NodeRef, annotation: Record<string, RawAnnotationValue>): Tree;
|
|
851
|
+
/**
|
|
852
|
+
* Get the label for a given node
|
|
853
|
+
* @param node
|
|
854
|
+
*/
|
|
855
|
+
getLabel(node: NodeRef): string;
|
|
856
|
+
/**
|
|
857
|
+
* Check if a node has a label
|
|
858
|
+
* @param node
|
|
859
|
+
*/
|
|
860
|
+
hasLabel(node: NodeRef): boolean;
|
|
861
|
+
/**
|
|
862
|
+
* Get all the names of annotations in the tree
|
|
863
|
+
*/
|
|
864
|
+
getAnnotationKeys(): string[];
|
|
865
|
+
/**
|
|
866
|
+
* Get the type of an annotation found in the tree.
|
|
867
|
+
* @param name string - Name of the annotation
|
|
868
|
+
*/
|
|
869
|
+
getAnnotationType(name: string): BaseAnnotationType;
|
|
870
|
+
/**
|
|
871
|
+
* Return an array of summary data for all annotations in the tree.
|
|
872
|
+
*/
|
|
873
|
+
getAnnotations(): AnnotationSummary[];
|
|
874
|
+
/**
|
|
875
|
+
* Return a summary of an annotation in the tree
|
|
876
|
+
* @param name - name of the annotation
|
|
877
|
+
*/
|
|
878
|
+
getAnnotationSummary(name: string): AnnotationSummary;
|
|
879
|
+
/**
|
|
880
|
+
* Add nodes to a tree.
|
|
881
|
+
* The nodes can be accessed by their indices, but have no relationships with other nodes in the tree.
|
|
882
|
+
* Returns an object with {tree: the new tree with nodes,node: An array of the new nodes}
|
|
883
|
+
* @param n - number of nodes to add default 1
|
|
884
|
+
*/
|
|
885
|
+
addNodes(n?: number): {
|
|
886
|
+
tree: Tree;
|
|
887
|
+
nodes: NodeRef[];
|
|
888
|
+
};
|
|
889
|
+
/**
|
|
890
|
+
* Delete a node from a tree.
|
|
891
|
+
* It is not possible to delete the root node.
|
|
892
|
+
* @param n - NodeRef
|
|
893
|
+
*/
|
|
894
|
+
deleteNode(n: NodeRef): Tree;
|
|
895
|
+
/**
|
|
896
|
+
* Remove a child node from a parent node's descendants
|
|
897
|
+
* @param parent - The node whose child will be removed
|
|
898
|
+
* @param child - The child that is removed from the parent.
|
|
899
|
+
*/
|
|
900
|
+
removeChild(parent: NodeRef, child: NodeRef): Tree;
|
|
901
|
+
/**
|
|
902
|
+
* Get the next sibling.
|
|
903
|
+
* This will wrap back to the first sibling if the provided node is the last sibling.
|
|
904
|
+
* @param node - NodeRef
|
|
905
|
+
*/
|
|
906
|
+
getNextSibling(node: NodeRef): NodeRef;
|
|
907
|
+
/**
|
|
908
|
+
* A checker function to determine if a node has a right sibling
|
|
909
|
+
* @param node - NodeRef
|
|
910
|
+
*/
|
|
911
|
+
hasRightSibling(node: NodeRef): boolean;
|
|
912
|
+
/**
|
|
913
|
+
* Return a node's right sibling (if it has one) or error.
|
|
914
|
+
* @param node
|
|
915
|
+
*/
|
|
916
|
+
getRightSibling(node: NodeRef): NodeRef;
|
|
917
|
+
/**
|
|
918
|
+
* Check if a node has a left sibling
|
|
919
|
+
* @param node
|
|
920
|
+
*/
|
|
921
|
+
hasLeftSibling(node: NodeRef): boolean;
|
|
922
|
+
/**
|
|
923
|
+
* Return a node's left sibling (if it has one) or throw an error.
|
|
924
|
+
* @param node
|
|
925
|
+
*/
|
|
926
|
+
getLeftSibling(node: NodeRef): NodeRef;
|
|
927
|
+
/**
|
|
928
|
+
* Set the distance between a node and the node furthest from the root.
|
|
929
|
+
* @param node
|
|
930
|
+
* @param height number - the new node height
|
|
931
|
+
*/
|
|
932
|
+
setHeight(node: NodeRef, height: number): Tree;
|
|
933
|
+
/**
|
|
934
|
+
* Set the distance between a node and the root node.
|
|
935
|
+
* @param node
|
|
936
|
+
* @param divergence number - new divergence
|
|
937
|
+
*/
|
|
938
|
+
setDivergence(node: NodeRef, divergence: number): Tree;
|
|
939
|
+
/**
|
|
940
|
+
* Set the length of the branch subtending a node
|
|
941
|
+
* @param node NodeRef
|
|
942
|
+
* @param length - number - the new length
|
|
943
|
+
*/
|
|
944
|
+
setLength(node: NodeRef, length: number): Tree;
|
|
945
|
+
/**
|
|
946
|
+
* Assign a taxon to a node.
|
|
947
|
+
* @param node NodRef
|
|
948
|
+
* @param taxon Taxon
|
|
949
|
+
*/
|
|
950
|
+
setTaxon(node: NodeRef, taxon: Taxon): Tree;
|
|
951
|
+
/**
|
|
952
|
+
* Set the label on a node.
|
|
953
|
+
* @param node Noderf
|
|
954
|
+
* @param label string
|
|
955
|
+
*/
|
|
956
|
+
setLabel(node: NodeRef, label: string): Tree;
|
|
957
|
+
/**
|
|
958
|
+
* Add a child to a node.
|
|
959
|
+
* @param parent the parent that gets a new child
|
|
960
|
+
* @param child The child added to a parent
|
|
961
|
+
*/
|
|
962
|
+
addChild(parent: NodeRef, child: NodeRef): Tree;
|
|
963
|
+
/**
|
|
964
|
+
*
|
|
965
|
+
* @param node - An optional node start writing from. If not provided the whole tree will be written.
|
|
966
|
+
* @param options { includeAnnotations: boolean } - include annotations in newick string
|
|
967
|
+
*/
|
|
968
|
+
toNewick(node?: NodeRef, options?: {
|
|
969
|
+
includeAnnotations: boolean;
|
|
970
|
+
}): string;
|
|
971
|
+
/**
|
|
972
|
+
* Sort children arrays by the number of offspring.
|
|
973
|
+
* @param down Boolean to sort down or up.
|
|
974
|
+
*/
|
|
975
|
+
orderNodesByDensity(down: boolean): Tree;
|
|
976
|
+
/**
|
|
977
|
+
*
|
|
978
|
+
* @param node Node whose children will be sorted
|
|
979
|
+
* @param compare - A function which compares two nodes. Will be used as in an array sort
|
|
980
|
+
*/
|
|
981
|
+
sortChildren(node: NodeRef, compare: (a: NodeRef, b: NodeRef) => number): Tree;
|
|
982
|
+
/**
|
|
983
|
+
* Get the most recent common ancestor of two nodes
|
|
984
|
+
* @param node1
|
|
985
|
+
* @param node2
|
|
986
|
+
*/
|
|
987
|
+
getMRCA(node1: NodeRef, node2: NodeRef): NodeRef;
|
|
988
|
+
/**
|
|
989
|
+
* Get the most recent common ancestor of an array of nodes
|
|
990
|
+
* @param nodes
|
|
991
|
+
*/
|
|
992
|
+
getMRCA(nodes: NodeRef[]): NodeRef;
|
|
993
|
+
/**
|
|
994
|
+
* Rotate a node's children
|
|
995
|
+
* @param node
|
|
996
|
+
* @param recursive - rotate the children as well down the tree
|
|
997
|
+
*/
|
|
998
|
+
rotate(node: NodeRef, recursive: boolean): Tree;
|
|
999
|
+
/**
|
|
1000
|
+
* Reroot a tree along a branch subtending a new node.
|
|
1001
|
+
* @param node The root will be inserted along the branch subtending this node
|
|
1002
|
+
* @param proportion - proportion along the branch to place the root.
|
|
1003
|
+
*/
|
|
1004
|
+
reroot(node: NodeRef, proportion: number): Tree;
|
|
1005
|
+
}
|
|
1006
|
+
|
|
1007
|
+
export declare type TreeListener = (tree: Tree, node: NodeRef) => void;
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* An interface for tree traversals
|
|
1011
|
+
*/
|
|
1012
|
+
declare interface TreeTraversal {
|
|
1013
|
+
getNext(tree: Tree, node: NodeRef): NodeRef | undefined;
|
|
1014
|
+
getPrevious(tree: Tree, node: NodeRef): NodeRef | undefined;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
export declare type ValueOf<T extends BaseAnnotationType> = T extends BaseAnnotationType.DISCRETE ? string : T extends BaseAnnotationType.BOOLEAN ? boolean : T extends BaseAnnotationType.NUMERICAL ? number : T extends BaseAnnotationType.NUMERICAL_SET ? number[] : T extends BaseAnnotationType.DISCRETE_SET ? string[] : T extends BaseAnnotationType.MARKOV_JUMPS ? MarkovJumpValue[] : T extends BaseAnnotationType.DENSITIES ? Record<string, number> : never;
|
|
1018
|
+
|
|
1019
|
+
export { }
|