Pseudobulk DESeq2 differential expression for scRNA-seq. Use when running DE between conditions, comparing wound timepoints, or performing pseudobulk analysis.
library(DESeq2)
library(Seurat)
# Aggregate to pseudobulk
pseudo <- AggregateExpression(sobj, group.by = c("condition", "sample"),
return.seurat = TRUE)
# Run DESeq2
dds <- DESeqDataSetFromMatrix(
countData = GetAssayData(pseudo, slot = "counts"),
colData = [email protected],
design = ~ condition
)
dds <- DESeq(dds)
res <- results(dds, contrast = c("condition", "wound_7d", "control"),
lfcThreshold = 0, alpha = 0.05)
res <- lfcShrink(dds, coef = "condition_wound_7d_vs_control", type = "ashr")
padj < 0.05|log2FoldChange| > 1.0ashrCSV files with columns: gene, log2FC, padj, baseMean
res_df <- as.data.frame(res) %>%
tibble::rownames_to_column("gene") %>%
dplyr::arrange(padj)
write.csv(res_df, "analysis/de/de_wound_7d_vs_control.csv", row.names = FALSE)
wound_3d vs controlwound_7d vs controlwound_14d vs control