-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_script.R
260 lines (151 loc) · 13.1 KB
/
example_script.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
#==================================================================================
# Written by Noushin Farnoud, Jul 2018. Last updated April 2024
#----------------------------------------------------------------------------------
# This is an example of how to run Oncoprint-Scripts for a set of mutations/cnvs/svs.
#
# Contact Noushin Farnoud ([email protected]) if you faced any error.
#
# Many thanks to Teja for proving the SV example data that is used in this example.
#
# See also generate_complex_oncoprint.R
#==================================================================================
rm(list=ls()) #clear all vars
library(reshape)
library(gsheet)
library(readxl)
library(plyr)
library(dplyr)
#########################
# Initialize
#########################
setwd("/Users/rahnaman/Documents/Oncoprint/")
muts.file <- "./example_data/Mutations.xlsx" # 1st dataframe (Noushin's)
teja.url <- "https://docs.google.com/spreadsheets/d/1yZzCSA38mZbGyeCjlzh6xups2t0S6y_JY0jcTwDKp5A/edit#gid=1786134805" # 2nd dataframe (Teja's)
savePath <- "./example_oncoprints/"
min.freq <- 1
#########################
# Load SUBs and INDELs
#########################
MUT <- read_excel(muts.file) %>% filter(Noush_annot2 %in% c("ONCOGENIC","LIKELY"))
###########################################################################
# EXAMPLE 1.A: Generate Simple Oncoprint of Mutations ----
###########################################################################
cat(paste("\n>>>>> Staring Example 2. Show genes with >= 2 freq, Add Response and a new added ribbon (for Race). Control visualizations ... \n"))
source("./generate_complex_oncoprint.R")
ht <- generate_complex_oncoprint(muts= MUT,
show.sample.names = TRUE, show.border= FALSE,
min.freq= 1, show.title= TRUE, title.str= "Example 1 - YOHOOOO I managed to get this without any error, but these default font sizes are NOT good.",
save.name= "Example_1.A", #******* NAME of the saved oncoprint fig
save.path= "./example_oncoprints/", #******* DIR of the saved oncoprint fig
)
###########################################################################
# EXAMPLE 1.B: Run previ. Example with better fonts ----
###########################################################################
cat(paste("\nFinished Example 1. Now I like to improve the size of the fonts.\n"))
ht <- generate_complex_oncoprint(muts= MUT,
show.sample.names = TRUE, show.border= FALSE,
min.freq= 1, show.title= TRUE, title.str= "Example 1.B - YOHOOOO - GOOD FONTs!",
save.name= "Example_1.B", #******* NAME/DIR of the saved oncoprint fig
save.path= "./example_oncoprints/", #******* DIR of the saved oncoprint fig
cols.font= 18,
rows.font= 18,
pct.font= 20,
legend.label.font= 20,
legend.title.font= 25,
fig.title.font= 25,
barplot.font= 20,
right.w= 8, top.w= 5 , w=2000, h=1600, #**** Sizes of barplots and fig
axis.side= "left")
cat(paste("\nFinished Example 1. Now I like to define the order of the response in the legend.\n"))
##############################################################################################
# EXAMPLE 5: How to override default clustering with an input order of patients (cols)? ----
##############################################################################################
my.pts.order <- c("E-H-131710-T1-1-D1-1", "E-H-131712-T1-1-D1-1", "E-H-131721-T1-1-D1-1", "E-H-131713-T1-1-D1-1", "E-H-131717-T1-1-D1-1", "E-H-131719-T1-1-D1-1", "E-H-131720-T1-1-D1-1",
"E-H-131714-T1-1-D1-1", "E-H-131711-T1-1-D1-1", "E-H-131716-T1-1-D1-1","E-H-131715-T1-1-D1-1", "E-H-131718-T1-1-D1-1")
ht.order <- generate_complex_oncoprint(muts= MUT,
show.sample.names = TRUE, patients.order = my.pts.order,
min.freq= 1, show.title= TRUE, title.str= "Example 6 user-specified patients.order",
save.name= "Example_5",
save.path= "./example_oncoprints/",
cols.font= 18,
rows.font= 18,
pct.font= 20,
legend.label.font= 20,
legend.title.font= 25,
fig.title.font= 25,
barplot.font= 20,
right.w= 8, top.w= 5 , w=2000, h=1600, #**** Sizes of barplots and fig
axis.side= "left")
cat(paste("\nFinished USER-defined ORDER example.\n"))
###########################################################################
# Load and prepare CNVs : Required columns (TARGET_NAME, VAR_ID, VT)
###########################################################################
rm(list=ls()) #clear all vars
# savePath <- "./example_oncoprints/"
load("./example_data/Example2.RData")
############################################################
# EXAMPLE (2): Oncoprint with MUT + CNV + SV ====
############################################################
cat(paste("\n>>>>> Staring Example 2 ... \n"))
source("./generate_complex_oncoprint.R")
ht <- generate_complex_oncoprint(muts= MUTs, svs= SVs, cnvs=cnvs, min.freq= 1,
save.name= "Example_2",
save.path= "./example_oncoprints/",
title.str= "Example 2 - Mutuations + CNVs + SVs",
heatmap.legend.side= "bottom", #**change the default location of mutation legend
num.rows.heatmap.lgd= 2,
mut.legend.title.side = "leftcenter",
pct.font = 18,
legend.label.font = 20,
legend.title.font = 18,
barplot.font = 18,
right.w = 5)
# this saved the jpg version of the heatmap at the specified location;
# you can load the heatmap and save the pdf ver using ht$ht.obj
cat(paste("\nFinished an example with default MUTs plus CNVs and SVs.\n"))
cat(paste("================================\n\n"))
###################################################
# EXAMPLE (3): Oncoprint with RESPONSE annotation
###################################################
cat(paste("\n>>>>> Staring Example 3. Show genes with >= 2 freq, Add Response and a new added ribbon (for Race). Control visualizations ... \n"))
source("./generate_complex_oncoprint.R")
ht <- generate_complex_oncoprint(muts= MUTs, cnvs= cnvs, svs= SVs , # define variants DFs
save.name= "Example_3",
cnvs.order= NULL, svs.order= NULL, muts.order= NULL, patients.order= NULL, # define pre-set orders (if needed to)
show.response= TRUE, response.order= NULL, ## ***** show RESPONSE
lookup.table= my.table, #******* REQUIRED: PASS lookup.table
show.sample.names = TRUE, show.border= FALSE, show.multis= FALSE, rem.empty= TRUE, # ******* params to show in legend
heatmap.legend.side= "right", mut.legend.title.side= "topcenter", num.rows.heatmap.lgd= NULL, #******* HEATMAP.legend
annot.legend.side= "bottom", annot.title.side= "topleft", num.rows.annot.lgd= NULL, #******* ANNOT.legend
min.freq= 2, show.title= TRUE, title.str= "Notice the impact of setting show.multis to TRUE",
save.path= "./example_oncoprints/", #******* title and save path
cols.font= 22, rows.font= 22, pct.font= 22, legend.label.font= 20,
legend.title.font= 25, fig.title.font= 22, barplot.font= 20,
multis.dot.size = 0.8, #****FONTs: (for noush => 'row.groupname.font' is the same as rows.font)
right.w= 8, top.w= 5 , w=3200, h=2800, #**** Sizes of barplots (right.w and top.w) and saved figure (w,h)
axis.side= "left")
cat(paste("\nFinished Example 3. Now I like to also visualize my multi-hit genes.\n"))
cat(paste("===========================================================================\n"))
#########################################################
# EXAMPLE (4): Example 3 + multi-hit Visualization ====
#########################################################
source("./generate_complex_oncoprint.R")
ht <- generate_complex_oncoprint(muts= MUTs, cnvs= cnvs, svs= SVs , # define variants DFs
cnvs.order= NULL, svs.order= NULL, muts.order= NULL, patients.order= NULL, # define pre-set orders
surval.data= NULL,
show.response= TRUE, response.order= c("CR","PR","NR"), show.another.banner=TRUE, banner.name= "Race", show.individuals= FALSE, show.individuals.legend= FALSE, show.survival= FALSE, # ******* user-defined ORDERs
lookup.table= my.table, #******* pass lookup.table
show.sample.names = FALSE, show.border= FALSE, show.multis= TRUE, rem.empty= TRUE, # ******* what params to show in legend?
heatmap.legend.side= "right", mut.legend.title.side= "topcenter", num.rows.heatmap.lgd= NULL, #******* HEATMAP.legend
annot.legend.side= "bottom", annot.title.side= "topleft", num.rows.annot.lgd= NULL, #******* ANNOT.legend
min.freq= 2, show.title= TRUE, title.str= "Notice the order of RESPONSE in the legend",
#******* title and save path
save.name = "Example_4",
save.path= "./example_oncoprints/",
cols.font= 22, rows.font= 22, pct.font= 22, legend.label.font= 20, legend.title.font= 25, fig.title.font= 22, barplot.font= 10,
multis.dot.size = 0.8, #****FONTs: row.groupname.font is the same as rows.font
right.w= 8, top.w= 5 , w=3200, h=2800, #**** Sizes of barplots and fig
axis.side= "left")
cat(paste("============================================================================"))
cat(paste("\nEnd of Tutorial. Try playing with the params and observe the difference.\n"))
cat(paste("============================================================================\n"))