-
Notifications
You must be signed in to change notification settings - Fork 2
/
PlotsDIU.java
158 lines (145 loc) · 5.87 KB
/
PlotsDIU.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
/*
* 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.binding.Bindings;
import javafx.concurrent.Task;
import javafx.scene.Node;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Pedro Salguero - [email protected]
*/
public class PlotsDIU extends AppObject {
ProgressIndicator pi;
Pane paneImgChart;
ImageView imgChart;
boolean plotShown = false;
Path runScriptPath = null;
double ratio = 0.75;
DataApp.DataType dataType;
SubTabBase.SubTabInfo subTabInfo = null;
TaskHandler.ServiceExt service = null;
String export_name = "DIU_ScatterPlot.png";
public PlotsDIU(Project project) {
super(project, null);
}
public void showDIUScatterPlot(DataApp.DataType type, SubTabBase.SubTabInfo subTabInfo, Node tabNode, boolean update) {
this.dataType = type;
this.subTabInfo = subTabInfo;
paneImgChart = (Pane) tabNode.lookup("#paneImgChart");
imgChart = (ImageView) tabNode.lookup("#imgChart");
pi = (ProgressIndicator) tabNode.lookup("#piDIUScatterPlot");
pi.layoutXProperty().bind(Bindings.subtract(Bindings.divide(paneImgChart.widthProperty(), 2.0), 25.0));
pi.layoutYProperty().bind(Bindings.subtract(Bindings.divide(paneImgChart.heightProperty(), 2.0), 25.0));
imgChart.fitHeightProperty().bind(paneImgChart.heightProperty());
imgChart.fitWidthProperty().bind(paneImgChart.widthProperty());
imgChart.setPreserveRatio(true);
app.ctls.setupImageExport(imgChart, "DIU Scatter Plot", "tappAS_" + export_name, null);
//Change loading and load DIU table results
String filepath = project.data.getScatterPlotFilepath(dataType.name());
if(!plotShown) {
if(Files.exists(Paths.get(filepath)) && !update) {
plotShown = true;
showScatterPlotImage(filepath);
}
else {
boolean runDLT = true;
if(!Files.exists(Paths.get(project.data.getMatrixDIUFilepath(dataType.name())))) {
runDLT = false;
}
// start task to create chart in R and return image
if(runDLT)
runDataLoadThread();
}
}
}
//
// Internal Functions
//
private void showScatterPlotImage(String filepath) {
Image img = new Image("file:" + filepath);
pi.setVisible(false);
imgChart.setImage(img);
imgChart.setVisible(true);
}
//
// Data Load
//
private void runDataLoadThread() {
// get script path and run service/task
runScriptPath = app.data.getTmpScriptFileFromResource("DIU_ScatterPlot.R");
service = new DataLoadService();
service.start();
}
private class DataLoadService extends TaskHandler.ServiceExt {
@Override
protected void onRunning() {
pi.setProgress(-1);
pi.setVisible(true);
}
@Override
protected void onStopped() {
pi.setVisible(false);
pi.setProgress(0);
}
@Override
protected void onFailed() {
java.lang.Throwable e = getException();
if(e != null)
app.logWarning("ScatterPlot failed - task aborted. Exception: " + e.getMessage());
else
app.logWarning("ScatterPlot - task aborted.");
app.ctls.alertWarning("DIU Scatter Plot", "ScatterPlot failed - task aborted");
}
@Override
protected void onSucceeded() {
String filepath = project.data.getScatterPlotFilepath(dataType.name());
if(Files.exists(Paths.get(filepath))) {
if(!plotShown) {
plotShown = true;
showScatterPlotImage(filepath);
}
}
else
app.ctls.alertWarning("DIU Scatter Plot", "Unable to generate expression levels density plot.");
}
@Override
protected Task<Void> createTask() {
Task task = new Task<Void>() {
@Override
protected Void call() throws Exception {
String logfilepath = project.data.getSubTabLogFilepath(subTabInfo.subTabId);
subTabInfo.subTabBase.outputFirstLogLine("DIU Scatter Plot Running...", logfilepath);
// setup script arguments
List<String> lst = new ArrayList<>();
lst.add(app.data.getRscriptFilepath());
lst.add(runScriptPath.toString());
String type = app.data.getDataTypeSingular(dataType.name());
lst.add("-d" + type.toLowerCase());
lst.add("-i" + project.data.getMatrixDIUFilepath(dataType.name()));
lst.add("-o" + project.data.getScatterPlotFilepath(dataType.name()));
subTabInfo.subTabBase.appendLogLine("Starting R script...", logfilepath);
logger.logDebug("Running expression levels density plot script:\n " + lst);
subTabInfo.subTabBase.runScript(taskInfo, lst, "DIU Scatter Plot", logfilepath);
// remove script file from temp folder
Utils.removeFile(runScriptPath);
runScriptPath = null;
return null;
}
};
taskInfo = new TaskHandler.TaskInfo("DIU Scatter Plot", task);
return task;
}
}
}