EnrichR - MattHuff/scRNASeq_011224 GitHub Wiki

Previous EnrichR Documentation

Load Packages, Set Working Directory, and Obtain DE Genes

# Load Dependencies
library(topGO)
library(tidyr)
library(biomaRt)
library(ggplot2)
library(Rgraphviz)
library(enrichR)

# Set Working Directory
setwd("~/Downloads/scRNASeq_011224/5_Seurat/")

# Set EnrichR Site
setEnrichrSite("Enrichr")

# Set GO Databases
dbs <- c("GO_Biological_Process_2018", "GO_Cellular_Component_2018", "GO_Molecular_Function_2018")

# Load DE Genes
combined_df_sign <- read.table(file = "outputs/de_out/Norris_Dge_FindMarkersMAST_Sign_run2.txt",
                               sep = "\t", header = TRUE)

Run EnrichR

## Create Main Directory
go_path <- "outputs/de_out/GO_enrichment/"
if(!dir.exists(go_path)){dir.create(go_path,recursive = T)}

## Obtain Cell Types
cellTypes <- unique(combined_df_sign$celltype)

for (f in 1:length(cellTypes)) {
  cur_celltype <- cellTypes[f](/MattHuff/scRNASeq_011224/wiki/f)
  cur_df <- subset(combined_df_sign, celltype == cur_celltype)
  cur_genes <- cur_df$genes
  cur_enriched <- enrichr(cur_genes, dbs)
  cur_path <- paste0(go_path, cur_celltype, "/")
  if(!dir.exists(cur_path)){dir.create(cur_path,recursive = T)}
  
  for (i in 1:length(dbs)) {
    cur_GO <- dbs[i](/MattHuff/scRNASeq_011224/wiki/i)
    cur_GO <- gsub("GO_|_2018", "", cur_GO)
    
    enrichPlot <- plotEnrich(cur_enriched[i](/MattHuff/scRNASeq_011224/wiki/i), showTerms = 20, numChar = 40, y = "Count", orderBy = "P.value")
    ggsave(paste0(cur_path, "EnrichPlot_", cur_celltype, "_", cur_GO, ".pdf"), height = 12, width = 12)
  }
}