-
Notifications
You must be signed in to change notification settings - Fork 0
/
GSE107385.Rmd
198 lines (158 loc) · 4.71 KB
/
GSE107385.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
---
title: "GSE107385 Differential Expression"
author: "João Vitor F. Cavalcante"
date: "`r Sys.setlocale('LC_TIME', 'C'); format(Sys.time(), '%d %B, %Y')`"
knit: (function(inputFile, encoding) {
rmarkdown::render(inputFile, encoding = encoding, output_dir = "../reports/") })
output:
html_document:
toc: true
toc_float: true
toc_collapsed: false
theme:
bslib: true
bootswatch: minty
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
message = FALSE,
warning = FALSE,
eval = FALSE)
```
# Methodology
* Microarray Differential expression
- To obtain the normalized count matrices for this study, we used the **oligo**
R package.
- To perform the differential expression analysis itself, we used the **limma** R package.
- Differentially expressed genes determined for p-value < 0.01 and BH method for p-value adjustment.
# Differential Expression
## Loading libraries and functions
```{r}
library(oligo)
library(limma)
library(readr)
library(dplyr)
library(affy)
```
```{r}
# Acquire metadata for the study
get_phenodata <- function(gse_id) {
read_csv("data/Plataformas.csv") %>%
janitor::clean_names() %>%
filter(gse == gse_id) %>%
dplyr::select(gsm, grupo, grupo_no_trabalho_original)
}
# Run differential expression with limma
get_limma_dexp <-
function(eset,
phenodata,
contraste,
symbol = NULL,
add_id = NULL,
platform_df = NULL) {
eset_df <- exprs(eset)
design <- model.matrix(~ 0 + factor(phenodata$grupo))
colnames(design) <- unique(phenodata$grupo)
fit <- limma::lmFit(eset, design)
if (is.null(platform_df)) {
db_symbol <- as.data.frame(symbol[rownames(eset_df)])
db_add_id <- as.data.frame(add_id[rownames(eset_df)])
platform_df <-
db_add_id %>% left_join(db_symbol, by = "probe_id")
}
contrasts <-
limma::makeContrasts(contrasts = contraste, levels = design)
fit2 <- contrasts.fit(fit, contrasts)
ct.fit <- limma::eBayes(fit2)
res.fit <-
limma::decideTests(
ct.fit,
method = "global",
adjust.method = "BH",
p.value = 0.01,
)
is_de = as.data.frame(res.fit@.Data) %>%
tibble::rownames_to_column("probe") %>%
setNames(., c("probe", "is_de"))
topTable(
ct.fit,
coef = 1,
adjust.method = "BH",
number = "inf",
confint = TRUE
) %>%
tibble::rownames_to_column("probe") %>%
left_join(is_de, by = "probe") %>%
left_join(platform_df, by = c("probe" = "probe_id"))
}
clean_toptable <- function(toptable, unique_col) {
ref_col = dplyr::sym(unique_col)
toptable %>%
group_by(!!ref_col) %>%
slice(which.max(abs(logFC))) %>%
ungroup()
}
# Main function
# Loads dataset with appropriate platform technology (affymetrix, affy-oligo or agilent)
# Run differential expression with limma and return output table
get_dge_table <-
function(gse_id,
celfile_path,
contraste,
refcol,
symbol = NULL,
add_id = NULL,
platform_df = NULL,
oligo_exp = FALSE,
agilent = FALSE) {
phenodata_file <- get_phenodata(gse_id)
if (oligo_exp == TRUE) {
celfiles <-
list.files(celfile_path, pattern = "CEL.gz", full.names = TRUE)
data <-
oligo::read.celfiles(celfile.path = celfiles)
eset <- oligo::rma(data)
} else if (agilent == TRUE) {
celfiles <- list.files(celfile_path, pattern = "txt.gz")
raw <-
read.maimages(celfiles,
path = celfile_path,
source = "agilent",
green.only = TRUE)
norm <- backgroundCorrect(raw, method = "normexp")
norm <- normalizeBetweenArrays(norm, method = "quantile")
norm.ave <- avereps(norm, ID = norm$genes$ProbeName)
eset <- Biobase::ExpressionSet(assayData = norm.ave$E)
} else {
data <-
affy::ReadAffy(celfile.path = celfile_path)
eset <- affy::rma(data)
}
toptable <- get_limma_dexp(
eset,
phenodata_file,
contraste,
symbol = symbol,
add_id = add_id,
platform_df = platform_df
)
clean_toptable(toptable, refcol)
}
```
## Analysis
Now, we perform the differential expression analysis itself.
```{r run-analysis}
GPL16686 <- read_csv("data/GPL16686.csv", col_types = c(rep("c", 3))) %>%
janitor::clean_names()
GSE107385 <-
get_dge_table(
"GSE107385",
"data/GSE107385",
"Tratado-Controle",
refcol = "hgnc_symbol",
platform_df = GPL16686,
oligo_exp = TRUE,
)
GSE107385 %>%
write_csv("results/GSE107385.csv")
```