-
Notifications
You must be signed in to change notification settings - Fork 2
/
DrillDownGSEACluster.java
293 lines (277 loc) · 13.4 KB
/
DrillDownGSEACluster.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
/*
* 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.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javafx.scene.layout.Pane;
import javafx.stage.Window;
import tappas.SubTabGSEAClusters.NodesTableData;
import java.util.*;
/**
*
* @author Hector del Risco - [email protected] & Pedro Salguero - [email protected]
*/
public class DrillDownGSEACluster extends DlgBase {
static int id = 0;
static String exportFilename = "";
Label lblHeader, lblDescription;
Button btnHelpTbl, btnExportTbl;
TableView tblMembers;
Pane paneMenu;
ProgressIndicator pi;
int toolId;
DlgGSEAnalysis.Params params;
String analysisId = "";
String cluster, itemName;
int clusterId;
String hdrName;
String panel;
HashMap<String, Object> hmTest = new HashMap<>();
HashMap<String, Object> hmBkgnd = new HashMap<>();
DataGSEA.EnrichedFeaturesData featuresData = null;
ObservableList<NodesTableData> nodesData;
TaskHandler.ServiceExt service = null;
DataGSEA gseaData;
ObservableList<GSEAClusterDrillDownData> data = null;
public DrillDownGSEACluster(Project project, Window window) {
super(project, window);
toolId = ++id;
}
public HashMap<String, String> showAndWait(DlgGSEAnalysis.Params params, String analysisId, String cluster, int clusterId, ObservableList<NodesTableData> nodesData) {
if(createToolDialog("DrillDownGSEACluster.fxml", "GSEA Cluster Drill Down Data", null)) {
this.params = params;
this.analysisId = analysisId;
this.cluster = cluster;
this.clusterId = clusterId;
this.nodesData = nodesData;
gseaData = new DataGSEA(project);
panel = TabGeneDataViz.Panels.TRANS.name();
switch(params.dataType) {
case TRANS:
itemName = "Transcript";
break;
case PROTEIN:
itemName = "Protein";
break;
default:
itemName = "Gene";
break;
}
// get control objects
lblHeader = (Label) scene.lookup("#lblHeader");
lblDescription = (Label) scene.lookup("#lblDescription");
pi = (ProgressIndicator) scene.lookup("#piImage");
tblMembers = (TableView) scene.lookup("#tblMembers");
paneMenu = (Pane) scene.lookup("#paneMenu");
// setup dialog
exportFilename = "tappAS_GSEA_Cluster_"+params.name+".tsv";
dialog.setTitle("GSEA Cluster Drill Down Data for " + cluster);
lblHeader.setText(itemName + "s in cluster '" + cluster + "'");
lblDescription.setText("Cluster: " + cluster); // not meaningful, already shown - something else?
tblMembers.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
ObservableList<TableColumn> cols = tblMembers.getColumns();
cols.get(0).setText(itemName);
cols.get(0).setCellValueFactory(new PropertyValueFactory<>("Gene"));
cols.get(1).setCellValueFactory(new PropertyValueFactory<>("InTest"));
cols.get(2).setCellValueFactory(new PropertyValueFactory<>("Nodes"));
cols.get(3).setCellValueFactory(new PropertyValueFactory<>("GeneDescription"));
SubTabBase.addRowNumbersCol(tblMembers);
ContextMenu cm = new ContextMenu();
addGeneDVItem(cm, tblMembers, panel);
app.export.setupTableExport(this, cm, true);
tblMembers.setContextMenu(cm);
app.export.addCopyToClipboardHandler(tblMembers);
// setup menu buttons
double yoffset = 3.0;
btnExportTbl = app.ctls.addImgButton(paneMenu, "export.png", "Export table data...", yoffset, 32, true);
btnExportTbl.setOnAction((event) -> { onButtonExport(); });
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_GSEACluster.html", Tappas.getWindow()); });
// process dialog - modeless
dialog.setOnShown(e -> { runThread();});
dialog.showAndWait();
}
return null;
}
@Override
protected void onButtonExport() {
DlgExportData.Config cfg = new DlgExportData.Config(true, itemName + "s list (IDs only)", false, "");
DlgExportData.Params results = app.ctlr.getExportDataParams(cfg, null, null);
if(results != null) {
HashMap<String, String> hmColNames = new HashMap<>();
Export.ExportSelection selection = Export.ExportSelection.All;
if(results.dataSelection.equals(DlgExportData.Params.DataSelection.SELECTEDROWS))
selection = Export.ExportSelection.Highlighted;
if(results.dataType.equals(DlgExportData.Params.DataType.TABLEROWS.name()))
app.export.exportTableDataToFile(tblMembers, selection, exportFilename);
else if(results.dataType.equals(DlgExportData.Params.DataType.LIST.name())) {
hmColNames.put(itemName, "");
app.export.exportTableDataListToFile(tblMembers, selection, hmColNames, exportFilename);
}
}
}
//
// Internal Functions
//
private void addGeneDVItem(ContextMenu cm, TableView tbl, String panel) {
MenuItem item = new MenuItem("Show gene data visualization");
cm.getItems().add(item);
item.setOnAction((event) -> {
// get highlighted row's data and show gene data visualization
ObservableList<Integer> lstIdxs = tbl.getSelectionModel().getSelectedIndices();
if(lstIdxs.size() != 1) {
String msg = "You have multiple gene rows highlighted.\nHighlight a single row with the gene you want to visualize.";
app.ctls.alertInformation("Display Gene Data Visualization", msg);
}
else {
GSEAClusterDrillDownData dd = (GSEAClusterDrillDownData) tbl.getItems().get((tbl.getSelectionModel().getSelectedIndex()));
String member = dd.getGene();
String gene = project.data.getGenes(params.dataType, member);
String genes[] = gene.split(",");
if(genes.length > 1) {
List<String> lst = Arrays.asList(genes);
Collections.sort(lst);
ChoiceDialog dlg = new ChoiceDialog(lst.get(0), lst);
dlg.setTitle("Gene Data Visualization");
dlg.setHeaderText("Select gene to visualize");
Optional<String> result = dlg.showAndWait();
if(result.isPresent()) {
gene = result.get();
showGeneDataVisualization(gene, panel);
}
}
else
showGeneDataVisualization(gene, panel);
}
});
}
private void showGeneDataVisualization(String gene, String panel) {
HashMap<String, Object> args = new HashMap<>();
args.put("panels", panel);
app.tabs.openTabGeneDataViz(project, project.getDef().id, gene, project.data.getResultsGeneTrans().get(gene), "Project '" + project.getDef().name + "'", args);
}
//
// Data Load
//
private void runThread() {
// get script path and run service/task
service = new DataService();
service.initialize();
service.start();
}
private class DataService extends TaskHandler.ServiceExt {
@Override
protected void onRunning() {
pi.setVisible(true);
}
@Override
protected void onStopped() {
pi.setVisible(false);
}
@Override
protected void onFailed() {
Throwable e = getException();
if(e != null)
app.logWarning("DrillDownGSEACluster failed - task aborted. Exception: " + e.getMessage());
else
app.logWarning("DrillDownGSEACluster - task aborted.");
app.ctls.alertWarning("Drill Down Funtional Enrichment Analysis Cluster", "DrillDownGSEACluster - task aborted");
}
@Override
protected void onSucceeded() {
if(data != null) {
tblMembers.setItems(data);
if(!data.isEmpty())
tblMembers.getSelectionModel().select(0);
}
else
app.ctls.alertWarning("GSEA Cluster Drill Down Data", "Unable to load drill down data.");
}
@Override
protected Task<Void> createTask() {
Task task = new Task<Void>() {
@Override
protected Void call() throws Exception {
try {
// get GSEA results - String dataType, String id, double sigValue
//featuresData = gseaData.getGSEAEnrichedFeaturesData(params.dataType.name(), analysisId, params.sigValue);
featuresData = gseaData.getGSEAEnrichedFeaturesData(params.dataType.name(), analysisId, params.sigValue);
HashMap<String, GSEAClusterDrillDownData> hmMembers = new HashMap<>();
for(NodesTableData nd : nodesData) {
if(nd.getClusterID().equals(clusterId)) {
String node = nd.getID();
int idx = 0;
for(DataGSEA.GSEAStatsData st : featuresData.lstStats) {
if(st.feature.get().equals(node)) {
String member;
if(data == null)
data = FXCollections.observableArrayList();
//cambiar la obtención de nodos-clusters? !!!
BitSet bs = featuresData.lstTermMembers.get(idx);
for(int mbr = 0; mbr < bs.size(); mbr++) {
if(bs.get(mbr)) {
member = featuresData.lstMembers.get(mbr);
if(!hmMembers.containsKey(member)) {
String geneDesc = project.data.getGeneDescriptions(params.dataType, member);
GSEAClusterDrillDownData cd = new GSEAClusterDrillDownData(member, hmTest.containsKey(member), node, geneDesc);
hmMembers.put(member, cd);
data.add(cd);
}
else {
GSEAClusterDrillDownData cd = hmMembers.get(member);
cd.nodes.set(cd.nodes.get() + ", " + node);
}
}
}
}
idx++;
}
}
}
if(data != null)
FXCollections.sort(data);
else
app.logError("Unable to find cluster, " + cluster + ", nodes in GSEA results.");
}
catch (Exception e) {
app.logError("Unable to load " + hdrName + ": " + e.getMessage());
}
return null;
}
};
taskInfo = new TaskHandler.TaskInfo("GSEA Cluster Node Drill Down Data " + toolId, task);
return task;
}
}
//
// Data Classes
//
static public class GSEAClusterDrillDownData implements Comparable<GSEAClusterDrillDownData> {
public SimpleStringProperty gene;
public SimpleStringProperty inTest;
public SimpleStringProperty nodes;
public SimpleStringProperty geneDescription;
public GSEAClusterDrillDownData(String gene, boolean inTest, String nodes, String geneDescription) {
this.gene = new SimpleStringProperty(gene);
this.inTest = new SimpleStringProperty(inTest? "YES" : "NO");
this.nodes = new SimpleStringProperty(nodes);
this.geneDescription = new SimpleStringProperty(geneDescription);
}
public String getGene() { return gene.get(); }
public String getInTest() { return inTest.get(); }
public String getNodes() { return nodes.get(); }
public String getGeneDescription() { return geneDescription.get(); }
@Override
public int compareTo(GSEAClusterDrillDownData td) {
return (gene.get().compareToIgnoreCase(td.gene.get()));
}
}
}