forked from ConesaLab/tappAS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DrillDownDFI.java
168 lines (153 loc) · 6.99 KB
/
DrillDownDFI.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
/*
* 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.scene.SnapshotParameters;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.control.Button;
import javafx.scene.control.Tooltip;
import javafx.scene.image.WritableImage;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.Pane;
import javafx.stage.Window;
import java.util.ArrayList;
import java.util.HashMap;
/**
*
* @author Hector del Risco - [email protected] & Pedro Salguero - [email protected]
*/
public class DrillDownDFI extends DlgBase {
static int id = 0;
static String exportFilename = "";
LineChartTimeSeries chartMain;
Button btnHelpTbl, btnExportChart;
GridPane grdCharts;
Pane paneMenu;
int toolId;
boolean timeSeries = false;
boolean timeMultiple = false;
DataDFI.DFISelectionResults data = null;
public DrillDownDFI(Project project, Window window) {
super(project, window);
toolId = ++id;
timeSeries = project.data.isTimeCourseExpType();
timeMultiple = project.data.getExperimentType().equals(DataApp.ExperimentType.Time_Course_Multiple);
}
public HashMap<String, String> showAndWait(DataDFI.DFISelectionResults data) {
if(createToolDialog("DrillDownDFI.fxml", "DFI Gene FeatureId Data Visualization", null)) {
this.data = data;
// get control objects
grdCharts = (GridPane) scene.lookup("#grdCharts");
paneMenu = (Pane) scene.lookup("#paneMenu");
// determine time lines for time series
ArrayList<Integer> lstTimeLines = new ArrayList<>();
if(timeSeries) {
int[] scnt = project.data.getGroupTimes();
int pt = 0;
int n = scnt.length;
for(int i = 0; i < (n - 1); i++) {
lstTimeLines.add(pt + scnt[i]);
pt += scnt[i];
}
}
// create chart
chartMain = new LineChartTimeSeries(new CategoryAxis(), new NumberAxis(), project.data.getGroupsTimeNames().length);
chartMain.setMultipleGroupsTS(timeMultiple);
chartMain.setAnimated(false);
chartMain.addTimeLines(lstTimeLines);
grdCharts.add(chartMain, 0, 0);
// setup dialog
setProjectName();
dialog.setTitle("DFI Gene FeatureId Data Visualization");
chartMain.setTitle("DFI Gene '" + data.getGene() + "' Feature Id '" + data.getFeatureId() + "' - " + data.getDS() + "\n");
exportFilename = "tappAS_DFI_"+ data.getGene() +"_FeatureId.png";
// determine number of
ArrayList<Integer> lstCounts = new ArrayList<>();
int[] grps = project.data.getGroupTimes();
for(int i = 0; i < grps.length; i++) {
int timecnt = grps[i];
for(int j = 0; j < timecnt; j++) {
lstCounts.add(project.data.getGroupTimeSamples(i, j));
}
}
int totalCols = lstCounts.size();
Integer[] scnt = new Integer[totalCols];
scnt = lstCounts.toArray(scnt);
String[] names;
if(project.data.isTimeCourseExpType()) {
int idx = 0;
names = new String[totalCols];
for(int i = 0; i < grps.length; i++) {
String[] timeNames = project.data.getGroupTimeNames(i);
for(int j = 0; j < timeNames.length; j++) {
names[idx++] = timeNames[j];
}
}
}
else {
names = project.data.getGroupNames();
}
XYChart.Series<String, Number> series1 = new XYChart.Series();
series1.setName("With Feature Id");
for(int i = 0; i < totalCols; i++) {
series1.getData().add(new XYChart.Data(names[i], data.getWithMeanExp(i)));
}
XYChart.Series<String, Number> series2 = new XYChart.Series();
series2.setName("Without Feature Id");
for(int i = 0; i < totalCols; i++) {
series2.getData().add(new XYChart.Data(names[i], data.getWithoutMeanExp(i)));
}
chartMain.getYAxis().setLabel("Expression Level");
if(project.data.isSingleTimeSeriesExpType())
chartMain.getXAxis().setLabel("Favored times (" + data.getFavored() + ")");
else
chartMain.getXAxis().setLabel("Conditions (" + data.getFavored() + " favored)");
chartMain.getData().addAll(series1, series2);
Tooltip tt;
for(int i = 0; i < series1.getData().size(); i++) {
XYChart.Data item = series1.getData().get(i);
String tooltip = names[i] + " withFeatureID: " + String.format("%.2f", item.getYValue());
tt = new Tooltip(tooltip);
tt.setStyle("-fx-font: 13 system;");
Tooltip.install(item.getNode(), tt);
}
for(int i = 0; i < series2.getData().size(); i++) {
XYChart.Data item = series2.getData().get(i);
String tooltip = names[i] + " withoutFeatureID: " + String.format("%.2f", item.getYValue());
tt = new Tooltip(tooltip);
tt.setStyle("-fx-font: 13 system;");
Tooltip.install(item.getNode(), tt);
}
app.ctls.setupChartExport(chartMain, "DFI Gene FeatureId Data Visualization", exportFilename, null);
// setup menu buttons
double yoffset = 3.0;
btnExportChart = app.ctls.addImgButton(paneMenu, "export.png", "Export chart image...", yoffset, 32, true);
btnExportChart.setOnAction((event) -> { onButtonExportChart(); });
yoffset += 36;
btnHelpTbl = app.ctls.addImgButton(paneMenu, "help.png", "Help", yoffset, 32, true);
btnHelpTbl.setOnAction((event) -> { DlgHelp dlg = new DlgHelp(); dlg.show(title, "Help_DrillDown_DFI.html", Tappas.getWindow()); });
// process dialog - modeless
dialog.showAndWait();
}
return null;
}
@Override
protected void onButtonExportChart() {
SnapshotParameters sP = new SnapshotParameters();
double x = chartMain.getWidth();
double ratio = 3840/x;
chartMain.setScaleX(ratio);
chartMain.setScaleY(ratio);
WritableImage img = chartMain.snapshot(sP, null);
double newX = chartMain.getWidth();
ratio = x/newX;
chartMain.setScaleX(ratio);
chartMain.setScaleY(ratio);
//WritableImage img = chartMain.snapshot(new SnapshotParameters(), null);
app.export.exportImage("DFI Gene FeatureId Data Visualization", exportFilename, img);
}
}