# phytree

Data structure containing phylogenetic tree

## Description

A `phytree` object is a data structure containing a phylogenetic tree. Phylogenetic trees are binary rooted trees, which means that each branch is the parent of two other branches, two leaves, or one branch and one leaf. A `phytree` object can be ultrametric or nonultrametric.

## Creation

### Syntax

``tree = phytree(B)``
``tree = phytree(B,D)``
``tree = phytree(B,C)``
``tree = phytree(BC)``
``tree = phytree(___,N)``
``tree = phytree``

### Description

````tree = phytree(B)` creates an ultrametric phylogenetic tree object. In an ultrametric phylogenetic tree object, all leaves are the same distance from the root.```

example

````tree = phytree(B,D)` creates an additive (ultrametric or nonultrametric) phylogenetic tree object with branch distances defined by `D`.```

example

````tree = phytree(B,C)` creates an ultrametric phylogenetic tree object with distances between branches and leaves defined by `C`.```

example

````tree = phytree(BC)` creates an ultrametric phylogenetic binary tree object with branch pointers in `BC(:,[1 2])` and branch coordinates in `BC(:,3)`. Same as `phytree(B,C)`. ```
````tree = phytree(___,N)` specifies the names for the leaves, the branches, or both. Use this syntax with any of the previous arguments.```
````tree = phytree` creates an empty phylogenetic tree object.```

### Input Arguments

expand all

Branches of the tree, specified as a numeric array of size ```[NUMBRANCHES X 2]```. Each row represents a branch of the tree. It contains two pointers to the branch or leaf nodes, which are its children.

Leaf nodes are numbered from `1` to `NUMLEAVES` and branch nodes are numbered from `NUMLEAVES + 1` to `NUMLEAVES + NUMBRANCHES`. Note that because only binary trees are allowed, ```NUMLEAVES = NUMBRANCHES + 1```.

Branches are defined in chronological order (for example, ```B(i,:) > NUMLEAVES + i```). As a consequence, the first row can only have pointers to leaves, and the last row must represent the root branch. Parent-child distances are set to `1`, unless the child is a leaf and to satisfy the ultrametric condition of the tree its distance is increased.

Data Types: `double`

Distances from every node to their parent branch, specified as a numeric array of size `[NUMNODES X 1]` with the distances of every child node (leaf or branch) to its parent branch equal to ```NUMNODES = NUMLEAVES + NUMBRANCHES```. The last distance in `D` is the distance of the root node and is meaningless.

Data Types: `double`

Distances for every branch to the leaves, specified as a numeric array of size `[NUMBRANCHES X 1]`. In ultrametric trees, all of the leaves are at the same location (same distance to the root).

Data Types: `double`

Pointers to branches or leaves and distances of branches, specified as a combined matrix. The branch pointers are in `BC(:,[1 2])` and branch coordinates are in `BC(:,3)`.

The syntax `phytree(BC)` is the same as `phytree(B,C)`.

Data Types: `double`

Names of leaves and branches, specified as a string vector or cell array of character vectors. If `NUMEL(N)==NUMLEAVES`, then the names are assigned chronologically to the leaves. If `NUMEL(N)==NUMBRANCHES`, the names are assigned to the branch nodes. If ```NUMEL(N)==NUMLEAVES + NUMBRANCHES```, all the nodes are named. Unassigned names default to `'Leaf #'` and/or `'Branch #'` as required.

Data Types: `string` | `cell`

## Properties

expand all

Note

You can access these properties using the `get` method.

Number of leaves, stored as a positive integer.

Number of branches, stored as a positive integer.

Number of nodes (`NumLeaves + NumBranches`), stored as a positive integer.

Branch to leaf or branch connectivity list, stored as a matrix.

Edge length for every leaf or branch, stored as a numeric array of size `[NUMNODES X 1]`. Here, ```NUMNODES = NUMLEAVES + NUMBRANCHES```.

Names of the leaves, stored as a cell array of character vectors.

Names of the branches, stored as a cell array of character vectors.

Names of all the nodes, stored as a cell array of character vectors.

## Object Functions

 `cluster` Validate clusters in phylogenetic tree `get` Retrieve information about phylogenetic tree object `getbyname` Branches and leaves from phytree object `getcanonical` Calculate canonical form of phylogenetic tree `getmatrix` Convert phytree object into relationship matrix `getnewickstr` Create Newick-formatted character vector `pdist` Calculate pairwise patristic distances in phytree object `plot` Draw phylogenetic tree `prune` Remove branch nodes from phylogenetic tree `reorder` Reorder leaves of phylogenetic tree `reroot` Change root of phylogenetic tree `select` Select tree branches and leaves in phytree object `subtree` Extract phylogenetic subtree `view` View phylogenetic tree `weights` Calculate weights for phylogenetic tree

## Examples

collapse all

Create a tree with three leaves and two branches.

```B = [1 2;3 4]; tree = phytree(B)```
``` Phylogenetic tree object with 3 leaves (2 branches) ```
`view(tree)`

Create an additive (ultrametric or nonultrametric) phylogenetic tree object with branch distances specified as a column vector.

```B = [1 2;3 4]; D = [1 2 1.5 1 0]'; tree = phytree(B,D); view(tree)```

Create an ultrametric phylogenetic tree object with distances between branches and leaves defined by a vector.

```B = [1 2;3 4]; C = [1 4]'; tree = phytree(B,C)```
``` Phylogenetic tree object with 3 leaves (2 branches) ```
`view (tree)`

Create a phylogenetic tree from a multiple sequence alignment file.

Read a multiple sequence alignment file.

`Sequences = multialignread('aagag.aln');`

Calculate the distance between each pair of sequences.

`distances = seqpdist(Sequences);`

Construct a phylogenetic tree object from the pairwise distances calculated previously.

`tree = seqlinkage(distances);`

View the phylogenetic tree.

`phytreeviewer(tree)`

## Version History

Introduced in R2006b