-
Notifications
You must be signed in to change notification settings - Fork 2
/
DlgSelectGraph.java
456 lines (430 loc) · 21.7 KB
/
DlgSelectGraph.java
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
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tappas;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.stage.Window;
import tappas.DataApp.EnumData;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Optional;
/**
*
* @author Hector del Risco - [email protected] & Pedro Salguero - [email protected]
*/
public class DlgSelectGraph extends DlgBase {
Label lblItemGroups;
ComboBox cbItemGroups;
ListView lvGraphs;
Params dfltParams;
private static ArrayList<ImageData> lstImages = new ArrayList<>();
ArrayList<EnumData> lstItemGroups = new ArrayList<>();
AppController.DAMenuFlags daflags;
AppController.EAMenuFlags eaflags;
AppController.MAMenuFlags maflags;
public DlgSelectGraph(Project project, Window window) {
super(project, window);
}
public Params showAndWait(Params dfltParamsArg) {
// create default parameters if not given
dfltParams = dfltParamsArg == null? new Params() : dfltParamsArg;
// setup acording to item type specified
String type = "data";
String lbl = "Data Type";
switch(dfltParams.itemType) {
case AF:
daflags = app.ctlr.getDAMenuFlags();
maflags = app.ctlr.getMAMenuFlags();
lstItemGroups.add(new EnumData("", "All"));
lstItemGroups.add(new EnumData(Params.AFItems.Features.name(), "Annotation Features"));
if(maflags.viewDiversity)
lstItemGroups.add(new EnumData(Params.AFItems.FDA.name(), "Functional Diversity Analysis"));
if(daflags.hasDFI)
lstItemGroups.add(new EnumData(Params.AFItems.DFI.name(), "Differential Feature Inclusion Analysis"));
type = "annotation features";
lbl = "Visualization";
break;
case Data:
lstItemGroups.add(new EnumData("", "All"));
lstItemGroups.add(new EnumData(Params.DataItems.Transcripts.name(), "Transcripts"));
lstItemGroups.add(new EnumData(Params.DataItems.Proteins.name(), "Proteins"));
lstItemGroups.add(new EnumData(Params.DataItems.Genes.name(), "Genes"));
break;
case DA:
daflags = app.ctlr.getDAMenuFlags();
lstItemGroups.add(new EnumData("", "All"));
if(daflags.hasDEA) {
if(daflags.hasDEA_Trans)
lstItemGroups.add(new EnumData(Params.DAItems.DEATranscripts.name(), "Differential Expression Analysis - Transcripts"));
if(daflags.hasDEA_Protein)
lstItemGroups.add(new EnumData(Params.DAItems.DEAProteins.name(), "Differential Expression Analysis - Proteins"));
if(daflags.hasDEA_Gene)
lstItemGroups.add(new EnumData(Params.DAItems.DEAGenes.name(), "Differential Expression Analysis - Genes"));
}
if(daflags.hasDIU)
lstItemGroups.add(new EnumData(Params.DAItems.DIU.name(), "Differential Isoform Usage"));
type = "differential analysis";
lbl = "Analysis";
break;
case EA:
eaflags = app.ctlr.getEAMenuFlags();
lstItemGroups.add(new EnumData("", "All"));
if(eaflags.hasFEA)
lstItemGroups.add(new EnumData(Params.EAItems.FEA.name(), "Functional Enrichment Analysis"));
if(eaflags.hasGSEA)
lstItemGroups.add(new EnumData(Params.EAItems.GSEA.name(), "Gene Set Enrichment Analysis"));
type = "enrichment analysis";
lbl = "Analysis";
break;
case EM:
lstItemGroups.add(new EnumData("", "All"));
lstItemGroups.add(new EnumData(Params.EMItems.ExpressionMatrix.name(), "Expression Matrix"));
break;
}
// create dialog
String dlgTitle = "View " + type + " graphs, charts, and summaries";
if(createDialog("SelectGraph.fxml", dlgTitle, true, "Help_Dlg_SelGraph.html")) {
setProjectName();
// get control objects
lblItemGroups = (Label) scene.lookup("#lblItemGroups");
cbItemGroups = (ComboBox) scene.lookup("#cbItemGroups");
lvGraphs = (ListView) scene.lookup("#lvGraphs");
// populate dialog
lblItemGroups.setText(lbl + ":");
for(EnumData item : lstItemGroups)
cbItemGroups.getItems().add(item.name);
// setup listeners and bindings
lvGraphs.setCellFactory(listView -> new ListCell<SubTabBase.SubTabInfo>() {
private ImageView imageView = new ImageView();
@Override
public void updateItem(SubTabBase.SubTabInfo item, boolean empty) {
super.updateItem(item, empty);
if (empty) {
setText(null);
setGraphic(null);
} else {
setText(" " + item.description);
imageView.setImage(getImage(item.imgName));
setGraphic(imageView);
setOnMouseClicked((MouseEvent event) -> {
if(event.getButton() == MouseButton.PRIMARY && event.getClickCount() > 1){
ObservableList<ButtonType> lst = dialog.getDialogPane().getButtonTypes();
for(ButtonType bt : lst) {
if(bt.getText().equals("OK")) {
if(dialog.getDialogPane().lookupButton(bt) != null) {
System.out.println("Firing OK button...");
((Button) dialog.getDialogPane().lookupButton(bt)).fire();
}
}
}
}
});
}
}
});
cbItemGroups.getSelectionModel().selectedIndexProperty().addListener((ObservableValue<? extends Number> ov, Number oldValue, Number newValue) -> {
ArrayList<SubTabBase.SubTabInfo> lstItems = TabProjectDataViz.getItemTypePanels(dfltParams.itemType);
ObservableList<SubTabBase.SubTabInfo> olItems = FXCollections.observableArrayList();
ArrayList<SubTabBase.SubTabInfo> dynamicItems;
String sel = "";
if(cbItemGroups.getSelectionModel().getSelectedItem() != null)
sel = (String) cbItemGroups.getSelectionModel().getSelectedItem();
boolean allflg = sel.equals("All");
switch(dfltParams.itemType) {
case AF:
for(SubTabBase.SubTabInfo sti : lstItems) {
String[] items = sti.item.split(";");
for(String item : items) {
boolean addit = false;
if(item.equals(Params.AFItems.Features.name())) {
if(allflg || sel.equals("Annotation Features"))
addit = true;
}
else if(item.equals(Params.AFItems.FDA.name())) {
if(maflags.viewDiversity) {
if(allflg || sel.equals("Functional Diversity Analysis"))
addit = true;
}
}
else if(item.equals(Params.AFItems.DFI.name())) {
if(daflags.hasDFI) {
if(allflg || sel.equals("Differential Feature Inclusion Analysis"))
addit = true;
}
}
// check if OK to add item
if(addit) {
olItems.add(sti);
break;
}
}
}
break;
case Data:
for(SubTabBase.SubTabInfo sti : lstItems) {
String[] items = sti.item.split(";");
for(String item : items) {
boolean addit = false;
if(item.equals(Params.DataItems.Transcripts.name())) {
if(allflg || sel.equals("Transcripts"))
addit = true;
}
else if(item.equals(Params.DataItems.Proteins.name())) {
if(allflg || sel.equals("Proteins"))
addit = true;
}
else if(item.equals(Params.DataItems.Genes.name())) {
if(allflg || sel.equals("Genes"))
addit = true;
}
// check if OK to add item
if(addit) {
olItems.add(sti);
break;
}
}
}
break;
case DA:
for(SubTabBase.SubTabInfo sti : lstItems) {
String[] items = sti.item.split(";");
for(String item : items) {
boolean addit = false;
if(item.equals(Params.DAItems.DEATranscripts.name())) {
if(daflags.hasDEA_Trans) {
if(allflg || sel.equals("Differential Expression Analysis - Transcripts"))
addit = true;
}
}
else if(item.equals(Params.DAItems.DEAProteins.name())) {
if(daflags.hasDEA_Protein) {
if(allflg || sel.equals("Differential Expression Analysis - Proteins"))
addit = true;
}
}
else if(item.equals(Params.DAItems.DEAGenes.name())) {
if(daflags.hasDEA_Gene) {
if(allflg || sel.equals("Differential Expression Analysis - Genes"))
addit = true;
}
}
else if(item.equals(Params.DAItems.DIU.name())) {
if(daflags.hasDIU) {
if(allflg || sel.equals("Differential Isoform Usage "))
addit = true;
}
}
// check if OK to add item
if(addit) {
olItems.add(sti);
break;
}
}
}
break;
case EA:
dynamicItems = TabProjectDataViz.getItemTypeDynamicPanels(dfltParams.itemType);
ArrayList<DataApp.EnumData> lstFEA = project.data.analysis.getFEAResultsList();
ArrayList<DataApp.EnumData> lstGSEA = project.data.analysis.getGSEAResultsList();
for(SubTabBase.SubTabInfo sti : lstItems) {
String[] items = sti.item.split(";");
for(String item : items) {
boolean addit = false;
if(item.equals(Params.EAItems.FEA.name())) {
if(eaflags.hasFEA) {
if(allflg || sel.equals("Functional Enrichment Analysis"))
addit = true;
}
}
else if(item.equals(Params.EAItems.GSEA.name())) {
if(eaflags.hasGSEA) {
if(allflg || sel.equals("Gene Set Enrichment Analysis"))
addit = true;
}
}
// check if OK to add item
if(addit) {
olItems.add(sti);
break;
}
}
}
if(eaflags.hasFEA && (allflg || sel.equals("Functional Enrichment Analysis"))) {
for(DataApp.EnumData data : lstFEA) {
for(SubTabBase.SubTabInfo sti : dynamicItems) {
if(sti.item.equals(Params.EAItems.FEA.name())) {
SubTabBase.SubTabInfo dsti = new SubTabBase.SubTabInfo(sti.subTabId, sti.resId, sti.group, sti.item, sti.title, sti.tooltip, sti.menuName, sti.imgName, sti.description);
dsti.subTabId = sti.subTabId + "\t" + data.id;
dsti.description = sti.description + " - " + data.name;
olItems.add(dsti);
}
}
}
}
if(eaflags.hasGSEA && (allflg || sel.equals("Gene Set Enrichment Analysis"))) {
for(DataApp.EnumData data : lstGSEA) {
for(SubTabBase.SubTabInfo sti : dynamicItems) {
if(sti.item.equals(Params.EAItems.GSEA.name())) {
SubTabBase.SubTabInfo dsti = new SubTabBase.SubTabInfo(sti.subTabId, sti.resId, sti.group, sti.item, sti.title, sti.tooltip, sti.menuName, sti.imgName, sti.description);
dsti.subTabId = sti.subTabId + "\t" + data.id;
dsti.description = sti.description + " - " + data.name;
olItems.add(dsti);
}
}
}
}
FXCollections.sort(olItems);
break;
case EM:
for(SubTabBase.SubTabInfo sti : lstItems) {
String[] items = sti.item.split(";");
for(String item : items) {
boolean addit = false;
if(item.equals(Params.EMItems.ExpressionMatrix.name())) {
if(allflg || sel.equals("Expression Matrix"))
addit = true;
}
// check if OK to add item
if(addit) {
olItems.add(sti);
break;
}
}
}
break;
}
lvGraphs.setItems(olItems);
if(lvGraphs.getItems().size() > 0)
lvGraphs.getSelectionModel().select(0);
});
// select after adding listener
if(cbItemGroups.getItems().size() > 0)
cbItemGroups.getSelectionModel().select(0);
// setup dialog event handlers
dialog.setOnCloseRequest((DialogEvent event) -> {
if(dialog.getResult() != null && dialog.getResult().containsKey("ERRMSG")) {
showDlgMsg((String)dialog.getResult().get("ERRMSG"));
dialog.setResult(null);
event.consume();
}
});
dialog.setResultConverter((ButtonType b) -> {
HashMap<String, String> params = null;
System.out.println(b.getButtonData().toString());
if (b.getButtonData() == ButtonBar.ButtonData.OK_DONE)
params = validate(dialog);
return params;
});
// process dialog
Optional<HashMap> result = dialog.showAndWait();
if(result.isPresent())
return new Params(result.get());
}
return null;
}
private Image getImage(String imgName) {
Image img = null;
for(ImageData id : lstImages) {
if(id.name.equals(imgName)) {
img = id.image;
break;
}
}
if(img == null) {
img = new Image(getClass().getResourceAsStream("/tappas/images/" + imgName));
lstImages.add(new ImageData(imgName, img));
}
return img;
}
//
// Dialog Validation
//
private HashMap<String, String> validate(Dialog dialog) {
HashMap<String, String> results = new HashMap<>();
String errmsg = "";
int gidx = cbItemGroups.getSelectionModel().getSelectedIndex();
if(gidx >= 0) {
results.put(Params.ITEMTYPE_PARAM, dfltParams.itemType.name());
results.put(Params.ITEMGROUP_PARAM, lstItemGroups.get(gidx).id);
SubTabBase.SubTabInfo item = (SubTabBase.SubTabInfo) lvGraphs.getSelectionModel().getSelectedItem();
if(item != null)
results.put(Params.ITEMPANEL_PARAM, item.subTabId);
else {
lvGraphs.requestFocus();
errmsg = "You must select an item from list.";
}
}
else {
cbItemGroups.requestFocus();
errmsg = "You must select a type from drop-down list.";
}
if(!errmsg.isEmpty())
results.put("ERRMSG", errmsg);
return results;
}
//
// Data Classes
//
public static class ImageData {
String name;
Image image;
public ImageData(String name, Image image) {
this.name = name;
this.image = image;
}
}
public static class Params extends DlgParams {
public static final String ITEMTYPE_PARAM = "itemType";
public static final String ITEMGROUP_PARAM = "itemGroup";
public static final String ITEMPANEL_PARAM = "itemPanel";
private static ItemType dfltItemType = ItemType.Data;
public static enum ItemType { AF, Data, DA, EA, EM }
public static enum DataItems { Transcripts, Proteins, Genes }
public static enum AFItems { Features, FDA, DFI }
public static enum DAItems { DEATranscripts, DEAProteins, DEAGenes, DIU }
public static enum EAItems { FEA, GSEA }
public static enum EMItems { ExpressionMatrix }
ItemType itemType;
String itemGroup, itemPanel;
public Params() {
this.itemType = dfltItemType;
this.itemGroup = "";
this.itemPanel = "";
}
public Params(ItemType itemType, String itemGroup, String itemPanel) {
this.itemType = itemType;
this.itemGroup = itemGroup;
this.itemPanel = itemPanel;
}
public Params(HashMap<String, String> hmParams) {
this.itemType = hmParams.containsKey(ITEMTYPE_PARAM)? ItemType.valueOf(hmParams.get(ITEMTYPE_PARAM)) : dfltItemType;
this.itemGroup = hmParams.containsKey(ITEMGROUP_PARAM)? hmParams.get(ITEMGROUP_PARAM) : "";
this.itemPanel = hmParams.containsKey(ITEMPANEL_PARAM)? hmParams.get(ITEMPANEL_PARAM) : "";
}
@Override
public HashMap<String, String> getParams() {
HashMap<String, String> hm = new HashMap<>();
hm.put(ITEMTYPE_PARAM, itemType.name());
hm.put(ITEMPANEL_PARAM, itemPanel);
return hm;
}
// base class implements boolean save(String filepath)
//
// Static functions
//
public static Params load(String filepath) {
HashMap<String, String> params = new HashMap<>();
Utils.loadParams(params, filepath);
return (new Params(params));
}
}
}