We generated a RNA-sequencing dataset to investigate the effect of
obesity-associated stressors (high glucose, free fatty acids,
noradrenaline, angiotensin II) on human primary vascular smooth muscle
cells, using cells from various male donors.
We apply here the same strategy designed to identify sex-specific gene expression patterns in
vascular smooth muscle cells and genes
regulated by EGF in female VSMC.
As a reminder, this strategy consists in…
Additionally, we propose here an alternative analysis pipeline for the analysis of paired samples.
## Required packages ##
# DEA
library(DESeq2)
library(edgeR)
# annotation
library(biomaRt)
# GO
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_Obesity_revised/")
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_male_obesity-ALL-final.csv", header=T, row.names = 1)
# n_occur <- data.frame(table(sampleTable$donor_replicate))
# sampleTable = sampleTable[sampleTable$donor_replicate %in% n_occur$Var1[n_occur$Freq == 2],]
### Raw counts
counts = read.csv("inputFiles/counts_male_obesity-ALL-final.csv", header=T, stringsAsFactors = F, row.names = 1)
### Data annotation (biomart output)
load("Data_biomaRt_v109.RData")
### Match sample information and raw counts
counts.f = counts[,which(names(counts) %in% rownames(sampleTable))]
### STOP! before anything, we need to check if sample table and count matrix are fitting
all(rownames(sampleTable) == colnames(counts.f))## [1] TRUE
##
## AS2M AS3M AS4M
## control 2 3 3
## obesity 2 2 2
#### Functions ##
# Population standard deviation
sdpop = function(x){
sqrt(mean((x-mean(x))^2))
}
# confidence interval
conf = 0.95
# function for CI and False coverage rate
ci_adjust = function(ci, # input : table with calculated ratios and the log transformed values
q = 0.05, # target FCR
conf = 0.99, # level of the original CI
df = NULL # n_donors - 1; NULL = original CI was z-based
) {
#stopifnot(all(c("gene", "I_mean", "low", "high") %in% names(ci)))
m = nrow(ci) # number of genes in total
# preparation
ci = ci[is.finite(rowSums(ci[,grep("log", colnames(ci))])), ]
## 1. Calculation of means and sd
ci$mean = apply(ci[,grep("log", colnames(ci))],1, mean)
ci$sd = apply(ci[,grep("log", colnames(ci))],1, sdpop)
n = length(ci[,grep("log", colnames(ci))])
ci$se = ci$sd/sqrt(n)
## 2. calculation of CI for all genes
t_0 = if (is.null(df)) qnorm(1 - (1 - conf) / 2) else qt(1 - (1 - conf) / 2, df)
ci$ci_lo = ci$mean - t_0 * ci$se
ci$ci_hi = ci$mean + t_0 * ci$se
lo = ci$ci_lo; hi = ci$ci_hi
# 3. selection: original CI excludes null
selected = (lo > 0) | (hi < 0)
ci$selected_orig = selected
R <- sum(selected, na.rm = TRUE) # number of genes that pass this filter
## 4. FCR-adjusted level: 1 - R*q/m
alpha_adj <- R * q / m
t_adj <- if (is.null(df)) qnorm(1 - alpha_adj / 2) else qt(1 - alpha_adj / 2, df)
ci$ci_lo_adj = ci$mean - t_adj * ci$se
ci$ci_hi_adj = ci$mean + t_adj * ci$se
# which genes are lost after correction?
lo_adj = ci$ci_lo_adj; hi_adj = ci$ci_hi_adj
ci$selected_adj = ifelse(selected & ((lo_adj > 0) | (hi_adj < 0)), "regulated",
ifelse(selected, "lost after FCR", "not selected"))
## return results
ci
}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.
### 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 half of the samples
dds <- estimateSizeFactors(dds)
idx <- rowSums( counts(dds, normalized=TRUE) >= 1 ) >= 3
dds <- dds[idx,]
# How many genes are included in our DESeq object AFTER filtering for the lowly expressed ones?
print(paste0(nrow(dds), " genes (out of ", nrow(counts.f),") remained after pre-filtering."))## [1] "25769 genes (out of 62656) remained after pre-filtering."
Euclidean distances in between the samples are calculated.
### sample-to-sample distance
sampleDists = dist(t(vst.df)); sampleDistMatrix = as.matrix(sampleDists)
rownames(sampleDistMatrix) = paste0(vst$condition, "_", vst$donor)
colnames(sampleDistMatrix) = NULL
pheatmap(sampleDistMatrix, col = colorRampPalette(rev(brewer.pal(9,"Blues")))(255),
clustering_distance_cols = sampleDists,
clustering_distance_rows = sampleDists,fontsize_row = 6)Principal component analysis is performed using DESeq2 function
plotPCA.
### PCA
## Calculation
PCA_info = c("sampleName", "donor", "condition", "replicate")
data <- plotPCA(vst, intgroup=PCA_info, returnData=TRUE)
percentVar <- round(100 * attr(data, "percentVar"))
## visualization
data$Donors = as.factor(data$donor)
g = ggscatter(data, x = "PC1", y = "PC2",
color = "donor", shape = "condition", palette = rev(brewer.pal(4,"Spectral")),
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 = "donor", shape = "replicate", palette = rev(brewer.pal(4,"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 highlights a major effect of the donor origin on the data variability.
Differential expression analysis is performed in order to identify
genes that are differentially expressed upon EGF treatment. 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). Based on the
output of the exploratory analysis, a batch (i.e. donor origin)
correction is included in the analysis process.
cond.f = "condition" # column where contrast values are stored
control = "control" # Condition used as reference
treatment = "obesity" # 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 = ~ donor + 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: 33870"
### 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
donors.design = factor(sampleTable[,c("donor")])
design = model.matrix(~ donors.design + 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) After filtering for FDR 0.05 each, the output of DESeq2 and edgeR are
compared.
Numbers of DEG (total, up and down) per tool:
### 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)
res.summary## control treatment DEG DEG_up DEG_down tool
## 1 control obesity 0 0 0 DESeq2
## 2 control obesity 0 0 0 edgeR
## 3 control obesity 0 0 0 overlap
if(nrow(o) > 0){
### 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-0.2, size = 3) + stat_regline_equation(label.x = minAxis , label.y = maxAxis-0.5, size = 3)
g = g + theme_bw() + rremove("grid")
g = ggpar(g, ylim = c(minAxis-1,maxAxis), xlim = c(minAxis-1,maxAxis), font.x = 10, font.y = 10)
### 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 = 10, font.xtickslab = 10,
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
}else{
print("No DEG were identified")
}## [1] "No DEG were identified"
The classical analysis pipeline failed to identify any
regulated genes.
The alternative analysis pipeline proposed to when investigating the effect of EGF on female VSMC will be
applied instead. Upstream of these, relevant and data driven cutoffs can
still be determined on the FPM generated by edgeR.
While working on a first data set exploring the sex-specific gene expression patterns in vascular smooth muscle cells, we have developed rational strategies to determine cut-off values for the abundance and for the magnitude of change. This strategy aimed to exclude background signal (genes with very low expression and/or with minimal changes) while retaining small but putative biologically relevant changes.
As mentioned in the “Differential expression analysis” section, DESeq2 and edgeR both include functions to remove extremely lowly expressed genes (mostly not detectable genes or with very few raw counts). But despite this filtering, how many genes with low expression were retained in for the analysis?
To investigate this matter, we used the FPM computed by edgeR and determine the mean expression of each gene, but also its variation throughout the sample population by calculating its coefficient of variation (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)\nAverage FPM of the gene with the lowest expression level in this list: ", round(min(t$maxFPMmeans), digits = 2)))## Number of genes kept by edgeR after automatic removal of the genes with very low expression (filterByExp function): 16149 (out of 75118 annotated genes)
## Average FPM of the gene with the lowest expression level in this list: 0.27
As previously, we compare here the CV obtained (i) when considering all donors included in our study as a unique population, or (ii) when considering each donor individually. It appears here particularly relevant since the exploratory analysis performed on this data set suggests a major effect of the donor origin and only a minor one of the treatment. This is performed for each experimental group.
### CV per donor
#####################
df_cv_meanDonors = data.frame()
for(i in unique(sampleTable$donor)){
for(j in unique(sampleTable$condition)){
# get samples corresponding to one donor
sampleDonor = paste0("FPM_", sampleTable$sampleName[sampleTable$condition == j & sampleTable$donor == i])
# calculations of mean, sd, and CV
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, j, 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_", j, "_", i), paste0("FPM_sd_", j, "_", i), paste0("FPM_cv_", j, "_", i))
}
}
colnames(df_cv_meanDonors) = c("Donor", "Condition", "mean CV")
# get mean CV 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", "control",
round(mean(t[!is.na(t$FPM_cv_control_meanDonors),]$FPM_cv_control_meanDonors), digits = 2)),
list("mean CV individual donors", "obesity",
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", "control", round(mean(t[!is.na(t$FPM_cv_control),]$FPM_cv_control), digits = 2)),
list("CV all together", "obesity", round(mean(t[!is.na(t$FPM_cv_treatment),]$FPM_cv_treatment), digits = 2)))
### Summary table
# treatment
tab1 = ggtexttable(df_cv_meanDonors[df_cv_meanDonors$Condition == "control",],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")
# control
tab2 = ggtexttable(df_cv_meanDonors[df_cv_meanDonors$Condition == "obesity",],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)
tab
The results show that the CV obtained by calculating the CV of the
individual donors and then the mean is lower than when considering all
donors as one homogeneous population (last two lines of each table).
This means that ignoring the donor-dependent variability leads to an
overestimation of the gene expression variability. Moreover, we observe
that the inherent variability of the two experimental groups (control
and treatment) are here again rather similar.
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("#EFC00055", "#00A08755"),
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("#EFC00055", "#00A08755"),
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)#geom_smooth(aes(colour = group), se = F )
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")
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 in control samples.
### 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[t_under1$group == "control",], x = "CV", add = "median", rug = T,
color = "group", fill ="group", palette = c("#EFC00055"), alpha = 0.3, bins = 200,
xlab = "CV", ylab = "Count") + theme_bw() + rremove("grid") + rotate_x_text()
g_sd = g_sd + geom_vline(xintercept = 0.25, linetype = "dotted", 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. We see here that a large majority 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("#EFC000FF", "#00A087FF"))
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 = 3, 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("#EFC000FF", "#00A087FF"))
g = ggpar(g, legend = "none",
xlab = "FPM mean 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). Both curves of the median CV cross this line. In that case, an abundance filter of FPM > 3 is applied, since it’s the first value from when the two curves are cross the 0.25 line.
Differential expression analyses commonly include a log2 fold change thresholding 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 our analysis of sex-specific gene expression patterns in vascular smooth muscle cells), 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).
FPMcutoff = 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)
colnames(tmp) = c("Factor f", "CV x f", "LFC threshold")
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 = "#0073C255", color = "#0073C255")
tab = table_cell_bg(tab, row = 4, column = tab_ncol(tab), fill = "#0073C2FF", color = "#0073C2FF")
tab = tab %>% tbody_add_border() %>%
tab_add_vline(at.column = c(1,4), 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).
The high inter-individual variability observed in the exploratory analysis may sometimes turn out to be an obstacle for the identification of regulated genes. Indeed, if the effect of a given treatment is low key, the prevalence of the e.g. “donor effect” might prevent the identification of significantly regulated genes with traditional tools (e.g. edgeR / DESeq2). In such cases, a batch correction for this external factor might not be sufficient to recover the analysis. The data set presently analyzed in the perfect illustration of this.
We tested an alternative analysis method for such cases, when we investigated the effect of EGF on female VSMC. This one is based on the paired comparison of the normalized counts (pre-filtered for the abundance threshold previously determined - see section 5.1)).
t_filter_FPM = t[t$maxFPMmeans > FPMcutoff,]
# pre-requisit: corresponding control and treated samples must be listed one after the other in the sample table + both samples must be present in seq data
n_occur <- data.frame(table(sampleTable$donor_replicate))
sampleTable2 = sampleTable[sampleTable$donor_replicate %in% n_occur$Var1[n_occur$Freq == 2],]
### How many replicates are included here?
table(sampleTable2$condition, sampleTable2$donor)##
## AS2M AS3M AS4M
## control 2 2 2
## obesity 2 2 2
for(i in unique(sampleTable2$donor)){
for(j in sampleTable2$sampleName[sampleTable2$donor == i & sampleTable2$condition == control]){
#where are the info stored in the sample table?
ctrlID = which(sampleTable2$sampleName == j) ; treatID = which(sampleTable2$sampleName == j)+1
# check if matching samples
if((sampleTable2$donor_replicate[ctrlID] == sampleTable2$donor_replicate[treatID])){
# get the sample names
ctrlName = j; treatName = sampleTable2$sampleName[treatID]
# get the FPM
ctrlFPM = t_filter_FPM[,paste0("FPM_", ctrlName)]
treatFPM = t_filter_FPM[,paste0("FPM_", treatName)]
# calculate impact
t_filter_FPM$I = treatFPM/ctrlFPM
colnames(t_filter_FPM)[ncol(t_filter_FPM)] = paste0("I_", sampleTable2$donor_replicate[ctrlID])
}else{
print("Samples do not correspond - check sample table!")
}
}
}
t_filter_FPM = t_filter_FPM[complete.cases(t_filter_FPM),] # remove potential NA generated (security net)
### calculate CI and corresponding adjusted values
impact = t_filter_FPM[,grep("^I_", colnames(t_filter_FPM))] # isolate impacts for better handling
n_rep = ncol(impact) # number of considered replicates (necessary for calculation of the degrees of freedom)
# log transformation
impactlog = cbind(impact, log(impact[,1:ncol(impact)],2))
colnames(impactlog)[(ncol(impact)+1):ncol(impactlog)] = paste0(colnames(impactlog)[(ncol(impact)+1):ncol(impactlog)], "_log")
# apply function to calculate ci but also adjust it
res_CI_FCR = ci_adjust(impactlog, q = 0.1, conf = conf, df = n_rep -1)
# add information if the genes pass the LFC threshold
res_CI_FCR$LFC = FALSE
res_CI_FCR$LFC[abs(res_CI_FCR$mean) > LFC_threshold$`LFC threshold`[3]] = TRUE
# annotate these results with gene names
res_CI_FCR = cbind(res_CI_FCR, t_filter_FPM[t_filter_FPM$ensembl_gene_id %in% rownames(res_CI_FCR),
c("ensembl_gene_id", "external_gene_name")])
# how many of the genes passed the different steps?
d_fcr = data.frame(x = c("CI","CI + log", "CI + FCR", "CI + FCR + log"),
y = c(nrow(res_CI_FCR[res_CI_FCR$selected_orig == TRUE,]),
nrow(res_CI_FCR[res_CI_FCR$selected_orig == TRUE & res_CI_FCR$LFC == TRUE,]),
nrow(res_CI_FCR[res_CI_FCR$selected_adj == "regulated",]),
nrow(res_CI_FCR[res_CI_FCR$selected_adj == "regulated" & res_CI_FCR$LFC == TRUE,])
))
# visualization of the effect of FCR, combined with LFC thresholding
b = ggbarplot(d_fcr, fill = "grey80", color="grey60",
x = "x", y = "y", label = T, lab.size = 3, width = 0.5) + theme_bw() + rotate_x_text(angle = 90) + rremove("grid")
b = ggpar(b, xlab = "", ylab = "Number of genes",
font.y = 10, font.xtickslab = 10,
ylim = c(0, max(d_fcr$y)+max(d_fcr$y)*10/100))
bDEG were identified with this second approach. We check if this low
number of genes were enriched in GO terms, using
gprofiler2.
GOoutput = gost(query = res_CI_FCR[res_CI_FCR$selected_orig == TRUE & res_CI_FCR$LFC == TRUE,]$ensembl_gene_id,
organism = "hsapiens", ordered_query = F, multi_query = F,
significant = T, correction_method = "fdr", user_threshold = 0.05,
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"))
GOoutput_size = GOoutput
GOoutput_size$result = GOoutput_size$result[GOoutput_size$result$term_size < 5000,]toHighlight = c("GO:0006954", "GO:0016126", "GO:0043114","GO:0060192",
"KEGG:04670", "REAC:R-HSA-1650814","REAC:R-HSA-1474244", "REAC:R-HSA-8963899", "REAC:R-HSA-1430728")
p = gostplot(GOoutput_size, capped = F, interactive = F)
pp = publish_gostplot(p, highlight_terms = toHighlight,
width = NA, height = NA, filename = paste0(outputDir,"/GO_MultiQuery-highlights_paired.png") )Terms representing recurring biological functions have been highlighted in the Manhattan plots and the corresponding p-values are shown. We observe that the main information remain the same when comparing the two approaches, showing the validity of the alternative one to analyze such paired data. This also highlights the potential of this approach to rescue dataset in which effects are minimal.
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.
## 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 formatR_1.14
## [4] httr2_1.1.2 rlang_1.1.6 magrittr_2.0.3
## [7] compiler_4.5.0 RSQLite_2.3.11 mgcv_1.9-1
## [10] png_0.1-8 vctrs_0.6.5 stringr_1.5.1
## [13] pkgconfig_2.0.3 crayon_1.5.3 fastmap_1.2.0
## [16] backports_1.5.0 dbplyr_2.5.0 XVector_0.48.0
## [19] labeling_0.4.3 rmarkdown_2.29 UCSC.utils_1.4.0
## [22] purrr_1.0.4 bit_4.6.0 xfun_0.52
## [25] cachem_1.1.0 jsonlite_2.0.0 progress_1.2.3
## [28] blob_1.2.4 DelayedArray_0.34.1 BiocParallel_1.42.0
## [31] broom_1.0.8 parallel_4.5.0 prettyunits_1.2.0
## [34] R6_2.6.1 bslib_0.9.0 stringi_1.8.7
## [37] car_3.1-3 jquerylib_0.1.4 Rcpp_1.0.14
## [40] knitr_1.50 splines_4.5.0 Matrix_1.7-3
## [43] tidyselect_1.2.1 rstudioapi_0.17.1 abind_1.4-8
## [46] yaml_2.3.10 codetools_0.2-19 curl_6.2.2
## [49] lattice_0.22-5 tibble_3.2.1 withr_3.0.2
## [52] KEGGREST_1.48.0 evaluate_1.0.3 lambda.r_1.2.4
## [55] BiocFileCache_2.16.0 xml2_1.3.8 Biostrings_2.76.0
## [58] pillar_1.10.2 filelock_1.0.3 carData_3.0-5
## [61] plotly_4.10.4 RCurl_1.98-1.17 hms_1.1.3
## [64] scales_1.4.0 glue_1.8.0 lazyeval_0.2.2
## [67] tools_4.5.0 data.table_1.17.0 locfit_1.5-9.12
## [70] ggsignif_0.6.4 cowplot_1.1.3 tidyr_1.3.1
## [73] crosstalk_1.2.1 AnnotationDbi_1.70.0 nlme_3.1-168
## [76] GenomeInfoDbData_1.2.14 Formula_1.2-5 cli_3.6.5
## [79] rappdirs_0.3.3 futile.options_1.0.1 S4Arrays_1.8.0
## [82] viridisLite_0.4.2 gtable_0.3.6 rstatix_0.7.2
## [85] sass_0.4.10 digest_0.6.37 SparseArray_1.8.0
## [88] htmlwidgets_1.6.4 farver_2.1.2 memoise_2.0.1
## [91] htmltools_0.5.8.1 lifecycle_1.0.4 httr_1.4.7
## [94] statmod_1.5.0 MASS_7.3-65 bit64_4.6.0-1