Learn R Programming

iCAMP (version 1.8.6)

NTI.cm.big: Calculate nearest taxon index (NTI) under multiple metacommunities for big data

Description

Calculate nearest taxon index (NTI) of each sample with parallel computing, for big dataset. This function can deal with local communities under different metacommunities (regional pools).

Usage

NTI.cm.big(comm, pd.desc, pd.spname, pd.wd,
           meta.group = NULL, meta.spool = NULL,
           nworker = 4, memo.size.GB = 50,
           weighted = c(TRUE, FALSE), rand = 1000,
           check.name = TRUE, output.MNTD = c(FALSE, TRUE),
           sig.index = c("SES", "NTI", "Confidence", "RC", "all"),
           silent = FALSE)

Value

If output.MNTD is FALSE, output is a one-column matrix where rownames are sample IDs and the only column shows NTI values. If output.MNTD is TRUE, output is a list of three elements.

NTI

matrix, NTI values.

MNTD

matrix, observed MNTD.

MNTD.rand

array, null MNTD values, the third dimension represent randomization times.

Arguments

comm

community data matrix. rownames are sample names. colnames are species names.

pd.desc

character, the name to describe bigmemory file of phylogenetic distance matrix, default is "pd.desc".

pd.spname

vector, the OTU ids (species names) in exactly the same order as the phylogenetic matrix rows or columns

pd.wd

the path of the folder saving the phylogenetic distance matrix.

meta.group

matrix or data.frame, a one-column (n x 1) matrix indicating which metacommunity each sample belongs to. rownames are sample IDs. first column is metacommunity names. Such that different samples can belong to different metacommunities. If input a n x m matrix, only the first column is used. NULL means all samples belong to the same metacommunity. Default is NULL, means all samples from the same metacommunity.

meta.spool

a list object, each element is a character vector listing all taxa IDs in a metacommunity. The names of the elements indicate metacommunity names, which should be the same as the metacommunity names in meta.group. Default is NULL, means to use the observed taxa in comm across samples within the same metacommunity that is defined by meta.group.

nworker

for parallel computing. Either a character vector of host names on which to run the worker copies of R, or a positive integer (in which case that number of copies is run on localhost). default is 4, means 4 threads will be run.

memo.size.GB

numeric, to set the memory size as you need, so that calculation of large tree will not be limited by physical memory. unit is Gb. default is 50Gb.

weighted

Logic, consider abundances or not (just presence/absence). default is TRUE.

check.name

Logic, whether to check the species names in comm and dis. default is TRUE.

rand

integer, randomization times. default is 1000.

output.MNTD

Logic, whether to output observed MNTD, so that you do not need to calculate observed MNTD alone. default is FALSE.

sig.index

character, the index for null model significance test. SES or NTI, standard effect size, i.e. nearest taxon index (NTI); Confidence, percentage of null values less extreme than the observed value, i.e. non-parametric one-side confidence level; RC, modified Raup-Crick index (RC) based on MNTD, i.e. count the number of null MNTD lower than observed MNTD plus a half of the number of null MNTD equal to observed MNTD, to get alpha, then calculate MNTD-based RC as (2 x alpha - 1); all, output all the three indexes. default is SES. If input a vector, only the first element will be used.

silent

Logic, if FALSE, some messages will be showed during calculation. Default is FALSE.

Author

Daliang Ning

Details

This function is particularly designed for samples from different metacommunities. The null model "taxa shuffle" will be done under different metacommunities, separately (and independently). Bigmemory is used to deal with big data matrix. All other details are the same as the function NTI.p.

References

Webb CO, Ackerly DD, and Kembel SW. 2008. Phylocom: software for the analysis of phylogenetic community structure and trait evolution. Bioinformatics 18:2098-2100

Kembel, S.W. (2009). Disentangling niche and neutral influences on community assembly: assessing the performance of community phylogenetic structure tests. Ecol Lett, 12, 949-960.

Chase, J.M., Kraft, N.J.B., Smith, K.G., Vellend, M. & Inouye, B.D. (2011). Using null models to disentangle variation in community dissimilarity from variation in alpha-diversity. Ecosphere, 2, 1-11.

Ning, D., Yuan, M., Wu, L., Zhang, Y., Guo, X., Zhou, X. et al. (2020). A quantitative framework reveals ecological drivers of grassland microbial community assembly in response to warming. Nature Communications, 11, 4717.

See Also

NTI.p, NTI.cm

Examples

Run this code
data("example.data")
comm=example.data$comm
pd=example.data$pd
tree=example.data$tree

# in this example, 10 samples from one metacommunity,
# the other 10 samples from another metacommunity.
meta.group=data.frame(meta.com=c(rep("meta1",10),rep("meta2",10)))
rownames(meta.group)=rownames(comm)

# since it needs to save some file to a certain folder,
# the following code is set as 'not test'.
# but you may test the code on your computer
# after change the folder path for 'save.wd'.
# \donttest{
wd0=getwd()
save.wd=paste0(tempdir(),"/pdbig.nticm.big")
nworker=2 # parallel computing thread number.
pd.big=pdist.big(tree = tree, wd=save.wd, nworker = nworker)
rand.time=20 # usually use 1000 for real data.
sigmntd=NTI.cm.big(comm=comm, pd.desc = pd.big$pd.file,
               pd.spname = pd.big$tip.label, pd.wd = pd.big$pd.wd,
               meta.group=meta.group, nworker=nworker,
               weighted=TRUE, rand=rand.time,
               sig.index="all")
NTI=sigmntd$SES
CMNTD=sigmntd$Confidence
RCMNTD=sigmntd$RC
# }

Run the code above in your browser using DataLab