1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.gui.structurechooser; |
22 |
|
|
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.Arrays; |
25 |
|
import java.util.BitSet; |
26 |
|
import java.util.Collection; |
27 |
|
import java.util.Collections; |
28 |
|
import java.util.Comparator; |
29 |
|
import java.util.List; |
30 |
|
import java.util.Locale; |
31 |
|
|
32 |
|
import jalview.datamodel.SequenceI; |
33 |
|
import jalview.fts.api.FTSData; |
34 |
|
import jalview.fts.core.FTSRestRequest; |
35 |
|
|
|
|
| 0% |
Uncovered Elements: 178 (178) |
Complexity: 46 |
Complexity Density: 0.44 |
|
36 |
|
public class TDBResultAnalyser |
37 |
|
{ |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
private static List<String> EXP_CATEGORIES = Arrays |
46 |
|
.asList(new String[] |
47 |
|
{ "EXPERIMENTALLY DETERMINED", "DEEP-LEARNING", "AB-INITIO", |
48 |
|
"TEMPLATE-BASED", "CONFORMATIONAL ENSEMBLE" }); |
49 |
|
|
50 |
|
private SequenceI seq; |
51 |
|
|
52 |
|
private Collection<FTSData> collectedResults; |
53 |
|
|
54 |
|
private FTSRestRequest lastTdbRequest; |
55 |
|
|
56 |
|
private int idx_ups; |
57 |
|
|
58 |
|
private int idx_upe; |
59 |
|
|
60 |
|
private int idx_mcat; |
61 |
|
|
62 |
|
private int idx_mqual; |
63 |
|
|
64 |
|
private int idx_mqualtype; |
65 |
|
|
66 |
|
private int idx_resol; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
private String filter = null; |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
private String sourceFilter = null; |
77 |
|
|
78 |
|
private int idx_mprov; |
79 |
|
|
|
|
| 0% |
Uncovered Elements: 12 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
|
80 |
0 |
public TDBResultAnalyser(SequenceI seq,... |
81 |
|
Collection<FTSData> collectedResults, |
82 |
|
FTSRestRequest lastTdbRequest, String fieldToFilterBy, |
83 |
|
String string) |
84 |
|
{ |
85 |
0 |
this.seq = seq; |
86 |
0 |
this.collectedResults = collectedResults; |
87 |
0 |
this.lastTdbRequest = lastTdbRequest; |
88 |
0 |
this.filter = fieldToFilterBy; |
89 |
0 |
this.sourceFilter = string; |
90 |
0 |
idx_ups = lastTdbRequest.getFieldIndex("Uniprot Start"); |
91 |
0 |
idx_upe = lastTdbRequest.getFieldIndex("Uniprot End"); |
92 |
0 |
idx_mcat = lastTdbRequest.getFieldIndex("Model Category"); |
93 |
0 |
idx_mprov = lastTdbRequest.getFieldIndex("Provider"); |
94 |
0 |
idx_mqual = lastTdbRequest.getFieldIndex("Confidence"); |
95 |
0 |
idx_resol = lastTdbRequest.getFieldIndex("Resolution"); |
96 |
0 |
idx_mqualtype = lastTdbRequest.getFieldIndex("Confidence Score Type"); |
97 |
|
} |
98 |
|
|
99 |
|
|
100 |
|
|
101 |
|
|
102 |
|
|
103 |
|
@param |
104 |
|
@return |
105 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
106 |
0 |
public final int scoreCategory(String cat)... |
107 |
|
{ |
108 |
0 |
if (cat == null) |
109 |
|
{ |
110 |
0 |
return 0; |
111 |
|
} |
112 |
0 |
String upper_cat = cat.toUpperCase(Locale.ROOT); |
113 |
0 |
int idx = EXP_CATEGORIES.indexOf(upper_cat); |
114 |
0 |
if (idx == -1) |
115 |
|
{ |
116 |
0 |
jalview.bin.Console.outPrintln("Unknown category: '" + cat + "'"); |
117 |
0 |
EXP_CATEGORIES.add(upper_cat); |
118 |
0 |
idx = EXP_CATEGORIES.size() - 1; |
119 |
|
} |
120 |
0 |
return -EXP_CATEGORIES.size() - idx; |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
@return |
128 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 8 |
Complexity Density: 0.62 |
|
129 |
0 |
public List<FTSData> getFilteredResponse()... |
130 |
|
{ |
131 |
0 |
List<FTSData> filteredResponse = new ArrayList<FTSData>(); |
132 |
|
|
133 |
|
|
134 |
0 |
for (FTSData row : collectedResults) |
135 |
|
{ |
136 |
0 |
if (row.getSummaryData() != null |
137 |
|
&& row.getSummaryData()[idx_ups] != null) |
138 |
|
{ |
139 |
0 |
int up_s = (Integer) row.getSummaryData()[idx_ups]; |
140 |
0 |
int up_e = (Integer) row.getSummaryData()[idx_upe]; |
141 |
0 |
String provider = (String) row.getSummaryData()[idx_mprov]; |
142 |
0 |
String mcat = (String) row.getSummaryData()[idx_mcat]; |
143 |
|
|
144 |
0 |
int scorecat = scoreCategory(mcat); |
145 |
0 |
if (sourceFilter == null || sourceFilter.equals(provider)) |
146 |
|
{ |
147 |
0 |
if (seq == row.getSummaryData()[0] && up_e > seq.getStart() |
148 |
|
&& up_s < seq.getEnd()) |
149 |
|
{ |
150 |
0 |
filteredResponse.add(row); |
151 |
|
} |
152 |
|
} |
153 |
|
} |
154 |
|
} |
155 |
|
|
156 |
|
|
157 |
0 |
Collections.sort(filteredResponse, new Comparator<FTSData>() |
158 |
|
{ |
|
|
| 0% |
Uncovered Elements: 85 (85) |
Complexity: 24 |
Complexity Density: 0.59 |
|
159 |
0 |
@Override... |
160 |
|
public int compare(FTSData o1, FTSData o2) |
161 |
|
{ |
162 |
0 |
Object[] o1data = o1.getSummaryData(); |
163 |
0 |
Object[] o2data = o2.getSummaryData(); |
164 |
0 |
int o1_s = (Integer) o1data[idx_ups]; |
165 |
0 |
int o1_e = (Integer) o1data[idx_upe]; |
166 |
0 |
int o1_cat = scoreCategory((String) o1data[idx_mcat]); |
167 |
0 |
String o1_prov = ((String) o1data[idx_mprov]) |
168 |
|
.toUpperCase(Locale.ROOT); |
169 |
0 |
int o2_s = (Integer) o2data[idx_ups]; |
170 |
0 |
int o2_e = (Integer) o2data[idx_upe]; |
171 |
0 |
int o2_cat = scoreCategory((String) o2data[idx_mcat]); |
172 |
0 |
String o2_prov = ((String) o2data[idx_mprov]) |
173 |
|
.toUpperCase(Locale.ROOT); |
174 |
0 |
String o1_qualtype = (String) o1data[idx_mqualtype], |
175 |
|
o2_qualtype = (String) o2data[idx_mqualtype]; |
176 |
|
|
177 |
0 |
if (o1_cat == o2_cat) |
178 |
|
{ |
179 |
0 |
if (o1_s == o2_s) |
180 |
|
{ |
181 |
0 |
int o1_xtent = o1_e - o1_s; |
182 |
0 |
int o2_xtent = o2_e - o2_s; |
183 |
0 |
if (o1_xtent == o2_xtent) |
184 |
|
{ |
185 |
|
|
186 |
0 |
if (o1_cat == scoreCategory(EXP_CATEGORIES.get(0))) |
187 |
|
{ |
188 |
0 |
if (o1_prov.equals(o2_prov)) |
189 |
|
{ |
190 |
0 |
if ("PDBE".equals(o1_prov)) |
191 |
|
{ |
192 |
0 |
if (eitherNull(idx_resol, o1data, o2data)) |
193 |
|
{ |
194 |
0 |
return nonNullFirst(idx_resol, o1data, o2data); |
195 |
|
} |
196 |
|
|
197 |
0 |
double o1_res = (Double) o1data[idx_resol]; |
198 |
0 |
double o2_res = (Double) o2data[idx_resol]; |
199 |
0 |
return (o2_res < o1_res) ? 1 |
200 |
0 |
: (o2_res == o1_res) ? 0 : -1; |
201 |
|
} |
202 |
|
else |
203 |
|
{ |
204 |
0 |
return 0; |
205 |
|
} |
206 |
|
} |
207 |
|
else |
208 |
|
{ |
209 |
|
|
210 |
|
|
211 |
0 |
return "PDBE".equals(o1_prov) ? -1 |
212 |
0 |
: "PDBE".equals(o2_prov) ? 1 : 0; |
213 |
|
} |
214 |
|
} |
215 |
|
else |
216 |
|
{ |
217 |
|
|
218 |
0 |
if (eitherNull(idx_mqualtype, o1data, o2data)) |
219 |
|
{ |
220 |
0 |
return nonNullFirst(idx_mqualtype, o1data, o2data); |
221 |
|
} |
222 |
|
|
223 |
0 |
if (!o1_qualtype.equals(o2_qualtype)) |
224 |
|
{ |
225 |
|
|
226 |
0 |
return "pLDDT".equals(o1_qualtype) ? -1 |
227 |
0 |
: "pLDDT".equals(o2_qualtype) ? 1 : 0; |
228 |
|
} |
229 |
|
|
230 |
0 |
if (eitherNull(idx_mqual, o1data, o2data)) |
231 |
|
{ |
232 |
0 |
return nonNullFirst(idx_mqual, o1data, o2data); |
233 |
|
} |
234 |
|
|
235 |
0 |
double o1_mq = (Double) o1data[idx_mqual]; |
236 |
0 |
double o2_mq = (Double) o2data[idx_mqual]; |
237 |
0 |
int res = (o2_mq < o1_mq) ? 1 : (o2_mq == o1_mq) ? 0 : -1; |
238 |
0 |
return ("pLDDT".equals(o1_qualtype)) ? -res : res; |
239 |
|
} |
240 |
|
} |
241 |
|
else |
242 |
|
{ |
243 |
0 |
return o1_xtent - o2_xtent; |
244 |
|
} |
245 |
|
} |
246 |
|
else |
247 |
|
{ |
248 |
0 |
return o1_s - o2_s; |
249 |
|
} |
250 |
|
} |
251 |
|
else |
252 |
|
{ |
253 |
|
|
254 |
0 |
if (o2_cat > 0 && o1_cat > 0) |
255 |
|
{ |
256 |
0 |
return "ALPHAFOLD DB".equals(o1_prov) ? -1 |
257 |
0 |
: "ALPHAFOLD DB".equals(o2_prov) ? 1 : 0; |
258 |
|
} |
259 |
0 |
return o2_cat - o1_cat; |
260 |
|
} |
261 |
|
} |
262 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 3 |
Complexity Density: 3 |
|
263 |
0 |
private int nonNullFirst(int idx_resol, Object[] o1data,... |
264 |
|
Object[] o2data) |
265 |
|
{ |
266 |
0 |
return o1data[idx_resol] == o2data[idx_resol] ? 0 |
267 |
0 |
: o1data[idx_resol] != null ? -1 : 1; |
268 |
|
} |
269 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
270 |
0 |
private boolean eitherNull(int idx_resol, Object[] o1data,... |
271 |
|
Object[] o2data) |
272 |
|
{ |
273 |
0 |
return (o1data[idx_resol] == null || o2data[idx_resol] == null); |
274 |
|
} |
275 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
276 |
0 |
@Override... |
277 |
|
public boolean equals(Object obj) |
278 |
|
{ |
279 |
0 |
return super.equals(obj); |
280 |
|
} |
281 |
|
}); |
282 |
0 |
return filteredResponse; |
283 |
|
} |
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
@param |
290 |
|
|
291 |
|
|
292 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 4 |
Complexity Density: 0.2 |
|
293 |
0 |
public List<FTSData> selectStructures(List<FTSData> filteredStructures)... |
294 |
|
{ |
295 |
0 |
List<FTSData> selected = new ArrayList<FTSData>(); |
296 |
0 |
BitSet cover = new BitSet(); |
297 |
0 |
cover.set(seq.getStart(), seq.getEnd()); |
298 |
|
|
299 |
|
|
300 |
|
|
301 |
0 |
for (FTSData structure : filteredStructures) |
302 |
|
{ |
303 |
0 |
Object[] odata = structure.getSummaryData(); |
304 |
0 |
int o1_s = (Integer) odata[idx_ups]; |
305 |
0 |
int o1_e = (Integer) odata[idx_upe]; |
306 |
0 |
int o1_cat = scoreCategory((String) odata[idx_mcat]); |
307 |
0 |
BitSet scover = new BitSet(); |
308 |
|
|
309 |
0 |
scover.set(o1_s, o1_e); |
310 |
0 |
scover.and(cover); |
311 |
0 |
if (scover.cardinality() > 4) |
312 |
|
{ |
313 |
0 |
selected.add(structure); |
314 |
|
|
315 |
0 |
cover.andNot(scover); |
316 |
|
} |
317 |
|
} |
318 |
0 |
if (selected.size() == 0) |
319 |
|
{ |
320 |
0 |
return selected; |
321 |
|
} |
322 |
|
|
323 |
|
|
324 |
0 |
Collections.sort(selected, new Comparator<FTSData>() |
325 |
|
{ |
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
326 |
0 |
@Override... |
327 |
|
public int compare(FTSData o1, FTSData o2) |
328 |
|
{ |
329 |
0 |
Object[] o1data = o1.getSummaryData(); |
330 |
0 |
Object[] o2data = o2.getSummaryData(); |
331 |
0 |
int o1_xt = ((Integer) o1data[idx_upe]) |
332 |
|
- ((Integer) o1data[idx_ups]); |
333 |
0 |
int o1_cat = scoreCategory((String) o1data[idx_mcat]); |
334 |
0 |
int o2_xt = ((Integer) o2data[idx_upe] - (Integer) o2data[idx_ups]); |
335 |
0 |
int o2_cat = scoreCategory((String) o2data[idx_mcat]); |
336 |
0 |
return o2_xt - o1_xt; |
337 |
|
} |
338 |
|
}); |
339 |
0 |
if (filter.equals( |
340 |
|
ThreeDBStructureChooserQuerySource.FILTER_FIRST_BEST_COVERAGE)) |
341 |
|
{ |
342 |
0 |
return selected.subList(0, 1); |
343 |
|
} |
344 |
0 |
return selected; |
345 |
|
} |
346 |
|
|
347 |
|
} |