-
Notifications
You must be signed in to change notification settings - Fork 0
/
EXIS_Workflow.R
317 lines (188 loc) · 10.8 KB
/
EXIS_Workflow.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
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
############# #### #### #### #########
############# #### #### #### ##########
##### ########### #### #####
##### ####### #### #####
############# ########### #### ########
############# #### #### #### ########
##### #### #### #### ######
##### #####
#####################################################
#####################################################
#Isoform expression analysis
#CREATED BY JARNO KOETSIER
#EXIS 1.0.0 (June, 2021)
###############################################################################################################################
#INSTRUCTIONS WORKFLOW SCRIPT
###############################################################################################################################
#1. Source run the global R script every time you use the workflow.
#2. Make sure that the exon/transcript-specific CDF file is in your working directory
# OR has been installed as a CDF package previously.
#3. When you would like to use the exon-specific probe set definition,
# also make sure to place the exon annotation file in your working directory
################################################################################################################################
#get database accession
################################################################################################################################
#Enter GEO or ArrayExpress accession number
#You can run the code with "GSE36980" (GEO dataset) for an example analysis.
database = "GEO" #choose "GEO" or "ArrayExpress"
accession = "GSE36980"
################################################################################################################################
#get meta
################################################################################################################################
#In this step, the grouping variable is selected from the metadata.
#This grouping variable is later used in the differentially expression analysis.
#ACCESS DATA
##Only run if dataset is from GEO
gset <- getGEO(accession, GSEMatrix =TRUE, getGPL = FALSE)
##Only run if dataset is from ArrayExpress
gset <- ArrayExpress(accession)
#GET METADATA
groups <- get_grouping(gset, database = database)
#SELECT GROUPING VARIABLE
#auto-group() automatically selects the relevant grouping variable.
#However, you can also select your grouping variable manually instead.
selected_group <- auto_group(groups)
groupingvar <- groups[,selected_group]
#Make meta table
#This table indicates to which group each sample belongs.
meta <- get_meta(gset = gset,
grouping_column = groupingvar,
pairing_column = NULL,
database = database)
################################################################################################################################
#get data
################################################################################################################################
#GET CHIPTYPE
#The get_chiptype function automatically searches for this chiptype in the dataset.
#You can also select the chipytpe manually.
#IMPORTANT: the chiptype should be written without capitals, spaces, dots, comma's, etc.
#e.g. "hugene10st" or "huex10st"
chiptype = get_chiptype(gset, database = database)
#GET ORGANISM
#The get_organism function automatically searches for the organism in the dataset.
#You can also select the organism manually.
#IMPORTANT: the organism should be written in a two-letter code with lowercase letters only.
#e.g. "hs" or "mm"
organism = get_organism(gset, database = database)
#GET BRAINARRAY VERSION
#Currently, 25 is the latest version.
version = 25
#GET PROBESET ANNOTATION
# "ense" for exon-specific probsets
# "enst" for transcript-specific probesets
annotation = "enst"
#MAKE AFFYBATCH
#The readcels1 function requires the CDF to be in the working directory
#unless the CDF has been installed as a package previously
data1 <- readcels1(accession = accession,
database = database,
chiptype = chiptype,
organism = organism,
version = version,
annotation = annotation,
robust = FALSE,
outliers = "GSM4764672")
################################################################################################################################
#Normalization
################################################################################################################################
#Perform RMA normalization
data.rma <- affy::rma(data1, normalize = TRUE, background = TRUE)
#Retrieve probe set expression
data.expr <- exprs(data.rma)
#Remove the "nonsense" probeset.
#This probeset is only included for normalization purposes.
data.expr <- data.expr[rownames(data.expr) != "nonsense",]
################################################################################################################################
#Quality control
################################################################################################################################
#BOXPLOTS OF LOG2 INTENSITIES
##Raw data
par(mar=c(8,4,2,1))
boxplot(data1,which='pm', col = "red", las = 2, main = "Boxplot of raw data", ylab = "log2 intensity")
##Normalized data
par(mar=c(8,4,2,1))
boxplot(data.expr, col = "blue", las = 2, main = "Boxplot of normalized data", ylab = "log2 intensity")
#DENSITY PLOTS OF LOG2 INTENSITIES
##Raw data
par(mar=c(5,4,2,1))
hist(data1,lwd=2,which='pm',ylab='Density',xlab='log2 intensity',main='Density plot of raw data')
##Normalized data
par(mar=c(5,4,2,1))
plotDensity(data.expr,lwd=2,ylab='Density',xlab='log2 intensity',main='Density plot of normalized data')
#PCA PLOT
data.PC <- prcomp(t(data.expr),scale.=TRUE)
pca.plot(data.PC = data.PC,
meta = meta,
hpc = 1, #horizontal axis (1 = PC1 on horizontal axis, 2 = PC2 on horizontal axis, etc.)
vpc = 2) #vertical axis (2 = PC2 on vertical axis, 3 = PC3 on vertical axis, etc.)
################################################################################################################################
#Differential expression analysis
################################################################################################################################
#GET COMPARISONS
#Get comparisons for the differential expression analysis
#The get_contrast function retrieves all possible comparisons that are possible according to the meta table.
comparisons <- get_contrasts(meta)
#GET TOP TABLE
#Make top table using the meta data
#This function performs DE analysis for all possible comparisons and returns a list object.
top.table <- diff_expr(data.expr = data.expr,
meta = meta,
comparisons = comparisons)
################################################################################################################################
#SELECT AND ANNOTATE THE EXON-SPECIFIC PROBESETS
#IMPORTANT: you can only use run these codes if you used the "ense" annotation in the readcels function
#Get annotation file from the working directory
exonannotation <- read.table(file = paste(chiptype, organism, version, "ExonAnnotation.txt", sep = "_"), header = TRUE)
#Select exons of interest AND annotate the exons with their corresponding transcript(s) and gene
select.top.table <- exon_selection(top.table = top.table,
annotated = exonannotation,
genes = c("ENSG00000065989",
"ENSG00000184588",
"ENSG00000105650",
"ENSG00000113448"),
transcripts = NULL,
genome_wide = TRUE,
unique_exons = FALSE)
################################################################################################################################
#SELECT AND ANNOTATE THE TRANSCRIPT-SPECIFIC PROBESETS
#IMPORTANT: you can only use run these codes if you used the "enst" annotation in the readcels function
#Select transcripts of interest AND annotate the transcripts with their corresponding gene
select.top.table <- transcript_selection(top.table = top.table,
genes = c("ENSG00000065989",
"ENSG00000184588",
"ENSG00000105650",
"ENSG00000113448"),
transcripts = NULL,
genome_wide = FALSE)
################################################################################################################################
#Output plots
################################################################################################################################
#BOXPLOTS
#IMPORTANT: this function is not suitable for genome-wide analyses
#Thus, only run this function if you selected a hand-full of transcripts/exons in the select.top.table.
makeBoxplots1(contrast = comparisons[7],
meta = meta,
data.expr = data.expr,
select.top.table = select.top.table,
annotated = NULL) #In case of exon-specific probesets:
#annotated = exonannotation
#PROBE MAPPING PLOT
#These plots show the probes included in each transcript/exon-specific probesets
#These plots can not be used in genome-wide analyses
#Transcript-specific probe sets
probemapping.enst(chiptype = chiptype,
organism = organism,
version = version,
gene = "ENSG00000113448")
#Exon-specific probe sets
probemapping.ense(chiptype = chiptype,
organism = organism,
version = version,
gene = "ENSG00000113448",
annotated = exonannotation)
#VOLCANO PLOT
plotvolcano(select.top.table = select.top.table,
contrast = comparisons[1],
p = "raw", #choose from "raw" or "FDR"
p.threshold = 0.05,
logFC.threshold = 1)