lightblue_Golm_only = VennList$q11
lOTUs_sc <- c(lightblue_Cologne_only,lightblue_BOTH)
lOTUs_sg <- c(lightblue_Golm_only,lightblue_BOTH)
# rOTUs (Cologne and Golm soils)
darkblue_Cologne_only = VennList$q8
darkblue_BOTH = VennList$q1
darkblue_Golm_only = VennList$q9
rOTUs_sc <- c(darkblue_Cologne_only,darkblue_BOTH)
rOTUs_sg <- c(darkblue_Golm_only, darkblue_BOTH)
### Figure 2f (bargraph per compartment)
#############################################################
Actinocorallia <- "OTU36"
subset_greenhouse <- c(subset_cologne, subset_golm)     # to plot Cologne and Golm soil samples
site = as.vector(pData(eset)[subset_greenhouse,]$Site)  # to group compartments by soil (=site)
# pdf("Figure_2f.pdf")
bargraph.CI(pData(eset)[subset_greenhouse,]$Compartment, group = site, legend = T, exprs(eset)[Actinocorallia,subset_greenhouse], main = "Figure 2f / Actinocorallia per compartments", ylab = "relative abundance (log2)")
# dev.off()
### no LIMMA statistics for the COMPARTMENT effect in both Soils here
### since Actinocorallia is a rOTUs member both in Cologne and Golm soils
### Figure 2g (bargraph per genotypes)
###########################################################
eset_sgh <- eset[,subset_greenhouse]                                # to plot Cologne and Golm soil samples
eset_sgh_root <- eset_sgh[,pData(eset_sgh)$Compartment == "Root"]   # to plot root samples
dig <- as.vector(pData(eset_sgh_root)$Dig)                          # to group by dig
genotype <- as.vector(pData(eset_sgh_root)$Genotype)                # to split by genotype
# pdf("Figure_2g.pdf")
bargraph.CI(genotype, group = dig, legend = T, exprs(eset_sgh_root)[Actinocorallia,], main = "Figure 2g / Actinocorallia per genotypes", ylab = "relative abundance (log2)")
# dev.off()
### LIMMA statistics for the GENOTYPE effect in Cologne Soil (dig corrected)
# define factor genotype, corrected for dig
genotype_sc <- as.vector(paste(design_sc$Compartment, design_sc$Genotype, design_sc$Dig, sep="."))
# model for genotype
model_sc_geno <- model.matrix(~0 + genotype_sc)
colnames(model_sc_geno) <- make.names(colnames(model_sc_geno))
colnames(model_sc_geno)
fit_sc_geno <- lmFit(eset_sc, model_sc_geno)
cont.matrix_sc_geno <- makeContrasts(
Ler_vs_Sha_K2 = genotype_scRoot.Ler.K2 - genotype_scRoot.Sha.K2,
Ler_vs_Sha_K3 = genotype_scRoot.Ler.K3 - genotype_scRoot.Sha.K3,
levels = model_sc_geno)
# Compute estimated coefficients and standard errors for the given contrasts
fit2_sc_geno <- contrasts.fit(fit_sc_geno, cont.matrix_sc_geno)
fit2_sc_geno <- eBayes(fit2_sc_geno)
de_tab_sc_geno <- decideTests(fit2_sc_geno)
# pdf("Figure_2g_Cologne_stats.pdf")
vennDiagram(de_tab_sc_geno, main = "Figure 2g / genotype stats by digs / Cologne")
# dev.off()
rownames(de_tab_sc_geno)[de_tab_sc_geno[,1]==1 & de_tab_sc_geno[,2]==1]
rownames(de_tab_sc_geno)[de_tab_sc_geno[,1]==-1 & de_tab_sc_geno[,2]==-1]
Actinocorallia <- "OTU36"
### LIMMA statistics for the GENOTYPE effect in Golm Soil (dig corrected)
# define factor genotype, corrected for dig
genotype_sg <- as.vector(paste(design_sg$Compartment, design_sg$Genotype, design_sg$Dig, sep="."))
# model for genotype
model_sg_geno <- model.matrix(~0 + genotype_sg)
colnames(model_sg_geno) <- make.names(colnames(model_sg_geno))
colnames(model_sg_geno)
fit_sg_geno <- lmFit(eset_sg, model_sg_geno)
cont.matrix_sg_geno <- makeContrasts(
Ler_vs_Sha_G1 = genotype_sgRoot.Ler.G1 - genotype_sgRoot.Sha.G1,
Ler_vs_Sha_G2 = genotype_sgRoot.Ler.G2 - genotype_sgRoot.Sha.G2,
levels=model_sg_geno)
# Compute estimated coefficients and standard errors for a given set of contrasts
fit2_sg_geno <- contrasts.fit(fit_sg_geno, cont.matrix_sg_geno)
fit2_sg_geno <- eBayes(fit2_sg_geno)
de_tab_sg_geno <- decideTests(fit2_sg_geno)  # no OTU identified
# pdf("Figure_2g_Golm_stats.pdf")
vennDiagram(de_tab_sg_geno, main = "Figure 2g / genotype stats by digs / Golm" )
# dev.off()
#############################################################
#
# Ref to the ARTICLE
#
# Klaus Schlaeppi
# schlaeppi@mpipz.mpg.de
# 22-6-12
# script for datanalysis as presented in Figure 2 and Supplementary Figure 11
# files* needed: "Design_Matrix.txt", "PyroTagger_counts.txt", "OTU_classification_SILVA.txt"
# *are comprised as individual worksheets in the Supplementary Database 1
#
#############################################################
#############################################################
# Libraries and functions required
#############################################################
library("limma")
library("gplots")
library("marray")
library("sciplot")
source("file2Exprs.R")
source("tern_e.R")
source("http://faculty.ucr.edu/~tgirke/Documents/R_BioCond/My_R_Scripts/vennDia.R")
#############################################################
# Data upload and rearrangements
#############################################################
### uploading of "Design_Matrix.txt"
design <- read.delim("Design_matrix.txt", sep = "\t", header=TRUE )
rownames(design) <- design[,1]
dim(design)
design
### uploading of data file "PyroTagger_counts.txt"
dat_raw <- read.table("PyroTagger_counts.txt", row.names=1, sep="\t", header=T, blank.lines.skip = FALSE)
dat_raw[is.na(dat_raw)] = 0   # set NA to zero
dim(dat_raw)
colnames(dat_raw)
sort(colSums(dat_raw), dec=T)
### sample rearrangenemts required due to depletion of Chloroflexi
## (see Supplementary Information, Bulgarelli et al.)
# pooling of samples
R_AtSha19K20K <- dat_raw[,"R_AtSha19K"] + dat_raw[,"R_AtSha20K"]
R_AtLer17G18G <- dat_raw[,"R_AtLer17G"] + dat_raw[,"R_AtLer18G"]
Bulk35G36G <- dat_raw[,"Bulk35G"] + dat_raw[,"Bulk36G"]
dat_raw_2 <- cbind(dat_raw, R_AtSha19K20K, R_AtLer17G18G, Bulk35G36G)
# removing samples with less than 1000 counts after depletion of Chloroflexi
samples_to_remove <- c("R_AtLer20K", "R_AtSha3K", "R_AtSha19K", "R_AtSha20K", "R_AtLer15K",
"R_AtSha13K", "R_AtSha14K", "Bulk1K", "R_AtLer18G", "R_AtLer17G",
"R_AtSha34G", "Bulk7G", "Bulk36G", "Bulk35G", "AtWild3")
finalsamples <- rownames(design)[!rownames(design) %in% samples_to_remove]
## adjusting design matrix and PyroTagger counts to contain  only the final samples
design <- design[finalsamples, ]
dim(design)
dat_raw_2 <- dat_raw_2[ ,finalsamples]
dim(dat_raw_2)
### uploading of SILVA taxonommy
SILVAtax <- read.delim("OTU_classification_SILVA.txt", row.names=1, sep="\t", header=T)
dim(SILVAtax)
SILVAtax[1:10,]
### SUBSETTING the pyrotagger count data matrix and DEPLETION of Chloroflexi-OTUs
# preparation of subsets from design matrix (does not contain the 2 technial replicate samples "Bulk26K" & "Bulk27K")
# note, "Bulk25K" is the third technical replicate
# this subsetting is required, as the pyrotagger counts contains these 2 additional samples of the technical replicates
subset_cologne <- rownames(design)[which(design$Site == "Cologne")]
subset_golm <- rownames(design)[which(design$Site == "Golm")]
subset_naturalsite <- rownames(design)[which(design$Site == "naturalsite")]
# preparation of list with non-Chloroflexi OTUs
noChloro <- rownames(SILVAtax)[which(SILVAtax$Phylum != "Chloroflexi")]
length(noChloro)
noChloro <- noChloro[noChloro %in% rownames(dat_raw_2)]
length(noChloro)
table(SILVAtax[noChloro,2])
## SUBSETTING and DEPLETION
dat_raw_noC <- dat_raw_2[noChloro, c(subset_cologne, subset_golm, subset_naturalsite)]
dim(dat_raw_noC)
dat_raw_noC[1:10,1:5]
sort(colSums(dat_raw_noC), dec=T) # all samples have at least 1000 counts
#############################################################
# Data transformation and thresholding
#############################################################
# normalization by sample size and transformation in "/1000"
dat_norm <- t(t(dat_raw_noC)/colSums(dat_raw_noC)) * 1000
# application of threshold for lower presence limit of relative abundance
threshold <- 5    # 0.5% presence: use integer 5 considering x1000 normalization
dat_thres <- dat_norm[ apply(dat_norm, 1, max) > threshold, ]
# log2-transformation
dat_log <- log2(dat_thres + 1)
dim(dat_log)
subsettedOTUs <- rownames(dat_log)
# preparation of eset format required for limma based analysis
eset <- new("ExpressionSet")
exprs(eset) <- dat_log
pData(eset) <- design
#############################################################
#############################################################
# Figure 2 (based on Cologne soil samples)
#############################################################
#############################################################
### subsetting of design matrix and eset for Cologne soil samples
design_sc <- design[subset_cologne,]    # "_sc" for subset Cologne
eset_sc <- eset[,subset_cologne]
eset_sc = eset_sc[rowSums((2^exprs(eset_sc)) >= threshold + 1) >= 1,] # re-application of threshold within subset of Cologne samples
dim(eset_sc)
### limma based statistics at the level of COMPARTMENTS
sample_sc <- as.vector(design_sc$Compartment)
model_sc <- model.matrix(~0 + sample_sc)
colnames(model_sc) <- make.names(colnames(model_sc))
fit_sc <- lmFit(eset_sc, model_sc)
### Figure 2a (ternary plot)
#############################################################
# contrasts: root against soil and root against rhizo and Rhizo -soil
cont.matrix_1A <- makeContrasts(sample_scRoot - sample_scSoil, sample_scRoot - sample_scRhizosphere, sample_scRhizosphere - sample_scSoil, levels = model_sc)
fit2_1A <- contrasts.fit(fit_sc, cont.matrix_1A)
fit2_1A <- eBayes(fit2_1A)
tab_1A <- topTable(fit2_1A, n=dim(exprs(eset_sc))[1], adjust="fdr")
de_tab_1A <- decideTests(fit2_1A)
# defining vector with root-enriched OTUs (over Soil and Rhizosphere) in Cologne Soil
RootOTUs_sc <- rownames(de_tab_1A)[de_tab_1A[,1]==1 & de_tab_1A[,2]==1]
length(RootOTUs_sc)
### Extraction of mean abundance values for all compartments
means_sc_wood <- fit_sc$coef[,4]
means_sc_rhizo <- fit_sc$coef[,1]
means_sc_root <- fit_sc$coef[,2]
means_sc_soil <- fit_sc$coef[,3]
### Ternary plot
temat_1A <- cbind(means_sc_root, means_sc_rhizo, means_sc_soil)
colnames(temat_1A) <- c("Root","Rhizosphere","Soil")
dim(temat_1A)
# remove OTUs which are only detected in the Wood
temat_1A <- temat_1A[!(rowSums(temat_1A) == 0),]
dim(temat_1A)
# define color coding for ternary plot
fig1a_colors <- ifelse(rownames(temat_1A) %in% RootOTUs_sc, "blue","darkgrey")
### plotting Figure 2a
# pdf("Figure_2a.pdf", width=8, height=8)
tern_e(temat_1A, prop=T, col=fig1a_colors, main="Figure 2a / Cologne soil samples")
# dev.off()
### Figure 2b (ternary plot)
#############################################################
# contrasts: root - wood, wood - soil and wood -rhizo
cont.matrix_1B <- makeContrasts(sample_scRoot - sample_scWood, sample_scWood - sample_scSoil, sample_scWood - sample_scRhizosphere, levels=model_sc)
fit2_1B <- contrasts.fit(fit_sc, cont.matrix_1B)
fit2_1B <- eBayes(fit2_1B)
de_tab_1B <- decideTests(fit2_1B)
# defining vector with root-specific OTUs that are wood-corrected in Cologne soil
rOTUs_sc <- rownames(de_tab_1B)[de_tab_1B[,1]==1][rownames(de_tab_1B)[de_tab_1B[,1]==1] %in% RootOTUs_sc]
length(rOTUs_sc)
# defining vector with OTUs shared between root and wood in Cologne Soil
lOTUs_sc <- RootOTUs_sc[! RootOTUs_sc %in% rOTUs_sc]
length(lOTUs_sc)
# defining vector with wood-specific OTUs in Cologne Soil
WoodOTUs_sc <- rownames(de_tab_1B)[(de_tab_1B[,1]==-1) & (de_tab_1B[,2]==1) & (de_tab_1B[,3]==1)]
wOTUs_sc <- WoodOTUs_sc[!(WoodOTUs_sc %in% RootOTUs_sc)]
length(wOTUs_sc)
#### Ternary plot
temat_1B <- cbind(means_sc_root, means_sc_wood, means_sc_soil)
colnames(temat_1B) <- c("Root","Wood","Soil")
dim(temat_1B)
# remove OTUs which are only detected in the Rhizosphere
temat_1B <- temat_1B[!(rowSums(temat_1B) ==0),]
dim(temat_1B)
# define colorcoding for ternary plot
fig1b_colors <- ifelse(rownames(temat_1B) %in% RootOTUs_sc, "lightblue","darkgrey")
names( fig1b_colors) <- rownames(temat_1B)
fig1b_colors[rOTUs_sc] <- "blue"
fig1b_colors[wOTUs_sc] <- "orange"
### Plotting Figure 2b
# pdf("Figure_2b.pdf", width=8, height=8)
tern_e(temat_1B, prop=T, col=fig1b_colors, main = "Figure 2b / Cologne soil samples")
# dev.off()
### Figure 2c (heatmap)
#############################################################
# clustering based on Pearson distance
distPearson <- function(x){mydist <- as.dist(1-cor(t(x)))}
# color coding
RowSCol <- fig1b_colors[fig1b_colors != "grey"] # same as in Figure 2b
ColSCol = c("brown","green","darkgreen","black")[as.factor(sample_sc)]
cols <- maPalette(l="black",m="yellow",h="orange")
# arranging samples and row order
no_rhizo_ind <- design_sc$Compartment != "Rhizosphere"
Row.order <- names(c(which(RowSCol == "blue"), which(RowSCol == "lightblue"), which(RowSCol == "orange")))
### Plotting Figure 2c
# pdf("Figure_2c.pdf", height=8, width=8)
heatmap.2(exprs(eset_sc)[Row.order,no_rhizo_ind],scale="none",trace="none",ColS=ColSCol[no_rhizo_ind],RowS=RowSCol[Row.order],col=cols,density.info="none",cexRow=.7,cexCol=1.2,Rowv=F,margins = c(8, 8),lhei=c(2,6), hclust=function(x)hclust(d=x,method="ward"),dist=distPearson)
# dev.off()
### Figure 2d (taxonomy pies)
#############################################################
### extraction of the SILVA taxonomy of rOTUs Cologne
rOTUs_sc_SILVA <- table(SILVAtax[rOTUs_sc ,2])
rOTUs_sc_SILVA <- sort(rOTUs_sc_SILVA[which(rOTUs_sc_SILVA !=0)], dec=T)
rOTUs_sc_SILVA
Phylum <- names(rOTUs_sc_SILVA)[1:2]  # note, downstream function "colSums" requires at minimum 2 OTUs, single OTUs are appended later)
# step 2: preparation of "Phylum-RA matrix"
y <- c()
otunames <- rOTUs_sc
for (i in Phylum){
x <- colSums(dat_thres[otunames
[otunames %in%
rownames(SILVAtax)[which(SILVAtax$Phylum == paste(i))] ],])
y <- rbind(y,x)
}
rownames(y) <- paste(Phylum)
rOTUs_RA <- y
rOTUs_RA
# RA values of single OTUs are appended here
Cyanobacteria <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Cyanobacteria")] ],]
Bacteroidetes <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Bacteroidetes")] ],]
rOTUs_RA <- rbind(rOTUs_RA, Bacteroidetes, Cyanobacteria)
# step 3: subsetting for Root compartment samples of Cologne soil and generation of MEAN values
rOTUs_RA_root_sc <- rOTUs_RA[,subset_cologne[which(design_sc$Compartment == "Root")]]
rOTUs_RA_root_sc_mean <- apply(rOTUs_RA_root_sc, 1, mean)
rOTUs_RA_root_sc_mean <- sort(rOTUs_RA_root_sc_mean, dec=T)
lbls_rOTUs_sc <- paste(names(rOTUs_RA_root_sc_mean), "\n", rOTUs_RA_root_sc_mean, sep="")
# pdf("Figure_2d_rOTUs.pdf")
pie(rOTUs_RA_root_sc_mean, labels = lbls_rOTUs_sc, col=rainbow(length(lbls_rOTUs_sc)), main="rOTUs / Cologne / RA / Root / SILVA")
# dev.off()
### extraction of the SILVA taxonomy of lOTUs Cologne
lOTUs_sc_SILVA <- table(SILVAtax[lOTUs_sc ,2])
lOTUs_sc_SILVA <- sort(lOTUs_sc_SILVA[which(lOTUs_sc_SILVA !=0)], dec=T)
lOTUs_sc_SILVA
### Preparation to plot the OTUs RA per Phylum
## new matrix with RA of each Phylum in every sample (=Phylum-RA matrix)
# step 1: list with Phyla in question
Phylum <- names(lOTUs_sc_SILVA)
# step 2: preparation of "Phylum-RA matrix"
y <- c()
otunames <- lOTUs_sc
for (i in Phylum){
x <- colSums(dat_thres[otunames
[otunames %in%
rownames(SILVAtax)[which(SILVAtax$Phylum == paste(i))] ],])
y <- rbind(y,x)
}
rownames(y) <- paste(Phylum)
lOTUs_RA <- y
lOTUs_RA
# step 3a: subsetting for Root compartment samples of Cologne soil and generation of MEAN values
lOTUs_RA_root_sc_mean <- mean(lOTUs_RA[,subset_cologne[which(design_sc$Compartment == "Root")]])
lbls1_lOTUs_sc <- paste(Phylum, "\n", lOTUs_RA_root_sc_mean, sep="")
# pdf("Figure_2d_lOTUs_root.pdf") # used in the MS
pie(lOTUs_RA_root_sc_mean, labels = lbls1_lOTUs_sc, col=rainbow(length(lbls1_lOTUs_sc)), main="lOTUs / Cologne / RA / Root / SILVA")
# dev.off()
### extraction of the SILVA taxonomy of wOTUs Cologne
wOTUs_sc_SILVA <- table(SILVAtax[wOTUs_sc ,2])
wOTUs_sc_SILVA <- sort(wOTUs_sc_SILVA[which(wOTUs_sc_SILVA !=0)], dec=T)
wOTUs_sc_SILVA
Phylum <- names(wOTUs_sc_SILVA)[1:2]
# step 2: preparation of "Phylum-RA matrix"
y <- c()
otunames <- wOTUs_sc
for (i in Phylum){
x <- colSums(dat_thres[otunames
[otunames %in%
rownames(SILVAtax)[which(SILVAtax$Phylum == paste(i))] ],])
y <- rbind(y,x)
}
rownames(y) <- paste(Phylum)
wOTUs_RA <- y
wOTUs_RA
# RA values of single OTUs are appended here
Actinobacteria <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Actinobacteria")] ], ]
wOTUs_RA <- rbind(wOTUs_RA, Actinobacteria)
# step 3: subsetting for Wood compartment samples of Cologne soil and generation of MEAN values
wOTUs_RA_wood_sc <- wOTUs_RA[,subset_cologne[which(design_sc$Compartment == "Wood")]]
wOTUs_RA_wood_sc_mean <- apply(wOTUs_RA_wood_sc, 1, mean)
wOTUs_RA_wood_sc_mean <- sort(wOTUs_RA_wood_sc_mean, dec=T)
lbls_wOTUs_sc <- paste(names(wOTUs_RA_wood_sc_mean), "\n", wOTUs_RA_wood_sc_mean, sep="")
# pdf("Figure_2d_wOTUs.pdf")
pie(wOTUs_RA_wood_sc_mean, labels = lbls_wOTUs_sc, col=rainbow(length(lbls_wOTUs_sc)), main="wOTUs / Cologne / RA / wood / SILVA")
# dev.off()
#############################################################
#############################################################
### Supplementary Figure 11 (based on Golm soil samples)
#############################################################
#############################################################
### subsetting of design matrix and eset for Golm soil samples
design_sg <- design[subset_golm,]   # "_sg" for subset Golm
eset_sg <- eset[,subset_golm]
eset_sg = eset_sg[rowSums((2^exprs(eset_sg)) >= threshold + 1) >= 1,] # re-application of threshold within subset of Golm samples
dim(eset_sg)
### limma based statistics at the level of COMPARTMENTS
sample_sg <- as.vector(design_sg$Compartment)
model_sg <- model.matrix(~0 + sample_sg)
colnames(model_sg) <- make.names(colnames(model_sg))
fit_sg <- lmFit(eset_sg, model_sg)
## Supplementary Figure 11a (ternary plot)
#############################################################
# contrasts: root against soil and root against rhizo and rhizo - soil
cont.matrix_1Ag <- makeContrasts(sample_sgRoot - sample_sgSoil, sample_sgRoot - sample_sgRhizosphere, sample_sgRhizosphere - sample_sgSoil, levels = model_sg)
fit2_1Ag <- contrasts.fit(fit_sg, cont.matrix_1Ag)
fit2_1Ag <- eBayes(fit2_1Ag)
tab_1Ag <- topTable(fit2_1Ag, n=dim(exprs(eset_sg))[1], adjust="fdr")
de_tab_1Ag <- decideTests(fit2_1Ag)
# defining vector with root-enriched OTUs (over Soil and Rhizosphere) in Golm Soil
RootOTUs_sg <- rownames(de_tab_1Ag)[de_tab_1Ag[,1]==1 & de_tab_1Ag[,2]==1]
length(RootOTUs_sg)
### Extraction of mean abundance values for all compartments
means_sg_wood <- fit_sg$coef[,4]
means_sg_rhizo <- fit_sg$coef[,1]
means_sg_root <- fit_sg$coef[,2]
means_sg_soil <- fit_sg$coef[,3]
### Ternary plot
temat_1Ag <- cbind(means_sg_root, means_sg_rhizo, means_sg_soil)
colnames(temat_1Ag) <- c("Root","Rhizosphere","Soil")
dim(temat_1Ag)
# remove OTUs which are only detected in the Wood
temat_1Ag <- temat_1Ag[!(rowSums(temat_1Ag) ==0),]
dim(temat_1Ag)
# define color coding for ternary plot
suppFig11a_colors <- ifelse(rownames(temat_1Ag) %in% RootOTUs_sg, "blue","darkgrey")
### plotting Supplementary Figure 11a
# pdf("suppFigure_11a.pdf", width=8, height=8)
tern_e(temat_1Ag, prop=T, col= suppFig11a_colors, main = "Supplementary Figure 11a / Golm soils samples")
# dev.off()
## Supplementary Figure 11b (ternary plot)
#############################################################
# contrasts: root - wood, wood - soil and wood -rhizo
cont.matrix_1Bg <- makeContrasts(sample_sgRoot - sample_sgWood, sample_sgWood - sample_sgSoil, sample_sgWood - sample_sgRhizosphere, levels=model_sg)
fit2_1Bg <- contrasts.fit(fit_sg, cont.matrix_1Bg)
fit2_1Bg <- eBayes(fit2_1Bg)
de_tab_1Bg <- decideTests(fit2_1Bg)
# defining vector with root-specific OTUs that are wood corrected in Golm Soil
rOTUs_sg <- rownames(de_tab_1Bg)[de_tab_1Bg[,1]==1][rownames(de_tab_1Bg)[de_tab_1Bg[,1]==1] %in% RootOTUs_sg]
length(rOTUs_sg)
# defining vector with OTUs shared between root and wood in Golm Soil
lOTUs_sg <- RootOTUs_sg[! RootOTUs_sg %in% rOTUs_sg]
length(lOTUs_sg)
# defining vector with wood-specific OTUs in Golm Soil
WoodOTUs_sg <- rownames(de_tab_1Bg)[(de_tab_1Bg[,1]==-1) & (de_tab_1Bg[,2]==1) & (de_tab_1Bg[,3]==1)]
wOTUs_sg <- WoodOTUs_sg[!(WoodOTUs_sg %in% RootOTUs_sg)]
length(wOTUs_sg)
### Ternary plot
temat_1Bg <- cbind(means_sg_root, means_sg_wood, means_sg_soil)
colnames(temat_1Bg) <- c("Root","Wood","Soil")
dim(temat_1Bg)
# remove OTUs which are only detected in the Rhizosphere
temat_1Bg <- temat_1Bg[!(rowSums(temat_1Bg) ==0),]
dim(temat_1Bg)
# define color coding for ternary plot
suppFig11b_colors <- ifelse(rownames(temat_1Bg) %in% RootOTUs_sg, "lightblue","darkgrey")
names(suppFig11b_colors) <- rownames(temat_1Bg)
suppFig11b_colors[rOTUs_sg] <- "blue"
suppFig11b_colors[wOTUs_sg] <- "orange"
### Plotting Supplementary Figure 11b
# pdf("suppFigure_11b.pdf", width=8, height=8)
tern_e(temat_1Bg, prop=T, col=suppFig11b_colors, main = "Supplementary Figure 11b / Golm soils samples")
# dev.off()
## Supplementary Figure 11c (taxonomy pies)
#############################################################
### extraction of the SILVA taxonomy of rOTUs Golm
rOTUs_sg_SILVA <- table(SILVAtax[rOTUs_sg ,2])
rOTUs_sg_SILVA <- sort(rOTUs_sg_SILVA[which(rOTUs_sg_SILVA !=0)], dec=T)
rOTUs_sg_SILVA
### Preparation
Phylum <- names(rOTUs_sg_SILVA)[1:3]  # note, downstream function "colSums" requires at minimum 2 OTUs, single OTUs are appended later)
# step 2: preparation of "Phylum-RA matrix"
y <- c()
otunames <- rOTUs_sg
for (i in Phylum){
x <- colSums(dat_thres[otunames
[otunames %in%
rownames(SILVAtax)[which(SILVAtax$Phylum == paste(i))] ],])
y <- rbind(y,x)
}
rownames(y) <- paste(Phylum)
rOTUs_sg_RA <- y
rOTUs_sg_RA
# RA values of single OTUs are appended here
Candidate_Division_TM7 <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Candidate division TM7")] ],]
rOTUs_sg_RA <- rbind(rOTUs_sg_RA, Candidate_Division_TM7)
# step 3: subsetting for Root compartment samples of Golm soil and generation of MEAN values
rOTUs_RA_root_sg <- rOTUs_sg_RA[,subset_golm[which(design_sg$Compartment == "Root")]]
rOTUs_RA_root_sg_mean <- apply(rOTUs_RA_root_sg, 1, mean)
rOTUs_RA_root_sg_mean <- sort(rOTUs_RA_root_sg_mean, dec=T)
lbls_rOTUs_sg <- paste(names(rOTUs_RA_root_sg_mean), "\n", rOTUs_RA_root_sg_mean, sep="")
# pdf("suppFigure_11c_rOTUs.pdf")
pie(rOTUs_RA_root_sg_mean, labels = lbls_rOTUs_sg, col=rainbow(length(lbls_rOTUs_sg)), main="rOTUs / Golm / RA / Root / SILVA")
# dev.off()
### extraction of the SILVA taxonomy of lOTUs Golm
lOTUs_sg_SILVA <- table(SILVAtax[lOTUs_sg ,2])
lOTUs_sg_SILVA <- sort(lOTUs_sg_SILVA[which(lOTUs_sg_SILVA !=0)], dec=T)
lOTUs_sg_SILVA
# step 1: list with Phyla in question
Phylum <- names(lOTUs_sg_SILVA)
# step 2: preparation of "Phylum-RA matrix"
y <- c()
otunames <- lOTUs_sg
for (i in Phylum){
x <- colSums(dat_thres[otunames
[otunames %in%
rownames(SILVAtax)[which(SILVAtax$Phylum == paste(i))] ],])
y <- rbind(y,x)
}
rownames(y) <- paste(Phylum)
lOTUs_RA_sg <- y
lOTUs_RA_sg
lOTUs_RA_root_sg <- lOTUs_RA_sg[,subset_golm[which(design_sc$Compartment == "Root")]]
lOTUs_RA_root_sg_mean <- apply(lOTUs_RA_root_sg, 1, mean)
lbls1_lOTUs_sg <- paste(names(lOTUs_RA_root_sg_mean), "\n", lOTUs_RA_root_sg_mean, sep="")
# pdf("suppFigure_11c_lOTUs_root.pdf")  # used in the MS
pie(lOTUs_RA_root_sg_mean, labels = lbls1_lOTUs_sg, col=rainbow(length(lbls1_lOTUs_sg)), main="lOTUs / Golm / RA / Root / SILVA")
# dev.off()
lOTUs_RA_root_sg <- lOTUs_RA_sg[,subset_golm[which(design_sg$Compartment == "Root")]]
lOTUs_RA_root_sg_mean <- apply(lOTUs_RA_root_sg, 1, mean)
lbls1_lOTUs_sg <- paste(names(lOTUs_RA_root_sg_mean), "\n", lOTUs_RA_root_sg_mean, sep="")
# pdf("suppFigure_11c_lOTUs_root.pdf")  # used in the MS
pie(lOTUs_RA_root_sg_mean, labels = lbls1_lOTUs_sg, col=rainbow(length(lbls1_lOTUs_sg)), main="lOTUs / Golm / RA / Root / SILVA")
# dev.off()
# step 3: subsetting for Root compartment samples of Golm soil and generation of MEAN values
lOTUs_RA_root_sg <- lOTUs_RA_sg[,subset_golm[which(design_sg$Compartment == "Root")]]
lOTUs_RA_root_sg_mean <- apply(lOTUs_RA_root_sg, 1, mean)
lbls1_lOTUs_sg <- paste(names(lOTUs_RA_root_sg_mean), "\n", lOTUs_RA_root_sg_mean, sep="")
# pdf("suppFigure_11c_lOTUs_root.pdf")
pie(lOTUs_RA_root_sg_mean, labels = lbls1_lOTUs_sg, col=rainbow(length(lbls1_lOTUs_sg)), main="lOTUs / Golm / RA / Root / SILVA")
# dev.off()
### extraction of the SILVA taxonomy of wOTUs Golm
wOTUs_sg_SILVA <- table(SILVAtax[wOTUs_sg ,2])
wOTUs_sg_SILVA <- sort(wOTUs_sg_SILVA[which(wOTUs_sg_SILVA !=0)], dec=T)
wOTUs_sg_SILVA
# step 1: list with Phyla in question
Phylum <- names(wOTUs_sg_SILVA)[1:3]
# step 2: preparation of "Phylum-RA matrix"
y <- c()
otunames <- wOTUs_sg
for (i in Phylum){
x <- colSums(dat_thres[otunames
[otunames %in%
rownames(SILVAtax)[which(SILVAtax$Phylum == paste(i))] ],])
y <- rbind(y,x)
}
rownames(y) <- paste(Phylum)
wOTUs_sg_RA <- y
wOTUs_sg_RA
# RA values of single OTUs are appended here
Planctomycetes <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Planctomycetes")] ],]
Nitrospirae <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Nitrospirae")] ],]
wOTUs_sg_RA <- rbind(wOTUs_sg_RA, Nitrospirae, Planctomycetes)
# step 3: subsetting for Wood compartment samples of Golm soil and generation of MEAN values
wOTUs_RA_root_sg <- wOTUs_sg_RA[,subset_golm[which(design_sg$Compartment == "Wood")]]
wOTUs_RA_root_sg_mean <- apply(wOTUs_RA_root_sg, 1, mean)
wOTUs_RA_root_sg_mean <- sort(wOTUs_RA_root_sg_mean, dec=T)
lbls_wOTUs_sg <- paste(names(wOTUs_RA_root_sg_mean), "\n", wOTUs_RA_root_sg_mean, sep="")
# pdf("suppFigure_11c_wOTUs.pdf")
pie(wOTUs_RA_root_sg_mean, labels = lbls_wOTUs_sg, col=rainbow(length(lbls_wOTUs_sg)), main="wOTUs / Golm / RA / Root / SILVA")
# dev.off()
