@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.d.ts CHANGED
@@ -9,6 +9,9 @@ export declare type AbstractAnnotation<T extends BaseAnnotationType> = {
9
9
  value: ValueOf<T>;
10
10
  };
11
11
 
12
+ /**
13
+ * The type of summary information that can be provided by a tree.
14
+ */
12
15
  export declare interface AbstractAnnotationSummary<T extends BaseAnnotationType> {
13
16
  id: string;
14
17
  type: T;
@@ -19,6 +22,9 @@ export declare type Annotation = {
19
22
  [K in BaseAnnotationType]: AbstractAnnotation<K>;
20
23
  }[BaseAnnotationType];
21
24
 
25
+ /**
26
+ * unions across all types of annotations.
27
+ */
22
28
  export declare type AnnotationDomain = {
23
29
  [K in BaseAnnotationType]: DomainOf<K>;
24
30
  }[BaseAnnotationType];
@@ -31,35 +37,6 @@ export declare type AnnotationValue = {
31
37
  [K in BaseAnnotationType]: ValueOf<K>;
32
38
  }[BaseAnnotationType];
33
39
 
34
- export declare interface ArbitraryVertex {
35
- hidden: boolean;
36
- labelHidden: boolean;
37
- number: number;
38
- x: number;
39
- y: number;
40
- level: number;
41
- theta?: number;
42
- pathPoints: {
43
- x: number;
44
- y: number;
45
- }[];
46
- nodeLabel: {
47
- dx: number;
48
- dy: number;
49
- alignmentBaseline: string;
50
- textAnchor: string;
51
- rotation?: number;
52
- };
53
- }
54
-
55
- export declare interface ArbitraryVertices {
56
- vertices: ArbitraryVertex[];
57
- extent: {
58
- x: [number, number];
59
- y: [number, number];
60
- };
61
- }
62
-
63
40
  /** Attribute as they are passed internally to possibly animated svg elements */
64
41
  declare type Attrs = Record<string, number | string>;
65
42
 
@@ -107,6 +84,10 @@ declare type AxisTicksOptions = {
107
84
  values?: number[];
108
85
  };
109
86
 
87
+ /**
88
+ * Types of annotations that can exist on nodes in a tree.
89
+ * Each type corresponds to a value type.
90
+ */
110
91
  export declare enum BaseAnnotationType {
111
92
  DISCRETE = "DISCRETE",// string could also be stringy numbers
112
93
  BOOLEAN = "BOOLEAN",// true false
@@ -175,11 +156,6 @@ declare type CartoonAttrs = ExposedAttrs<PathAttrs>;
175
156
 
176
157
  export declare function CartoonClades(options: CartoonOptions): InternalCladeOptions;
177
158
 
178
- export declare interface CartoonData {
179
- cartooned: boolean;
180
- collapseFactor: number;
181
- }
182
-
183
159
  export declare type CartoonOptions = BaseBaubleOptions<CartoonAttrs>;
184
160
 
185
161
  declare type CircleAttrs = Omit<BaseCircleDOMProps, "cx" | "cy"> & {
@@ -233,6 +209,10 @@ export declare const defaultInternalLayoutOptions: {
233
209
  minRadius: number;
234
210
  };
235
211
 
212
+ /**
213
+ * A helper type function that returns the domain of an annotation based on the
214
+ * type of an annotation.
215
+ */
236
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;
237
217
 
238
218
  declare type ExposedAttrs<A> = {
@@ -426,11 +406,6 @@ export declare type InternalLabelOptions = LabelOptions & ({
426
406
  target: BaubleTarget.BranchLabel;
427
407
  });
428
408
 
429
- export declare interface internalLayoutOptions extends layoutOptions {
430
- width?: number;
431
- height?: number;
432
- }
433
-
434
409
  export declare type InternalNodeOptions = ((CircleNodeOptions & {
435
410
  shape: NodeShapes.Circle;
436
411
  }) | (RectangleNodeOptions & {
@@ -439,18 +414,6 @@ export declare type InternalNodeOptions = ((CircleNodeOptions & {
439
414
  target: BaubleTarget.Node;
440
415
  };
441
416
 
442
- export declare interface Label {
443
- x: number;
444
- y: number;
445
- alignmentBaseline: string;
446
- textAnchor: string;
447
- rotation: number;
448
- alignedPos?: {
449
- x: number;
450
- y: number;
451
- };
452
- }
453
-
454
417
  declare type LabelAttrs = ExposedAttrs<LabelSpecificTextAttrs>;
455
418
 
456
419
  declare type LabelOptions = BaseBaubleOptions<LabelAttrs> & ExposedAttrs<{
@@ -509,6 +472,14 @@ declare enum MaybeType {
509
472
  Nothing = "nothing"
510
473
  }
511
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
+ */
512
483
  export declare interface newickParsingOptions {
513
484
  dateFormat?: string;
514
485
  datePrefix?: string;
@@ -518,6 +489,10 @@ export declare interface newickParsingOptions {
518
489
  taxonSet?: TaxonSet;
519
490
  }
520
491
 
492
+ /**
493
+ * A nexus importing class that parses a stream and into an asynchronous
494
+ * iterator over trees.
495
+ */
521
496
  export declare class NexusImporter {
522
497
  reader: ReadableStreamDefaultReader<string>;
523
498
  taxonSet: TaxonSet;
@@ -530,6 +505,10 @@ export declare class NexusImporter {
530
505
  constructor(stream: ReadableStream<BufferSource>, options?: {
531
506
  labelName?: string;
532
507
  });
508
+ /**
509
+ * The main public api.
510
+ * an asynchronous iterator over the trees provided by the stream
511
+ */
533
512
  getTrees(): AsyncIterableIterator<ImmutableTree>;
534
513
  private parseNextBlock;
535
514
  private nextToken;
@@ -574,6 +553,10 @@ declare type nodeOption = {
574
553
  nodes: NodeRef[];
575
554
  };
576
555
 
556
+ /**
557
+ * The base interface for a node.
558
+ * Information about the node will be provided by the tree.
559
+ */
577
560
  export declare interface NodeRef {
578
561
  number: number;
579
562
  _id: string;
@@ -605,6 +588,10 @@ export declare function postOrderIterator(tree: Tree, node?: NodeRef | undefined
605
588
 
606
589
  export declare function preOrderIterator(tree: Tree, node?: NodeRef | undefined): Generator<NodeRef>;
607
590
 
591
+ /**
592
+ * A class for a cached pre-order traversal.
593
+ * This needs to be revisited before it can be used.
594
+ */
608
595
  export declare class PreOrderTraversalCache implements TreeTraversal {
609
596
  _forwardCache: Map<NodeRef, NodeRef>;
610
597
  _reverseCache: Map<NodeRef, NodeRef>;
@@ -618,185 +605,415 @@ export declare function psuedoRootPostOrderIterator(tree: Tree, node?: NodeRef |
618
605
 
619
606
  export declare function psuedoRootPreOrderIterator(tree: Tree, node?: NodeRef | undefined, sort?: (a: NodeRef, b: NodeRef) => number): Generator<NodeRef>;
620
607
 
621
- export declare function radialLayout(tree: ImmutableTree, options?: {
622
- spread?: number;
623
- }): (node: NodeRef) => FunctionalVertex;
624
-
625
- export declare type RawAnnotationValue = {
626
- [K in BaseAnnotationType]: RawValueOf<K>;
627
- }[BaseAnnotationType];
628
-
629
- 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;
630
-
631
- declare type RectangleNodeAttrs = ExposedAttrs<RectAttrs>;
632
-
633
- export declare type RectangleNodeOptions = BaseBaubleOptions<RectangleNodeAttrs>;
634
-
635
- export declare function RectangleNodes(options: RectangleNodeOptions): InternalNodeOptions;
636
-
637
- export declare const rectangularLayout: (tree: ImmutableTree) => (node: NodeRef) => FunctionalVertex;
638
-
639
- declare type RectAttrs = BaseRectangleDOMProps & {
640
- width: number;
641
- height: number;
642
- };
643
-
644
- export declare interface simplePolarVertex extends simpleVertex {
645
- theta: number;
646
- r: number;
647
- }
648
-
649
- export declare interface simpleVertex {
650
- x: number;
651
- y: number;
652
- }
653
-
654
- declare type Some<T> = {
655
- type: typeof MaybeType.Some;
656
- value: T;
657
- };
658
-
659
- declare const Some: <T>(value: T) => Some<T>;
660
-
661
- export declare interface Taxon {
662
- name: string;
663
- number: number;
664
- annotations: {
665
- [annotation: string]: string | string[] | number | number[];
666
- };
667
- }
668
-
669
- export declare class TaxonSet implements TaxonSetInterface {
670
- _data: TaxonSetData;
671
- constructor(taxonSetData?: TaxonSetData);
672
- lockTaxa(): TaxonSetInterface;
673
- addTaxon(taxonOrName: string | Taxon): this;
674
- getTaxon(id: number): Taxon;
675
- getTaxonByName(name: string): Taxon;
676
- hasTaxon(id: string): boolean;
677
- getTaxonCount(): number;
678
- get isFinalized(): boolean;
679
- }
680
-
681
- export declare interface TaxonSetData {
682
- allNames: string[];
683
- byName: {
684
- [taxon: string]: Taxon;
685
- };
686
- finalized: boolean;
687
- }
688
-
689
- export declare interface TaxonSetInterface {
690
- addTaxon(name: string): TaxonSetInterface;
691
- getTaxon(id: number): Taxon | undefined;
692
- getTaxonByName(name: string): Taxon;
693
- getTaxonCount(): number;
694
- lockTaxa(): TaxonSetInterface;
695
- }
696
-
697
- declare type TextAttrs = BaseTextDOMProps & {
698
- text: string;
699
- };
700
-
701
- export declare function tipIterator(tree: Tree, node?: NodeRef): Generator<NodeRef>;
702
-
703
- export declare interface Tree {
704
- getRoot(): NodeRef;
705
- isRooted(): boolean;
706
- getNodeCount(): number;
707
- getInternalNodeCount(): number;
708
- getExternalNodeCount(): number;
709
- getNode(i: string | Taxon | number): NodeRef;
710
- getInternalNodes(): NodeRef[];
711
- getExternalNodes(): NodeRef[];
712
- getNodes(): NodeRef[];
713
- getTaxon(id: number | NodeRef): Taxon;
714
- isExternal(node: NodeRef): boolean;
715
- isInternal(node: NodeRef): boolean;
716
- isRoot(node: NodeRef): boolean;
717
- getChildCount(node: NodeRef): number;
718
- getChild(node: NodeRef, i: number): NodeRef;
719
- getNodeByTaxon(taxon: Taxon): NodeRef;
720
- getNodeByLabel(label: string): NodeRef;
721
- getDivergence(node: NodeRef): number;
722
- getHeight(node: NodeRef): number;
723
- getLength(node: NodeRef): number;
724
- getParent(node: NodeRef): NodeRef;
725
- getChildren(node: NodeRef): NodeRef[];
726
- getAnnotation(node: NodeRef, name: string, d?: AnnotationValue): AnnotationValue;
727
- annotateNode(node: NodeRef, name: string, value: RawAnnotationValue): Tree;
728
- annotateNode(node: NodeRef, annotation: Record<string, RawAnnotationValue>): Tree;
729
- getLabel(node: NodeRef): string;
730
- hasLabel(node: NodeRef): boolean;
731
- getAnnotationKeys(): string[];
732
- getAnnotationType(name: string): BaseAnnotationType;
733
- getAnnotations(): AnnotationSummary[];
734
- getAnnotationSummary(name: string): AnnotationSummary;
735
- addNodes(n?: number): {
736
- tree: Tree;
737
- nodes: NodeRef[];
738
- };
739
- deleteNode(n: NodeRef): Tree;
740
- removeChild(parent: NodeRef, child: NodeRef): Tree;
741
- deleteClade(n: NodeRef): Tree;
742
- getNextSibling(node: NodeRef): NodeRef;
743
- hasRightSibling(node: NodeRef): boolean;
744
- getRightSibling(node: NodeRef): NodeRef;
745
- hasLeftSibling(node: NodeRef): boolean;
746
- getLeftSibling(node: NodeRef): NodeRef;
747
- setHeight(node: NodeRef, height: number): Tree;
748
- setDivergence(node: NodeRef, divergence: number): Tree;
749
- setLength(node: NodeRef, length: number): Tree;
750
- setTaxon(node: NodeRef, taxon: Taxon): Tree;
751
- setLabel(node: NodeRef, label: string): Tree;
752
- addChild(parent: NodeRef, child: NodeRef): Tree;
753
- unroot(node: NodeRef): Tree;
754
- toNewick(node?: NodeRef, options?: {
755
- includeAnnotations: boolean;
756
- }): string;
757
- orderNodesByDensity(down: boolean): Tree;
758
- sortChildren(node: NodeRef, compare: (a: NodeRef, b: NodeRef) => number): Tree;
759
- isRoot(node: NodeRef): boolean;
760
- getMRCA(node1: NodeRef, node2: NodeRef): NodeRef;
761
- getMRCA(nodes: NodeRef[]): NodeRef;
762
- rotate(node: NodeRef, recursive: boolean): Tree;
763
- reroot(node: NodeRef, proportion: number): Tree;
764
- }
765
-
766
- export declare type TreeListener = (tree: Tree, node: NodeRef) => void;
767
-
768
- declare interface TreeTraversal {
769
- getNext(tree: Tree, node: NodeRef): NodeRef | undefined;
770
- getPrevious(tree: Tree, node: NodeRef): NodeRef | undefined;
771
- }
772
-
773
- 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;
774
-
775
- export declare interface Vertex {
776
- number: number;
777
- x: number;
778
- y: number;
779
- hidden: boolean | undefined;
780
- labelHidden: boolean | undefined;
781
- level: number;
782
- branch?: {
783
- d: string;
784
- label: Label;
785
- };
786
- theta?: number;
787
- r?: number;
788
- nodeLabel: Label;
789
- }
790
-
791
- export declare interface Vertices {
792
- type: "Rectangular" | "Polar" | "Radial";
793
- vertices: Vertex[];
794
- origin?: {
795
- x: number;
796
- y: number;
797
- };
798
- theta?: [number, number];
799
- axisLength?: number;
800
- }
801
-
802
- export { }
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 { }