######################################################################### ################Making the presence/absence matrix####################### ######################################################################### #####ITS comITS <- read.csv("input/ITS_Fungi_taxonomy_metadata2.csv") comITS <- comITS[,c(-1,-78)] comITS [comITS > 1] <- 1 comITS <- as.data.frame(comITS) nrow (comITS) #write.csv(comITS , "otu_ITS_presence_absence.csv") ######18S com18S <- read.csv("input/18S_Fungi_taxonomy_metadata.csv") com18S <- com18S[,c(-1,-78)] com18S [com18S > 1] <- 1 com18S <- as.data.frame(com18S) nrow (com18S) #write.csv(com18S , "otu_18S_presence_absence.csv") ######COI comCOI <- read.csv("input/COI_Fungi_taxonomy_metadata.csv") comCOI <- comCOI[,c(-1,-78)] comCOI [comCOI > 1] <- 1 comCOI <- as.data.frame(comCOI) nrow (comCOI) #write.csv(comCOI , "otu_COI_presence_absence.csv") ##########Betadiversity analysis biol <- read.csv("input/meta_soil_data2.csv") head(biol) #####ITS ITS.nmds <- metaMDS(as.matrix(t(Abu_VST_ITS2)), distance="jaccard",k=2, autotransform=F) ITS.nmds <- metaMDS(as.matrix(t(Abu_VST_ITS2)), distance="jaccard",k=2, autotransform=F, previou.best = ITS.nmds) summary(ITS.nmds) scITS <- data.frame(scores(ITS.nmds)) scITS$ID <- rownames(scITS) write.csv(scITS, "ITS_NMDS_metadata.csv") scITS <- scITS %>% as_data_frame()%>% inner_join(biol, by = "ID") #####18S s18S.nmds <- metaMDS(as.matrix(t(Abu_VST_18S2)), distance="jaccard",k=2, autotransform=F) s18S.nmds <- metaMDS(as.matrix(t(Abu_VST_18S2)), distance="jaccard",k=2, autotransform=F, previou.best = s18S.nmds) summary(s18S.nmds) sc18S <- data.frame(scores(s18S.nmds)) sc18S$ID <- rownames(sc18S) write.csv(sc18S, "18S_NMDS_metadata.csv") sc18S <- sc18S %>% as_data_frame()%>% inner_join(biol, by = "ID") #####COI COI.nmds <- metaMDS(as.matrix(t(Abu_VST_COI2)), distance="jaccard",k=2, autotransform=F) COI.nmds <- metaMDS(as.matrix(t(Abu_VST_COI2)), distance="jaccard",k=2, autotransform=F, previou.best = COI.nmds) summary(COI.nmds) scCOI <- data.frame(scores(COI.nmds)) scCOI$ID <- rownames(scCOI) write.csv(scCOI, "COI_NMDS_metadata.csv") scCOI <- scCOI %>% as_data_frame()%>% inner_join(biol, by = "ID") ##envfit ###Eukaryote(ITS) envfit(scITS[,1:2] ~ as.factor(scITS$locality)) envfit(scITS[,1:2] ~ as.factor(scITS$habitat)) envfit(scITS[,1:2] ~ as.factor(scITS$kind)) ###Eukaryote(18S) envfit(sc18S[,1:2] ~ as.factor(sc18S$locality)) envfit(sc18S[,1:2] ~ as.factor(sc18S$habitat)) envfit(sc18S[,1:2] ~ as.factor(sc18S$kind)) ###Eukaryote(COI) envfit(scCOI[,1:2] ~ as.factor(scCOI$locality)) envfit(scCOI[,1:2] ~ as.factor(scCOI$habitat)) envfit(scCOI[,1:2] ~ as.factor(scCOI$kind)) cols1 <- c("#fddbc7", "#5e3c99", "#e66101", "#a6dba0") cols2 <- c("#ca0020", "#dfc27d", "#92c5de", "#0571b0") #subfigure A figA <- scITS %>% ggplot()+ geom_point(aes(x = NMDS1, y = NMDS2, colour = habitat, shape = kind), size = 5)+ ggtitle("A - ITS Habitat")+ xlab("")+ ylab("")+ scale_fill_discrete(name = "Environmental\ntype")+ scale_color_manual(values=cols1)+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black"), panel.border = element_rect(colour = "black", fill=NA, size=1), legend.position = ("left")) #subfigure B figB <- scITS %>% ggplot()+ geom_point(aes(x = NMDS1, y = NMDS2, colour = locality, shape = kind), size = 5)+ ggtitle("B - ITS Locality")+ xlab("")+ ylab("")+ scale_fill_discrete(name = "Environmental\ntype")+ scale_shape_manual(values=c(16:17))+ scale_color_manual(values=cols2)+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black"), panel.border = element_rect(colour = "black", fill=NA, size=1), legend.position = ("left")) #subfigure C figC <- sc18S %>% ggplot()+ geom_point(aes(x = NMDS1, y = NMDS2, colour = habitat, shape = kind), size = 5)+ ggtitle("C - 18S Habitat")+ xlab("")+ ylab("")+ scale_fill_discrete(name = "Environmental\ntype")+ scale_color_manual(values=cols1)+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black"), panel.border = element_rect(colour = "black", fill=NA, size=1), legend.position = ("left")) #subfigure D figD <- sc18S %>% ggplot()+ geom_point(aes(x = NMDS1, y = NMDS2, colour = locality, shape = kind), size = 5)+ ggtitle("D - 18S Locality")+ xlab("")+ ylab("")+ scale_fill_discrete(name = "Environmental\ntype")+ scale_shape_manual(values=c(16:17))+ scale_color_manual(values=cols2)+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black"), panel.border = element_rect(colour = "black", fill=NA, size=1), legend.position = ("left")) #subfigure E figE <- scCOI %>% ggplot()+ geom_point(aes(x = NMDS1, y = NMDS2, colour = habitat, shape = kind), size = 5)+ ggtitle("E - COI Habitat")+ xlab("")+ ylab("")+ scale_fill_discrete(name = "Environmental\ntype")+ scale_color_manual(values=cols1)+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black"), panel.border = element_rect(colour = "black", fill=NA, size=1), legend.position = ("left")) #subfigure F figF <- scCOI %>% ggplot()+ geom_point(aes(x = NMDS1, y = NMDS2, colour = locality, shape = kind), size = 5)+ ggtitle("F - COI Locality")+ xlab("")+ ylab("")+ scale_fill_discrete(name = "Environmental\ntype")+ scale_shape_manual(values=c(16:17))+ scale_color_manual(values=cols2)+ theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(), panel.background = element_blank(), axis.line = element_line(colour = "black"), panel.border = element_rect(colour = "black", fill=NA, size=1), legend.position = ("left")) fig2 <- gridExtra::grid.arrange(figA,figB,figC,figD,figE,figF,bottom = "NMDS1", left = "NMDS2") ggsave("output/Fig_NMDS_Habitat_and_Locality.pdf", plot = fig2, width =10, height = 12) ######################################################### ###################PERMANOVA############################# ######################################################### ###ITS tcomITS <- t(Abu_VST_ITS2) tcomITS <- as.data.frame (tcomITS) adoITS <- adonis2(tcomITS ~ biol$habitat + biol$locality+ biol$kind + soil_phy_che_st$pH + soil_phy_che_st$C + Chemical.pc1 + Physical.PC1, strata = biol$ID, data = tcomITS, type = 'Jaccard', binary = TRUE) adoITS ###Posthoc test multiple categorical variables #install.packages('devtools') library(devtools) #install_github("pmartinezarbizu/pairwiseAdonis/pairwiseAdonis") library(pairwiseAdonis) pair.mod.hab<-pairwise.adonis(tcomITS,factors=biol$habitat) pair.mod.loc<-pairwise.adonis(tcomITS,factors=biol$locality) pair.mod.kin<-pairwise.adonis(tcomITS,factors=biol$kind) adoITS2 <- adonis(tcomITS ~ biol$habitat + biol$locality+ biol$kind + soil_phy_che_st$pH + soil_phy_che_st$C + Chemical.pc1 + Physical.PC1, strata = biol$ID, data = tcomITS, type = 'Jaccard', binary = TRUE) adoITS2 ###18S tcom18S <- t(Abu_VST_18S2) tcom18S <- as.data.frame (tcom18S) ado18S <- adonis2(tcom18S ~ biol$habitat + biol$locality+ biol$kind + soil_phy_che_st$pH + soil_phy_che_st$C + Chemical.pc1 + Physical.PC1, strata = biol$ID, data = tcom18S, type = 'Jaccard', binary = TRUE) ado18S pair.mod.hab18s<-pairwise.adonis(tcom18S,factors=biol$habitat) pair.mod.loc18s<-pairwise.adonis(tcom18S,factors=biol$locality) pair.mod.kin18<-pairwise.adonis(tcom18S,factors=biol$kind) ado18S2 <- adonis(tcom18S ~ biol$habitat + biol$locality+ biol$kind + soil_phy_che_st$pH + soil_phy_che_st$C + Chemical.pc1 + Physical.PC1, strata = biol$ID, data = tcom18S, type = 'Jaccard', binary = TRUE) ado18S2 ###COI tcomCOI <- t(Abu_VST_COI2) tcomCOI <- as.data.frame (tcomCOI) adoCOI <- adonis2(tcomCOI ~ biol$habitat + biol$locality+ biol$kind + soil_phy_che_st$pH + soil_phy_che_st$C + Chemical.pc1 + Physical.PC1, strata = biol$ID, data = tcomCOI, type = 'Jaccard', binary = TRUE) adoCOI pair.mod.habcoi<-pairwise.adonis(tcomCOI,factors=biol$habitat) pair.mod.loccoi<-pairwise.adonis(tcomCOI,factors=biol$locality) pair.mod.kincoi<-pairwise.adonis(tcomCOI,factors=biol$kind) adoCOI2 <- adonis(tcomCOI ~ biol$habitat + biol$locality+ biol$kind + soil_phy_che_st$pH + soil_phy_che_st$C + Chemical.pc1 + Physical.PC1, strata = biol$ID, data = tcomCOI, type = 'Jaccard', binary = TRUE) adoCOI2 ################################################################ ################## Mantel ######################### ################################################################ ###ITS disITS <- vegdist(as.matrix(t(Abu_VST_ITS2)), method = "jaccard") ###18S dis18S <- vegdist(as.matrix(t(Abu_VST_18S2)), method = "jaccard") ###COI disCOI <- vegdist(as.matrix(t(Abu_VST_COI2)), method = "jaccard") #Correlation between datasets similarity matrices vegan::mantel(disITS, disCOI, method="pearson", permutations=999) vegan::mantel(disITS, dis18S, method="pearson", permutations=999) vegan::mantel(dis18S, disCOI, method="pearson", permutations=999) #################################################### ### Community structure and soil characteristics #### #################################################### # multiple regresioon with dissimilarity matrix #soil metaPCs <- cbind(meta[,1:7], meta[,13:14], Chemical.pc1, Physical.PC1) metaPCs.s <- metaPCs[39:76, ] latlong.s <- cbind(metaPCs.s$long, metaPCs.s$lat) geo.dist.s <- vegdist((latlong.s), method = "euclidean") log.geo.dist.s <- log(geo.dist.s) #litter metaPCs.l <- metaPCs[1:38, ] latlong.l <- cbind(metaPCs.l$long, metaPCs.l$lat) geo.dist.l <- vegdist((latlong.l), method = "euclidean") log.geo.dist.l <- log(geo.dist.l) #18S s18s <- Abu_VST_18S2[,39:76] s18s <-t(s18) s18sjac.dist <- vegdist((s18), method = "jaccard") glm18ss <- MRM(s18sjac.dist ~ geo.dist.s+ dist(pH)+ dist(C)+ dist(Chemical.pc1) + dist(Physical.PC1),data=metaPCs.s, nperm=10000, mrank = T) glm18ss glm18ss2 <- MRM(s18sjac.dist ~ log.geo.dist.s+ dist(pH)+ dist(C)+ dist(Chemical.pc1) + dist(Physical.PC1),data=metaPCs.s, nperm=10000, mrank = T) glm18ss2 s18l <- Abu_VST_18S2[,1:38] s18l <-t(s18l) l18sjac.dist <- vegdist((s18l), method = "jaccard") glm18sl <- MRM(l18sjac.dist ~ geo.dist.l + dist(pH)+ dist(C)+ dist(Chemical.pc1) + dist(Physical.PC1),data=metaPCs.l, nperm=10000, mrank = T) glm18sl glm18sl2 <- MRM(l18sjac.dist ~ log.geo.dist.l + dist(pH)+ dist(C)+ dist(Chemical.pc1) + dist(Physical.PC1),data=metaPCs.l, nperm=10000, mrank = T) glm18sl2 #COI sCOI <- Abu_VST_COI2[,39:76] sCOI <-t(sCOI) sCOIjac.dist <- vegdist((sCOI), method = "jaccard") glmCOIs <- MRM(sCOIjac.dist ~ geo.dist.s+ dist(pH)+ dist(C)+ dist(Chemical.pc1) + dist(Physical.PC1),data=metaPCs.s, nperm=10000, mrank = T) glmCOIs glmCOIs2 <- MRM(sCOIjac.dist ~ log.geo.dist.s+ dist(pH)+ dist(C)+ dist(Chemical.pc1) + dist(Physical.PC1),data=metaPCs.s, nperm=10000, mrank = T) glmCOIs2 COIl <- Abu_VST_COI2[,1:38] COIl <-t(COIl) lCOIjac.dist <- vegdist((COIl), method = "jaccard") glmCOIl <- MRM(lCOIjac.dist ~ geo.dist.l + dist(pH)+ dist(C)+ dist(Chemical.pc1) + dist(Physical.PC1),data=metaPCs.l, nperm=10000, mrank = T) glmCOIl glmCOIl2 <- MRM(lCOIjac.dist ~ log.geo.dist.l + dist(pH)+ dist(C)+ dist(Chemical.pc1) + dist(Physical.PC1),data=metaPCs.l, nperm=10000, mrank = T) glmCOIl2 #ITS sITS <- Abu_VST_ITS2[,39:76] sITS <-t(sITS) sITSjac.dist <- vegdist((sITS), method = "jaccard") glmITSs <- MRM(sITSjac.dist ~ geo.dist.s+ dist(pH)+ dist(C)+ dist(Chemical.pc1) + dist(Physical.PC1),data=metaPCs.s, nperm=10000, mrank = T) glmITSs glmITSs2 <- MRM(sITSjac.dist ~ log.geo.dist.s+ dist(pH)+ dist(C)+ dist(Chemical.pc1) + dist(Physical.PC1),data=metaPCs.s, nperm=10000, mrank = T) glmITSs2 ITSl <- Abu_VST_ITS2[,1:38] ITSl <-t(ITSl) lITSjac.dist <- vegdist((ITSl), method = "jaccard") glmITSl <- MRM(lITSjac.dist ~ geo.dist.l + dist(pH)+ dist(C)+ dist(Chemical.pc1) + dist(Physical.PC1),data=metaPCs.l, nperm=10000, mrank = T) glmITSl glmITSl2 <- MRM(lITSjac.dist ~ log.geo.dist.l + dist(pH)+ dist(C)+ dist(Chemical.pc1) + dist(Physical.PC1),data=metaPCs.l, nperm=10000, mrank = T) glmITSl2