#############################################################
# Libraries and functions required
#############################################################
library("limma")
source("file2Exprs.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)
#############################################################
#############################################################
# Supplementary Figure 19
#############################################################
#############################################################
# preparation of eset containing raw count values
eset_raw <- new("ExpressionSet")
exprs(eset_raw) <- as.matrix(dat_raw_noC)
pData(eset_raw) <- design
dim(eset_raw)
# preparation of subsetting files
subset_soil <- rownames(design)[which(design$Compartment == "Soil")]
subset_rhizo <- rownames(design)[which(design$Compartment == "Rhizosphere")]
subset_root <- rownames(design)[which(design$Compartment == "Root")]
# Supplementary Figure 19a, ALL compartments
#############################################################
# subsetting eset_raw for OTUs above threshold and the three compartments soil, rhizosphere and root
eset_raw_ssrr <- eset_raw[subsettedOTUs, c(subset_soil, subset_rhizo, subset_root)] # "_ssrr" stands for "subset soil rhizosphere root"
## exploiting LIMMA to obtain mean abundance values of all sites
site_ssrr <- as.vector(pData(eset_raw_ssrr)$Site)
model_ssrr <- model.matrix(~0 + site_ssrr)
colnames(model_ssrr) <- make.names(colnames(model_ssrr))
fit_ssrr <- lmFit(eset_raw_ssrr, model_ssrr)
means_ssrr_Cologne <- fit_ssrr$coef[,1]
means_ssrr_Golm <- fit_ssrr$coef[,2]
means_ssrr_naturalsite <- fit_ssrr$coef[,3]
temat_ssrr <- cbind(means_ssrr_Cologne, means_ssrr_Golm, means_ssrr_naturalsite)
colnames(temat_ssrr) <- c("Cologne","Golm","naturalsite")
# define vectors with present OTUs (>0) in individual sites:
temat_ssrr_df <- as.data.frame(temat_ssrr)
Cologne_ssrr <- rownames(temat_ssrr_df)[which(temat_ssrr_df[,"Cologne"] > 0)]
Golm_ssrr <- rownames(temat_ssrr_df)[which(temat_ssrr_df[,"Golm"] > 0)]
naturalsite_ssrr <- rownames(temat_ssrr_df)[which(temat_ssrr_df[,"naturalsite"] > 0)]
# pdf("suppFigure_19a.pdf")
VennList <- venndiagram(x=Cologne_ssrr, y=Golm_ssrr, z=naturalsite_ssrr, unique=T, title="Supplementary Figure 19a / all compartments", labels=c("Cologne", "Golm", "naturalsite"), lines=c(2,3,4), lcol=c(2,3,4), tcol=1, lwd=3, cex=1, printsub=T, type="3")
# dev.off()
# Supplementary Figure 19b, SOIL compartments
#############################################################
# subsetting eset_raw for OTUs above threshold and the soil compartment
eset_raw_ssoil <- eset_raw[subsettedOTUs, subset_soil] # "_ssoil" stands for "subset soil"
## exploiting LIMMA to obtain mean abundance values of all sites
site_ssoil <- as.vector(pData(eset_raw_ssoil)$Site)
model_ssoil <- model.matrix(~0 + site_ssoil)
colnames(model_ssoil) <- make.names(colnames(model_ssoil))
fit_ssoil <- lmFit(eset_raw_ssoil, model_ssoil)
means_ss_Cologne <- fit_ssoil$coef[,1]
means_ss_Golm <- fit_ssoil$coef[,2]
means_ss_naturalsite <- fit_ssoil$coef[,3]
temat_ss <- cbind(means_ss_Cologne, means_ss_Golm, means_ss_naturalsite)
colnames(temat_ss) <- c("Cologne","Golm","naturalsite")
# define vectors with present OTUs (>0) in individual sites:
temat_ss_df <- as.data.frame(temat_ss)
Cologne_ss <- rownames(temat_ss_df)[which(temat_ss_df[,"Cologne"] > 0)]
Golm_ss <- rownames(temat_ss_df)[which(temat_ss_df[,"Golm"] > 0)]
naturalsite_ss <- rownames(temat_ss_df)[which(temat_ss_df[,"naturalsite"] > 0)]
# pdf("suppFigure_19b.pdf")
VennList <- venndiagram(x=Cologne_ss, y=Golm_ss, z=naturalsite_ss, unique=T, title="Supplementary Figure 19b / Soil compartment", labels=c("Cologne", "Golm", "naturalsite"), lines=c(2,3,4), lcol=c(2,3,4), tcol=1, lwd=3, cex=1, printsub=T, type="3")
# dev.off()
# Supplementary Figure 19c, RHIZOSPHERE compartments
#############################################################
# subsetting eset_raw for OTUs above threshold and the rhizosphere compartment
eset_raw_srhizo <- eset_raw[subsettedOTUs, subset_rhizo] # "_srhizo" stands for "subset rhizosphere"
## exploiting LIMMA to obtain mean abundance values of all sites
site_srhizo <- as.vector(pData(eset_raw_srhizo)$Site)
model_srhizo <- model.matrix(~0 + site_srhizo)
colnames(model_srhizo) <- make.names(colnames(model_srhizo))
fit_srhizo <- lmFit(eset_raw_srhizo, model_srhizo)
means_sri_Cologne <- fit_srhizo$coef[,1]
means_sri_Golm <- fit_srhizo$coef[,2]
means_sri_naturalsite <- fit_srhizo$coef[,3]
temat_sri <- cbind(means_sri_Cologne, means_sri_Golm, means_sri_naturalsite)
colnames(temat_sri) <- c("Cologne","Golm","naturalsite")
# define vectors with present OTUs (>0) in individual sites:
## vennDiagram dissecting presence/absence of OTUs
temat_sri_df <- as.data.frame(temat_sri)
Cologne_sri <- rownames(temat_sri_df)[which(temat_sri_df[,"Cologne"] > 0)]
Golm_sri <- rownames(temat_sri_df)[which(temat_sri_df[,"Golm"] > 0)]
naturalsite_sri <- rownames(temat_sri_df)[which(temat_sri_df[,"naturalsite"] > 0)]
# pdf("suppFigure_19c.pdf")
VennList <- venndiagram(x=Cologne_sri, y=Golm_sri, z=naturalsite_sri, unique=T, title="Supplementary Figure 19c / Rhizosphere compartment", labels=c("Cologne", "Golm", "naturalsite"), lines=c(2,3,4), lcol=c(2,3,4), tcol=1, lwd=3, cex=1, printsub=T, type="3")
# dev.off()
# Supplementary Figure 19d, ROOT compartments
#############################################################
# subsetting eset_raw for OTUs above threshold and the root compartment
eset_raw_sroot <- eset_raw[subsettedOTUs, subset_root] # "_sroot" stands for "subset root"
## exploiting LIMMA to obtain mean abundance values of all sites
site_sroot <- as.vector(pData(eset_raw_sroot)$Site)
model_sroot <- model.matrix(~0 + site_sroot)
colnames(model_sroot) <- make.names(colnames(model_sroot))
fit_sroot <- lmFit(eset_raw_sroot, model_sroot)
means_sr_Cologne <- fit_sroot$coef[,1]
means_sr_Golm <- fit_sroot$coef[,2]
means_sr_naturalsite <- fit_sroot$coef[,3]
temat_sr <- cbind(means_sr_Cologne, means_sr_Golm, means_sr_naturalsite)
colnames(temat_sr) <- c("Cologne","Golm","naturalsite")
## vennDiagram dissecting presence/absence of OTUs
temat_sr_df <- as.data.frame(temat_sr)
# define vectors with present (OTU > 0) OTUs of individual exps:
Cologne_sr <- rownames(temat_sr_df)[which(temat_sr_df[,"Cologne"] > 0)]
Golm_sr <- rownames(temat_sr_df)[which(temat_sr_df[,"Golm"] > 0)]
naturalsite_sr <- rownames(temat_sr_df)[which(temat_sr_df[,"naturalsite"] > 0)]
# pdf("suppFigure_19d.pdf")
VennList <- venndiagram(x=Cologne_sr, y=Golm_sr, z=naturalsite_sr, unique=T, title="Supplementary Figure 19d / Root compartment", labels=c("Cologne", "Golm", "naturalsite"), lines=c(2,3,4), lcol=c(2,3,4), tcol=1, lwd=3, cex=1, printsub=T, type="3")
# dev.off()
