1 Background and aim

We generated a RNA-sequencing dataset to investigate the effect of EGF (10 µg/L) on human primary vascular smooth muscle cells, using cells from various female donors.
We apply here the same strategy designed to identify sex-specific gene expression patterns in vascular smooth muscle cells.

As a reminder, this strategy consists in…

  1. Identifying genes differentially expressed (DE) upon treatment, using the “gold standard” tools that are DESeq2 and edgeR
  2. Define rational thresholds to filter “real” DE genes based on…
    • their abundance
    • the amplitude of change (log2 fold change)

Additionally, we propose here an alternative analysis pipeline for the analysis of paired samples, to be eventually considered when the factor under investigation is not the main cause of variation of the data.


2 Session setting and data loading

  • Sample information were gathered (sex, donor) during the sample preparation. (The number of replicates is indicated below)
  • Total RNA were isolated, and polyA enrichement and paired-end sequencing were successively performed. The fragments were mapped and counted with HISAT and featureCounts, respectively. The list of counts generated by featureCounts is used here as input.
  • The Ensembl archive v101 has been used for the counting step and for further annotation.
###   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_EGF_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_female_EGF-final.csv", header=T, row.names = 1)
# Raw counts
counts = read.csv("inputFiles/counts_female_EGF-final.csv", header=T, stringsAsFactors = F, row.names = 1)
# Data annotation (biomart output)
load("Data_biomaRt_v101.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
# How many replicates are included here?
table(sampleTable$condition, sampleTable$donor)
##    
##     AS1F AS2F CS1F
##   C    8    4    9
##   E    8    4    9
###     Functions     
# Population standard deviation
sdpop = function(x){
  sqrt(mean((x-mean(x))^2))
}
# confidence interval
conf = 0.99
# 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
}

3 Exploratory analysis

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.

  1. Raw counts are pre-filtered for those having at least one normalized counts in more than 3 samples (remove the genes not detected at all).
  2. A DESeq2 object is created and raw counts undergo variance stabilizing transformation (vst function)
  3. Visualization

3.1 Data preparation

### 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,]
# 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] "25466 genes (out of 60612) remained after pre-filtering."
### Creation of DESeq2 object
dds.f <- DESeq(dds)

### vst transformation (varianceStabilizingTransformation)
vst <- vst(dds.f, blind=F)
vst.df <- assay(vst)

3.2 Sample-to-sample distance

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)

3.3 Principal component analysis

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 = "replicate", shape = "donor", 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") 
k

This first step of the analysis highlights a major effect of the donor origin on the data variability. Meanwhile, the treatment itself seems to have a minor effect on the data.




4 Differential expression analysis

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 = "C" # Condition used as reference
treatment = "E" # Condition to compare
# to which samples to they correspond ?
control.samples = sampleTable$sampleName[sampleTable$condition == control]
treatment.samples = sampleTable$sampleName[sampleTable$condition == treatment]

4.1 DESeq2

The full list of genes (i.e. without pre-filtering like we had done in previous section) is considered for the analysis with DESeq2. However, the independent filtering option of the function results is set as TRUE to remove very lowly expressed genes that may distort the results of the DEA.

### 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: 21495"
### 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 = df

4.2 - edgeR

  • The DEA is then performed with edgeR, also using the full list of annotated genes as input. Similarly to the independent filtering option in DESeq2, the function filterByExp of edgeR automatically filters out lowly expressed genes that should be excluded of the statistical analysis.
  • Normalization factors are calculated with the “trimmed mean of M value” (TMM) method, and are used to obtained effective library sizes.
  • FPM (fragment per million) are computed and the means of FPM per experimental group calculated.
  • The functions 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) 

4.3 - Overlap of DESeq2 and edgeR

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) 
print("Numbers of DEG (total, up and down) per tool: ")
## [1] "Numbers of DEG (total, up and down) per tool: "
res.summary
##   control treatment  DEG DEG_up DEG_down    tool
## 1       C         E 4125   2039     2086  DESeq2
## 2       C         E 3979   1959     2020   edgeR
## 3       C         E 3718   1862     1856 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-0.5,  size = 3) + stat_regline_equation(label.x = minAxis , label.y = maxAxis-0.8, size = 3) 
g = g + theme_bw() + rremove("grid")
g = ggpar(g, ylim = c(minAxis-0.5,maxAxis), xlim = c(minAxis-0.5,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.

4.4 - Master file generation

The results for the genes in the overlap are merged in one single table, which comprise the following elements:

  • gene information (ensembl ID, gene name)
  • log2 fold change, log2 fold change standard error and FDR calculated by DESeq2
  • log2 fold change and FDR calculated by edgeR
  • for each considered group, the mean and standard deviation of their FPM
  • FPM for each sample
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("C", "E"); 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],]$donor, 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)




