Skip to content
Snippets Groups Projects
GO_enrichment.R 1.54 KiB
Newer Older
aakan96's avatar
aakan96 committed
library(clusterProfiler) # For functional enrichment analysis
library(org.Hs.eg.db)    # Annotation database for human genes
library(AnnotationDbi)   # Annotation utilities
yunusek77's avatar
yunusek77 committed

aakan96's avatar
aakan96 committed
# Read data from a CSV file named "go.csv" and store it in the "data" variable.
yunusek77's avatar
yunusek77 committed
data <- read.csv("C:/Users/Emre/Desktop/go.csv", sep = ";", header = TRUE)

aakan96's avatar
aakan96 committed
# Extract the ENSEMBL gene IDs from the "data" variable and store them in "genes_to_test".
yunusek77's avatar
yunusek77 committed
genes_to_test <- data$ensembl_gene_id

aakan96's avatar
aakan96 committed
# Perform Gene Ontology (GO) enrichment analysis for Biological Process (BP) terms using "enrichGO" function.
yunusek77's avatar
yunusek77 committed
GO_results <- enrichGO(gene = genes_to_test, OrgDb = "org.Hs.eg.db", keyType = "ENSEMBL", ont = "BP")
as.data.frame(GO_results)

aakan96's avatar
aakan96 committed
# Create a barplot visualizing the top 15 enriched GO terms for Biological Process.
yunusek77's avatar
yunusek77 committed
fit <- plot(barplot(GO_results, showCategory = 15))
fit

aakan96's avatar
aakan96 committed
# Perform GO enrichment analysis for Molecular Function (MF) terms using "enrichGO" function.
yunusek77's avatar
yunusek77 committed
GO_results2 <- enrichGO(gene = genes_to_test, OrgDb = "org.Hs.eg.db", keyType = "ENSEMBL", ont = "MF")
as.data.frame(GO_results2)

aakan96's avatar
aakan96 committed
# Create a barplot visualizing the top 15 enriched GO terms for Molecular Function.
yunusek77's avatar
yunusek77 committed
fit2 <- plot(barplot(GO_results2, showCategory = 15))
fit2

aakan96's avatar
aakan96 committed
# Perform GO enrichment analysis for Cellular Component (CC) terms using "enrichGO" function.
yunusek77's avatar
yunusek77 committed
GO_results3 <- enrichGO(gene = genes_to_test, OrgDb = "org.Hs.eg.db", keyType = "ENSEMBL", ont = "CC")
as.data.frame(GO_results3)

aakan96's avatar
aakan96 committed
# Create a barplot visualizing the top 15 enriched GO terms for Cellular Component.
yunusek77's avatar
yunusek77 committed
fit3 <- plot(barplot(GO_results3, showCategory = 15))
fit3