subs.tree: Substitute a taxon of a given phylogenetic tree by another...

View source: R/subs_tree.R

subs.treeR Documentation

Substitute a taxon of a given phylogenetic tree by another tree

Description

The goal of this function is to enhance manipualtion between trees, especially for constructing composite trees, by allowing one to substitute a taxon (tip or subtree) of a tree by another tree.

Usage

subs.tree(back.tree,fore.tree,where,drop.where=TRUE,poly.where=FALSE,stem.edge.length=NULL,node.age=NULL)

Arguments

back.tree

The tree on which a taxon is substituted by another tree, named "background" tree because it is the general support/scaffold/backbone.

fore.tree

The tree to put in the "background" tree, named "foreground" tree because it is the one to put on the other tree.

where

The taxon of back.tree one wants to replace by the fore.tree. It can be the number or the name of the taxon (tip or node), but it can also be a vector of some tips (allowing for specifying a node without having to search for it and without having to quote every of its descendants).

drop.where

Optional. The user can discard the given taxon where to put the fore.tree (default condition, set to TRUE), or it can keep it if the user wants to place the fore.tree on the edge leading to that taxon (if set to FALSE).

poly.where

Optional. The user can chose whether the fore.tree has to be on a distinct edge (default condition, set to FALSE) or if it has to be in a polytomy with the specified taxon if the taxon is a node (if set to TRUE).

stem.edge.length

Optional. The length of the edge leading to the fore.tree in the new tree. Complementary with the node.age parameter; please do not specify both.

node.age

Optional. The age of the 'root' node of the fore.tree is the new tree. Must be lower than the age of the previous node (if not, a warning message with the age of that previous node is displayed). Complementary with the stem.edge.length parameter; please do not specify both.

Details

This function replaces a taxon of a given "background" tree, be it a single tip or a node (i.e., part of the tree), by another "foreground" tree. The age of the node of the "foreground" tree is not necessarily the same than the age of the taxon to replace in the "background" tree; there are therefore options allowing for specifying its age.

Value

A tree of class phylo with both the back.tree and the fore.tree merged together.

Examples

require(ape)
back.tree<-read.tree(text="((((A:1,B:2):0.5,(C:3,(D:4,E:1):2):5):1,(F:3,(G:2.5,(H:2.5,(I:1.5,J:1):1):1):2):1):4,K:10);")
plot(back.tree)
nodelabels()

fore.tree<-read.tree(text="((x:0.5,y:1.5):5,z:11);")
plot(fore.tree)

where<-c("C","E")

plot(subs.tree(back.tree,fore.tree,where,node.age=8))
plot(subs.tree(back.tree,fore.tree,where,stem.edge.length=0.1))
plot(subs.tree(back.tree,fore.tree,where))


jacobmaugoust/ULT documentation built on May 16, 2023, 1:29 p.m.