1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package jalview.fts.service.threedbeacons; |
22 |
|
|
23 |
|
import java.net.HttpURLConnection; |
24 |
|
import java.util.HashMap; |
25 |
|
import java.util.HashSet; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
|
import javax.swing.SwingUtilities; |
29 |
|
|
30 |
|
import jalview.bin.Console; |
31 |
|
import jalview.datamodel.AlignmentI; |
32 |
|
import jalview.fts.api.FTSDataColumnI; |
33 |
|
import jalview.fts.api.FTSRestClientI; |
34 |
|
import jalview.fts.core.FTSRestRequest; |
35 |
|
import jalview.fts.core.FTSRestResponse; |
36 |
|
import jalview.fts.core.GFTSPanel; |
37 |
|
import jalview.gui.SequenceFetcher; |
38 |
|
import jalview.io.DataSourceType; |
39 |
|
import jalview.io.FileFormat; |
40 |
|
import jalview.io.FormatAdapter; |
41 |
|
import jalview.util.MessageManager; |
42 |
|
|
43 |
|
@SuppressWarnings("serial") |
|
|
| 16.9% |
Uncovered Elements: 98 (118) |
Complexity: 28 |
Complexity Density: 0.33 |
|
44 |
|
public class TDBeaconsFTSPanel extends GFTSPanel |
45 |
|
{ |
46 |
|
private static String defaultFTSFrameTitle = MessageManager |
47 |
|
.getString("label.pdb_sequence_fetcher"); |
48 |
|
|
49 |
|
private static Map<String, Integer> tempUserPrefs = new HashMap<>(); |
50 |
|
|
51 |
|
private static final String THREEDB_FTS_CACHE_KEY = "CACHE.THREEDB_FTS"; |
52 |
|
|
53 |
|
private static final String THREEDB_AUTOSEARCH = "FTS.THREEDB.AUTOSEARCH"; |
54 |
|
|
55 |
|
private static HttpURLConnection connection; |
56 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
57 |
1 |
public TDBeaconsFTSPanel(SequenceFetcher fetcher)... |
58 |
|
{ |
59 |
|
|
60 |
1 |
super(null); |
61 |
1 |
pageLimit = TDBeaconsFTSRestClient.getInstance() |
62 |
|
.getDefaultResponsePageSize(); |
63 |
1 |
this.seqFetcher = fetcher; |
64 |
1 |
this.progressIndicator = (fetcher == null) ? null |
65 |
|
: fetcher.getProgressIndicator(); |
66 |
|
} |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
68 |
0 |
@Override... |
69 |
|
public void searchAction(boolean isFreshSearch) |
70 |
|
{ |
71 |
0 |
mainFrame.requestFocusInWindow(); |
72 |
0 |
if (isFreshSearch) |
73 |
|
{ |
74 |
0 |
offSet = 0; |
75 |
|
} |
76 |
0 |
new Thread() |
77 |
|
{ |
|
|
| 0% |
Uncovered Elements: 50 (50) |
Complexity: 9 |
Complexity Density: 0.22 |
|
78 |
0 |
@Override... |
79 |
|
public void run() |
80 |
|
{ |
81 |
0 |
reset(); |
82 |
0 |
boolean allowEmptySequence = false; |
83 |
0 |
if (getTypedText().length() > 0) |
84 |
|
{ |
85 |
0 |
setSearchInProgress(true); |
86 |
0 |
long startTime = System.currentTimeMillis(); |
87 |
|
|
88 |
0 |
String searchTarget = ((FTSDataColumnI) cmb_searchTarget |
89 |
|
.getSelectedItem()).getCode(); |
90 |
0 |
wantedFields = TDBeaconsFTSRestClient.getInstance() |
91 |
|
.getAllDefaultDisplayedFTSDataColumns(); |
92 |
0 |
String searchTerm = getTypedText(); |
93 |
|
|
94 |
0 |
FTSRestRequest request = new FTSRestRequest(); |
95 |
0 |
request.setAllowEmptySeq(allowEmptySequence); |
96 |
0 |
request.setResponseSize(100); |
97 |
|
|
98 |
0 |
request.setSearchTerm(searchTerm + ".json"); |
99 |
0 |
request.setOffSet(offSet); |
100 |
0 |
request.setWantedFields(wantedFields); |
101 |
0 |
FTSRestClientI tdbRestClient = TDBeaconsFTSRestClient |
102 |
|
.getInstance(); |
103 |
0 |
FTSRestResponse resultList; |
104 |
0 |
try |
105 |
|
{ |
106 |
0 |
resultList = tdbRestClient.executeRequest(request); |
107 |
|
} catch (Exception e) |
108 |
|
{ |
109 |
0 |
setErrorMessage(e.getMessage()); |
110 |
0 |
checkForErrors(); |
111 |
0 |
setSearchInProgress(false); |
112 |
0 |
return; |
113 |
|
} |
114 |
|
|
115 |
0 |
if (resultList.getSearchSummary() != null |
116 |
|
&& resultList.getSearchSummary().size() > 0) |
117 |
|
{ |
118 |
0 |
getResultTable().setModel(FTSRestResponse.getTableModel(request, |
119 |
|
resultList.getSearchSummary())); |
120 |
0 |
FTSRestResponse.configureTableColumn(getResultTable(), |
121 |
|
wantedFields, tempUserPrefs); |
122 |
0 |
getResultTable().setVisible(true); |
123 |
|
} |
124 |
|
|
125 |
0 |
long endTime = System.currentTimeMillis(); |
126 |
0 |
totalResultSetCount = resultList.getNumberOfItemsFound(); |
127 |
0 |
resultSetCount = resultList.getSearchSummary() == null ? 0 |
128 |
|
: resultList.getSearchSummary().size(); |
129 |
0 |
String result = (resultSetCount > 0) |
130 |
|
? MessageManager.getString("label.results") |
131 |
|
: MessageManager.getString("label.result"); |
132 |
|
|
133 |
0 |
if (isPaginationEnabled() && resultSetCount > 0) |
134 |
|
{ |
135 |
0 |
String f1 = totalNumberformatter |
136 |
|
.format(Integer.valueOf(offSet + 1)); |
137 |
0 |
String f2 = totalNumberformatter |
138 |
|
.format(Integer.valueOf(offSet + resultSetCount)); |
139 |
0 |
String f3 = totalNumberformatter |
140 |
|
.format(Integer.valueOf(totalResultSetCount)); |
141 |
0 |
updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result |
142 |
|
+ " " + f1 + " to " + f2 + " of " + f3 + " " + " (" |
143 |
|
+ (endTime - startTime) + " milli secs)"); |
144 |
|
} |
145 |
|
else |
146 |
|
{ |
147 |
0 |
updateSearchFrameTitle(defaultFTSFrameTitle + " - " |
148 |
|
+ resultSetCount + " " + result + " (" |
149 |
|
+ (endTime - startTime) + " milli secs)"); |
150 |
|
} |
151 |
|
|
152 |
0 |
setSearchInProgress(false); |
153 |
0 |
refreshPaginatorState(); |
154 |
0 |
updateSummaryTableSelections(); |
155 |
|
} |
156 |
0 |
txt_search.updateCache(); |
157 |
|
} |
158 |
|
}.start(); |
159 |
|
} |
160 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 2 |
Complexity Density: 0.11 |
|
161 |
0 |
@Override... |
162 |
|
public void okAction() |
163 |
|
{ |
164 |
|
|
165 |
0 |
disableActionButtons(); |
166 |
0 |
StringBuilder selectedIds = new StringBuilder(); |
167 |
0 |
final HashSet<String> selectedIdsSet = new HashSet<>(); |
168 |
0 |
int primaryKeyColIndex = 0; |
169 |
0 |
try |
170 |
|
{ |
171 |
0 |
primaryKeyColIndex = getFTSRestClient() |
172 |
|
.getPrimaryKeyColumIndex(wantedFields, false); |
173 |
|
} catch (Exception e) |
174 |
|
{ |
175 |
0 |
e.printStackTrace(); |
176 |
|
} |
177 |
0 |
int[] selectedRows = getResultTable().getSelectedRows(); |
178 |
0 |
String searchTerm = getTypedText(); |
179 |
0 |
for (int summaryRow : selectedRows) |
180 |
|
{ |
181 |
0 |
String idStr = getResultTable() |
182 |
|
.getValueAt(summaryRow, primaryKeyColIndex).toString(); |
183 |
0 |
selectedIdsSet.add(idStr); |
184 |
|
} |
185 |
|
|
186 |
0 |
for (String idStr : paginatorCart) |
187 |
|
{ |
188 |
0 |
selectedIdsSet.add(idStr); |
189 |
|
} |
190 |
|
|
191 |
0 |
for (String selectedId : selectedIdsSet) |
192 |
|
{ |
193 |
0 |
selectedIds.append(selectedId).append(";"); |
194 |
|
} |
195 |
|
|
196 |
0 |
SwingUtilities.invokeLater(new Runnable() |
197 |
|
{ |
|
|
| 0% |
Uncovered Elements: 15 (15) |
Complexity: 4 |
Complexity Density: 0.36 |
|
198 |
0 |
@Override... |
199 |
|
public void run() |
200 |
|
{ |
201 |
0 |
AlignmentI allSeqs = null; |
202 |
0 |
FormatAdapter fl = new jalview.io.FormatAdapter(); |
203 |
0 |
for (String tdbURL : selectedIdsSet) |
204 |
|
{ |
205 |
0 |
try |
206 |
|
{ |
207 |
|
|
208 |
0 |
AlignmentI tdbAl = fl.readFile(tdbURL, DataSourceType.URL, |
209 |
|
FileFormat.MMCif); |
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
0 |
if (tdbAl != null) |
216 |
|
{ |
217 |
0 |
if (allSeqs != null) |
218 |
|
{ |
219 |
0 |
allSeqs.append(tdbAl); |
220 |
|
} |
221 |
|
else |
222 |
|
{ |
223 |
0 |
allSeqs = tdbAl; |
224 |
|
} |
225 |
|
} |
226 |
|
} catch (Exception x) |
227 |
|
{ |
228 |
0 |
Console.warn("Couldn't retrieve 3d-beacons model for uniprot id" |
229 |
|
+ searchTerm + " : " + tdbURL, x); |
230 |
|
} |
231 |
|
} |
232 |
0 |
seqFetcher.parseResult(allSeqs, |
233 |
|
"3D-Beacons models for " + searchTerm, FileFormat.MMCif, |
234 |
|
null); |
235 |
|
|
236 |
|
} |
237 |
|
}); |
238 |
0 |
delayAndEnableActionButtons(); |
239 |
|
} |
240 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
241 |
3 |
@Override... |
242 |
|
public FTSRestClientI getFTSRestClient() |
243 |
|
{ |
244 |
3 |
return TDBeaconsFTSRestClient.getInstance(); |
245 |
|
} |
246 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
247 |
2 |
@Override... |
248 |
|
public String getFTSFrameTitle() |
249 |
|
{ |
250 |
2 |
return defaultFTSFrameTitle; |
251 |
|
} |
252 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
253 |
1 |
@Override... |
254 |
|
public boolean isPaginationEnabled() |
255 |
|
{ |
256 |
1 |
return true; |
257 |
|
} |
258 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
259 |
4 |
@Override... |
260 |
|
public Map<String, Integer> getTempUserPrefs() |
261 |
|
{ |
262 |
4 |
return tempUserPrefs; |
263 |
|
} |
264 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
265 |
1 |
@Override... |
266 |
|
public String getCacheKey() |
267 |
|
{ |
268 |
1 |
return THREEDB_FTS_CACHE_KEY; |
269 |
|
} |
270 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
271 |
1 |
@Override... |
272 |
|
public String getAutosearchPreference() |
273 |
|
{ |
274 |
1 |
return THREEDB_AUTOSEARCH; |
275 |
|
} |
276 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
277 |
0 |
@Override... |
278 |
|
protected void showHelp() |
279 |
|
{ |
280 |
0 |
jalview.bin.Console.outPrintln("No help implemented yet."); |
281 |
|
|
282 |
|
} |
283 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
284 |
0 |
public static String decodeSearchTerm(String enteredText)... |
285 |
|
{ |
286 |
|
|
287 |
0 |
return enteredText; |
288 |
|
} |
289 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
290 |
1 |
public String getDbName()... |
291 |
|
{ |
292 |
1 |
return "3D-Beacons"; |
293 |
|
} |
294 |
|
} |