#### Diversity Standardization: Coverage-based and size-based approach #### ## OTU richness(q=0)/Shannon's(q=1)/Simpson's(q=2) index library(iNEXT) Result_coverage=estimateD(otutable, datatype = "abundance", base = "coverage", level = fixed_coverage) Result_size=estimateD(otutable, datatype = "abundance", base = "size", level = fixed_size) ## Phylogenetic diversity library(ape) library(devtools) library(ade4) library(iNextPD) tree=readChar("tree.txt",file.info("tree.txt")$size) phy=newick2phylog(tree) otutable=read.table("otutable.txt",header=T) PD=iNextPD(otutable[,2:ncol(otutable)],otutable[,1],phy, q=0, knots=knots, endpoint=endpoint) # Picking fixed diversity value (coverage-based or size-based) for (i in 1:ncol(otutable)){ for(k in 1:knots){ pd=PD$iNextPDEst[[[i]]$m[k]==Fixed_Coverage/size if(pd==TRUE){ Result[i,1]=PD$iNextPDEst[[i]]$SC[k] #Fixed coverage or size Result[[i,2]=PD$iNextPDEst[[[i]]$m[k] #number of reads of fixed PD Result[[i,3]=PD$iNextPDEst[[[i]]$qPD[k] #PD estimates stop } } } rownames(Result)=names(PD$iNextPDEst) colnames(Result)=c("Coverage/Size","Numb_of_reads","PD") #### GLMM analysis and regression plot #### library(gdata) library(lavaan) library(lme4) library(nlme) library(MASS) R=Data$Season Summer=which(R == "Summer") Spring=which(R == "Spring") par(mfrow = c(3, 2)) par(oma = c(1, 1, 2, 2)) par(mar = c(4, 4, 1, 1)) # Testing Hypothesis I X=Data$C_HNF_Sh Y=Data$HBA_biomass glmm_plot(X,Y,R) mtext('(a)', side = 3, line = 0, at=1, outer = F,cex=1) mtext('Predator diversity', side = 1, outer = F,cex=0.8,line=2.4) mtext('Prey biomass (ngC)', side = 2, outer = F,cex=0.8,line=2.5) X=Data$C_HNF_Sh Y=Data$PPBR_H glmm_plot(X,Y,R) mtext('(b)', side = 3, line = 0, at=1, outer = F,cex=1) mtext('Predator diversity', side = 1, outer = F,cex=0.8,line=2.5) mtext('PPBR', side = 2, outer = F,cex=0.8,line=2.4) #Testing Hypothesis II X=Data$C_HB_Sh Y=Data$HNF_biomass glmm_plot(X,Y,R) mtext('(c)', side = 3, line = 0, at=5, outer = F,cex=1) mtext('Prey diversity', side = 1, outer = F,cex=0.8,line=2.5) mtext('Predator biomass (ngC)', side = 2, outer = F, cex=0.8, line=2.4) X=a$C_NonArchaeaCyano_Sh Y=a$PPBR_H points(X[Spring],Y[Spring],pch=2,lwd = 1.5,cex=1.1) glmm_plot(X,Y,R) mtext('(d)', side = 3, line = 0, at=5, outer = F,cex=1) mtext('Prey diversity', side = 1, outer = F,cex=0.8, line=2.5) mtext('PPBR', side = 2, outer = F, cex=0.8, line=2.4) #testing Hypothesis III X=Data$C_HB_Sh Y=Data$C_HNF_Sh glmm_plot_III(X,Y,R) mtext('(e)', side = 3, line = 0, at=1, outer = F,cex=1) mtext('Prey diversity', side = 1, outer = F,cex=0.8,line=2.5) mtext('Predator diversity', side = 2, outer = F,cex=0.8,line=2.4) ## Function: glmm_plot() glmm_plot=function(X,Y,R){ plot(Y~X,type = "n", log = "y", xlab='',ylab='',las=1) points(X[Summer],Y[Summer],ylab ='',xlab ='',pch=1,lwd = 1.5,cex=1.1, xlim=c(min(X),max(X)),ylim=c(min(Y),max(Y))) points(X[Spring],Y[Spring],pch=2,lwd = 1.5,cex=1.1) PQL=glmmPQL(Y~X, ~1 | R, family = gaussian(link = "log"),verbose = FALSE) t=summary(PQL)[]$tTable[2,5] rp = vector('expression',1) if(t<0.01){ rp[1]=substitute(expression(paste(italic("P")," < 0.01",sep="")))[2] }else{ rp[1]=substitute(expression(italic(P)==MYOTHERVALUE), list(MYOTHERVALUE =format(t, digits = 2)))[2] } legend('topright', legend = rp, bty = 'n',cex=1) if(t<0.0500){ abline(lm(log10(Y)~X),lty=1) } } ## Function: glmm_plot_III() glmm_plot_III=function(X,Y,R){ plot(Y~X,type = "n", log = "y", xlab='',ylab='',las=1) points(X[Summer],Y[Summer],ylab ='',xlab ='',pch=1,lwd = 1.5,cex=1.1, xlim=c(min(X),max(X)),ylim=c(min(Y),max(Y))) points(X[Spring],Y[Spring],pch=2,lwd = 1.5,cex=1.1) PQL=glmmPQL(Y~X, ~1 | R, family = gaussian, verbose = FALSE) t=summary(PQL)[]$tTable[2,5] rp = vector('expression',1) if(t<0.01){ rp[1]=substitute(expression(paste(italic("P")," < 0.01",sep="")))[2] }else{ rp[1]=substitute(expression(italic(P)==MYOTHERVALUE), list(MYOTHERVALUE =format(t, digits = 2)))[2] } legend('topright', legend = rp, bty = 'n',cex=1) if(t<0.0500){ abline(lm(Y~X),lty=1) } } ####PLS_SEM analysis and plot#### PLS=function(Data){ ##Do scalping sa=matrix(0,nrow(Data),ncol(Data)) for (i in 1:ncol(Data)){ sData[,i]=scale(Data[,i]) } colnames(sData)=colnames(Data) rownames(sData)=rownames(Data) ##model setting Tem= c(0,0,0,0,0,0) Nut= c(0,0,0,0,0,0) HBD= c(1,1,0,0,0,0) HNFD= c(1,1,1,0,0,0) HNFB= c(1,1,1,1,0,0) HBB= c(1,1,1,1,1,0) sat.inner = rbind(Tem,Nut,HBD,HNFD,HNFB,HBB) sat_mod=rep("A", 6) sat.outer = list(1,2:4,5,6,7,8) satpls = plspm(sData, sat.inner, sat.outer,scheme="centroid", br=1000,mode=sat_mod) r=satpls$path txt=matrix(0,nrow(r),nrow(r)) for(j in 1:nrow(r)){ for (i in 1:ncol(r)){ if ( abs(r[i,j])>0.26) { txt[i,j]=1 } else if (r[i,j]==0) { txt[i,j]=0 } else txt[i,j]=0.5 } } line.width=matrix(0,nrow(r),nrow(r)) for(j in 1:nrow(r)){ for (i in 1:ncol(r)){ if (abs(r[i,j])>0.26) { line.width[i,j]=2.6 } else if (r[i,j]==0) { line.width[i,j]=0 } else line.width[i,j]=1 } } line.color=matrix(0,nrow(r),nrow(r)) for(j in 1:nrow(r)){ for (i in 1:ncol(r)){ if (abs(r[i,j])>=0.26) { line.color[i,j]="black" } else if (r[i,j]==0) { line.color[i,j]=0 } else line.color[i,j]="grey" } } D=round(satpls$path,digits=2) d=format(D) dd=as.data.frame(d) plotmat(D,arr.type="triangle", arr.length=0.3, shadow.size =0, box.type="ellipse", box.col="grey", box.prop =0.6, box.size=0.08, cex.txt =txt, arr.lcol=line.color, arr.col=line.color, arr.lwd =line.width,curve =0, arr.pos =0.65) t=summary(satpls)$gof rp = vector('expression',1) rp[1]=substitute(expression(italic(gof)==MYOTHERVALUE), list(MYOTHERVALUE =format(t, digits = 3)))[2] legend('bottomright', legend = rp, bty = 'n',cex=0.8) } #### Pearson's correlation coefficient and P-value#### Result=matrix(0, ncol(Data), ncol(Data)) Result_pvalue=matrix(0, ncol(Data), ncol(Data)) for(i in 1:ncol(Data)){ for(j in 1:ncol(a)){ Result[i,j]=cor(as.numeric(Data[,i]),as.numeric(Data[,j]),use= "na.or.complete") Result_pvalue[i,j]=cor.test(as.numeric(Data[,i]),as.numeric(Data[,j]))$p.value } } colnames(Result)=colnames(Data) rownames(Result)=colnames(Data) colnames(Result_pvalue)=colnames(Data) rownames(Result_pvalue)=colnames(Data)