-
Notifications
You must be signed in to change notification settings - Fork 2
/
DlgFDAnalysisCombinedResults.java
199 lines (167 loc) · 6.89 KB
/
DlgFDAnalysisCombinedResults.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
/*
* 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.control.*;
import javafx.stage.Window;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Optional;
/**
*
* @author Pedro Salguero - [email protected]
*/
public class DlgFDAnalysisCombinedResults extends DlgBase {
ChoiceBox cbFeatures;
public DlgFDAnalysisCombinedResults(Project project, Window window) {
super(project, window);
}
public Params showAndWait(Params dfltParams) {
if(createDialog("FDAParamsCombinedResults.fxml", "Functional Diversity Analysis Combined Results", true, "Help_PD_FAIDCOMBINED.html")) {
if(dfltParams == null)
dfltParams = new Params(project);
// get control objects
cbFeatures = (ChoiceBox) scene.lookup("#cbFeatures");
// set features list
for(String feat : Params.FeatureList) {
cbFeatures.getItems().add(feat);
}
cbFeatures.getSelectionModel().select(Params.getIdxByName(Params.FeatureList[0], Params.FeatureList));
int idx = 0;
for(int i = 0; i < cbFeatures.getItems().size(); i++) {
if(((String)cbFeatures.getItems().get(i)).startsWith(getCompareNameStart(Params.FeatureList[idx]))){
cbFeatures.getSelectionModel().select(i);
break;
}
}
// 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 HashMap<String, String> validate(Dialog dialog) {
HashMap<String, String> results = new HashMap<>();
System.out.println("Validate dialog");
// get the feature list
int idx = cbFeatures.getSelectionModel().getSelectedIndex();
String feature = Params.FeatureList[idx];
results.put(Params.FEATURELIST_PARAM, feature);
String ana1 = Params.hmFeatures.get(feature).get(Params.GENEPOS);
results.put(Params.ANALYSISGENOMIC_PARAM, ana1);
String ana2 = Params.hmFeatures.get(feature).get(Params.PRESENCE);
results.put(Params.ANALYSISPRESENCE_PARAM, ana2);
return results;
}
private static String getCompareNameStart(String name) {
int idx = name.indexOf("@");
if(idx != -1)
return name.substring(0, idx);
return name;
}
//
// Data Classes
//
public static class Params extends DlgParams {
public static DataFDA fdaData;
public static HashMap<String, HashMap<String, String>> hmFeatures;
public static String[] FeatureList;
public static final String GENEPOS = "GENPOS";
public static final String PRESENCE = "PRESENCE";
public static final String FEATURELIST_PARAM = "feature";
public static final String ANALYSISGENOMIC_PARAM = "analysis_genomic";
public static final String ANALYSISPRESENCE_PARAM = "analysis_presence";
String feature;
String analysis_genomic;
String analysis_presence;
public String getFeature(int i){
return FeatureList[i];
}
public String[] hmToArray(HashMap<String, HashMap<String, String>> hmFeature){
String[] features = new String[hmFeature.size()];
int cont = 0;
for(String aux : hmFeature.keySet()){
features[cont] = aux;
cont++;
}
return features;
}
public Params(Project project) {
fdaData = new DataFDA(project);
hmFeatures = fdaData.getFDAIdDataFeatures();
ArrayList<String> delete = new ArrayList<String>();
for(String feat : hmFeatures.keySet()) {
if (hmFeatures.get(feat).size() < 2)
delete.add(feat);
}
for(String d : delete)
hmFeatures.remove(d);
FeatureList = hmToArray(hmFeatures);
this.feature = "";
this.analysis_genomic = "";
this.analysis_presence = "";
}
public Params(HashMap<String, String> hmParams){
hmFeatures = fdaData.getFDAIdDataFeatures();
ArrayList<String> delete = new ArrayList<String>();
for(String feat : hmFeatures.keySet()) {
if (hmFeatures.get(feat).size() < 2)
delete.add(feat);
}
for(String d : delete)
hmFeatures.remove(d);
FeatureList = hmToArray(hmFeatures);
this.feature = hmParams.containsKey(FEATURELIST_PARAM)? hmParams.get(FEATURELIST_PARAM) : "";
this.analysis_genomic = hmParams.containsKey(ANALYSISGENOMIC_PARAM)? hmParams.get(ANALYSISGENOMIC_PARAM) : "";
this.analysis_presence = hmParams.containsKey(ANALYSISPRESENCE_PARAM)? hmParams.get(ANALYSISPRESENCE_PARAM) : "";
}
@Override
public HashMap<String, String> getParams() {
HashMap<String, String> hm = new HashMap<>();
hm.put(ANALYSISGENOMIC_PARAM, analysis_genomic);
hm.put(ANALYSISPRESENCE_PARAM, analysis_presence);
return hm;
}
//
// Static functions
//
public static Params load(String filepath) {
HashMap<String, String> params = new HashMap<>();
Utils.loadParams(params, filepath);
return (new Params(params));
}
private static int getIdxByName(String name, String[] lst) {
int idx = 0;
for(String entry : lst) {
String cmpName = getCompareNameStart(entry);
if(name.startsWith(cmpName)) {
// "All @" matches "All multiple..." so handle it at end
if(idx != 0)
break;
}
idx++;
}
if(idx >= lst.length)
idx = 0;
return idx;
}
}
}