model_sc <- model.matrix(~0 + sample_sc)
colnames(model_sc) <- make.names(colnames(model_sc))
fit_sc <- lmFit(eset_sc, model_sc)
# 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)
# 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)
### plotting 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
### Preparation to plot the OTUs RELATIVE ABUNDANCE (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(rOTUs_sc_SILVA)[1:4]  # 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")] ],]
Deinococcus_Thermus <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Deinococcus-Thermus")] ],]
Firmicutes <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Firmicutes")] ],]
Verrucomicrobia <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Verrucomicrobia")] ],]
rOTUs_RA <- rbind(rOTUs_RA, Cyanobacteria, Deinococcus_Thermus, Firmicutes, Verrucomicrobia)
# 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("suppFigure_14b_rOTUs.pdf")
pie(rOTUs_RA_root_sc_mean, labels = lbls_rOTUs_sc, col=rainbow(length(lbls_rOTUs_sc)), main="Supplementary Figure 14b / rOTUs")
# dev.off()
pdf("suppFigure_14b_rOTUs.pdf", height=4, width=4)
pie(rOTUs_RA_root_sc_mean, labels = lbls_rOTUs_sc, col=rainbow(length(lbls_rOTUs_sc)), main="Supplementary Figure 14b / rOTUs")
# dev.off()
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)[1:3]
# 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
# RA values of single OTUs are appended here
Candidate_division_TM7 <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Candidate division TM7")] ],]
lOTUs_RA <- rbind(lOTUs_RA, Candidate_division_TM7)
# step 3: subsetting for Root compartment samples of Cologne soil and generation of MEAN values
lOTUs_RA_root_sc <- lOTUs_RA[,subset_cologne[which(design_sc$Compartment == "Root")]]
lOTUs_RA_root_sc_mean <- apply(lOTUs_RA_root_sc, 1, mean)
lOTUs_RA_root_sc_mean <- sort(lOTUs_RA_root_sc_mean, dec=T)
lbls1_lOTUs_sc <- paste(Phylum, "\n", lOTUs_RA_root_sc_mean, sep="")
# pdf("suppFigure_14b_lOTUs_root.pdf")
pie(lOTUs_RA_root_sc_mean, labels = lbls1_lOTUs_sc, col=rainbow(length(lbls1_lOTUs_sc)), main="Supplementary Figure 14b / lOTUs on roots")
# dev.off()
pdf("suppFigure_14b_lOTUs_root.pdf", height=4, width=4)
pie(lOTUs_RA_root_sc_mean, labels = lbls1_lOTUs_sc, col=rainbow(length(lbls1_lOTUs_sc)), main="Supplementary Figure 14b / lOTUs on roots")
# dev.off()
dev.off()
ion 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
### 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(wOTUs_sc_SILVA)[1:3]
# 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")] ], ]
Firmicutes <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Firmicutes")] ], ]
wOTUs_RA <- rbind(wOTUs_RA, Actinobacteria, Firmicutes)
# 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("suppFigure_14b_wOTUs.pdf")
pie(wOTUs_RA_wood_sc_mean, labels = lbls_wOTUs_sc, col=rainbow(length(lbls_wOTUs_sc)), main="Supplementary Figure 14b / wOTUs")
# dev.off()
pdf("suppFigure_14b_wOTUs.pdf", height=4, width=4)
pie(wOTUs_RA_wood_sc_mean, labels = lbls_wOTUs_sc, col=rainbow(length(lbls_wOTUs_sc)), main="Supplementary Figure 14b / wOTUs")
# dev.off()
dev.off()
### Supplementary Figure 14c (taxonomy 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)
# 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)
# 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)
### plotting 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 to plot the OTUs RELATIVE ABUNDANCE (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(rOTUs_sg_SILVA)[1:4]  # 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_14c_rOTUs.pdf")
pie(rOTUs_RA_root_sg_mean, labels = lbls_rOTUs_sg, col=rainbow(length(lbls_rOTUs_sg)), main="Supplementary Figure 14c / rOTUs")
# dev.off()
pdf("suppFigure_14c_rOTUs.pdf", height=4, width=4)
pie(rOTUs_RA_root_sg_mean, labels = lbls_rOTUs_sg, col=rainbow(length(lbls_rOTUs_sg)), main="Supplementary Figure 14c / rOTUs")
# dev.off()
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
### 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_sg_SILVA)[1:2]
# 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
# RA values of single OTUs are appended here
Chloroflexi <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Chloroflexi")] ],]
lOTUs_RA_sg <- rbind(lOTUs_RA_sg, Chloroflexi)
# 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_14c_lOTUs_root.pdf")
pie(lOTUs_RA_root_sg_mean, labels = lbls1_lOTUs_sg, col=rainbow(length(lbls1_lOTUs_sg)), main="Supplementary Figure 14c/ lOTUs on roots")
# dev.off()
pdf("suppFigure_14c_lOTUs_root.pdf", height=4, width=4)
pie(lOTUs_RA_root_sg_mean, labels = lbls1_lOTUs_sg, col=rainbow(length(lbls1_lOTUs_sg)), main="Supplementary Figure 14c/ lOTUs on roots")
#
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
### 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(wOTUs_sg_SILVA)[1:5]
# 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
Nitrospirae <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Nitrospirae")] ],]
wOTUs_sg_RA <- rbind(wOTUs_sg_RA, Nitrospirae)
# 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_14c_wOTUs.pdf")
pie(wOTUs_RA_root_sg_mean, labels = lbls_wOTUs_sg, col=rainbow(length(lbls_wOTUs_sg)), main="Supplementary Figure 14c / wOTUs")
# dev.off()
pdf("suppFigure_14c_wOTUs.pdf", height=4, width=4)
pie(wOTUs_RA_root_sg_mean, labels = lbls_wOTUs_sg, col=rainbow(length(lbls_wOTUs_sg)), main="Supplementary Figure 14c / wOTUs")
# dev.off()
dev.off()
lbls_rOTUs_sc
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)[1:3]
# 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
# RA values of single OTUs are appended here
Candidate_division_TM7 <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Candidate division TM7")] ],]
lOTUs_RA <- rbind(lOTUs_RA, Candidate_division_TM7)
lOTUs_RA
lOTUs_RA_root_sc <- lOTUs_RA[,subset_cologne[which(design_sc$Compartment == "Root")]]
lOTUs_RA_root_sc_mean <- apply(lOTUs_RA_root_sc, 1, mean)
lOTUs_RA_root_sc_mean <- sort(lOTUs_RA_root_sc_mean, dec=T)
lbls1_lOTUs_sc <- paste(Phylum, "\n", lOTUs_RA_root_sc_mean, sep="")
# pdf("suppFigure_14b_lOTUs_root.pdf", height=4, width=4)
pie(lOTUs_RA_root_sc_mean, labels = lbls1_lOTUs_sc, col=rainbow(length(lbls1_lOTUs_sc)), main="Supplementary Figure 14b / lOTUs on roots")
# dev.off()
lbls1_lOTUs_sc
lbls1_lOTUs_sc <- paste(names(lOTUs_RA_root_sc_mean), "\n", lOTUs_RA_root_sc_mean, sep="")
# pdf("suppFigure_14b_lOTUs_root.pdf", height=4, width=4)
pie(lOTUs_RA_root_sc_mean, labels = lbls1_lOTUs_sc, col=rainbow(length(lbls1_lOTUs_sc)), main="Supplementary Figure 14b / lOTUs on roots")
lbls1_lOTUs_sc
### 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:3]
# 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")] ], ]
Firmicutes <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Firmicutes")] ], ]
wOTUs_RA <- rbind(wOTUs_RA, Actinobacteria, Firmicutes)
# 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("suppFigure_14b_wOTUs.pdf", height=4, width=4)
pie(wOTUs_RA_wood_sc_mean, labels = lbls_wOTUs_sc, col=rainbow(length(lbls_wOTUs_sc)), main="Supplementary Figure 14b / wOTUs")
lbls_wOTUs_sc
wOTUs_sg_SILVA <- table(SILVAtax[wOTUs_sg ,2])
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
Phylum <- names(wOTUs_sg_SILVA)[1:5]
# 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
wOTUs_sg_SILVA
Nitrospirae <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Nitrospirae")] ],]
wOTUs_sg_RA <- rbind(wOTUs_sg_RA, Nitrospirae)
# step 3: subsetting for Wood compartment samples of Golm soil and generation of MEAN values
wOTUs_RA_wood_sg <- wOTUs_sg_RA[,subset_golm[which(design_sg$Compartment == "Wood")]]
wOTUs_RA_wood_sg <- wOTUs_sg_RA[,subset_golm[which(design_sg$Compartment == "Wood")]]
wOTUs_RA_wood_sg_mean <- apply(wOTUs_RA_wood_sg, 1, mean)
wOTUs_RA_wood_sg_mean <- sort(wOTUs_RA_wood_sg_mean, dec=T)
lbls_wOTUs_sg <- paste(names(wOTUs_RA_wood_sg_mean), "\n", wOTUs_RA_wood_sg_mean, sep="")
# pdf("suppFigure_14c_wOTUs.pdf", height=4, width=4)
pie(wOTUs_RA_wood_sg_mean, labels = lbls_wOTUs_sg, col=rainbow(length(lbls_wOTUs_sg)), main="Supplementary Figure 14c / wOTUs")
# dev.off()
#############################################################
# Libraries and functions required
#############################################################
library("limma")
library("vegan")
library("sciplot")
source("file2Exprs.R")
source("http://faculty.ucr.edu/~tgirke/Documents/R_BioCond/My_R_Scripts/vennDia.R")
#############################################################
# Supplementary Figure 14a (Cluster dendrogram)
#############################################################
dat_rare <- read.delim("PyroTagger_counts_rarefied_B.txt", header=T, row.names=1, sep="\t")
# normalization by sample size and transformation in "/1000"
dat_rare_norm <- t(t(dat_rare)/colSums(dat_rare)) * 1000
# application of threshold for lower presence limit of relative abundance
threshold <- 5    # 0.5% presence: use integer 5 considering x1000 normalization
dat_rare_thres <- dat_rare_norm[ apply(dat_rare_norm,1,max) > threshold, ]
# log2-transformation
dat_rare_thres_log <- log2(dat_rare_thres + 1)
dim(dat_rare_thres_log)
# calculate Bray-Curtis dissimilarity
dat_dist <- vegdist(t(dat_rare_thres_log), method="bray")
# clustering
dat_dist_clu <- hclust(dat_dist, "average")
# pdf("suppFigure_14a.pdf", width=15, height=5)
plot(dat_dist_clu, main = "Supplementary Figure 14a / Bray Curtis", lwd=1.5, cex=.5)
# dev.off()
#############################################################
# Supplementary Figure 14b-f
#############################################################
# 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)
# the design matrix contains 3 pre-defined samples which are only
# required for the analysis where OTUs assigned to Chloroflexi are depeleted
design <- design[design$after_Depletion_of_Chloroflexi != "combined",]
dim(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)  # all samples have at least 2638 counts
## SUBSETTING the pyrotagger count data matrix
# this subsetting is required, as the pyrotagger counts contains the the 2 technial replicate samples "Bulk26K" & "Bulk27K"
subset_cologne <- rownames(design)[which(design$Site == "Cologne")]
subset_golm <- rownames(design)[which(design$Site == "Golm")]
subset_naturalsite <- rownames(design)[which(design$Site == "naturalsite")]
dat_raw <- dat_raw[, c(subset_cologne, subset_golm, subset_naturalsite)]
dim(dat_raw)
### uploading of SILVA taxonommy
SILVAtax <- read.delim("OTU_classification_SILVA.txt", row.names=1, sep="\t", header=T)
dim(SILVAtax)
SILVAtax[1:10,1:5]
#############################################################
# Data transformation and thresholding
#############################################################
# normalization by sample size and transformation in "/1000"
dat_norm <- t(t(dat_raw)/colSums(dat_raw)) * 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
### Supplementary Figure 14c (taxonomy 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)
# 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)
# 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)
olm
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
### 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(wOTUs_sg_SILVA)[1:5]
# 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
Nitrospirae <- dat_thres[otunames[otunames %in% rownames(SILVAtax)[which(SILVAtax$Phylum == "Nitrospirae")] ],]
wOTUs_sg_RA <- rbind(wOTUs_sg_RA, Nitrospirae)
# step 3: subsetting for Wood compartment samples of Golm soil and generation of MEAN values
wOTUs_RA_wood_sg <- wOTUs_sg_RA[,subset_golm[which(design_sg$Compartment == "Wood")]]
wOTUs_RA_wood_sg_mean <- apply(wOTUs_RA_wood_sg, 1, mean)
wOTUs_RA_wood_sg_mean <- sort(wOTUs_RA_wood_sg_mean, dec=T)
lbls_wOTUs_sg <- paste(names(wOTUs_RA_wood_sg_mean), "\n", wOTUs_RA_wood_sg_mean, sep="")
# pdf("suppFigure_14c_wOTUs.pdf", height=4, width=4)
pie(wOTUs_RA_wood_sg_mean, labels = lbls_wOTUs_sg, col=rainbow(length(lbls_wOTUs_sg)), main="Supplementary Figure 14c / wOTUs")
# dev.off()
