/
bulkRNAana_2a_DESeq.R
63 lines (47 loc) · 1.54 KB
/
bulkRNAana_2a_DESeq.R
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
# MESSAGE -----------------------------------------------------------------
#
# author: Yulin Lyu
# email: lvyulin@pku.edu.cn
#
# require: R < 4.0 (recommended)
#
# note: DESeq is only for visualization usage in my protocols.
# It was no longer available since bioconductor 3.11 for R4.
# The last version of DESeq was built on R3.
# So this package may not work on R4.
#
# ---
# 1. Load packages --------------------------------------------------------
setwd("exampleData/RNA")
# grammar
library(tidyverse)
library(magrittr)
library(glue)
# analysis
library(DESeq)
# for more information, please refer to:
# http://bioconductor.org/packages/3.10/bioc/vignettes/DESeq/inst/doc/DESeq.pdf
# 2. Load data ------------------------------------------------------------
dataMtx <- readRDS("mid/dataMtx.rds")
colnames(dataMtx)
usedMtx <- dataMtx[c(
c("wanted sample names"),
NULL
)]
# 3. Analyze --------------------------------------------------------------
dir.create("DESeq")
condition <- factor(
c("a", "b", "c"),
levels = c("a", "b", "c")
)
cds <- newCountDataSet(usedMtx, condition) %>%
estimateSizeFactors() %>%
estimateDispersions(method = "blind", sharingMode = "fit-only")
# save vsd profile for visualization later
vsd <- varianceStabilizingTransformation(cds)
saveRDS(vsd, "DESeq/vsd.rds")
# perform DEG test (BETTER DO NOT, only if there is no other choice)
# DEGres <- list()
# DEGres$a_vs_b <- nbinomTest(cds, "a", "b")
# DEGres$a_vs_c <- nbinomTest(cds, "a", "c")
# iwalk(DEGres, ~ write_csv(.x, glue("DESeq/{.y}.DEG.csv")))