5 Data filtering

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).

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, which exclude background signal (genes with very low expression and/or with minimal changes) while retaining small but putative biologically relevant changes. Here, we test these approaches on a second and independent data set, in order to validate them.

5.1 Abundance filtering

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 included in the analysis actually have an expression level distinct from the background signal?

5.1.1 FPM mean vs. CV

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): 15880 (out of 67495 annotated genes)
## Average FPM of the gene with the lowest expression level in this list: 0.42

5.1.2 x donors = 1 population or x donors = x sub-populations

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", "C",
                                                      round(mean(t[!is.na(t$FPM_cv_control_meanDonors),]$FPM_cv_control_meanDonors), digits = 2)),
                                                 list("mean CV individual donors", "E",
                                                      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", "C", round(mean(t[!is.na(t$FPM_cv_control),]$FPM_cv_control), digits = 2)),
                                                 list("CV all together", "E", 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 == "C",],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 == "E",],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 (noted C) and treated with EGF (E)) are similar.

5.1.3 Expression level vs. variation

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")
k

Figure A shows for all considered genes their FPM mean and CV in samples from male and female cells (1 dot = 1 gene - yellow and green for control and EGF-treated, 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?

5.1.4 Noise signal and CV

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", add = "median", rug = T,
                  color = "group", fill ="group", palette = c("#EFC00055","#00A08755"), 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 = "twodash", 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_sd

The figure shows the distribution of the “noise” genes for male and female samples (yellow and green for control and EGF-treated, respectively). 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).

5.1.4.1 Cut-off determination

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 = 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("#EFC000FF", "#00A087FF"))
g = ggpar(g, legend = "none",  
          xlab = "FPM mean categories", ylab = "Median of CV" ,font.tickslab = 14, font.y = 14, font.x = 14)
g

The 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, an abundance filter of FPM > 4 is applied.

5.1.5 Filter x DEA output

The newly abundance determined 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", "#0073C288"), 
                     labels = c(paste("FPM >",FPMcutoff), paste("FPM <",FPMcutoff))) 
volc =  volc + scale_x_continuous(limits = c(min(MF$edgeR_LFC)-0.5, max(MF$edgeR_LFC)+0.5)) 
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 regulated (group “no filter”, corresponds to the genes comprised in the overlap of DESeq2 and edgeR outputs, filtered for FDR 0.05 only). The volcano plot ( right panel) shows the distribution of the genes that are removed by this filter (marked in blue).

5.2 log2 fold change filtering

5.2.1 Concept

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.


5.2.2 Estimation of the background noise of gene expression data

To determine the “background” noise in the gene expression dataset, the inherent variability of the sample group used as reference is estimated as follow:

  1. We considered of the genes detected in the reference group that meet the FPM-filtering threshold (see section 5.1.4)
  2. The inherent variability v of the dataset (= “background noise”) is defined as the mean CV of the remaining genes. (*)
  3. The log2 fold change threshold L is defined 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 = "#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,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).

5.2.3 Filters x DEA output

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)
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("#0073C255","#0073C2FF")
  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),
              labels = c("(A)", "", "(B)"), font.label = list(size = 10, face = "bold"))
gfilter

Applying 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)). These different filters are also visualized on volcano plots (see previous table for color legend).

However, a question still remains: which 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)?

5.2.4 Filtering x functional analysis

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 = 4)
g = g + theme_bw() + rremove("grid") + rotate_x_text()
g = ggpar(g, xlab = "LFC thresholds", ylab = "Number of enriched terms",
          font.ytickslab = 14, font.xtickslab = 14, font.y = 14, font.x = 14,
          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) 
k

toHighlight = c("GO:0001568", "GO:0007169", "GO:0007186", "GO:0030154", 
                "GO:0030198","GO:0042127","GO:0070371", "GO:0072359", 
                "KEGG:04610", "REAC:R-HSA-1474244")
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 homeostasis (e.g. cell differentiation, extracellular matrix).

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.

gostplot(GOoutput_size, capped = TRUE, interactive = TRUE)

6 Alternative analysis

6.1 Concept

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, as shown with our third analysis focusing on the effect of obesity-related stressors on male VSMC.

We use the present data set to test an alternative approach, based on the paired comparison of the normalized counts (pre-filtered for the abundance threshold previously determined - see section 5.1)). We then compare the obtained results with those of the classical pipeline that includes edgeR and DESeq2.

Alternative approach for data sets with a strong inter-individuality component We propose here an alternative approach to identify regulated genes. The impact of the treatment is calculated for each single gene in each singe sample sets (WARNING: This approach requires sets of strictly paired samples). Using a 99% confidence interval, we determine which genes are putatively regualted. We then apply the log2 fold change filter previously determined, and obtain a list of genes to use for further analysis steps such as functional analysis.
Alternative approach for data sets with a strong inter-individuality component We propose here an alternative approach to identify regulated genes. The impact of the treatment is calculated for each single gene in each singe sample sets (WARNING: This approach requires sets of strictly paired samples). Using a 99% confidence interval, we determine which genes are putatively regualted. We then apply the log2 fold change filter previously determined, and obtain a list of genes to use for further analysis steps such as functional analysis.

