-
Notifications
You must be signed in to change notification settings - Fork 2
/
AppController.java
1914 lines (1785 loc) · 88.2 KB
/
AppController.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
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* 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.application.Platform;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.scene.Cursor;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.SeparatorMenuItem;
import javafx.scene.control.TabPane;
import javafx.stage.Window;
import tappas.DataApp.DataType;
import tappas.DataApp.EnumData;
import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
/**
*
* @author Hector del Risco - [email protected] & Pedro Salguero - [email protected]
*/
public class AppController extends AppObject {
// limits
static public final int MAX_RECENT_VALUES = 4;
static public final int MAX_GSEARESULTS = 9;
static public final int MAX_FEARESULTS = 9;
// WARNING: AppController always has the active project in curProject but it can be null if there is no active project
// that is the case when the focus is on a non-project subtab such as the Overview, App Log, etc. in the AppInfo tab
// Be aware that loading or selecting a non-project tab, e.g. Tabs.TAB_AI, will cause curProject to be cleared
private Project curProject;
public void setCurProject(Project project) { this.curProject = project; }
// FXML controller
public AppFXMLDocumentController fxdc;
public void setFXDC(AppFXMLDocumentController fxdc) { this.fxdc = fxdc; }
// class data
private boolean loadingTabs = false;
private boolean openingTabs = false;
public boolean isLoadingTabs() { return loadingTabs; }
public boolean isOpeningTabs() { return openingTabs; }
private Tabs tabs;
private String lastSubTabId = "";
private String lastTabId = "";
private String lastTabPaneId = "";
private long lastTime = 0;
public AppController(App app) {
super(app);
}
public void initialize() {
// Note: this is called before the application is fully loaded
}
public void postInitialize() {
// application is loaded and scene and other app objects are available
Tappas.getScene().focusOwnerProperty().addListener((observable, oldNode, newNode) -> focusChanged(newNode));
loadInitialTabs();
fxdc.setupSearch();
}
// load initial tabs - even if no project active
public void loadInitialTabs() {
loadingTabs = true;
openingTabs = true;
tabs = app.tabs;
tabs.openTab(Tabs.TAB_AI, null, null);
loadingTabs = false;
tabs.selectTab(Tabs.TAB_AI);
fxdc.showStartPage(getProjectsHTML(), Tappas.APP_STRVER);
//First check if we have Rscript
// check to see if we got the Rscript path
app.checkRScriptPath();
//Check R packages
Path path = app.data.getTmpScriptFileFromResource("tappas_checkPackages.R");
app.runGetInstalledPackages(path.toString());
Utils.removeFile(path);
if(!app.rsPackages){
fxdc.showAppPaneInstalling(true);
Window wnd = Tappas.getWindow();
boolean download = app.ctls.alertConfirmation("Do you want to download all R Packages?", "Some required R packages are missing. tappAS may not work properly. Would you like to download automatically? \n\n It could take a while.", null);
if(download) {
//app.ctls.alertInformation("Installing packages...", "Click on OK and wait until all packages will be installed.");
Window wnd_ins = Tappas.getWindow();
DlgInstallingPackages dlg_ins = new DlgInstallingPackages(null, wnd_ins);
boolean installed = dlg_ins.showAndWait(app, fxdc);
fxdc.showAppPaneInstalling(false);
if(!installed)
app.logError("The installation didn't work correctly.");
}else{
fxdc.showAppPaneInstalling(false);
}
}
}
protected void runScript(TaskHandler.TaskInfo taskInfo, List<String> lst, String name, String logFilepath) {
// run script
try {
ProcessBuilder pb = new ProcessBuilder(lst);
System.out.println(lst);
pb.redirectErrorStream(true);
process = pb.start();
taskInfo.process = process;
app.logDebug(name + " process started, process id: " + process.toString());
// monitor process output
// could change to have PB send it to a log but still need to update screen
Writer writer = null;
try {
String line, dspline;
LocalDate date = LocalDate.now();
LocalTime time = LocalTime.now();
writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(logFilepath, true), "utf-8"));
dspline = name + " script is running...\n";
//outputLogLine(dspline);
writer.write(dspline);
BufferedReader input = new BufferedReader(new InputStreamReader(process.getInputStream()));
int totalChars = 0;
boolean dspinfo = true;
while ((line = input.readLine()) != null) {
time = LocalTime.now();
dspline = time.toString() + " " + line + "\n";
writer.write(dspline);
totalChars += dspline.length();
if(totalChars > 100000){
if(dspinfo) {
//outputLogLine("Log display exceeded limit - no additional information will be displayed...");
dspinfo = false;
}
}
}
try { input.close(); } catch(Exception e) { }
int ev = process.waitFor();
dspline = time.toString() + " " + name + " script ended. Exit value: " + ev + "\n";
writer.write(dspline);
//outputLogLine(dspline);
} catch(Exception e) {
app.logError("Unable to capture " + name + " process output: " + e.getMessage());
} finally {
try {if(writer != null) writer.close();} catch (Exception e) { System.out.println("Writer close exception within exception: " + e.getMessage()); }
}
} catch(Exception e) {
app.logError("Unable to run " + name + " script: " + e.getMessage());
}
}
public void showSeeAppLog(boolean show) {
Platform.runLater(() -> {
fxdc.showSeeAppLog(show);
});
}
//
// Project Functions
//
// start command request handler - user request originates in start HTML page
public void processStartCmd(String cmd) {
if(cmd.equals("new"))
newProject();
else if(cmd.equals("open"))
openProject();
else if(cmd.startsWith("recent:")) {
String id = cmd.substring(7);
Project.ProjectDef def = app.getProjectDef(id);
if(def != null)
openRecentProject(def);
}
}
public String getProjectsHTML() {
String html = "";
ArrayList<Project.ProjectDef> lstRecents = getRecentProjects();
int cnt = 0;
if(!lstRecents.isEmpty()) {
for(Project.ProjectDef def : lstRecents) {
String name = def.name.length() > 30? def.name.substring(0, 27) + "..." : def.name;
html += "<div style=\"padding-bottom:3px;\">";
html += "<span style=\"color:slategray;\">• </span><span class=\"projectText\" onclick=\"setCmdRequest('recent:" + def.id + "')\">" + name + "</span>";
html += "</div>";
if(++cnt > Math.min(MAX_RECENT_VALUES, 4))
break;
}
}
return html;
}
// Note: only call after project base data has been loaded
private void loadProjectTabs(Project project, boolean newdata) {
// hide start page
fxdc.hideStartPage();
// minimal default tabs
loadingTabs = false;
openingTabs = true;
tabs.openTab(Tabs.TAB_AI, null, null);
// check if new project being created which does not have data yet
if(project.data.hasInputData()) {
loadingTabs = false;
if(newdata) {
openProjectDataVizSubTab(project, TabProjectDataViz.Panels.SUMMARYEXPMATRIX);
openProjectDataSubTab(project, TabProjectData.Panels.EXPMATRIX);
}
openProjectDataVizSubTab(project, TabProjectDataViz.Panels.SUMMARYALL);
openProjectDataSubTab(project, TabProjectData.Panels.TRANS);
openingTabs = false;
tabs.selectTab(Tabs.TAB_PROJECTDATA + project.getDef().id);
}
else
tabs.selectTab(Tabs.TAB_AI);
loadingTabs = false;
openingTabs = false;
}
public void newProject() {
ArrayList<TabBase> lstTabBases = tabs.getActiveProjectsTabBase();
if(lstTabBases.size() < App.MAX_ACTIVE_PROJECTS) {
DlgInputData dlg = new DlgInputData(null, Tappas.getWindow());
try {
DlgInputData.Params results = dlg.showAndWait(true, null);
if(results != null)
processInputData(null, results);
}
catch(IllegalArgumentException e){
System.out.println(e.toString());
app.logError("Error Opening a new Project");
}
}
else
app.ctls.alertInformation("Open Project", "You must close one of the opened projects.\nOnly " + App.MAX_ACTIVE_PROJECTS + " opened projects allowed.");
}
public void changeProjectName() {
DlgRenameProject dlg = new DlgRenameProject(curProject, Tappas.getWindow());
DlgRenameProject.Params results = dlg.showAndWait();
if(results != null) {
if(curProject.changeProjectName(results.name)) {
setTitle(results.name);
TabBase tabBase = app.tabs.getTabBase(Tabs.TAB_PROJECTDATA + curProject.getDef().id);
if(tabBase != null) {
HashMap<String, Object> hm = new HashMap<>();
hm.put("updateProjectName", "");
tabBase.processRequest(hm);
}
tabBase = app.tabs.getTabBase(Tabs.TAB_PROJECTDV + curProject.getDef().id);
if(tabBase != null) {
HashMap<String, Object> hm = new HashMap<>();
hm.put("updateProjectName", "");
tabBase.processRequest(hm);
}
}
else
app.ctls.alertWarning("Change Project Name", "Unable to change project name.");
}
}
public void loadInputData() {
// must check that project has no active tasks!!!
DlgInputData dlg = new DlgInputData(curProject, Tappas.getWindow());
DlgInputData.Params params = curProject.data.getParams();
params.name = curProject.getProjectName();
params.id = curProject.getProjectId();
//hmArgs.put(DlgInputData.Params.NAME_PARAM, curProject.def.name);
//hmArgs.put(DlgInputData.Params.ID_PARAM, curProject.def.id);
DlgInputData.Params results = dlg.showAndWait(false, params);
if(results != null) {
// check for any existing analysis data
boolean loadflg = true;
if(curProject.data.analysis.hasAnyAnalysisData()) {
if(app.ctls.alertConfirmation("Load Input Data", "All previous data and analysis results\nwill be cleared.\nDo you want to Proceeed?\n", null))
curProject.data.removeProjectData();
else
loadflg = false;
}
if(loadflg)
processInputData(curProject.getDef(), results);
}
}
private void processInputData(Project.ProjectDef def, DlgInputData.Params results) {
boolean newProject = (def == null);
// always show log
Project p = curProject;
openAppLogSubTab();
curProject = p;
// check if using any of the application reference files
if(results.useAppRef) {
// check if we haven't already downloaded it
if(!app.data.hasAppReferenceFiles(results.genus, results.species, results.refType.name(), results.refRelease)) {
// get approval from user
boolean fdok = false;
if(app.ctls.alertConfirmation("Download Reference Data Files", "The application files selected need\nto be downloaded from the tappAS server.\nOK to download files?", null)) {
String path = app.data.getAppReferenceFileFolder(results.genus, results.species, results.refType.name(), results.refRelease);
Utils.removeAllFolderFiles(Paths.get(path), true);
DlgFileDownload.Params params = new DlgFileDownload.Params(app.data.getAppReferenceFileUrl(results.refFile), Paths.get(path, results.refFile).toString(), 0L, false);
DlgFileDownload fdlg = new DlgFileDownload(curProject, params, Tappas.getWindow());
HashMap<String, String> fdresults = fdlg.showAndWait(Paths.get(path, results.refFile).toString(), path);
fdok = Boolean.valueOf(fdresults.get(DlgFileDownload.Params.RESULT_PARAM));
if(fdok) {
if(Files.exists(Paths.get(path, DataApp.ANNOTATION_DB))) {
fdok = app.data.createReferencesOKFile(path);
if(!fdok)
app.logError("Unable to create internal application file.");
}
else {
fdok = false;
app.logError("Missing annotation database file from download.");
}
if(!fdok)
app.ctls.alertInformation("File Download Error", "Unable to decompress or process downloaded file.\nSee application log for details.");
// always delete the compressed file to save disk space
Utils.removeFile(Paths.get(path, results.refFile));
}
else
app.ctls.alertInformation("File Download Error", "Unable to download selected file.\nSee application log for details.");
}
if(!fdok)
return;
}
}
try {
// check if this is a new project, create if so
if(def == null) {
// create project and open to get vars values
String name = results.name;
def = Project.createProject(app, name);
curProject = _openProject(def);
addRecentProject(def);
}
if(def != null) {
// save project's input data parameters to include annotation path, must initialize afterwards
System.out.println("results: " + results.toString());
app.logInfo("Input Data dialog results: " + results);
curProject.data.setParams(results);
curProject.data.initialize();
// process input data
DlgProcessInputData pid = new DlgProcessInputData(curProject, results.getParams(), Tappas.getWindow());
HashMap<String, String> pidResults = pid.showAndWait();
if(pidResults != null && pidResults.containsKey("result") && pidResults.get("result").equals("OK")) {
// close and reopen project for change to take effect
closeProject(def);
// set new data flag to show expression matrix data and visualization subtabs
def.newdata = true;
openProject(def);
}
else {
app.ctls.alertError(newProject? "New Project" : "Load Input Data", newProject? "Unable to create project." : "Unable to load input data.\nProject will be removed.");
String folder = app.data.getProjectFolder(def.id);
closeProject(def);
if(!folder.isEmpty())
app.data.removeFolder(Paths.get(folder));
// remove from start HTML page menu if page is showing (only shown if no active projects)
if(tabs.getActiveProjects().isEmpty())
fxdc.showStartPage(getProjectsHTML(), Tappas.APP_STRVER);
}
}
}
catch(Exception e) {
app.logError("Project " + (newProject? " creation" : "input data loading code exception: ") + e.getMessage());
}
}
public void viewProjectProperties(Project.ProjectDef def) {
// project may not be the active project tab
Project pro = app.getProject(def);
if(pro != null)
openProjectDataSubTab(pro, TabProjectData.Panels.PROPS, null);
}
public void closeAllProjects() {
// revisit? make sure it works and remove comment (not sure why it is here)!!!
tabs.closeAllTabs();
loadInitialTabs();
}
public void closeProject(Project.ProjectDef def) {
// close all project tabs - user can choose to cancel closing if task is running
// test for cancel!!!
app.logInfo("Closing project '" + def.name + "'\n");
tabs.closeProjectTabs(def);
// clear project vars
curProject = null;
ArrayList<Project.ProjectDef> pdlst = tabs.getActiveProjects();
if(pdlst.isEmpty()) {
fxdc.showStartPage(getProjectsHTML(), Tappas.APP_STRVER);
tabs.openTab(Tabs.TAB_AI, null, null);
}
}
public void deleteProject() {
try {
Window wnd = Tappas.getWindow();
DlgDeleteProject dlg = new DlgDeleteProject(curProject, wnd);
DlgDeleteProject.Params results = dlg.showAndWait(new DlgDeleteProject.Params());
if(results != null) {
String msg = "Are you sure you want to \ndelete selected project?";
if(results.hmProjects.size() > 1)
msg = "Are you sure you want to \ndelete all " + results.hmProjects.size() + " selected projects?";
if(app.ctls.alertConfirmation("Delete Project(s)", msg, null)) {
for(String name : results.hmProjects.keySet()) {
String path = app.data.getProjectFolder(results.hmProjects.get(name));
app.logInfo("Removing project '" + name + "'");
app.logInfo("Removing project folder '" + path + "'");
app.data.removeFolder(Paths.get(path));
// remove from start HTML page menu if page is showing (only shown if no active projects)
if(tabs.getActiveProjects().isEmpty())
fxdc.showStartPage(getProjectsHTML(), Tappas.APP_STRVER);
}
}
}
} catch(Exception e) { logger.logWarning("Delete project - internal program error: " + e.getMessage()); }
}
public void openProject() {
try {
ArrayList<TabBase> lstTabBases = tabs.getActiveProjectsTabBase();
if(lstTabBases.size() < App.MAX_ACTIVE_PROJECTS) {
Window wnd = Tappas.getWindow();
DlgOpenProject dlg = new DlgOpenProject(curProject, wnd);
DlgOpenProject.Params results = dlg.showAndWait(new DlgOpenProject.Params());
if(results != null) {
Project.ProjectDef def = new Project.ProjectDef(results.id, results.name);
openProject(def);
}
}
else
app.ctls.alertInformation("Open Project", "You must close one of the opened projects.\nOnly " + App.MAX_ACTIVE_PROJECTS + " opened projects allowed.");
} catch(Exception e) { logger.logWarning("Open project - internal program error: " + e.getMessage()); }
}
public void openRecentProject(Project.ProjectDef def) {
ArrayList<TabBase> lstTabBases = tabs.getActiveProjectsTabBase();
if(lstTabBases.size() < App.MAX_ACTIVE_PROJECTS)
openProject(def);
else
app.ctls.alertInformation("Open Recent Project", "You must close one of the opened projects.\nOnly " + App.MAX_ACTIVE_PROJECTS + " opened projects allowed.");
}
private void openProject(Project.ProjectDef def) {
app.logInfo("Open project '" + def.name + "'");
// see if this project is already opened
TabBase tb = app.tabs.getTabBase(Tabs.TAB_PROJECTDATA + def.id);
if(tb == null) {
runOpenProjectThread(def);
}
else {
// set focus to project tab
addRecentProject(def);
tb.onSelect(true);
}
}
public void projectDataLoaded(Project project) {
fxdc.showAppPane(false);
Tappas.getScene().setCursor(Cursor.DEFAULT);
// now load project tabs - only time we should do this
loadProjectTabs(project, project.getDef().newdata);
}
public void addRecentProject(Project.ProjectDef def) {
ArrayList<Project.ProjectDef> lst = new ArrayList<>();
// get existing projects
UserPrefs prefs = app.userPrefs;
for(int num = 1; num <= MAX_RECENT_VALUES; num++) {
String rpid = prefs.getRecentProject(num);
if(!rpid.trim().isEmpty()) {
Project.ProjectDef predef = app.getProjectDef(rpid);
if(predef != null && !predef.id.equals(def.id))
lst.add(predef);
}
if(lst.size() == (MAX_RECENT_VALUES - 1))
break;
}
// add most current one to start of list
lst.add(0, def);
// update list
for(int num = 1; num <= MAX_RECENT_VALUES; num++) {
String rpid = "";
if(lst.size() >= num)
rpid = lst.get(num-1).id;
prefs.setRecentProject(num, rpid);
}
}
public void clearRecentProjects() {
UserPrefs prefs = app.userPrefs;
for(int num = 1; num <= MAX_RECENT_VALUES; num++)
prefs.setRecentProject(num, "");
ArrayList<Project.ProjectDef> lst = new ArrayList<>();
}
public ArrayList<Project.ProjectDef> getRecentProjects() {
ArrayList<Project.ProjectDef> lst = new ArrayList<>();
UserPrefs prefs = app.userPrefs;
for(int num = 1; num <= MAX_RECENT_VALUES; num++) {
String id = prefs.getRecentProject(num);
if(!id.trim().isEmpty()) {
Project.ProjectDef def = app.getProjectDef(id);
if(def != null) {
if(DlgOpenProject.Params.isValidData(def.dataVersion))
lst.add(def);
}
}
}
return lst;
}
//
// Menu Functions
//
public ArrayList<MenuItem> getStartMenuItems() {
ArrayList<MenuItem> lstItems = new ArrayList<>();
ArrayList<Project.ProjectDef> lstProjects = app.getProjectsList();
ArrayList<Project.ProjectDef> lstRecents = getRecentProjects();
MenuItem miNew = new MenuItem("New Project...");
miNew.setOnAction((event) -> { newProject();});
lstItems.add(miNew);
lstItems.add(new SeparatorMenuItem());
MenuItem miOpen = new MenuItem("Open Project...");
miOpen.setDisable(lstProjects.isEmpty());
miOpen.setOnAction((event) -> { openProject();});
lstItems.add(miOpen);
Menu mr = new Menu("Recent Projects");
miOpen.setDisable(lstRecents.isEmpty());
for(Project.ProjectDef pd : lstRecents) {
MenuItem item = new MenuItem("'" + pd.name + "'");
item.setOnAction((event) -> { openRecentProject(pd);});
mr.getItems().add(item);
}
lstItems.add(mr);
return lstItems;
}
public ArrayList<MenuItem> getProjectsMenuItems() {
ArrayList<MenuItem> lstItems = getStartMenuItems();
lstItems.add(new SeparatorMenuItem());
ArrayList<Project.ProjectDef> pdlst = tabs.getActiveProjects();
Menu mProps = new Menu("View Project Properties");
mProps.setDisable(pdlst.isEmpty());
for(Project.ProjectDef pd : pdlst) {
MenuItem item = new MenuItem("'" + pd.name + "'");
item.setOnAction((event) -> { viewProjectProperties(pd);});
mProps.getItems().add(item);
}
lstItems.add(mProps);
lstItems.add(new SeparatorMenuItem());
Menu mClose = new Menu("Close Project");
mClose.setDisable(pdlst.isEmpty());
for(Project.ProjectDef pd : pdlst) {
MenuItem item = new MenuItem("'" + pd.name + "'");
item.setOnAction((event) -> { closeProject(pd);});
mClose.getItems().add(item);
}
lstItems.add(mClose);
MenuItem miCloseAll = new MenuItem("Close All Projects");
miCloseAll.setDisable(pdlst.isEmpty());
miCloseAll.setOnAction((event) -> { closeAllProjects();});
lstItems.add(miCloseAll);
ArrayList<Project.ProjectDef> lstProjects = app.getProjectsList();
lstItems.add(new SeparatorMenuItem());
MenuItem miDelete = new MenuItem("Delete Project(s)...");
miDelete.setDisable(lstProjects.isEmpty());
miDelete.setOnAction((event) -> { deleteProject();});
lstItems.add(miDelete);
return lstItems;
}
public DAMenuFlags getDAMenuFlags() {
DAMenuFlags flags = new DAMenuFlags();
flags.runDEA = true;
flags.runDIU = true;
flags.runDFI = true;
flags.runDPA = true;
flags.runUTRL = true;
flags.hasDEA_Trans = curProject.data.analysis.hasDEAData(DataApp.DataType.TRANS);
flags.hasDEA_Protein = curProject.data.analysis.hasDEAData(DataApp.DataType.PROTEIN);
flags.hasDEA_Gene = curProject.data.analysis.hasDEAData(DataApp.DataType.GENE);
flags.hasDEA = flags.hasDEA_Trans || flags.hasDEA_Protein || flags.hasDEA_Gene;
flags.hasDIU_Trans = curProject.data.analysis.hasDIUDataTrans();
flags.hasDIU_Protein = curProject.data.analysis.hasDIUDataProtein();
flags.hasDIU = flags.hasDIU_Trans || flags.hasDIU_Protein;
flags.hasDFI = curProject.data.analysis.hasAnyDFIData();
flags.hasDPA = curProject.data.analysis.hasDPAData();
flags.hasUTRL = curProject.data.analysis.hasUTRLData();
flags.hasAny = flags.hasDEA || flags.hasDIU || flags.hasDFI || flags.hasDPA || flags.hasUTRL;
flags.multipleTimes = curProject.data.isMultipleTimeSeriesExpType();
return flags;
}
public EAMenuFlags getEAMenuFlags() {
EAMenuFlags flags = new EAMenuFlags();
flags.runGSEA = true;
flags.runFEA = true;
flags.hasFEA = curProject.data.analysis.hasAnyFEAData();
flags.hasGSEA = curProject.data.analysis.hasAnyGSEAData();
flags.hasAny = flags.hasFEA || flags.hasGSEA;
flags.lstGSEAViewItems = new ArrayList<>();
flags.lstGSEAClearItems = new ArrayList<>();
ArrayList<DataApp.EnumData> lstItems = curProject.data.analysis.getGSEAResultsList();
for(DataApp.EnumData ed : lstItems) {
MenuItem mi = new MenuItem(ed.name);
mi.setOnAction((event) -> { openProjectDataSubTabId(curProject, TabProjectData.Panels.STATSGSEA, ed.id);});
flags.lstGSEAViewItems.add(mi);
mi = new MenuItem(ed.name);
mi.setOnAction((event) -> { clearGSEA(ed.name, ed.id, true); });
flags.lstGSEAClearItems.add(mi);
}
flags.lstFEAViewItems = new ArrayList<>();
flags.lstFEAClearItems = new ArrayList<>();
lstItems = curProject.data.analysis.getFEAResultsList();
for(DataApp.EnumData ed : lstItems) {
MenuItem mi = new MenuItem(ed.name);
mi.setOnAction((event) -> { openProjectDataSubTabId(curProject, TabProjectData.Panels.STATSFEA, ed.id);});
flags.lstFEAViewItems.add(mi);
mi = new MenuItem(ed.name);
mi.setOnAction((event) -> { clearFEA(ed.name, ed.id, true); });
flags.lstFEAClearItems.add(mi);
}
return flags;
}
public MAMenuFlags getMAMenuFlags() {
MAMenuFlags flags = new MAMenuFlags();
flags.runDiversity = true;
flags.hasFDA = curProject.data.analysis.hasAnyFDAData();
flags.viewDiversity = curProject.data.analysis.hasAnyFDAData();
flags.hasTwoData = curProject.data.analysis.hasTwoFDAIdData();
flags.lstFDAViewItems = new ArrayList<>();
flags.lstFDAClearItems = new ArrayList<>();
ArrayList<DataApp.EnumData> lstItems = curProject.data.analysis.getFDAResultsList();
for(DataApp.EnumData ed : lstItems) {
//results
MenuItem mi = new MenuItem(ed.name);
mi.setOnAction((event) -> { openProjectDataSubTabId(curProject, TabProjectData.Panels.STATSFDA, ed.id);});
flags.lstFDAViewItems.add(mi);
//clear
mi = new MenuItem(ed.name);
mi.setOnAction((event) -> { clearFDA(ed.name, ed.id, true); });
flags.lstFDAClearItems.add(mi);
}
return flags;
}
public FAMenuFlags getFAMenuFlags() {
FAMenuFlags flags = new FAMenuFlags();
flags.runDFI = true;
flags.hasDFI = curProject.data.analysis.hasAnyDFIData();
flags.lstDFIViewItems = new ArrayList<>();
flags.lstDFISummaryItems = new ArrayList<>();
flags.lstCoDFIViewItems = new ArrayList<>();
flags.lstDFIClearItems = new ArrayList<>();
ArrayList<DataApp.EnumData> lstItems = curProject.data.analysis.getDFIResultsList();
for(DataApp.EnumData ed : lstItems) {
//results
MenuItem mi = new MenuItem(ed.name);
mi.setOnAction((event) -> { openProjectDataSubTabId(curProject, TabProjectData.Panels.STATSDFI, ed.id);});
flags.lstDFIViewItems.add(mi);
//summary
mi = new MenuItem(ed.name);
mi.setOnAction((event) -> { openProjectDataSubTabId(curProject, TabProjectData.Panels.FIRESULTSSUMMARY, ed.id);});
flags.lstDFISummaryItems.add(mi);
//coDFI
mi = new MenuItem(ed.name);
mi.setOnAction((event) -> { openProjectDataSubTabId(curProject, TabProjectData.Panels.FIASSOCIATION, ed.id);});
flags.lstCoDFIViewItems.add(mi);
//clear
mi = new MenuItem(ed.name);
mi.setOnAction((event) -> { clearDFI(ed.id, true); });
flags.lstDFIClearItems.add(mi);
}
// DPA
flags.runDPA = true;
flags.hasDPA = curProject.data.analysis.hasDPAData();
// UTR Lengthrning
flags.runUTRL = true;
flags.hasUTRL = curProject.data.analysis.hasUTRLData();
// BOTH
flags.hasAny = flags.hasDPA || flags.hasDFI || flags.hasUTRL;
return flags;
}
public GraphsMenuFlags getGraphsMenuFlags() {
GraphsMenuFlags flags = new GraphsMenuFlags();
if(curProject != null && curProject.data != null) {
// enable based on data availability
flags.hasData = curProject.data.hasInputData();
flags.hasDA = curProject.data.analysis.hasAnyDAData();
flags.hasEA = curProject.data.analysis.hasAnyEAData();
// tools are always enabled - change if we come up with a reason not to do so
flags.toolVennDiag = true;
}
return flags;
}
// a focus change took place - set the top level menus enable/disable state
public void updateTopLevelMenus(String tabId, Boolean selTabId) {
TabBase tabBase = tabs.getTabBase(tabId);
if(tabBase != null) {
// update pipe vars and app window title
String projectName = "";
if(tabBase.project != null)
projectName = tabBase.project.getDef().name;
setCurProject(tabBase.project);
setTitle(projectName);
// check if project tab, data or graphs, enable toolbar button menus accordingly
System.out.println("updateTopLevelMenus: " + tabId);
boolean tabData = tabId.startsWith(Tabs.TAB_PROJECTDATA);
boolean tabDataViz = tabId.startsWith(Tabs.TAB_PROJECTDV);
boolean projectTab = tabData || tabDataViz;
fxdc.disableTopMenu("Project_Data", !projectTab);
fxdc.disableTopMenu("DA", !projectTab);
fxdc.disableTopMenu("EA", !projectTab);
fxdc.disableTopMenu("FDA", !projectTab);
fxdc.disableTopMenu("FA", !projectTab);
fxdc.disableTopMenu("Project_DataViz", !projectTab);
// call tab select function to make sure focus is given to main table, if any, to enable search controls
// the changing of the focused color for the sub tab, skyblue, is also handled there
// must call even if selTabId is false otherwise default table/node may not get the focus automatically
if(!isLoadingTabs()) {
//System.out.println("updateTopLevelMenus calling onSelect(true) for " + tabBase.tabId);
tabBase.onSelect(true);
}
}
}
//
// Tab and SubTab Functions
//
// WARNING: Selecting a non-project subtab causes the curProject variable to be cleared
public void openAppLogSubTab() {
HashMap<String, Object> hmArgs = new HashMap<>();
hmArgs.put("panels", TabAppInfo.Panels.LOG.name());
TabBase tb = app.tabs.getTabBase(Tabs.TAB_AI);
if(tb == null)
tabs.openTab(Tabs.TAB_AI, null, hmArgs);
else {
HashMap<String, Object> hm = new HashMap<>();
hm.put("panels", hmArgs);
tb.processRequest(hm);
}
}
public void showOverviewSection(String url) {
HashMap<String, Object> hmArgs = new HashMap<>();
hmArgs.put("panels", TabAppInfo.Panels.OVERVIEW.name());
hmArgs.put("url", url);
TabBase tb = app.tabs.getTabBase(Tabs.TAB_AI);
if(tb == null)
tabs.openTab(Tabs.TAB_AI, null, hmArgs);
else {
HashMap<String, Object> hm = new HashMap<>();
hm.put("panels", hmArgs);
tb.processRequest(hm);
}
}
public void openProjectDataSubTabId(Project project, TabProjectData.Panels panel, String id) {
openProjectDataSubTabId(project, panel, id, null);
}
public void openProjectDataSubTabId(Project project, TabProjectData.Panels panel, String id, HashMap<String, Object> args) {
if(args == null)
args = new HashMap<>();
if(panel != null)
args.put("panels", panel.name());
args.put("id", id);
TabBase tb = app.tabs.getTabBase(Tabs.TAB_PROJECTDATA + project.getDef().id);
if(tb == null)
tabs.openTab(Tabs.TAB_PROJECTDATA + project.getDef().id, project, args);
else {
HashMap<String, Object> hm = new HashMap<>();
hm.put("panels", args);
tb.processRequest(hm);
}
}
public void closeProjectDataVizSubTab(Project project, String panelId, boolean startWith) {
// close requested panel if project data viz tab is opened
TabBase tb = app.tabs.getTabBase(Tabs.TAB_PROJECTDV + project.getDef().id);
if(tb != null) {
HashMap<String, Object> hm = new HashMap<>();
hm.put(startWith? "closePanelsStartWith" : "closePanels", panelId);
tb.processRequest(hm);
}
}
public void closeProjectDataSubTab(Project project, String panelId) {
// close requested panel if project data tab is opened
TabBase tb = app.tabs.getTabBase(Tabs.TAB_PROJECTDATA + project.getDef().id);
if(tb != null) {
HashMap<String, Object> hm = new HashMap<>();
hm.put("closePanels", panelId);
tb.processRequest(hm);
}
}
public void openProjectDataSubTab(TabProjectData.Panels panel) {
openProjectDataSubTab(curProject, panel, null);
}
public void openProjectDataSubTab(Project project, TabProjectData.Panels panel) {
openProjectDataSubTab(project, panel, null);
}
public void openProjectDataSubTab(Project project, TabProjectData.Panels panel, HashMap<String, Object> args) {
if(args == null)
args = new HashMap<>();
if(panel != null)
args.put("panels", panel.name());
TabBase tb = app.tabs.getTabBase(Tabs.TAB_PROJECTDATA + project.getDef().id);
if(tb == null)
tabs.openTab(Tabs.TAB_PROJECTDATA + project.getDef().id, project, args);
else {
HashMap<String, Object> hm = new HashMap<>();
hm.put("panels", args);
tb.processRequest(hm);
}
}
public void openProjectDataVizSubTab(TabProjectDataViz.Panels panel) {
openProjectDataVizSubTab(curProject, panel);
}
public void openProjectDataVizSubTab(Project project, TabProjectDataViz.Panels panel) {
HashMap<String, Object> args = new HashMap<>();
if(panel != null)
args.put("panels", panel.name());
TabBase tb = app.tabs.getTabBase(Tabs.TAB_PROJECTDV + project.getDef().id);
if(tb == null)
tabs.openTab(Tabs.TAB_PROJECTDV + project.getDef().id, project, args);
else {
HashMap<String, Object> hm = new HashMap<>();
hm.put("panels", args);
tb.processRequest(hm);
}
}
public void openProjectDataVizSubTab(Project project, TabProjectDataViz.Panels panel, HashMap<String, Object> args) {
if(panel != null)
args.put("panels", panel.name());
TabBase tb = app.tabs.getTabBase(Tabs.TAB_PROJECTDV + project.getDef().id);
if(tb == null)
tabs.openTab(Tabs.TAB_PROJECTDV + project.getDef().id, project, args);
else {
HashMap<String, Object> hm = new HashMap<>();
hm.put("panels", args);
tb.processRequest(hm);
}
}
public void openProjectDataVizSubTabId(Project project, TabProjectDataViz.Panels panel, String id) {
openProjectDataVizSubTabId(project, panel, id, null);
}
public void openProjectDataVizSubTabId(Project project, TabProjectDataViz.Panels panel, String id, HashMap<String, Object> args) {
if(args == null)
args = new HashMap<>();
if(panel != null)
args.put("panels", panel.name());
args.put("id", id);
TabBase tb = app.tabs.getTabBase(Tabs.TAB_PROJECTDV + project.getDef().id);
if(tb == null)
tabs.openTab(Tabs.TAB_PROJECTDV + project.getDef().id, project, args);
else {
HashMap<String, Object> hm = new HashMap<>();
hm.put("panels", args);
tb.processRequest(hm);
}
}
public void viewFEAClusters(String id) {
openProjectDataSubTabId(curProject, TabProjectData.Panels.CLUSTERSFEA, id, new HashMap());
}
public void viewGSEAClusters(String id) {
openProjectDataSubTabId(curProject, TabProjectData.Panels.CLUSTERSGSEA, id, new HashMap());
}
//
// Analysis Dialog Functions
//
public void runDEAnalysis(DataType dataType) {
try {
DlgDEAnalysis dlg = new DlgDEAnalysis(curProject, Tappas.getWindow());
DlgDEAnalysis.Params dfltValues = DlgDEAnalysis.Params.load(curProject.data.analysis.getDEAParamsFilepath(dataType == null? DataType.GENE : dataType), curProject);
DlgDEAnalysis.Params results = dlg.showAndWait(dfltValues);
if(results != null) {
results.save(curProject.data.analysis.getDEAParamsFilepath(results.dataType));
TabProjectData.Panels panel;
switch(results.dataType) {
case PROTEIN:
panel = TabProjectData.Panels.STATSDEAPROT;
break;
case GENE:
panel = TabProjectData.Panels.STATSDEAGENE;
break;
case TRANS:
default:
panel = TabProjectData.Panels.STATSDEATRANS;
break;
}
// check if analysis already running
TabBase tb = tabs.getTabBase(Tabs.TAB_PROJECTDATA + curProject.getDef().id);
SubTabBase.SubTabInfo sti = tb.getSubTab(panel.name());
boolean taskRunning = false;
if(sti != null && sti.subTabBase != null)
taskRunning = sti.subTabBase.isServiceTaskRunning();
if(!taskRunning) {
// close data panel
closeProjectDataSubTab(curProject, panel.name());
// close all associated data visuzalization subtabs since underlying analysis data will be deleted
String subTabs = SubTabDEAResults.getAssociatedDVSubTabs(results.dataType);
closeProjectDataVizSubTab(curProject, subTabs, true);
// clear data and run analysis by opening subtab w/o data
curProject.data.analysis.clearDataDEA(results.dataType, false);
openProjectDataSubTab(curProject, panel, null);
}
else
app.ctls.alertInformation("DEAnalysis", "Selected analysis type is already running");
}
} catch(Exception e) {
app.logError("Unable to run DEAnalysis: " + e.getMessage());
}
}
public void runDIUnalysis(DataType dataType) {
try {
DlgDIUAnalysis dlg = new DlgDIUAnalysis(curProject, Tappas.getWindow());
DlgDIUAnalysis.Params dfltValues = DlgDIUAnalysis.Params.load(curProject.data.analysis.getDIUParamsFilepath(dataType == null? DataType.TRANS : dataType), curProject);
DlgDIUAnalysis.Params results = dlg.showAndWait(dfltValues);
if(results != null) {
results.save(curProject.data.analysis.getDIUParamsFilepath(results.dataType), curProject);
TabProjectData.Panels panel;
switch(results.dataType) {
case PROTEIN:
panel = TabProjectData.Panels.STATSDIUPROT;
break;
case TRANS:
default:
panel = TabProjectData.Panels.STATSDIUTRANS;
break;
}
// check if analysis already running
TabBase tb = tabs.getTabBase(Tabs.TAB_PROJECTDATA + curProject.getDef().id);
SubTabBase.SubTabInfo sti = tb.getSubTab(panel.name());
boolean taskRunning = false;
if(sti != null && sti.subTabBase != null)
taskRunning = sti.subTabBase.isServiceTaskRunning();
if(!taskRunning) {
// close data panel
closeProjectDataSubTab(curProject, panel.name());
// close all associated data visualization subtabs since underlying analysis data will be deleted
String subTabs = SubTabDIUResults.getAssociatedDVSubTabs(results.dataType);
closeProjectDataVizSubTab(curProject, subTabs, true);
// clear data and run analysis by opening subtab w/o data
curProject.data.analysis.clearDataDIU(results.dataType, false);
openProjectDataSubTab(curProject, panel, null);
}
else
app.ctls.alertInformation("DIUnalysis", "Selected analysis type is already running");
}
} catch(Exception e) {
app.logError("Unable to run DIUnalysis: " + e.getMessage());
}
}
public DlgExportData.Params getExportDataParams(DlgExportData.Config config, DlgExportData.Params prms, ArrayList<EnumData> lstOtherSelections) {
DlgExportData.Params results = null;
try {
Window wnd = Tappas.getWindow();
DlgExportData dlg = new DlgExportData(curProject, wnd);
results = dlg.showAndWait(config, prms, lstOtherSelections);
} catch(Exception e) {
app.logError("Unable to get export data parameters: " + e.getMessage());
}
return results;
}
public void runFDAnalysis(String id) {
try {
DlgFDAnalysis dlg = new DlgFDAnalysis(curProject, Tappas.getWindow());
DlgFDAnalysis.Params dfltParams;