We generated a RNA-sequencing dataset using human primary vascular
muscle cells from various male and female donors (cultivated in growth
media, without any additional treatment). Cells were synchronized using
medium without any additive before harvesting.
We aimed here to…
#### Required packages
# DEA
library(DESeq2)
library(edgeR)
# annotation
library(biomaRt)
# GO
# library(ViSEAGO); library(data.table)
# library(GOSemSim)
# library(dynamicTreeCut); library(dendextend)
library(gprofiler2)
# graphic
library(ggpubr)
library(RColorBrewer)
library(pheatmap)
library(gridExtra)
library(VennDiagram)
# other
library(dplyr)
library(mgsub)
#### Data saving
## Where to save the data?
outputDir = ("Output_SexDiff/")
mkdirCall = paste("mkdir ", outputDir, sep=""); system(mkdirCall, intern=F, ignore.stdout = F, ignore.stderr = F, wait=T)
#### Data loading
# sample information
sampleTable = read.csv("inputFiles/sampleTable_genderDiff-final.csv", header=T)
rownames(sampleTable) = sampleTable$sampleName
# Raw counts
counts = read.csv("inputFiles/counts_genderDiff-final.csv", header=T, stringsAsFactors = F, row.names = 1)
# Data annotation
load("Data_biomaRt_v109.RData")
### Match sample information and raw counts
counts.f = counts[,which(names(counts) %in% rownames(sampleTable))]
counts.f = counts.f[,order(colnames(counts.f))]
### STOP! before anything, we need to check if sample table and count matrix are fitting
#all(rownames(sampleTable) == colnames(counts.f))
### How many replicates are included here?
table(sampleTable$condition, sampleTable$Donors)##
## AS1F AS2F AS2M AS3M AS4M CS1F CS3F CS5M
## Female 8 4 0 0 0 10 5 0
## Male 0 0 3 3 3 0 0 6
#### Functions
# Population standard deviation
sdpop = function(x){
sqrt(mean((x-mean(x))^2))
}
# 99% confidence interval
CIpop = function(x){
z = qnorm(0.005)
s = sdpop(as.numeric(x))
n = length(x)
abs(z*s/sqrt(n))
}Formatting of donor names:
Vessel origin (A for aortic, C for coronary) + cell type (S for SMC) + number + sex
e.g. “AS1F” corresponds to aortic smooth muscle cells from the female donor n°1
Before performing differential expression analysis, exploratory
analysis is performed to identify (i) potential outliers within the
dataset, and (ii) putative counfounders and major causes of variability
(e.g. donor-origin, replicate).
The data are prepared for visualization using functions integrated in
DESeq2 package.
vst function)### Create summarizedExperiment
dds <- DESeqDataSetFromMatrix(countData = counts.f,
colData = sampleTable,
design = ~ condition)
### Pre-filtering
# How many genes are included?
nb = nrow(dds)
# remove the samples that do not have at least one normalized count in at least a quarter of the samples
dds <- estimateSizeFactors(dds)
idx <- rowSums( counts(dds, normalized=TRUE) >= 1 ) >= nrow(sampleTable)/4
dds <- dds[idx,]
### Creation of DESeq2 object
dds.f <- DESeq(dds)
### vst transformation (varianceStabilizingTransformation)
vst <- vst(dds.f, blind=F)
vst.df <- assay(vst)Euclidean distances in between the samples are calculated.
### sample-to-sample distance
sampleDists = dist(t(vst.df)); sampleDistMatrix = as.matrix(sampleDists)
rownames(sampleDistMatrix) = vst$Donors
colnames(sampleDistMatrix) = NULL
pheatmap(sampleDistMatrix, col = colorRampPalette(rev(brewer.pal(9,"Blues")))(255),
clustering_distance_cols = sampleDists,
clustering_distance_rows = sampleDists,fontsize_row = 7)Principal component analysis is performed using DESeq2 function
plotPCA.
### PCA
## Calculation
PCA_info = c("sampleName", "Donors", "condition", "replicate")
data <- plotPCA(vst, intgroup=PCA_info, returnData=TRUE)
percentVar <- round(100 * attr(data, "percentVar"))
## visualization
data$Donors = as.factor(data$Donors)
g = ggscatter(data, x = "PC1", y = "PC2",
color = "condition", shape = "Donors", palette = c( "#CD534CFF","#0073C2FF"),
ellipse = T, ellipse.type = "t", ellipse.level = 0.95)
g = g + theme_bw() + rremove("grid")
g = ggpar(g, xlab = paste("PC1: ",percentVar[1],"% variance"), ylab = paste("PC2: ",percentVar[2],"% variance"),
font.tickslab = c(14), font.y = c(14), font.x = c(14), font.legend = c(12))
g2 = ggscatter(data, x = "PC1", y = "PC2",
color = "replicate", shape = "Donors", palette = rev(brewer.pal(length(unique(data$replicate)),"Spectral")))
g2 = g2 + theme_bw() + rremove("grid")
g2 = ggpar(g2, xlab = paste("PC1: ",percentVar[1],"% variance"), ylab = paste("PC2: ",percentVar[2],"% variance"),
font.tickslab = c(14), font.y = c(14), font.x = c(14), font.legend = c(12))
k = ggarrange(g, NULL, g2,
widths = c(1,0.1,1),
ncol = 3, nrow =1, align = "hv")
kThis first step of the analysis shows a strong influence on the data of the sex of the donors (see PCA) but also of the donor itself (see PCA, as well as the sample-to-sample distance heatmap and its donor-wise clustering of the samples).
Differential expression analysis is performed in order to identify
genes that are differentially expressed in male and female cells, under
basal conditions. The analysis is performed with (i) DESeq2 and (ii)
edgeR, and (iii) their output (filtered for FDR 0.05) are
compared.
Standard analysis pipelines are both applied for DESeq2 and edgeR
(according to the vignettes of the respective packages).
cond.f = "condition" # column where contrast values are stored
control = "Male" # Condition used as reference
treatment = "Female" # Condition to compare
# to which samples to they correspond ?
control.samples = sampleTable$sampleName[sampleTable$condition == control]
treatment.samples = sampleTable$sampleName[sampleTable$condition == treatment]The full list of genes (without pre-filtering like in previous
section) is considered for the analysis with DESeq2. However,
independent filtering option of the function
results is set as TRUE. Shortly explained: this option
removes very lowly expressed genes that have an effect on multiple
testing adjustment and distort the results of the DEA.
results then comprises the estimation of the size factors
and dispersion, and the statistical testing (negative binomial GLM
fitting and Wald test).
### Create summarizedExperiment
dds <- DESeqDataSetFromMatrix(countData = counts.f,
colData = sampleTable,
design = ~ condition)
### Creation of DESeq2 object
dds.f <- DESeq(dds)
### Contrast setting
contrast.dds=c(cond.f,treatment,control)
### Generation of the results
res = results(dds.f, pAdjustMethod= "BH", contrast = contrast.dds, independentFiltering = T, alpha = 0.05)
print(paste("Number of kept genes:", sum(!is.na(res$padj)) ))## [1] "Number of kept genes: 26939"
### Annotation of the results
res.anno = cbind(res, bm[match (rownames(res), bm$ensembl_gene_id), c("ensembl_gene_id", "entrezgene_id", "external_gene_name", "gene_biotype", "chromosome_name", "start_position", "end_position", "strand","description") ])
res.anno = as.data.frame(res.anno)
### Filtering of the results
res.anno_DESeq2_unfiltered = res.anno
res.anno_DESeq2 = subset(res.anno, padj <= 0.05)
### Results summary
df = data.frame(control, treatment, nrow(res.anno_DESeq2),
nrow(res.anno_DESeq2[res.anno_DESeq2$log2FoldChange > 0,]), nrow(res.anno_DESeq2[res.anno_DESeq2$log2FoldChange < 0,]))
colnames(df) = c("control", "treatment", "DEG", "DEG_up", "DEG_down")
df$tool = "DESeq2"
res.summary = dffilterByExp of edgeR
determines automatically which genes have enough counts to be included
in the statistical analysis (sample group considered for that
step).glmQLFit and glmQLFTest are
used for dispersion calculation and statistical testing (
quasi-likelihood F-test ), respectively.### Creation of a DGEList data object
group = factor(sampleTable[,c(cond.f)])
group = relevel(group, ref = control)
dg = DGEList(counts = counts.f, group = group)
#### Filtering of the lowly expressed genes
keep = filterByExpr(dg)
dg = dg[keep, , keep.lib.sizes = F]
#### Normalization between samples
dg = calcNormFactors(dg, method="TMM")
#### Dispersion estimation
design = model.matrix(~ group)
dg = estimateDisp(dg, design , robust=TRUE)
#### Get CPM
allCPM <- as.data.frame(cpm(dg, normalized.lib.sizes=TRUE))
allCPM$mean_control = apply(allCPM[,control.samples],1, mean); allCPM$sd_control = apply(allCPM[,control.samples],1, sdpop)
allCPM$mean_treatment = apply(allCPM[,treatment.samples],1, mean); allCPM$sd_treatment = apply(allCPM[,treatment.samples],1, sdpop)
allCPM$cv_control = allCPM$sd_control / allCPM$mean_control; allCPM$cv_treatment = allCPM$sd_treatment / allCPM$mean_treatment;
colnames(allCPM) = paste("FPM_", colnames(allCPM), sep = "")
allCPM$maxFPMmeans = apply(allCPM[,grep("mean", colnames(allCPM))],1, max)
### Comparison + generation of the log2FC, FDR table
fit = glmQLFit(dg, design, robust = T)
qlf = glmQLFTest(fit, coef = grep(paste(treatment, "$", sep = ""), colnames(design)))
dge.table = topTags(qlf, n=nrow(dg), adjust.method = "BH")$table
### Get a general table with the FPM + the annotation from biomaRt
id.matches = match(rownames(allCPM), rownames(dge.table))
res.anno = cbind(allCPM, dge.table$logFC[id.matches], dge.table$FDR[id.matches], bm[match (rownames(dge.table)[id.matches], bm$ensembl_gene_id), c("ensembl_gene_id", "external_gene_name", "gene_biotype","description") ])
colnames(res.anno)[c(dim(allCPM)[2]+1, dim(allCPM)[2]+2)] = c("log2FC", "FDR")
### Filtering of the results (FDR 0.05)
res.anno_edgeR_unfiltered = res.anno
res.anno_edgeR = subset(res.anno, FDR <= 0.05)
### Results summary
df = data.frame(control, treatment, nrow(res.anno_edgeR),
nrow(res.anno_edgeR[res.anno_edgeR$log2FC > 0,]), nrow(res.anno_edgeR[res.anno_edgeR$log2FC < 0,]))
colnames(df) = c("control", "treatment", "DEG", "DEG_up", "DEG_down")
df$tool = "edgeR"
res.summary = rbind(res.summary, df) The output of DESeq2 and edgeR are filtered for FDR 0.05. The lists of genes obtained are compared.
### creation of the overlap
o = inner_join(res.anno_DESeq2, res.anno_edgeR, by ="ensembl_gene_id", suffix = c(".deseq2", ".edger"))
colnames(o)[colnames(o) == "log2FoldChange"] = "log2FC.deseq"
colnames(o)[colnames(o) == "log2FC"] = "log2FC.edge"
rownames(o) = o$ensembl_gene_id
### get summary
df = data.frame(control, treatment, nrow(o), nrow(o[o$log2FC.deseq > 0,]), nrow(o[o$log2FC.deseq < 0,]))
colnames(df) = c("control", "treatment", "DEG", "DEG_up", "DEG_down")
df$tool = "overlap"
res.summary = rbind(res.summary, df)
print("Numbers of DEG (total, up and down) per tool: ")## [1] "Numbers of DEG (total, up and down) per tool: "
## control treatment DEG DEG_up DEG_down tool
## 1 Male Female 8878 4466 4412 DESeq2
## 2 Male Female 7785 3529 4256 edgeR
## 3 Male Female 7321 3474 3847 overlap
###### Visualization
### Overlap - Venn diagram
grid.newpage()
v = draw.pairwise.venn(nrow(res.anno_DESeq2), nrow(res.anno_edgeR), nrow(o),
category = c("DESeq2", "EdgeR"),
cat.cex = rep(0.8,2), cat.dist = rep(0.04,2), cat.pos = c(0,2),
lwd = rep(1, 2), lty = rep("solid", 2), cop = rep("black", 2), fill = c("grey80", "grey60"),
scaled = F, ind=F, alpha = 0.5)
### Are the log2FC calculated by both tools correlated?
minAxis = round(head(sort(c(min(o$log2FC.edge), min(o$log2FC.deseq))),1))
maxAxis = round(head(sort(c(max(o$log2FC.edge), max(o$log2FC.deseq))),1))
g = ggscatter(o, x="log2FC.edge", y="log2FC.deseq",
add = "reg.line", conf.int=T, add.params = list(color="black"),
xlab = paste("log2 fold change by edgeR"), ylab= paste("log2 fold change by DESeq2"))
g = g + stat_cor(method="pearson", label.x = minAxis , label.y = maxAxis-1, size = 3) + stat_regline_equation(label.x = minAxis , label.y = maxAxis-2.5, size = 3)
g = g + theme_bw() + rremove("grid")
g = ggpar(g, ylim = c(minAxis,maxAxis), xlim = c(minAxis,maxAxis), font.x = 11, font.y = 11, font.tickslab = 11)
### What are the genes in the overlap?
o$gene_biotype.deseq2 = as.character(o$gene_biotype.deseq2)
id = grep("pseudogene", o$gene_biotype.deseq2); o$gene_biotype.deseq2[id] = "pseudogene" # gather all subgroups of pseudogenes in one group
bio = as.data.frame(table(o$gene_biotype.deseq2)); colnames(bio) = c("biotype", "freq")
b = ggbarplot(bio, fill = "grey80", color="grey60",
x = "biotype", y = "freq", label = T, lab.size = 3, width = 0.5) + theme_bw() + rotate_x_text(angle = 90) + rremove("grid")
b = ggpar(b, xlab = "", ylab = "Counts",
font.y = 11, font.xtickslab = 11,
ylim = c(0, max(bio$freq)+max(bio$freq)*10/100))
k = ggarrange(v, NULL, g, NULL, b,
widths = c(1,0.1,1,0.1,1),
ncol = 5, nrow =1, align = "hv")
k(left) Overlap of the outputs of DESeq2 and edgeR (filtered for FDR 0.05 each), (middle) Correlation between the log2 fold changes calculated by DESeq2 and edgeR for the genes in the overlap, (right) Biotype of the genes comprised in the overlap.
The results for the genes in the overlap are merged in one single table, which comprise the following elements:
MF = o[,c("external_gene_name.deseq2", "ensembl_gene_id", "gene_biotype.deseq2", "log2FC.deseq", "lfcSE", "padj", "log2FC.edge", "FDR")]
MF$log2FC.deseq = round(MF$log2FC.deseq, digits = 2); MF$log2FC.edge = round(MF$log2FC.edge, digits = 2); MF$lfcSE = round(MF$lfcSE, digits = 2)
colnames(MF) = c("geneName", "ensembl_gene_id", "biotype", "DESeq2_LFC", "DESeq2_LFCse", "DESeq2_FDR", "edgeR_LFC", "edgeR_FDR")
# Mean FPM per experimental group
MF = cbind(MF, o[match(MF$ensembl_gene_id, o$ensembl_gene_id), c("FPM_mean_control", "FPM_mean_treatment", "maxFPMmeans")])
# add detailed FPM, sorted by group
orderConditions = c("Male", "Female"); groups_sorted = factor(unique(sampleTable$condition), levels = orderConditions)
sampleTable$sampleName = as.character(sampleTable$sampleName)
for(m in groups_sorted){
sampleList = paste0("FPM_", sampleTable$sampleName[sampleTable$condition == m])
fpm_sampleList = o[,c(sampleList, "ensembl_gene_id")]
n_columns = paste0(sampleList,"_",sampleTable[sampleTable$sampleName[sampleTable$condition == m],]$Donors, sep="")
colnames(fpm_sampleList)[1:(dim(fpm_sampleList)[2]-1)] = n_columns
MF = inner_join(MF, fpm_sampleList, by = "ensembl_gene_id")
}
## save file
fileName = paste(outputDir, "Results_DEA_MasterFile.csv", sep = ""); write.csv(MF, file=fileName, row.names = F)
Once a list of “differentially expressed genes” is obtained, additional filtering steps are commonly applied to identify the “truly” regulated ones, based on their abundance (the expression level) or/and their log2 fold change. However, the cut-off values used in these steps often remain random or based on common usage (e.g. |log2 fold change| > 1 or even 2).
Here we develop rational strategies to determine cut-off values, which exclude background signal (genes with very low expression and/or with minimal changes) while retaining small but putatively biologically relevant changes.
As mentioned in the “Differential expression analysis” section, DESeq2 and edgeR both include functions to remove extremely lowly expressed genes (i.e. either not detected or with very few raw counts). Despite this filtering, we wondered how many genes still included in the analysis actually have an expression level distinct from the background signal.
To investigate this matter, we used the FPM computed by edgeR and determined the mean expression of each gene, but also the variation of their expression throughout the sample population by calculating coefficient of variation for each gene.
\[CV = standard Deviation/mean\]
### Number of genes included in edgeR analysis
t = res.anno_edgeR_unfiltered
cat(paste0("Number of genes kept by edgeR after automatic removal of the genes with very low expression (filterByExp function): ", nrow(t), " (out of ", nrow(bm), " annotated genes)\nLevel of expression of the less expressed gene still included in the list (min(mean(FPM))): ", round(min(t$maxFPMmeans), digits = 2)))## Number of genes kept by edgeR after automatic removal of the genes with very low expression (filterByExp function): 16826 (out of 75118 annotated genes)
## Level of expression of the less expressed gene still included in the list (min(mean(FPM))): 0.3
Before pursuing any further, we wondered if the whole group of donors
included in our study here should be considered as a unique population
or if the donor-related inter-variability could influence the CV
calculations. Indeed, as pointed out in the exploratory analysis, the
variance within the data is not just explain by the sex of the donors
but also by the donor themselves. Because we do not have the same number
of replicates per donor (see “Session setting and data loading”
section), the results of the previous steps may be impacted by this
donor variability.
To test this hypothesis, we take all genes and calculate (i) their CV
when considering all donors as one group, and (ii) their CV donor-wise.
The average values obtained by both approaches are compared. This is
performed for each experimental group.
### CV per donor
#####################
df_cv_meanDonors = data.frame()
for(i in unique(sampleTable$Donors)){
# get samples correponding to one donor
cond = unique(sampleTable$condition[sampleTable$Donors == i])
sampleDonor = paste0("FPM_", sampleTable$sampleName[sampleTable$Donors == i])
# calculations of mean, sd, and RSD
t$tmp_mean = apply(t[,sampleDonor], 1, mean)
t$tmp_sd = apply(t[,sampleDonor], 1, sdpop)
t$tmp_cv = t$tmp_sd / t$tmp_mean
# get table
tmp = data.frame(i, cond, round(mean(t[!is.na(t$tmp_cv),]$tmp_cv), digits = 2))
df_cv_meanDonors = rbind(df_cv_meanDonors, tmp)
colnames(t)[(ncol(t)-2):ncol(t)] = c(paste0("FPM_mean_", cond, "_", i), paste0("FPM_sd_", cond, "_", i), paste0("FPM_cv_", cond, "_", i))
}
colnames(df_cv_meanDonors) = c("Donor", "Condition", "mean CV")
# get mean RSD per experimental group
t$tmp_mean = apply(t[,grepl(paste0("FPM_cv_", control), colnames(t))], 1, mean); colnames(t)[ncol(t)] = "FPM_cv_control_meanDonors"
t$tmp_mean = apply(t[,grepl(paste0("FPM_cv_", treatment), colnames(t))], 1, mean); colnames(t)[ncol(t)] = "FPM_cv_treatment_meanDonors"
df_cv_meanDonors = rbind(df_cv_meanDonors, list("mean CV individual donors", "Male",
round(mean(t[!is.na(t$FPM_cv_control_meanDonors),]$FPM_cv_control_meanDonors), digits = 2)),
list("mean CV individual donors", "Female",
round(mean(t[!is.na(t$FPM_cv_treatment_meanDonors),]$FPM_cv_treatment_meanDonors), digits = 2)))
df_cv_meanDonors = rbind(df_cv_meanDonors, list("CV all together", "Male", round(mean(t[!is.na(t$FPM_cv_control),]$FPM_cv_control), digits = 2)),
list("CV all together", "Female", round(mean(t[!is.na(t$FPM_cv_treatment),]$FPM_cv_treatment), digits = 2)))
### Summary table
# female
tab1 = ggtexttable(df_cv_meanDonors[df_cv_meanDonors$Condition == "Female",],theme = ttheme("classic", colnames.style = colnames_style(size = 9, fill = "white")), rows = NULL)
tab1 = table_cell_font(tab1, row = 2:tab_nrow(tab1), column = 1:tab_ncol(tab1), size = 9)
tab1 = table_cell_font(tab1, row = (tab_nrow(tab1)-1):tab_nrow(tab1), column = 1:tab_ncol(tab1), size = 9, face = "bold")
# male
tab2 = ggtexttable(df_cv_meanDonors[df_cv_meanDonors$Condition == "Male",],theme = ttheme("classic", colnames.style = colnames_style(size = 9, fill = "white")), rows = NULL)
tab2 = table_cell_font(tab2, row = 2:tab_nrow(tab2), column = 1:tab_ncol(tab2), size = 9)
tab2 = table_cell_font(tab2, row = (tab_nrow(tab2)-1):tab_nrow(tab2), column = 1:tab_ncol(tab2), size = 9, face = "bold")
tab = ggarrange(tab1, tab2, ncol = 2, nrow = 1)
tabThe results show that the ignoring the donor-dependent variability leads to an overestimation of the gene expression variability, independently of the experimental group (comparison of the last two lines of each table). The CV based on group-wise information is therefore used in further steps. (i.e. here, 0.25-0.26)
To explore the abundance filtering matter, we first check for a correlation between the FPM mean and CV of each gene (calculated group-wise).
### FPM mean vs CV
t1 = t[,c("ensembl_gene_id", "FPM_mean_control", "FPM_cv_control_meanDonors")]; t1$group = "control"; colnames(t1)[2:3] = c("FPM_mean", "FPM_CV")
t2 = t[,c("ensembl_gene_id", "FPM_mean_treatment", "FPM_cv_treatment_meanDonors")]; t2$group = "treatment"; colnames(t2)[2:3] = c("FPM_mean", "FPM_CV")
t_cv = rbind(t1,t2)
g = ggscatter(t_cv, x="FPM_mean", y="FPM_CV", color = "group", palette = c("#0073C244", "#CD534C44"),
xlab = paste("FPM Mean"), ylab= paste("FPM CV"), shape = 1)
g = g + theme_bw() + rremove("grid") + rotate_x_text()
gAll = ggpar(g, font.x = 14, font.y = 14, font.tickslab = 12,ylim = c(0,3), legend = "none")
# zoom 1
g = ggscatter(t_cv[t_cv$FPM_mean < 600,], x="FPM_mean", y="FPM_CV",color = "group", palette = c("#0073C244", "#CD534C44"),
xlab = paste("FPM Mean"), ylab= paste("FPM CV"), shape = 1, size = 1)
g = g + theme_bw() + rremove("grid") + rotate_x_text()
gZoom1 = g + geom_smooth(colour = "grey20", size = 0.5)
gZoom1 = ggpar(gZoom1, font.x = 14, font.y = 14, font.tickslab = 12,ylim = c(0,3), legend = "none")
# zoom 2
gZoom2 = g + geom_vline(xintercept = 1, colour = "grey20", linetype = "dashed")
gZoom2 = gZoom2 + scale_x_continuous(breaks = sort(c(seq(0, 10, length.out=5), 1)))
gZoom2 = ggpar(gZoom2, font.x = 14, font.y = 14, font.tickslab = 12,ylim = c(0,0.8), xlim =c(0,10), legend = "none")
k = ggarrange(gAll, gZoom1, gZoom2,
ncol = 3, labels = c("A", "B", "C"), font.label = list(size=9), align = "hv")
kFigure A shows for all considered genes their FPM mean and CV in samples from male and female cells (1 dot = 1 gene - blue and red for male and female, respectively). This highlights that the distribution of the FPM mean is strongly skewed to the left, with most genes actually having rather low expression levels. Having a closer look at the genes with less than 1000 FPM in average (Figure B) confirms this observation but also shows that the genes with high CV are mostly genes with very low expression. Nonetheless, zooming-in once more on the very lowly expressed genes (below 10 FPM in average), we observe overall a quick decline of the CV for genes with mean FPM > 5.
A high CV indicates a great variability and less precision. Or said otherwise, it indicates a high noise level what can possibly lead to false positive or false negative results. It is therefore of interest to remove this noise to determine “real” regulated genes. We propose to do so using a CV-based approach. But which rational cut-off should be applied to remove it?
We define genes with an average expression level below 1 FPM as “noise”. We then check the distribution of the CV of these genes.
### Distribution of CV for "noise" genes
#together
t_under1 = t[t$FPM_mean_control < 1 | t$FPM_mean_treatment < 1,]
t1 = t_under1[,c("ensembl_gene_id","FPM_cv_control_meanDonors") ]; colnames(t1)[2] = "CV"; t1$group = "control"
t2 = t_under1[,c("ensembl_gene_id","FPM_cv_treatment_meanDonors") ]; colnames(t2)[2] = "CV"; t2$group = "treatment"
t_under1 = rbind(t1,t2)
g_sd = gghistogram(t_under1, x = "CV", rug = T,
color = "group", fill ="group", palette = c("#0073C2FF","#CD534CFF"), alpha = 0.5, bins = 200,
xlab = "FPM CV", ylab = "Count") + theme_bw() + rremove("grid") + rotate_x_text()
g_sd = g_sd + geom_vline(xintercept = 0.25, linetype = "dashed", color = "grey20")
g_sd = g_sd + scale_x_continuous(breaks = sort(c(seq(0, 2, length.out=5), 0.25)))
g_sd = ggpar(g_sd, legend.title = "", legend = "none", main = "", xlim = c(0,2),
font.tickslab = 14, font.y = 14, font.x = 14)
g_sdThe figure shows the distribution of the “noise” genes for male and female samples (blue and red, respectively). We see here that most of these genes have a CV larger than 0.25 (grey dotted line). Therefore, we aim to identify from which expression level, genes have a lower CV than the ones observed for noise signal (i.e. below 0.25).
We calculate the median of CV for genes with less than 10FPM, using intervals of length equal one. (interval 1: genes with mean FPM between 0 and 1, interval 2: genes with mean FPM between 1 and 2,…).
We then determine from which median abundance is the global CV lower than the one observed for the “noise” (lower than 0.25 - see above).
t = t[is.finite(rowSums(t[,c("FPM_cv_control_meanDonors", "FPM_cv_treatment_meanDonors")])), ]
## get median for each class of FPM from 0 to 10
df_cv = data.frame()
for(i in 1:10){
if(i == 1){
tmp_ctrl = t[t$FPM_mean_control < 1 & t$FPM_mean_control > 0,]
tmp_treat = t[t$FPM_mean_treatment < 1 & t$FPM_mean_treatment > 0,]
j = i
}else{
tmp_ctrl = t[t$FPM_mean_control > j & t$FPM_mean_control <= i,]
tmp_treat = t[t$FPM_mean_treatment > j & t$FPM_mean_treatment <= i,]
j = i
}
# get mean, medians and CI for rel stdev
tmp1 = data.frame(i, mean(tmp_ctrl$FPM_mean_control), median(tmp_ctrl$FPM_cv_control_meanDonors))
colnames(tmp1) = c("loop", "meanFPM", "medianCV")
tmp2 = data.frame(i, mean(tmp_treat$FPM_mean_treatment), median(tmp_treat$FPM_cv_treatment_meanDonors))
colnames(tmp2) = colnames(tmp1)
tmp1$condition = "control"; tmp2$condition = "treatment"
df_cv = rbind(df_cv,tmp1, tmp2)
}
## Visualization
cv_threshold = 0.25
g = ggplot(df_cv, aes(meanFPM, medianCV, colour = condition, group = condition)) + geom_point(size = 4)
g = g + geom_line() + scale_color_manual(values=c("#0073C2FF", "#CD534CFF"))
g = g + theme_bw() + rremove("grid")
g = g + scale_x_continuous(breaks = get_breaks(by = 2, from = 0), limits = c(0,10))
g = g + scale_y_continuous(breaks = sort(c(seq(0, 0.6, length.out=4), cv_threshold)), limits = c(0,0.6))
g = g + geom_hline(yintercept = cv_threshold, linetype = "dashed", color = "grey70")
g = g + geom_vline(xintercept = 4, linetype = "dashed", color = "grey70")
g = g + geom_point(aes(fill = factor(condition)), size = 4, shape = 21, colour = "black") + scale_fill_manual("condition",
breaks=c("control", "treatment"),
values = c("#0073C2FF", "#CD534CFF"))
g = ggpar(g, legend = "none",
xlab = "FPM mean\nper categories", ylab = "Median of CV" ,font.tickslab = 14, font.y = 14, font.x = 14)
gThe horizontal dotted line indicates the CV cut-off we determined
based on the distribution of the “noise” genes (see above).
The two curves of the medians CV cross this line. In that case,
4 FPM would be a rational cut-off to filter lowly expressed genes with
high variability.
The newly determined abundance filter is applied on the output of the DEA (see ““Differential expression analysis” section) as follow:
\[max(mean(FPM)_{experimental group 1}, mean(FPM)_{experimental group 2}) > threshold\] This distinction between the two experimental groups rather than the global average expression throughout all samples retain genes that are not expressed at all in one of the condition and therefore strongly skew the total mean.
The ouput of this filtering step is visualized here.
FPMcutoff = 4
# filter output of DEA analysis
MF_filter_FPM = MF[MF$maxFPMmeans > FPMcutoff,]
# get summary table
df_summary_filter = data.frame(type = c("FDR 0.05", paste("FPM >",FPMcutoff)),
DEG = c(nrow(MF), nrow(MF_filter_FPM)))
### Visualization of the impact of this filter
### numbers
g = ggbarplot(df_summary_filter, x = "type", y = "DEG",
fill = "gray", color = "black",
label = T, lab.size = 3.5)
g = g + theme_bw() + rremove("grid") #+ rotate_x_text()
g = ggpar(g, xlab = "", ylab = "Number of DEG",
font.ytickslab = 10, font.xtickslab = 10, font.y = 12, font.x = 12,
ylim = c(0, max(df_summary_filter$DEG)+400))
### volcano plot
MF$FPMfilter = "no"; MF$FPMfilter[MF$maxFPMmeans > FPMcutoff] = "yes"
MF$FPMfilter = factor(MF$FPMfilter, levels = c("yes", "no"))
# fig
volc = ggplot(data = MF, aes(x = edgeR_LFC, y = -log10(edgeR_FDR), col = FPMfilter))
volc = volc + geom_vline(xintercept = c(-0, 0), col = "gray", linetype = 'dashed')
volc = volc + geom_hline(yintercept = -log10(0.05), col = "gray", linetype = 'dashed')
volc = volc + geom_point(shape = 1) + scale_color_manual(values = c("black", "#20854EFF"),
labels = c(paste("FPM >",FPMcutoff), paste("FPM <",FPMcutoff)))
volc = volc + scale_x_continuous(breaks = seq(-16, 16, 4), limits = c(-16, 16))
volc = volc + theme_bw() + rremove("grid") + rotate_x_text()
volc = ggpar(volc, legend.title = "", legend = "bottom",
font.ytickslab = 12, font.xtickslab = 12, font.y = 14, font.x = 14, font.legend = 12,
xlab = "LFC", ylab = "-log(FDR)")
gfilter = ggarrange(g, NULL, volc,
ncol = 3, align = "hv", widths = c(0.8,0.2,1.2),
labels = c("(A)", "", "(B)"), font.label = list(size = 10, face = "bold"))
gfilter
As visualized in the left panel, applying an abundance filter
reduces the number of genes initially identified as differentially
expressed. The volcano plot ( right panel) shows the
distribution of the genes that are removed by this filter (marked in
green).
Differential expression analyses commonly include a log2 fold change threshold that aims at identifying genes that are truly regulated and whose amplitude of regulation is higher than the “noise” (here, the inherent variability of the samples). Cutoff values of 1 or even 2 (correspond to 2- and 4-fold changes, respectively) are commonly use. However, small and more subtle changes, which may be biological relevant as well, are filtered out by doing so.
Inspired by the principles applied in analytical chemistry (see picture below), we propose here to calculate the amplitude of the “background noise” of the data and to determine a rational threshold for amplitude changes.
To determine the “background” noise in the gene expression dataset, the inherent variability of the sample group used as reference is estimated as follow:
\[L = log_{2}(1 + v f) \]
with f = 2 or 3.
(*) The CV are calculated considering sub-groups of samples (i.e. calculation made for each donor): values are obtained for each sub-groups and the mean of these values are used for further steps (e.g. for a given gene, CVperDonor = mean(CVdonor1, CVdonor2, CVdonor3).
We compare here the thresholds obtained when multiplying these values by different factors, as described in step (3).
# get a table that contains the FPM for the reference samples
t_lFC = t[t$FPM_mean_control > FPMcutoff,c("ensembl_gene_id", "FPM_cv_control_meanDonors")] # extract the columns of interest
# determine the log2FC thresholds
LFC_threshold = data.frame()
for(i in 1:3){
CV_perDonor = mean(t_lFC[!is.na(t_lFC$FPM_cv_control_meanDonors),]$FPM_cv_control_meanDonors)*i
if(i == 1){
thr_perDonor = "--"
}else{
thr_perDonor = round(log2(1 + CV_perDonor), digits = 2)
}
tmp = data.frame(i, round(CV_perDonor, digits = 2), thr_perDonor,
nrow(MF_filter_FPM[abs(MF_filter_FPM$edgeR_LFC) > thr_perDonor,]))
colnames(tmp) = c("Factor f", "CV x f", "LFC threshold", "DEG")
LFC_threshold = rbind(LFC_threshold,tmp)
}
LFC_threshold$Legend = ""
tab = ggtexttable(LFC_threshold,
theme = ttheme("light", colnames.style = colnames_style(size = 9, fill = "white")), rows = NULL)
tab = table_cell_font(tab, row = 2:tab_nrow(tab), column = 1:tab_ncol(tab), size = 9)
tab = table_cell_bg(tab, row = 3, column = tab_ncol(tab), fill = "#20854E77", color = "#20854E77")
tab = table_cell_bg(tab, row = 4, column = tab_ncol(tab), fill = "#20854EFF", color = "#20854EFF")
tab = tab %>% tbody_add_border() %>%
tab_add_vline(at.column = c(1,5), column.side = "right", from.row = 2, linetype = 2)
tab
The CV is lowered when considering genes reaching the abundance cutoff
only (see section 5.1)). We
postulate that the fold change (FC) of a given gene needs to reach a
certain value (FC = 1 + CV x f) to be considered as regulated. This
value is converted to the log2 scale and then used to filter
lists of regulated genes (prefiltered for abundance - see section 5.1).
These thresholds with different levels of stringency are applied on the DEA output (genes prefiltered for statistical signficance (FDR 0.05) and abundance - see section 5.1).
# add info to summary df
for(n in 2:3){
L = as.numeric(LFC_threshold$`LFC threshold`[n])
tmp = data.frame(type = paste("|LFC| >",L), DEG = nrow(MF_filter_FPM[abs(MF_filter_FPM$edgeR_LFC) > L,]))
df_summary_filter = rbind(df_summary_filter, tmp)
}
df_summary_filter = rbind(df_summary_filter, data.frame(type = paste("|LFC| >",1), DEG = nrow(MF_filter_FPM[abs(MF_filter_FPM$edgeR_LFC) > 1,])))
df_summary_filter$filter = factor(c("None", "Abundance", rep("LFC",3)), levels = c("None", "Abundance", "LFC"))
### Visualization of the impact of this filter
########################################################
### numbers
g = ggbarplot(df_summary_filter, x = "type", y = "DEG",
fill = "filter", color = "black", palette = c("grey10", "grey50", "grey90"),
label = T, lab.size = 3.5)
g = g + theme_bw() + rremove("grid") + rotate_x_text()
g = ggpar(g, xlab = "", ylab = "Number of DEG",
font.ytickslab = 12, font.xtickslab = 12, font.y = 12, font.x = 12,
ylim = c(0, max(df_summary_filter$DEG)+400),
legend.title = "Filter type:", legend = "bottom")
### volcano plot
# (build up on previous plot)
for (i in 2:3){
col = c("#20854E77","#20854EFF")
cutoffValue = as.numeric(LFC_threshold$`LFC threshold`[i] )
volc = volc + geom_vline(xintercept = c(-cutoffValue, cutoffValue), col = col[i-1], linetype = 'dashed')
}
volc = volc + geom_vline(xintercept = c(-1, 1), col = "grey30", linetype = 'dotted')
gfilter = ggarrange(g, NULL, volc,
ncol = 3, align = "hv", widths = c(1,0.2,1))
gfilterApplying the different log2 fold changes listed in the previous table can lead to a drastic reduction of the number of genes defined as “differentially expressed” (figure (A)). The two different LFC filters are also visualized on volcano plots (see previous table for color legend), as well as a “classical” one (|LFC| > 1 - black dotted line).
However, a question still remains: which LFC cut-off is actually the most appropriate?, or in other words, which filter is the best compromise between removing “artificially” regulated genes (false positives) and preserving biologically relevant information removed by usual cutoffs (false negative)?
To test this question, we run GO term enrichment analysis, using
g:profiler2 package and its function gost.
This is done for the lists of genes obtained after applying the
different LFC filters on the data. The outputs are compared in the form
of Manhattan plots (shows enriched terms with a size below 5000).
LFC1 = MF_filter_FPM[abs(MF_filter_FPM$edgeR_LFC) > 1,]
LFC_cv3 = MF_filter_FPM[abs(MF_filter_FPM$edgeR_LFC) > as.numeric(LFC_threshold$`LFC threshold`[3]),]
LFC_cv2 = MF_filter_FPM[abs(MF_filter_FPM$edgeR_LFC) > as.numeric(LFC_threshold$`LFC threshold`[2]),]
GOinput = list(LFC1 = LFC1$ensembl_gene_id, LFC_cv3 = LFC_cv3$ensembl_gene_id, LFC_cv2 = LFC_cv2$ensembl_gene_id)
GOoutput = gost(query = GOinput,
organism = "hsapiens", ordered_query = F, multi_query = F,
significant = T, correction_method = "g_SCS", user_threshold = 0.001,
custom_bg = t$ensembl_gene_id,
exclude_iea = T,# remove the GO annotation that are assigned to genes using in silico curation methods
highlight = T,
sources = c("GO:BP", "KEGG", "REAC"))
if(length(GOoutput) > 0){
GOoutput$result$enrichment = rep(".", dim(GOoutput$result)[1])
GOoutput$result$enrichment = (GOoutput$result$intersection_size / GOoutput$result$query_size) / (GOoutput$result$term_size / GOoutput$result$effective_domain_size)
}
GOoutput_size = GOoutput
GOoutput_size$result = GOoutput_size$result[GOoutput_size$result$term_size < 5000,]
go = GOoutput_size$result
go_summary = data.frame()
for(i in unique(go$query)){
tmp = go[go$query == i,]
# how many terms
tmp_N = data.frame(i, nrow(tmp))
colnames(tmp_N) = c("threshold", "terms")
go_summary = rbind(go_summary,tmp_N)
# get the lists
go_name = paste0(i, "_GO")
assign(go_name, tmp)
}
v = draw.triple.venn(nrow(LFC_cv2_GO), nrow(LFC_cv3_GO), nrow(LFC1_GO),
nrow(inner_join(LFC_cv2_GO, LFC_cv3_GO, by = "term_id")),
nrow(inner_join(LFC1_GO, LFC_cv3_GO, by = "term_id")),
nrow(inner_join(LFC1_GO, LFC_cv2_GO, by = "term_id")),
nrow(inner_join(LFC_cv2_GO, inner_join(LFC1_GO, LFC_cv3_GO, by = "term_id"), by = "term_id")),
category = c("CV2", "CV3", "1"), col = rep("grey21",3), cat.cex = rep(0.8,3), cat.dist = rep(0.04,3), fill = c("grey94", "grey53", "grey30"), lty = "solid", ltw = rep(0.5,3), scaled = T, ind=F, alpha = 0.5)
g = ggbarplot(go_summary, x = "threshold", y = "terms",
fill = "grey90", color = "black",
label = T, lab.size = 3.5)
g = g + theme_bw() + rremove("grid") + rotate_x_text()
g = ggpar(g, xlab = "LFC thresholds", ylab = "Number of enriched terms",
font.ytickslab = 12, font.xtickslab = 12, font.y = 12, font.x = 12,
ylim = c(0, max(go_summary$terms)+40),
legend.title = "Filter type:", legend = "bottom")
k = ggarrange(g, NULL, v,
widths = c(0.7,0.1,1),
ncol = 3, nrow =1)
ktoHighlight = c("GO:0001944", "GO:0006119", "GO:0006754","GO:0008283",
"GO:0042776", "GO:0048514", "GO:1901135", "GO:1901293",
"KEGG:01100", "KEGG:00190", "KEGG:05415",
"REAC:R-HSA-1430728")
p = gostplot(GOoutput_size, capped = TRUE, interactive = F)
pp = publish_gostplot(p, highlight_terms = toHighlight,
width = NA, height = NA, filename = paste0(outputDir,"/GO_MultiQuery-highlights.png") )Terms representing recurring biological functions have been highlighted in the Manhattan plots and the corresponding p-values are shown. Using the classical threshold of |LFC| > 1 (lower panel of the Manhattan plots) was associated with a lower number of enriched terms (due to a lower number of genes). Meanwhile, using more loose thresholds based on the CV of the genes was associated with a higher number of enriched terms (due to a larger number of included genes). The biological functions that are only identified in the case of the loose filters are actually relevant for vascular cells (e.g. metabolic related processes).
An interactive version of the Manhattan plots is also available: by clicking on a “bubble” (corresponds to one term), the corresponding bubbles will appear in the other plots if there.
To assess if this strategy can actually be transposed to other data sets, particularly to data sets in which the intervention leads to more subtle gene expression regulation patterns than the sex-driven ones, and to test if adapted LFC thresholds indeed lead to a gain of relevant information, we applied the same pipeline to two other independent data sets of ours, which consisted in investigating the effect of EGF on female VSMC and the effect of obesity-associated stressors on male VSMC.
## R version 4.5.0 (2025-04-11)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 20.04.6 LTS
##
## Matrix products: default
## BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0 LAPACK version 3.9.0
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=de_DE.UTF-8 LC_COLLATE=en_US.UTF-8
## [5] LC_MONETARY=de_DE.UTF-8 LC_MESSAGES=en_US.UTF-8
## [7] LC_PAPER=de_DE.UTF-8 LC_NAME=C
## [9] LC_ADDRESS=C LC_TELEPHONE=C
## [11] LC_MEASUREMENT=de_DE.UTF-8 LC_IDENTIFICATION=C
##
## time zone: Europe/Berlin
## tzcode source: system (glibc)
##
## attached base packages:
## [1] grid stats4 stats graphics grDevices utils datasets
## [8] methods base
##
## other attached packages:
## [1] mgsub_1.7.3 dplyr_1.1.4
## [3] VennDiagram_1.7.3 futile.logger_1.4.3
## [5] gridExtra_2.3 pheatmap_1.0.12
## [7] RColorBrewer_1.1-3 ggpubr_0.6.0
## [9] ggplot2_3.5.2 gprofiler2_0.2.3
## [11] biomaRt_2.64.0 edgeR_4.6.1
## [13] limma_3.64.0 DESeq2_1.48.0
## [15] SummarizedExperiment_1.38.1 Biobase_2.68.0
## [17] MatrixGenerics_1.20.0 matrixStats_1.5.0
## [19] GenomicRanges_1.60.0 GenomeInfoDb_1.44.0
## [21] IRanges_2.42.0 S4Vectors_0.46.0
## [23] BiocGenerics_0.54.0 generics_0.1.3
##
## loaded via a namespace (and not attached):
## [1] bitops_1.0-9 DBI_1.2.3 polynom_1.4-1
## [4] formatR_1.14 httr2_1.1.2 rlang_1.1.6
## [7] magrittr_2.0.3 compiler_4.5.0 RSQLite_2.3.11
## [10] mgcv_1.9-1 png_0.1-8 vctrs_0.6.5
## [13] stringr_1.5.1 pkgconfig_2.0.3 crayon_1.5.3
## [16] fastmap_1.2.0 backports_1.5.0 dbplyr_2.5.0
## [19] XVector_0.48.0 labeling_0.4.3 rmarkdown_2.29
## [22] UCSC.utils_1.4.0 purrr_1.0.4 bit_4.6.0
## [25] xfun_0.52 cachem_1.1.0 jsonlite_2.0.0
## [28] progress_1.2.3 blob_1.2.4 DelayedArray_0.34.1
## [31] BiocParallel_1.42.0 broom_1.0.8 parallel_4.5.0
## [34] prettyunits_1.2.0 R6_2.6.1 bslib_0.9.0
## [37] stringi_1.8.7 car_3.1-3 jquerylib_0.1.4
## [40] Rcpp_1.0.14 knitr_1.50 splines_4.5.0
## [43] Matrix_1.7-3 tidyselect_1.2.1 rstudioapi_0.17.1
## [46] abind_1.4-8 yaml_2.3.10 codetools_0.2-19
## [49] curl_6.2.2 lattice_0.22-5 tibble_3.2.1
## [52] withr_3.0.2 KEGGREST_1.48.0 evaluate_1.0.3
## [55] lambda.r_1.2.4 BiocFileCache_2.16.0 xml2_1.3.8
## [58] Biostrings_2.76.0 pillar_1.10.2 filelock_1.0.3
## [61] carData_3.0-5 plotly_4.10.4 RCurl_1.98-1.17
## [64] hms_1.1.3 scales_1.4.0 glue_1.8.0
## [67] lazyeval_0.2.2 tools_4.5.0 data.table_1.17.0
## [70] locfit_1.5-9.12 ggsignif_0.6.4 cowplot_1.1.3
## [73] tidyr_1.3.1 crosstalk_1.2.1 AnnotationDbi_1.70.0
## [76] nlme_3.1-168 GenomeInfoDbData_1.2.14 Formula_1.2-5
## [79] cli_3.6.5 rappdirs_0.3.3 futile.options_1.0.1
## [82] S4Arrays_1.8.0 viridisLite_0.4.2 gtable_0.3.6
## [85] rstatix_0.7.2 sass_0.4.10 digest_0.6.37
## [88] SparseArray_1.8.0 htmlwidgets_1.6.4 farver_2.1.2
## [91] memoise_2.0.1 htmltools_0.5.8.1 lifecycle_1.0.4
## [94] httr_1.4.7 statmod_1.5.0 MASS_7.3-65
## [97] bit64_4.6.0-1