6.2 Comparison of the canonical and alternative approaches

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
for(i in unique(sampleTable$donor)){
  R = 1 # replicate indicator
  for(j in sampleTable$sampleName[sampleTable$donor == i & sampleTable$condition == control]){
    #where are the info stored in the sample table?
    ctrlID = which(sampleTable$sampleName == j) ; treatID = which(sampleTable$sampleName == j)+1
    # check if matching samples
    if((sampleTable$cellPassage[ctrlID] == sampleTable$cellPassage[treatID]) & (sampleTable$donor[ctrlID] == sampleTable$donor[treatID])){
      # get the sample names
      ctrlName = j; treatName = sampleTable$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_", i, "_", R)
      # go to the next replicate
      R = R+1
    }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))
b

#### paired
fileName = paste0(outputDir,"EGF_CI_log2FCfilter_CI99.csv"); write.csv(res_CI_FCR, file = fileName, row.names = F)

### Comparison with results obtain with canonical approach
t_filter_CI = res_CI_FCR[res_CI_FCR$selected_adj == "regulated",]

# overlap of the results of DESeq2/edgeR and paired approach (after FPM filtering)
oF = inner_join(t_filter_CI, MF_filter_FPM, by ="ensembl_gene_id", suffix = c(".paired", ".edger")) 

# overlap of the results of DESeq2/edgeR and paired approach (after log2FC filtering)
MF_filter_LFC = MF_filter_FPM[abs(MF_filter_FPM$edgeR_LFC) > LFC_threshold$`LFC threshold`[3],]
t_filter_LFC = res_CI_FCR[res_CI_FCR$selected_adj == "regulated" & res_CI_FCR$LFC == TRUE,]
oLFC = inner_join(t_filter_LFC, MF_filter_LFC, by ="ensembl_gene_id", suffix = c(".paired", ".edger")) 

#grid.newpage()
v1 = draw.pairwise.venn(nrow(MF_filter_FPM), nrow(t_filter_CI), nrow(oF), 
                       category = c("edgeR/DESeq2", "Paired"), 
                       cat.cex = rep(1,2), cat.dist = rep(0.03,2), cat.pos = c(-20,20), cex = rep(1.2,3),
                       lwd = rep(1, 2), lty = rep("solid", 2), cop = rep("black", 2), fill = c("grey80", "grey60"),  
                       scaled = T, ind=F, alpha = 0.5)

v2 = draw.pairwise.venn(nrow(MF_filter_LFC), nrow(t_filter_LFC), nrow(oLFC), 
                       category = c("edgeR/DESeq2", "Paired"), 
                       cat.cex = rep(1,2), cat.dist = rep(0.03,2), cat.pos = c(-30,50), cex = rep(1.2,3),
                       lwd = rep(1, 2), lty = rep("solid", 2), cop = rep("black", 2), fill = c("grey80", "grey60"),  
                       scaled = T, ind=F, alpha = 0.5)

# scatter plot of the changes
minAxis = round(head(sort(c(min(oLFC$mean), min(oLFC$edgeR_LFC))),1))
maxAxis = round(head(sort(c(max(oLFC$mean), max(oLFC$edgeR_LFC))),1))

g = ggscatter(oLFC, x="mean", y="edgeR_LFC", 
              add = "reg.line", conf.int=T, add.params = list(color="black"),  
              xlab = paste("Calculated impact (log2)"), ylab= paste("log2 fold change by edgeR"))
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-0.5,maxAxis+1), xlim = c(minAxis-0.5,maxAxis+1), font.x = 10, font.y = 10)

k = ggarrange(v1,v2, g,
              heights = c(0.8,0.8,1),
              ncol = 3, nrow =1, align = "hv",
              labels = c("(A)","(B)",  "(C)"), font.label = list(size = 10, face = "bold")) 
k

We compared the output of the canonical and alternative DEA approach, (A) after filtering for statistical signficance and abundance, and (B) after additional filtering for log2 fold change. (C) The amplitude of change calculated with the two methods are also compared for the genes comprised in the overlap of the second Venn Diagramm. This shows a strong correlation between the results obtained with each approach.

6.3 Impact on functional analysis

In addition to check the lists of regulated genes, we also check the output of subsequent functional analysis steps, using gprofiler2.

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.

gostplot(GOoutput_size, capped = TRUE, interactive = TRUE)

7 Extension

The same strategy regarding abundance and log2 fold change filtering was applied to a third dataset that was generated to investigate the effect of obesity-associated stressors on male VSMC. The alternative method based on paired-analysis is also implemented.



sessionInfo()
## 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