R—计算系统发育多样性PD (Calculate Faith’s Phylogenetic Diversity)

R计算 PD Calculate Faith’s Phylogenetic Diversity


网址: https://cran.r-project.org/web/packages/picante/index.html

Description: Calculate the sum of the total phylogenetic branch length for one or multiple samples.

Usage: pd(samp, tree, include.root=TRUE)

Arguments

samp: Community data matrix

tree:A phylo tree object

include.root: Should the root node be included in all PD calculations (default = TRUE)


#加载包

library(picante)

library(ape)

#测试数据

data(phylocom)

pd(phylocom$sample, phylocom$phylo)


1. 读取树文件:

tree= read.tree("D:/xxxxx.tre")

2. 读取sample数据矩阵

b = read.csv("D:/xxxxxxxx.csv", header = T, row.names=1)

b文件格式


#纵坐标代表的是每个物种,横坐标代表每个群落或者区域包括的物种组成。   Pen1中有Arre-elat,Brom_tect,其他pen2等同理

0代表这个物种(列名)在这个居群中不存在;数字代表一个程度、频率等数值,代表物种在某个区域出现的程度

3. 计算pd

c = pd(b, tree, include.root=TRUE)

4. 导出计算结果

write.csv(c,file = "D:/xxxxx.csv")   


报错:修改树命令:

If youwant the root ofyour tree to correspond to the most recent ancestor of the taxaactually present in your sample, you should prune the tree before running pd:

prunedTree<-prune.sample(b,tree)


参考资料:

https://daijiang.name/en/2014/05/04/notes-func-phylo-book-1/

你可能感兴趣的:(R—计算系统发育多样性PD (Calculate Faith’s Phylogenetic Diversity))