-
Notifications
You must be signed in to change notification settings - Fork 0
/
RNA-seq data analysis with limma.R
67 lines (48 loc) · 1.76 KB
/
RNA-seq data analysis with limma.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
# install required packages
BiocManager::install("limma")
BiocManager::install("edgeR")
# import neccessary libraries
library(limma)
library(edgeR)
library(dplyr)
# load expression data (TCGA expresssion data)
exprs <- get(load("dataFilt.RData"))
# Load clinical data
clinical_data <- read.csv("Clinical.csv")
clinical_data <- data.frame(clinical_data, row.names = T)
# rownames (sample id) of clinical data matches with colnames (sample id) of expression data
all(rownames(clinical_data) %in% colnames(exprs))
all(rownames(clinical_data) == colnames(exprs))
# create a DGE object (DGEList function from edgeR)
dge <- DGEList(exprs)
dge <- calcNormFactors(dge)
dim(dge)
# make braf_status as factor
group = factor(clinical_data$braf_status)
group = relevel(group, ref="WT")
# Filter lowly- expressed genes
cutoff <- 1
drop <- which(apply(cpm(dge), 1, max) < cutoff)
dge <- dge[-drop,]
head(dge$counts)
# Design model matrix
mm <- model.matrix(~0+group)
# Voom transformation
v <- voom(dge, mm, plot = T)
# fitting model
fit <- lmFit(v, mm)
head(coef(fit))
# make a contrast to compare samples between two condition
contr <- makeContrasts(groupV600E-groupWT, levels = colnames(coef(fit)))
# Fitting constrast
tmp <- contrasts.fit(fit, contr)
tmp <- eBayes(tmp)
# calculate log2 fold change and other parameters to get significant genes
top.table <- topTable(tmp,adjust.method ="fdr",n = Inf)
# how many genes are up-regulated
length(which(top.table$adj.P.Val < 0.05 & top.table$logFC > 1))
# how many genes are down-regulated
length(which(top.table$adj.P.Val < 0.05 & top.table$logFC < -1))
# save top.table file
write.csv(top.table,file="top.table.csv",row.names =T )
save(top.table, file="top.table.rda")