R计算 PD Calculate Faith’s Phylogenetic Diversity
网址: cran.r-project.org/web/package…
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(phylocomphylo)
-
读取树文件: tree= read.tree("D:/timberproject2021/sp_tree20210707.tre")
-
读取samp数据矩阵 b = read.csv("D:/timberproject2021/GridsID-species2.csv", header = T, row.names=1)
-
计算pd c = pd(b, tree, include.root=TRUE)
-
导出计算结果 write.csv(c,file = "D:/aaa.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)
参考资料: