#############################################################
# Libraries and functions required
#############################################################
library("limma")
source("~/Desktop/file2Exprs.R")
source("http://faculty.ucr.edu/~tgirke/Documents/R_BioCond/My_R_Scripts/vennDia.R")
#############################################################
# Data upload and rearrangements
#############################################################
### uploading of "Design_matrix_2.txt"
design <- read.delim("Design_matrix_2.txt", sep = "\t", header=TRUE )
rownames(design) <- design[,1]
dim(design)
design
### uploading of data file "PyroTagger_counts_2.txt"
dat_raw <- read.table("PyroTagger_counts_2.txt", row.names=1, sep="\t", header=T, blank.lines.skip = FALSE)
dat_raw[is.na(dat_raw)] = 0   # set NA to zero
colnames(dat_raw)
dim(dat_raw)
dat_raw <- dat_raw[,colnames(dat_raw)[!colnames(dat_raw) %in% c("Bulk26K","Bulk27K")]]
dim(dat_raw)
colnames(dat_raw)
## 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"]
# ... to bind to the raw data matrix
dat_raw_2 <- cbind(dat_raw, R_AtSha19K20K, R_AtLer17G18G, Bulk35G36G)
colnames(dat_raw_2)
# 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)
sort(colSums(dat_raw_2), dec=T)
### uploading of SILVA taxonommy
SILVA_tax <- read.delim("OTU_taxonomy_SILVA_2.txt", row.names=1, sep="\t", header=T)
dim(SILVA_tax)
SILVA_tax[1:10,1:5]
#############################################################
### Supplementary Figure 4b (taxonomy pies)
#############################################################
dat_raw_2_no2 <- dat_raw_2                                  # "_no2" for removed singletons and doubletons
dat_raw_2_no2[dat_raw_2_no2 <= 2 ] = 0                      # removing of singletons and doubletons
dat_raw_2_no2 <- dat_raw_2_no2[rowSums(dat_raw_2_no2) > 0,] # remove rows having a sum count = 0
dim(dat_raw_2_no2)
sort(colSums(dat_raw_2_no2), dec=T)
# normalization by sample size and transformation in "/1000"
dat_norm_no2 <- t(t(dat_raw_2_no2)/colSums(dat_raw_2_no2)) * 1000
dim(dat_norm_no2)
### SOIL samples / 799F2 PCR primer
# selection of samples (all Soil samples, Cologne soil, 799F2 primer)
F2sc_SOILsamples <- rownames(design)[(design$Primer == "799F2") & (design$Site == "Cologne") & (design$Compartment=="Soil")]
dat_norm_F2_soil <- dat_norm_no2[,F2sc_SOILsamples]
dat_norm_F2_soil <- dat_norm_F2_soil[rowSums(dat_norm_F2_soil) > 0,]
dim(dat_norm_F2_soil)
SOILotus_799F2 <- rownames(dat_norm_F2_soil)
### extraction of the SILVA taxonomy for SOILotus_799F2
SILVA_F2_soil_t <- table(SILVA_tax[SOILotus_799F2, 2])
SILVA_F2_soil_t <- sort(SILVA_F2_soil_t[which(SILVA_F2_soil_t !=0)], dec=T)
SILVA_F2_soil_t
### 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(SILVA_F2_soil_t)[1:21] # note, downstream function "colSums" requires at minimum 2 OTUs, single OTUs are appended later)
# step 2: preparation of "Phylum-RA matrix"
y <- c()
otunames <- rownames(dat_norm_F2_soil)
for (i in Phylum){
x <- colSums(dat_norm_F2_soil[otunames
[otunames %in%
rownames(SILVA_tax)[which(SILVA_tax$Phylum == paste(i))] ],])
y <- rbind(y,x)
}
rownames(y) <- paste(Phylum)
F2_SoilPhyla_RA <- y
F2_SoilPhyla_RA
# RA values of single OTUs are appended here
Candidate_division_BRC1 <- dat_norm_F2_soil[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Candidate division BRC1")] ], ]
Deinococcus_Thermus <- dat_norm_F2_soil[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Deinococcus-Thermus")] ], ]
TA06 <- dat_norm_F2_soil[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "TA06")] ], ]
TM6 <- dat_norm_F2_soil[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "TM6")] ], ]
F2_SoilPhyla_RA <- rbind(F2_SoilPhyla_RA, Candidate_division_BRC1, Deinococcus_Thermus, TA06, TM6)
# step 3: generation of MEAN values
F2_SoilPhyla_RA_mean <- apply(F2_SoilPhyla_RA, 1, mean)
F2_SoilPhyla_RA_mean <- sort(F2_SoilPhyla_RA_mean, dec=T)
lbls_F2_Soil <- paste(names(F2_SoilPhyla_RA_mean), "\n", F2_SoilPhyla_RA_mean, sep="")
# pdf("suppFigure_4b_799F2_Soil.pdf", width=4, height=4)
pie(F2_SoilPhyla_RA_mean, labels = lbls_F2_Soil, col=rainbow(length(lbls_F2_Soil)), main="Supplementary Figure 4b / Soil 799F2")
# dev.off()
lbls_F2_Soil
### ROOT samples / 799F2 PCR primer
# selection of samples (all root samples, Cologne soil, 799F2 primer)
F2sc_ROOTsamples <- rownames(design)[(design$Primer == "799F2") & (design$Site == "Cologne") & (design$Compartment == "Root")]
dat_norm_F2_root <- dat_norm_no2[,F2sc_ROOTsamples]
dat_norm_F2_root <- dat_norm_F2_root[rowSums(dat_norm_F2_root) > 0,]
dim(dat_norm_F2_root)
ROOTotus_779F2 <- rownames(dat_norm_F2_root)
### extraction of the SILVA taxonomy for ROOTotus_779F2
SILVA_F2_root_t <- table(SILVA_tax[ROOTotus_779F2, 2])
SILVA_F2_root_t <- sort(SILVA_F2_root_t[which(SILVA_F2_root_t !=0)], dec=T)
SILVA_F2_root_t
### 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(SILVA_F2_root_t)[1:22]
# step 2: preparation of "Phylum-RA matrix"
y <- c()
otunames <- rownames(dat_norm_F2_root)
for (i in Phylum){
x <- colSums(dat_norm_F2_root[otunames
[otunames %in%
rownames(SILVA_tax)[which(SILVA_tax$Phylum == paste(i))] ],])
y <- rbind(y,x)
}
rownames(y) <- paste(Phylum)
F2_RootPhyla_RA <- y
F2_RootPhyla_RA
# RA values of single OTUs are appended here
Caldiserica <- dat_norm_F2_root[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Caldiserica")] ], ]
Candidate_division_BRC1 <- dat_norm_F2_root[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Candidate division BRC1")] ], ]
Euryarchaeota <- dat_norm_F2_root[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Euryarchaeota")] ], ]
Elusimicrobia <- dat_norm_F2_root[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Elusimicrobia")] ], ]
F2_RootPhyla_RA <- rbind(F2_RootPhyla_RA, Caldiserica, Candidate_division_BRC1, Euryarchaeota, Elusimicrobia)
# step 3: generation of MEAN values
F2_RootPhyla_RA_mean <- apply(F2_RootPhyla_RA, 1, mean)
F2_RootPhyla_RA_mean <- sort(F2_RootPhyla_RA_mean, dec=T)
lbls_F2_root <- paste(names(F2_RootPhyla_RA_mean), "\n", F2_RootPhyla_RA_mean, sep="")
# pdf("suppFigure_4b_799F2_Root.pdf", width=4, height=4)
pie(F2_RootPhyla_RA_mean, labels = lbls_F2_root, col=rainbow(length(lbls_F2_root)), main="Supplementary Figure 4b / Root 799F2")
# dev.off()
lbls_F2_root
### SOIL samples / 799F PCR primer
# selection of samples (all Soil samples, Cologne soil, 799F primer)
F_SOILsamples <- rownames(design)[which(design$Compartment == "Soil" & design$Primer == "799F")]
dat_norm_F_soil <- dat_norm_no2[,F_SOILsamples]
dat_norm_F_soil <- dat_norm_F_soil[rowSums(dat_norm_F_soil) > 0,]
dim(dat_norm_F_soil)
SOILotus_799F <- rownames(dat_norm_F_soil)
### extraction of the SILVA taxonomy for SOILotus_799F
SILVA_F_soil_t <- table(SILVA_tax[SOILotus_799F, 2])
SILVA_F_soil_t <- sort(SILVA_F_soil_t[which(SILVA_F_soil_t !=0)], dec=T)
SILVA_F_soil_t
### 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(SILVA_F_soil_t)[1:22]
# step 2: preparation of "Phylum-RA matrix"
y <- c()
otunames <- rownames(dat_norm_F_soil)
for (i in Phylum){
x <- colSums(dat_norm_F_soil[otunames
[otunames %in%
rownames(SILVA_tax)[which(SILVA_tax$Phylum == paste(i))] ],])
y <- rbind(y,x)
}
rownames(y) <- paste(Phylum)
F_SoilPhyla_RA <- y
F_SoilPhyla_RA
# RA values of single OTUs are appended here
Candidate_division_OP9 <- dat_norm_F_soil[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Candidate division OP9")] ], ]
Deinococcus_Thermus <- dat_norm_F_soil[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Deinococcus-Thermus")] ], ]
Candidate_division_TM7 <- dat_norm_F_soil[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Candidate division TM7")] ], ]
Tenericutes <- dat_norm_F_soil[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Tenericutes")] ], ]
F_SoilPhyla_RA <- rbind(F_SoilPhyla_RA, Candidate_division_OP9, Candidate_division_TM7, Deinococcus_Thermus, Tenericutes)
# step 3: generation of MEAN values
F_SoilPhyla_RA_mean <- apply(F_SoilPhyla_RA, 1, mean)
F_SoilPhyla_RA_mean <- sort(F_SoilPhyla_RA_mean, dec=T)
lbls_F_soil <- paste(names(F_SoilPhyla_RA_mean), "\n", F_SoilPhyla_RA_mean, sep="")
# pdf("suppFigure_4b_799F_soil.pdf")
pie(F_SoilPhyla_RA_mean, labels = lbls_F_soil, col=rainbow(length(lbls_F_soil)), main="Supplementary Figure 4b / Soil 799F")
# dev.off()
lbls_F_soil
### ROOT samples / 799F PCR primer
# selection of samples (all Root samples, Cologne soil, 799F primer)
F_ROOTsamples <- rownames(design)[which(design$Compartment == "Root" & design$Primer == "799F")]
dat_norm_F_root <- dat_norm_no2[,F_ROOTsamples]
dat_norm_F_root <- dat_norm_F_root[rowSums(dat_norm_F_root) > 0,]
dim(dat_norm_F_root)
ROOTotus_799F <- rownames(dat_norm_F_root)
### extraction of the SILVA taxonomy for ROOTotus_799F
SILVA_F_root_t <- table(SILVA_tax[ROOTotus_799F, 2])
SILVA_F_root_t <- sort(SILVA_F_root_t[which(SILVA_F_root_t !=0)], dec=T)
SILVA_F_root_t
### 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(SILVA_F_root_t)[1:12]
# step 2: preparation of "Phylum-RA matrix"
y <- c()
otunames <- rownames(dat_norm_F_root)
for (i in Phylum){
x <- colSums(dat_norm_F_root[otunames
[otunames %in%
rownames(SILVA_tax)[which(SILVA_tax$Phylum == paste(i))] ],])
y <- rbind(y,x)
}
rownames(y) <- paste(Phylum)
F_RootPhyla_RA <- y
F_RootPhyla_RA
# RA values of single OTUs are appended here
Chlorobi <- dat_norm_F_root[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Chlorobi")] ], ]
Deinococcus_Thermus <- dat_norm_F_root[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Deinococcus-Thermus")] ], ]
Fibrobacteres <- dat_norm_F_root[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Fibrobacteres")] ], ]
WCHB1_60 <- dat_norm_F_root[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "WCHB1-60")] ], ]
F_RootPhyla_RA <- rbind(F_RootPhyla_RA, Chlorobi, Deinococcus_Thermus, Fibrobacteres, WCHB1_60)
# step 3: generation of MEAN values
F_RootPhyla_RA_mean <- apply(F_RootPhyla_RA, 1, mean)
F_RootPhyla_RA_mean <- sort(F_RootPhyla_RA_mean, dec=T)
lbls_F_root <- paste(names(F_RootPhyla_RA_mean), "\n", F_RootPhyla_RA_mean, sep="")
# pdf("suppFigure_4b_799F_root.pdf")
pie(F_RootPhyla_RA_mean, labels = lbls_F_root, col=rainbow(length(lbls_F_root)), main="Supplementary Figure 4b / root 799F")
# dev.off()
#############################################################
### Supplementary Figure 4c (Venn diagrams)
#############################################################
# analysis based on root and soil samples from Cologne soil generated with 799F2 primer
# subsets defined above: F2sc_ROOTsamples, F2sc_SOILsamples, F_SOILsamples, F_ROOTsamples
dat_raw_2_scF2 <- dat_raw_2[,c(F2sc_ROOTsamples, F2sc_SOILsamples)]  #"_scF2" for subset Cologne, 799F2 primer
dim(dat_raw_2_scF2)
dat_raw_2_sF <- dat_raw_2[,c(F_SOILsamples, F_ROOTsamples)]          #"_sF" for subset 799F primer
dim(dat_raw_2_sF)
### Data preprocessing to identify dominant OTUs (above 5/1000 threshold)
# normalization by sample size and transformation in "/1000"
dat_norm_F <- t(t(dat_raw_2_sF)/colSums(dat_raw_2_sF)) * 1000
dat_norm2_F <- dat_norm_F[rowSums(dat_norm_F) > 0,]    # remove rows having a sum count = 0
allOTUs_799F <- rownames(dat_norm2_F)                  # definition of all OTUs detected (no threshold) with 799F
dat_norm_F2 <- t(t(dat_raw_2_scF2)/colSums(dat_raw_2_scF2)) * 1000
# application of threshold for lower presence limit of relative abundance
threshold <- 5  # 0.5% presence: use integer 5 considering x1000 normalization
dat_thres_F <- dat_norm_F[ apply(dat_norm_F,1,max) > threshold, ]
dim(dat_thres_F)
dominantOTUs_799F <- rownames(dat_thres_F)
dat_thres_F2 <- dat_norm_F2[ apply(dat_norm_F2,1,max) > threshold, ]
dim(dat_thres_F2)
dominantOTUs_sc799F2 <- rownames(dat_thres_F2)
### Detection of dominant OTUs (799F) among dominant OTUs (799F2)
# pdf("suppFigure_14c_1_dominantOTUs.pdf")
List = venndiagram(x = dominantOTUs_sc799F2, y = dominantOTUs_799F,
unique = T, title = "Detection of dominant OTUs (799F) among dominant OTUs (799F2)",
labels=c("dominantOTUs_sc799F2", "dominantOTUs_799F"), lines=c(2,3), lcol=c(2,3), tcol = 1, lwd=3, cex=1, printsub=T, type ="2")
# dev.off()
### Detection of all (no threshold) OTUs (799F) among dominant OTUs (799F2)
# pdf("suppFigure_14c_2_allOTUs.pdf")
List = venndiagram(x = dominantOTUs_sc799F2, y = allOTUs_799F,
unique = T, title = "Detection of all OTUs (799F) among dominant OTUs (799F2)",
labels=c("dominantOTUs_sc799F2", "allOTUs_799F"), lines=c(2,3), lcol=c(2,3), tcol = 1, lwd=3, cex=1, printsub=T, type ="2")
# dev.off()
commonOTUs <- List$q1
#############################################################
### Supplementary Figure 4d (correlation plot with RA)
#############################################################
### plotting RA values (log2 transformed for scale)
dat_log_F <- log2(dat_norm_F +1)
dat_log_F2 <- log2(dat_norm_F2 +1)
# generation of mean values (soil and root)
dat_log_F_mean <- apply(dat_log_F, 1, mean)
dat_log_F2_mean <- apply(dat_log_F2, 1, mean)
### Definition of color code per bacterial Phyla for every OTU
# random (rainbow) colors for Phyla names in taxonomy file
PHYLAnames <- names(table(SILVA_tax[,2]))
PHYLAcols <- as.character(SILVA_tax[,2])
names(PHYLAcols) <- rownames(SILVA_tax)
for(i in 1:length(PHYLAnames)){PHYLAcols[SILVA_tax[,2] == PHYLAnames[i]] <- rainbow(100)[i]
}
length(PHYLAcols)
### Using defined colors for particulate Phyla
# Chloroflexis "OTU2/9...) mit "#FFF500FF"
PHYLAcols[names(PHYLAcols)[PHYLAcols == "#FFF500FF"]] <- "black"
# Actinobacteria "OTU5...) mit "#FF0F00FF"
PHYLAcols[names(PHYLAcols)[PHYLAcols == "#FF0F00FF"]] <- "deeppink3"
# Proteobacteria "OTU4...) mit "#00FF29FF"
PHYLAcols[names(PHYLAcols)[PHYLAcols == "#00FF29FF"]] <- "chartreuse3"
# Nitrospirae "OTU7...) mit "#00FF0AFF"
PHYLAcols[names(PHYLAcols)[PHYLAcols == "#00FF0AFF"]] <- "firebrick2"
# Bacteroidetes "OTU12...) mit "#FF4D00FF"
PHYLAcols[names(PHYLAcols)[PHYLAcols == "#FF4D00FF"]] <- "dodgerblue1"
### plotting colored figure
# pdf("suppfigure_14d.pdf", width=7, height=7)
plot(y=dat_log_F_mean[commonOTUs], x=dat_log_F2_mean[commonOTUs], pch = 19, cex=2, ylab="799F primer", xlab="799F2 primer", main="Supplementary Figure 4d / common OTUs", col=PHYLAcols[commonOTUs])
# dev.off()
cor(dat_log_F_mean[commonOTUs], dat_log_F2_mean[commonOTUs], method = "spearman")
#############################################################
### Supplementary Figure 4e (correlation plot with enrichement)
#############################################################
# removal 0-count OTUs with "application of threshold"
threshold <- 0  # 0.5% presence: use integer 5 considering x1000 normalization
dat_thres_F <- dat_norm_F[ apply(dat_norm_F,1,max) > threshold, ]
dat_thres_F2 <- dat_norm_F2[ apply(dat_norm_F2,1,max) > threshold, ]
### plotting RA values (log2 transformed for scale)
dat_log_F <- log2(dat_thres_F +1)
dat_log_F2 <- log2(dat_thres_F2 +1)
# enrichement (root RA vs. soil RA) calculated via limma
### Subset 799F
# preparation of eset format
eset_F <- new("ExpressionSet")
exprs(eset_F) <- dat_log_F[,c(F_SOILsamples, F_ROOTsamples)]
pData(eset_F) <- design[c(F_SOILsamples, F_ROOTsamples),]
# LIMMA stats: Compartment
sample_F <- as.vector(pData(eset_F)$Compartment)
model_F <- model.matrix(~0 + sample_F)
colnames(model_F) <- make.names(colnames(model_F))
fit_F <- lmFit(eset_F, model_F)
# Make contrasts: root against soil
cont_matrix_F <- makeContrasts(sample_FRoot-sample_FSoil, levels=model_F)
fit2_F <- contrasts.fit(fit_F, cont_matrix_F)
fit2_F <- eBayes(fit2_F)
tab_F <- topTable(fit2_F, n=dim(exprs(eset_F))[1], adjust="fdr")
rownames(tab_F) <- tab_F$ID
### Subset 799F2
# preparation of eset format
eset_F2 <- new("ExpressionSet")
exprs(eset_F2) <- dat_log_F2[,c(F2sc_SOILsamples, F2sc_ROOTsamples)]
pData(eset_F2) <- design[c(F2sc_SOILsamples, F2sc_ROOTsamples),]
# LIMMA stats: Compartment
sample_F2 <- as.vector(pData(eset_F2)$Compartment)
model_F2 <- model.matrix(~0 + sample_F2)
colnames(model_F2) <- make.names(colnames(model_F2))
fit_F2 <- lmFit(eset_F2, model_F2)
# Make contrasts: root against soil
cont.matrix_F2 <- makeContrasts(sample_F2Root-sample_F2Soil, levels=model_F2)
fit2_F2 <- contrasts.fit(fit_F2, cont.matrix_F2)
fit2_F2 <- eBayes(fit2_F2)
tab_F2 <- topTable(fit2_F2, n=dim(exprs(eset_F2))[1], adjust="fdr")
rownames(tab_F2) <- tab_F2$ID
### correlation plot with enrichemnts (logFC in topTable objects)
# pdf("suppFigure_14e.pdf", width=7, height=7)
plot(y=tab_F[commonOTUs,2], x=tab_F2[commonOTUs,2], xlab="799F2 primer", ylab="799F primer", main="intersect OTUs with 1p1000 noC", pch=19, cex=2, col = PHYLAcols[commonOTUs])
# dev.off()
cor(tab_F[commonOTUs,2], tab_F2[commonOTUs,2], method="spearman")
#############################################################
### Supplementary Figure 4f (taxonomy pies, Chloroflexi depleted)
#############################################################
# preparation for DEPLETION of Chloroflexi
noChloro <- rownames(SILVA_tax)[which(SILVA_tax$Phylum != "Chloroflexi")]
noChloro <- noChloro[noChloro %in% rownames(dat_raw_2)]
length(noChloro)
### Chloroflexi depletion
dat_raw_2_noC <- dat_raw_2[noChloro,]
# removing of singletons and doubletons
dat_raw_2_noC_no2 <- dat_raw_2_noC
dat_raw_2_noC_no2[dat_raw_2_noC_no2 <= 2 ] = 0
dat_raw_2_noC_no2 <- dat_raw_2_noC_no2[rowSums(dat_raw_2_noC_no2) > 0,]   # remove rows having a sum count = 0
# normalization by sample size and transformation in "/1000"
dat_norm_noC_no2 <- t(t(dat_raw_2_noC_no2)/colSums(dat_raw_2_noC_no2)) * 1000
dim(dat_norm_noC_no2)
### SOIL samples / 799F2 PCR primer / no Chloroflexi
#############################################################
# selection of samples (all Soil samples, Cologne soil, 799F2 primer)
dat_norm_F2_noC_soil <- dat_norm_noC_no2[,F2sc_SOILsamples]
dat_norm_F2_noC_soil <- dat_norm_F2_noC_soil[rowSums(dat_norm_F2_noC_soil) > 0,]
dim(dat_norm_F2_noC_soil)
SOILotus_noC_799F2 <- rownames(dat_norm_F2_noC_soil)
### extraction of the SILVA taxonomy for SOILotus_799F2
SILVA_F2_soil_noC_t <- table(SILVA_tax[SOILotus_noC_799F2, 2])
SILVA_F2_soil_noC_t <- sort(SILVA_F2_soil_noC_t[which(SILVA_F2_soil_noC_t !=0)], dec=T)
SILVA_F2_soil_noC_t
### 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(SILVA_F2_soil_noC_t)[1:20] # note, downstream function "colSums" requires at minimum 2 OTUs, single OTUs are appended later)
# step 2: preparation of "Phylum-RA matrix"
y <- c()
otunames <- rownames(dat_norm_F2_noC_soil)
for (i in Phylum){
x <- colSums(dat_norm_F2_noC_soil[otunames
[otunames %in%
rownames(SILVA_tax)[which(SILVA_tax$Phylum == paste(i))] ],])
y <- rbind(y,x)
}
rownames(y) <- paste(Phylum)
F2_SoilPhyla_noC_RA <- y
F2_SoilPhyla_noC_RA
# RA values of single OTUs are appended here
Candidate_division_BRC1 <- dat_norm_F2_noC_soil[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Candidate division BRC1")] ], ]
Deinococcus_Thermus <- dat_norm_F2_noC_soil[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Deinococcus-Thermus")] ], ]
TA06 <- dat_norm_F2_noC_soil[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "TA06")] ], ]
TM6 <- dat_norm_F2_noC_soil[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "TM6")] ], ]
F2_SoilPhyla_noC_RA <- rbind(F2_SoilPhyla_noC_RA, Candidate_division_BRC1, Deinococcus_Thermus, TA06, TM6)
# step 3: generation of MEAN values
F2_SoilPhyla_noC_RA_mean <- apply(F2_SoilPhyla_noC_RA, 1, mean)
F2_SoilPhyla_noC_RA_mean <- sort(F2_SoilPhyla_noC_RA_mean, dec=T)
lbls_F2_noC_Soil <- paste(names(F2_SoilPhyla_noC_RA_mean), "\n", F2_SoilPhyla_noC_RA_mean, sep="")
# pdf("suppFigure_4f_Soil.pdf", width=4, height=4)
pie(F2_SoilPhyla_noC_RA_mean, labels = lbls_F2_noC_Soil, col=rainbow(length(lbls_F2_noC_Soil)), main="Supplementary Figure 4f / Soil 799F2 (no Chloroflexi")
# dev.off()
lbls_F2_noC_Soil
### ROOT samples / 799F2 PCR primer / no Chloroflexi
#############################################################
# selection of samples (all root samples, Cologne soil, 799F2 primer)
dat_norm_F2_noC_root <- dat_norm_noC_no2[,F2sc_ROOTsamples]
dat_norm_F2_noC_root <- dat_norm_F2_noC_root[rowSums(dat_norm_F2_noC_root) > 0,]
dim(dat_norm_F2_noC_root)
ROOTotus_noC_779F2 <- rownames(dat_norm_F2_noC_root)
### extraction of the SILVA taxonomy for ROOTotus_779F2
SILVA_F2_root_noC_t <- table(SILVA_tax[ROOTotus_noC_779F2, 2])
SILVA_F2_root_noC_t <- sort(SILVA_F2_root_noC_t[which(SILVA_F2_root_noC_t !=0)], dec=T)
SILVA_F2_root_noC_t
### 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(SILVA_F2_root_noC_t)[1:21]
# step 2: preparation of "Phylum-RA matrix"
y <- c()
otunames <- rownames(dat_norm_F2_noC_root)
for (i in Phylum){
x <- colSums(dat_norm_F2_noC_root[otunames
[otunames %in%
rownames(SILVA_tax)[which(SILVA_tax$Phylum == paste(i))] ],])
y <- rbind(y,x)
}
rownames(y) <- paste(Phylum)
F2_RootPhyla_noC_RA <- y
F2_RootPhyla_noC_RA
# RA values of single OTUs are appended here
Caldiserica <- dat_norm_F2_noC_root[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Caldiserica")] ], ]
Candidate_division_BRC1 <- dat_norm_F2_noC_root[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Candidate division BRC1")] ], ]
Euryarchaeota <- dat_norm_F2_noC_root[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Euryarchaeota")] ], ]
Elusimicrobia <- dat_norm_F2_noC_root[otunames[otunames %in% rownames(SILVA_tax)[which(SILVA_tax$Phylum == "Elusimicrobia")] ], ]
F2_RootPhyla_noC_RA <- rbind(F2_RootPhyla_noC_RA, Caldiserica, Candidate_division_BRC1, Euryarchaeota, Elusimicrobia)
# step 3: generation of MEAN values
F2_RootPhyla_RA_noC_mean <- apply(F2_RootPhyla_noC_RA, 1, mean)
F2_RootPhyla_RA_noC_mean <- sort(F2_RootPhyla_RA_noC_mean, dec=T)
lbls_F2_noC_root <- paste(names(F2_RootPhyla_RA_noC_mean), "\n", F2_RootPhyla_RA_noC_mean, sep="")
# pdf("suppFigure_14f_799F2_Root_noChloroflexi.pdf", width=4, height=4)
pie(F2_RootPhyla_RA_noC_mean, labels = lbls_F2_noC_root, col=rainbow(length(lbls_F2_noC_root)), main="Supplementary Figure 4b / Root 799F2")
# dev.off()
lbls_F2_noC_root
#############################################################
### Supplementary Figure 4g
#############################################################
# analysis based on root and soil samples from Cologne soil generated with 799F2 primer
# subsets defined above: F2sc_ROOTsamples, F2sc_SOILsamples, F_SOILsamples, F_ROOTsamples
dat_raw_2_noC_scF2 <- dat_raw_2_noC[,c(F2sc_ROOTsamples, F2sc_SOILsamples)]  #"_scF2" for subset Cologne, 799F2 primer
dim(dat_raw_2_noC_scF2)
dat_raw_2_noC_sF <- dat_raw_2_noC[,c(F_SOILsamples, F_ROOTsamples)]          #"_sF" for subset 799F primer
dim(dat_raw_2_noC_sF)
### Data preprocessing to identify dominant OTUs (above 5/1000 threshold)
# normalization by sample size and transformation in "/1000"
dat_norm_noC_F <- t(t(dat_raw_2_noC_sF)/colSums(dat_raw_2_noC_sF)) * 1000
dat_norm_noC2_F <- dat_norm_noC_F[rowSums(dat_norm_noC_F) > 0,]    # remove rows having a sum count = 0
allOTUs_noC_799F <- rownames(dat_norm_noC2_F)                  # definition of all OTUs detected (no threshold) with 799F
dat_norm_noC_F2 <- t(t(dat_raw_2_noC_scF2)/colSums(dat_raw_2_noC_scF2)) * 1000
# application of threshold for lower presence limit of relative abundance
threshold <- 5  # 0.5% presence: use integer 5 considering x1000 normalization
dat_thres_noC_F2 <- dat_norm_noC_F2[ apply(dat_norm_noC_F2,1,max) > threshold, ]
dim(dat_thres_noC_F2)
dominantOTUs_noC_sc799F2 <- rownames(dat_thres_noC_F2)
### Detection of all (no threshold) OTUs (799F) among dominant OTUs (799F2)
List_noC = venndiagram(x = dominantOTUs_noC_sc799F2, y = allOTUs_noC_799F,
unique = T, title = "Detection of all OTUs (799F) among dominant OTUs (799F2) / noC",
labels=c("dominantOTUs_noC_sc799F2", "allOTUs_noC_799F"), lines=c(2,3), lcol=c(2,3), tcol = 1, lwd=3, cex=1, printsub=T, type ="2")
# dev.off()
commonOTUs_noC <- List_noC$q1
### correlation plot with RA
dat_log_noC_F <- log2(dat_norm_noC_F +1)
dat_log_noC_F2 <- log2(dat_norm_noC_F2 +1)
# generation of mean values (soil and root)
dat_log_noC_F_mean <- apply(dat_log_noC_F, 1, mean)
dat_log_noC_F2_mean <- apply(dat_log_noC_F2, 1, mean)
### plotting colored figure
# pdf("suppfigure_14g.pdf", width=7, height=7)
plot(y=dat_log_noC_F_mean[commonOTUs_noC], x=dat_log_noC_F2_mean[commonOTUs_noC], pch = 19, cex=2, ylab="799F primer", xlab="799F2 primer", main="Supplementary Figure 4g / common OTUs / no Chloroflexi", col=PHYLAcols[commonOTUs_noC])
# dev.off()
cor(dat_log_noC_F_mean[commonOTUs_noC], dat_log_noC_F2_mean[commonOTUs_noC], method = "spearman")
