-
Notifications
You must be signed in to change notification settings - Fork 127
/
runDESeq2.R
73 lines (43 loc) · 1.44 KB
/
runDESeq2.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
64
65
66
67
68
69
70
# script to perform differential gene expression analysis using DESeq2 package
# setwd("~/Desktop/demo/DESeq2_tutorial/data")
# load libraries
library(DESeq2)
library(tidyverse)
library(airway)
# Step 1: preparing count data ----------------
# read in counts data
counts_data <- read.csv('counts_data.csv')
head(counts_data)
# read in sample info
colData <- read.csv('sample_info.csv')
# making sure the row names in colData matches to column names in counts_data
all(colnames(counts_data) %in% rownames(colData))
# are they in the same order?
all(colnames(counts_data) == rownames(colData))
# Step 2: construct a DESeqDataSet object ----------
dds <- DESeqDataSetFromMatrix(countData = counts_data,
colData = colData,
design = ~ dexamethasone)
dds
# pre-filtering: removing rows with low gene counts
# keeping rows that have at least 10 reads total
keep <- rowSums(counts(dds)) >= 10
dds <- dds[keep,]
dds
# set the factor level
dds$dexamethasone <- relevel(dds$dexamethasone, ref = "untreated")
# NOTE: collapse technical replicates
# Step 3: Run DESeq ----------------------
dds <- DESeq(dds)
res <- results(dds)
res
# Explore Results ----------------
summary(res)
res0.01 <- results(dds, alpha = 0.01)
summary(res0.01)
# contrasts
resultsNames(dds)
# e.g.: treated_4hrs, treated_8hrs, untreated
results(dds, contrast = c("dexamethasone", "treated_4hrs", "untreated"))
# MA plot
plotMA(res)