## Documentation Center |

Reorder leaves of phylogenetic tree

* Tree1Reordered* = reorder(

[

[

, Tree1Tree2 | Phytree objects. |

Order | Vector with position indices for each leaf. |

ApproximateValue | Controls the use of the optimal leaf-ordering
calculation to find the closest order possible to the suggested one
without dividing the clades or producing crossing branches. Enter true to
use the calculation. Default is false. |

Tree1Reordered | Phytree object with reordered leaves. |

OptimalOrder | Vector of position indices for each leaf in ,
determined by the optimal leaf-ordering calculation.Tree1Reordered |

`Tree1Reordered = reorder(Tree1, Order)` reorders
the leaves of the phylogenetic tree

`[Tree1Reordered, OptimalOrder]
= reorder(Tree1, Order,
'Approximate', ApproximateValue)` controls
the use of the optimal leaf-ordering calculation, which finds the
best approximate order closest to the suggested one, without dividing
the clades or producing crossing branches. Enter

`[Tree1Reordered, OptimalOrder]
= reorder(Tree1, Tree2)` uses
the optimal leaf-ordering calculation to reorder the leaves in

**Reordering Leaves Using a Valid Order**

Create and view a phylogenetic tree.

b = [1 2; 3 4; 5 6; 7 8; 9 10]; tree = phytree(b) Phylogenetic tree object with 6 leaves (5 branches) view(tree)

Reorder the leaves on the phylogenetic tree, and then view the reordered tree.

treeReordered = reorder(tree, [5, 6, 3, 4, 1, 2]) view(treeReordered)

**Finding Best Approximate Order When Using an Invalid Order**

Create a phylogenetic tree by reading a Newick-formatted tree file (ASCII text file).

tree = phytreeread('pf00002.tree') Phylogenetic tree object with 33 leaves (32 branches)

Create a row vector of the leaf names in alphabetical order.

[dummy,order] = sort(get(tree,'LeafNames'));

Reorder the phylogenetic tree to match as closely as possible the row vector of alphabetically ordered leaf names, without dividing the clades or having crossing branches.

treeReordered = reorder(tree,order,'approximate',true) Phylogenetic tree object with 33 leaves (32 branches)

View the original and the reordered phylogenetic trees.

view(tree) view(treeReordered)

**Reordering Leaves to Match Leaf Order in Another Phylogenetic
Tree**

Create a phylogenetic tree by reading sequence data from a FASTA file, calculating the pairwise distances between sequences, and then using the neighbor-joining method.

seqs = fastaread('pf00002.fa') seqs = 33x1 struct array with fields: Header Sequence dist = seqpdist(seqs,'method','jukes-cantor','indels','pair'); NJtree = seqneighjoin(dist,'equivar',seqs) Phylogenetic tree object with 33 leaves (32 branches)

Create another phylogenetic tree from the same sequence data and pairwise distances between sequences, using the single linkage method.

HCtree = seqlinkage(dist,'single',seqs) Phylogenetic tree object with 33 leaves (32 branches)

Use the optimal leaf-ordering calculation to reorder the leaves in

`HCtree`such that it matches the order of leaves in`NJtree`as closely as possible, without dividing the clades or having crossing branches.HCtree_reordered = reorder(HCtree,NJtree) Phylogenetic tree object with 33 leaves (32 branches)

View the reordered phylogenetic tree and the tree used to reorder it.

view(HCtree_reordered) view(NJtree)

Was this topic helpful?