4.4 Sorting and Filtering Significant Genes

We order genes by adjusted p-value and filter to retain only those passing our significance thresholds: padj < 0.05 and |log2FC| ≥ 1 (i.e., at least a 2-fold change).

res_df <- as.data.frame(res_shrunk) %>%
  rownames_to_column("gene") %>%
  arrange(padj) %>%
  filter(!is.na(padj))

res_sig <- res_df %>%
  filter(padj < 0.05, abs(log2FoldChange) >= 1)

cat("Total genes tested       :", nrow(res_df), "\n")
## Total genes tested       : 3698
cat("Significant genes        :", nrow(res_sig), "\n")
## Significant genes        : 646
cat("  Upregulated (LFC ≥ 1)  :", sum(res_sig$log2FoldChange >= 1), "\n")
##   Upregulated (LFC ≥ 1)  : 258
cat("  Downregulated (LFC ≤ -1):", sum(res_sig$log2FoldChange <= -1), "\n")
##   Downregulated (LFC ≤ -1): 388

Interactive Results Table

DT::datatable(
  res_sig %>% mutate(across(where(is.numeric), \(x) round(x, 4))),
  rownames   = FALSE,
  extensions = c('Buttons', 'Scroller'),
  options    = list(
    dom         = 'Bfrtip',
    buttons     = c('copy', 'csv'),
    scrollX     = TRUE,
    scrollY     = 300,
    scroller    = TRUE
  ),
  caption = 'Significant DE genes — treatment vs control (padj < 0.05, |LFC| ≥ 1)'
)