-
Notifications
You must be signed in to change notification settings - Fork 133
/
3_min_GSEA_tutorial.Rmd
136 lines (60 loc) · 1.49 KB
/
3_min_GSEA_tutorial.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
---
title: "R Notebook"
output: html_notebook
---
```{r}
library(DESeq2)
Counts <- read.delim("count_table.csv", header = TRUE, row.names = 1, sep = ",")
Counts <- Counts[which(rowSums(Counts) > 0),]
condition <- factor(c("C","C","C","C", "S","S","S","S"))
coldata <- data.frame(row.names = colnames(Counts), condition)
dds <- DESeqDataSetFromMatrix(countData = Counts, colData = coldata, design = ~condition)
dds <- DESeq(dds)
res <- results(dds, contrast = c("condition", "S", "C"))
res <- na.omit(res)
res <- res[res$baseMean > 50,]
```
```{r}
res
```
```{r}
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("org.Hs.eg.db") #org.Mm.eg.db for mouse
if (!require("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("clusterProfiler")
if (!require("BiocManager", quietly = TRUE))
install.packages("BiocManager")
BiocManager::install("AnnotationDbi")
```
```{r}
library(org.Hs.eg.db)
library(clusterProfiler)
```
```{r}
res <- res[order(-res$stat),]
res
```
```{r}
gene_list <- res$stat
names(gene_list) <- rownames(res)
gene_list
```
```{r}
gse <- gseGO(gene_list,
ont = "BP",
keyType = "ENSEMBL",
OrgDb = "org.Hs.eg.db",
eps = 1e-300)
```
```{r}
as.data.frame(gse)
```
```{r}
fit <- gseaplot(gse, geneSetID = 1)
png("gsea.png", res = 250, width = 2000, height = 1300)
print(fit)
dev.off()
fit
```