forked from DeveauP/QuantumClone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI_windows.R
290 lines (245 loc) · 9.8 KB
/
GUI_windows.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
###########################################
#########GUI for QClone####################
###########################################
############Create file browser
create_browser_window<-function(button){
dialog<-gtkFileChooserDialog(title = "Browse file",
parent = NULL, action = "open",
"gtk-ok", GtkResponseType["ok"],
"gtk-cancel", GtkResponseType["cancel"],
show = T)
gtkFileChooserSetSelectMultiple(object = dialog,select.multiple = TRUE)
gSignalConnect(dialog, "response",f = function(dialog,response,data) {
if(response == GtkResponseType["ok"]) {
filename<-gtkFileChooserGetFilenames(object = dialog )
if(button == bSNV){
SNV.box$setText(paste(lapply(X = filename, FUN = function(z) gsub(pattern = "\\\\",replacement = "/",x = paste(z))),collapse = ","))
}
else if(button == bFREEC){
FREEC.box$setText(gsub(pattern = "\\\\",replacement = "/",x = paste(filename)))
}
}
dialog$destroy()
})
}
####
##############Convert file for analysis
ConvertSNVFile<-function(path){
paths<-strsplit(x = path,split=",")[[1]]
result<-lapply(X=paths,FUN = function(z) read.table(file = z,header = TRUE,sep = "\t",as.is = TRUE))
# for(i in 1:length(Names)){
# result[[i]]<-file[grepl(pattern = Names[i],x = file[,1])]
# }
return(result)
}
##############Create window for outputs
create.output.window<-function(button,user.data){
log = gtkWindow("modal")
log$title<-"LOG"
LOGbox<-gtkVBox(spacing = 0)
log$add(LOGbox)
box1<-gtkEntryNew()
box2<-gtkEntryNew()
LOGbox$add(box1)
LOGbox$add(box2)
box1$setText("Data pre-processing...")
#################Recreate variables from input for analysis
simulated<-Simulation$active
save.data<-save.box$active
if(simulated){
box1$setText("Creating data...")
SNV_list<-QuantumCat(number_of_clones = 4, number_of_mutations = 100 ,ploidy="AB",depth=100,
number_of_samples=2,Random_clones=F,contamination=c(0,0))
}
else{
print(SNV.box$getText())
SNV_list<-ConvertSNVFile(as.character(SNV.box$getText()))
}
if(sum(grepl(pattern = "Genotype",x = SNV_list))>0){
FREEC_list<-NULL
}
else{
FREEC_list<-ConvertSNVFile(as.character(SNV.box$getText()))
}
print(head(SNV_list[[1]]))
conta<-eval(parse(text = paste("c(",Contamination$getText(),")",sep="")))
nclone_range<-eval(parse(text = paste("c(",Clone_range$getText(),")",sep="")))
clone_priors<-eval(parse(text = PriorClone$getText()))
prior_weight<-eval(parse(text = PriorWeight$getText()))
maxit<-eval(parse(text =Maxit$getText()))
preclustering<-Preclust$active
save_plot<-save.box$active
ncores<-eval(parse(text= (Ncore$getText())))
box1$setText("Data pre-processing... DONE")
box2$setText("Clustering... MAY LAST SEVERAL MINUTES")
result<-One_step_clustering(SNV_list = SNV_list,FREEC_list = FREEC_list,contamination = conta,nclone_range = nclone_range,
plot_3D = Plot3D$active,plot_3D_before_clustering = Plot3D$active,
clone_priors = clone_priors,prior_weight =prior_weight ,
maxit = maxit,preclustering = preclustering,
simulated = simulated,
save_plot = save_plot,ncores=ncores)
box2$setText("Clustering... Finished")
if(save.data){
write.table(x = cbind(Reduce(f = cbind,x = result$filtered.data),result$cluster,result$EM.output$fik),file = paste(SNV_list[[1]][1,1],"/","clustering_",SNV_list[[1]][1,1],".tsv",sep=""),sep = "\t",row.names = FALSE,quote = FALSE)
}
Close<-gtkButtonNewFromStock("gtk-close")
gSignalConnect(Close, "clicked", log$destroy)
LOGbox$add(Close)
}
library(RGtk2)
library(QuantumClone)
library(ggplot2)
library(fpc)
library(doSNOW)
library(parallel)
###Graphical window to launch clonal heterogeneity research
## Inspired by http://tuxette.nathalievilla.org/?p=866&lang=en ; https://github.com/lawremi/RGtk2/blob/master/RGtk2/inst/doc/tutorial.sgml ; http://www.londonr.org/Presentations/Dec%202010%20-%20G%20Heywood%20Ruser%202010-12-06a.pdf
## http://www.r-bloggers.com/playing-with-guis-in-r-with-rgtk2/
window <- gtkWindow()
window["title"] <- "QuantumClone"
window$modifyBg(GtkStateType["normal"], "white")
frame <- gtkFrameNew("Files and options")
window$add(frame)
box0<-gtkVBox(spacing = 0)
frame$add(box0)
frame$modifyBg(GtkStateType["normal"], "orange")
### SNV file box
box0$add(File_dec_box<-gtkTextView())
File_desc <- File_dec_box$GetBuffer()
File_desc$SetText("Input: List of comma separated files
SNV_list is mandatory if \'Simulation\' is not ticked
FREEC_list is mandatory if genotype is not provided inside SNV_list dataframe")
gtkTextViewSetJustification(object = File_dec_box,justification = "center")
box1 <- gtkHBoxNew(spacing= 10)
box1$setBorderWidth(12)
box0$add(box1) #add box1 to the frame
bSNV<-gtkButton("Browse")
gSignalConnect(bSNV, "clicked", f = create_browser_window)
SNV.box<-gtkEntryNew(show = TRUE)
SNV.box$setText("SNV file(s)...")
box1$packStart(SNV.box,fill=TRUE,expand=TRUE)
box1$packStart(bSNV,fill=FALSE,expand=FALSE)
### FREEC file box
box2<- gtkHBoxNew(spacing= 10)
box2$setBorderWidth(12)
box0$add(box2)
bFREEC<-gtkButton("Browse")
gSignalConnect(bFREEC, "clicked", f= create_browser_window)
FREEC.box<-gtkEntryNew()
FREEC.box$setText("FREEC file(s)...")
box2$packStart(FREEC.box,expand = TRUE)
box2$packStart(bFREEC,fill=FALSE,expand = FALSE)
#################################################Options
box0$add(Option_box_txt<-gtkTextView())
Option_txt<-Option_box_txt$GetBuffer()
Option_txt$SetText("*************************************
OPTIONS
*************************************")
gtkTextViewSetJustification(object = Option_box_txt,justification = "center")
# box0$add(File_dec_box<-gtkTextView())
# File_desc <- File_dec_box$GetBuffer()
# File_desc$SetText("Input: List of comma separated files
# SNV_list is mandatory if \'Simulation\' is not ticked
# FREEC_list is mandatory if genotype is not provided inside SNV_list dataframe")
# gtkTextViewSetJustification(object = File_dec_box,justification = "center")
box0$add(Conta_desc_box<-gtkTextView())
Conta_desc<-Conta_desc_box$GetBuffer()
Conta_desc$SetText("Contamination input: comma separated values of the fraction of normal cells in each samples,in the same order as the SNV_list input. (between 0 and 1)
Clone range: comma separated values of the suspected number of clones that will be tested by the algorithm
Save plot: Should the 2-dimensional plots be saved?
Genotype provided: is the genotype provided in the SNV list?")
#################################################Contamination and Clone range
box3<-gtkHBoxNew(spacing= 2)
box3$setBorderWidth(12)
box0$add(box3) #add main box
Clone_range<-gtkEntryNew()
Clone_range$setText("2:5")
Contamination<-gtkEntryNew()
Contamination$setText("0,0")
Simulation<-gtkCheckButton(label = "Simulation",show = TRUE)
Align<-gtkAlignmentNew(xalign = 0.5)
#Simulation<-gcheckbox(text = "Simulation",checked = F,container = box0,toolkit = "RGtk2)
#setfont_hack(Simulation,list(scale=10))
####Separating the two frames in two sub-boxes
box4<-gtkHBoxNew()
box5<-gtkHBoxNew()
box3$add(box4)
box3$add(box5)
ContaFrame<-gtkFrame(label = "Contamination", show = TRUE)
box4$PackStart(ContaFrame,fill=TRUE,expand = TRUE)
#gtkTextViewSetJustification(object = Conta_desc,justification = "left")
ContaFrame$add(Contamination)
CloneFrame<-gtkFrame(label = "Clone range", show = TRUE)
box5$PackStart(CloneFrame,fill=TRUE,expand = TRUE)
CloneFrame$add(Clone_range)
####Add save plot on same line (box 3)
save.box<-gtkCheckButton(label = "Save plot",show=T)
save.data.box<-gtkCheckButton(label = "Save data in text",show=T)
save.data.box$active=T
save.box$active=T
save.data.box$active=T
box3$add(save.box)
box3$add(save.data.box)
############################## Priors and clustering options
AdvFrame<-gtkFrame(label = "Advanced options", show = TRUE)
AdvFrame$modifyBg(GtkStateType["normal"], "orange")
box0$PackStart(AdvFrame,fill=F)
OptBox<-gtkVBoxNew()
AdvFrame$add(OptBox)
Priors.box<-gtkHBoxNew()
OptBox$add(Priors.box)
PCbox<-gtkHBoxNew()
Priors.box$add(PCbox)
PCFrame<-gtkFrame(label = "Priors on clones", show = TRUE)
PCbox$add(PCFrame)
PWbox<-gtkHBoxNew()
PWFrame<-gtkFrame(label = "Priors on weight", show = TRUE)
PWbox$add(PWFrame)
PCbox$add(PWbox)
PriorClone<-gtkEntryNew()
PriorClone$setWidthChars(20)
PriorClone$setText("NULL")
PriorWeight<-gtkEntryNew()
PriorWeight$setWidthChars(20)
PriorWeight$setText("NULL")
PCFrame$add(PriorClone)
PWFrame$add(PriorWeight)
FinalOptions<-gtkHBoxNew()
OptBox$add(FinalOptions)
Preclust<-gtkCheckButton(label = "Preclustering",show = T)
Preclust$active<-TRUE
FinalOptions$add(Preclust)
Plot3D<-gtkCheckButton(label = "Plot 3D structures",show = T)
Plot3D$active<-F
FinalOptions$add(Plot3D)
MaxitBox<-gtkHBoxNew()
OptBox$add(MaxitBox)
MaxitFrame<-gtkFrame(label = "Number of initial conditions \n to be tested", show = TRUE)
MaxitBox$add(MaxitFrame)
Maxit<-gtkEntryNew()
Maxit$setWidthChars(2)
Maxit$setText("1")
MaxitFrame$add(Maxit)
NcoreBox<-gtkHBoxNew()
OptBox$add(NcoreBox)
NcoreFrame<-gtkFrame(label = "Number of cores", show = TRUE)
NcoreBox$add(NcoreFrame)
Ncore<-gtkEntryNew()
Ncore$setWidthChars(2)
Ncore$setText("1")
NcoreFrame$add(Ncore)
####################################################
####################################################
####################################################
##################Launch / Close
SNV.box$modifyBg(GtkStateType["normal"], "orange")
box0$add(Align)
Align$add(Simulation)
ButtonBox<-gtkHBoxNew()
box0$add(ButtonBox)
Start<-gtkButtonNewFromStock("gtk-ok")
Close<-gtkButtonNewFromStock("gtk-close")
gSignalConnect(Close, "clicked", window$destroy)
ButtonBox$add(Start)
ButtonBox$add(Close)
gSignalConnect(Start,signal = "clicked",create.output.window)