Main Content

reorder

Reorder leaves of phylogenetic tree

Syntax

Tree1Reordered = reorder(Tree1, Order)
[Tree1Reordered, OptimalOrder] = reorder(Tree1, Order, 'Approximate', ApproximateValue)
[Tree1Reordered, OptimalOrder] = reorder(Tree1, Tree2)

Input Arguments

Tree1, Tree2Phytree objects.
OrderVector with position indices for each leaf.
ApproximateValueControls 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.

Output Arguments

Tree1ReorderedPhytree object with reordered leaves.
OptimalOrderVector of position indices for each leaf in Tree1Reordered, determined by the optimal leaf-ordering calculation.

Description

Tree1Reordered = reorder(Tree1, Order) reorders the leaves of the phylogenetic tree Tree1, without modifying its structure and distances, creating a new phylogenetic tree, Tree1Reordered. Order is a vector of position indices for each leaf. If Order is invalid, that is, if it divides the clades (or produces crossing branches), then reorder returns an error message.

[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 true to use the calculation and return Tree1Reordered, the reordered tree, and OptimalOrder, a vector of position indices for each leaf in Tree1Reordered, determined by the optimal leaf-ordering calculation. Default is false.

[Tree1Reordered, OptimalOrder] = reorder(Tree1, Tree2) uses the optimal leaf-ordering calculation to reorder the leaves in Tree1 such that it matches the order of leaves in Tree2 as closely as possible, without dividing the clades or producing crossing branches. Tree1Reordered is the reordered tree, and OptimalOrder is a vector of position indices for each leaf in Tree1Reordered, determined by the optimal leaf-ordering calculation

Examples

Example 28. Reordering Leaves Using a Valid Order
  1. 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)
  2. Reorder the leaves on the phylogenetic tree, and then view the reordered tree.

     treeReordered = reorder(tree, [5, 6, 3, 4, 1, 2])
     view(treeReordered)
Example 29. Finding Best Approximate Order When Using an Invalid Order
  1. 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)
  2. Create a row vector of the leaf names in alphabetical order.

    [dummy,order] = sort(get(tree,'LeafNames'));
  3. 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) 
  4. View the original and the reordered phylogenetic trees.

    view(tree)
    view(treeReordered)   
Example 30. Reordering Leaves to Match Leaf Order in Another Phylogenetic Tree
  1. 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)
  2. 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)   
  3. 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)      
  4. View the reordered phylogenetic tree and the tree used to reorder it.

    view(HCtree_reordered)
    view(NJtree)   

Version History

Introduced in R2007a

See Also

| | |