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 s a m p l e , p h y l o c o m sample, phylocom sample,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)
参考资料:
https://daijiang.name/en/2014/05/04/notes-func-phylo-book-1/
原文网址:https://www.jianshu.com/p/789a93c2f62a