1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
package jalview.fts.service.uniprot; |
23 |
|
|
24 |
|
import java.util.HashMap; |
25 |
|
import java.util.HashSet; |
26 |
|
import java.util.Map; |
27 |
|
|
28 |
|
import javax.help.HelpSetException; |
29 |
|
|
30 |
|
import jalview.bin.Console; |
31 |
|
import jalview.fts.api.FTSDataColumnI; |
32 |
|
import jalview.fts.api.FTSRestClientI; |
33 |
|
import jalview.fts.core.FTSRestRequest; |
34 |
|
import jalview.fts.core.FTSRestResponse; |
35 |
|
import jalview.fts.core.GFTSPanel; |
36 |
|
import jalview.gui.Help; |
37 |
|
import jalview.gui.Help.HelpId; |
38 |
|
import jalview.gui.SequenceFetcher; |
39 |
|
import jalview.util.MessageManager; |
40 |
|
|
41 |
|
@SuppressWarnings("serial") |
|
|
| 0% |
Uncovered Elements: 157 (157) |
Complexity: 36 |
Complexity Density: 0.32 |
|
42 |
|
public class UniprotFTSPanel extends GFTSPanel |
43 |
|
{ |
44 |
|
|
45 |
|
private static String defaultFTSFrameTitle = MessageManager |
46 |
|
.getString("label.uniprot_sequence_fetcher"); |
47 |
|
|
48 |
|
private static Map<String, Integer> tempUserPrefs = new HashMap<>(); |
49 |
|
|
50 |
|
private static final String UNIPROT_FTS_CACHE_KEY = "CACHE.UNIPROT_2022_FTS"; |
51 |
|
|
52 |
|
private static final String UNIPROT_AUTOSEARCH = "FTS.UNIPROT.AUTOSEARCH"; |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
|
58 |
|
@param |
59 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
60 |
0 |
public UniprotFTSPanel(SequenceFetcher fetcher)... |
61 |
|
{ |
62 |
0 |
super(fetcher); |
63 |
0 |
pageLimit = UniProtFTSRestClient.getInstance() |
64 |
|
.getDefaultResponsePageSize(); |
65 |
0 |
this.seqFetcher = fetcher; |
66 |
0 |
this.progressIndicator = (fetcher == null) ? null |
67 |
|
: fetcher.getProgressIndicator(); |
68 |
|
} |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
70 |
0 |
@Override... |
71 |
|
public void searchAction(boolean isFreshSearch) |
72 |
|
{ |
73 |
0 |
searchAction(null, isFreshSearch); |
74 |
|
} |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 2 |
Complexity Density: 0.25 |
|
76 |
0 |
public void searchAction(String cursor, boolean isFreshSearch)... |
77 |
|
{ |
78 |
0 |
mainFrame.requestFocusInWindow(); |
79 |
0 |
if (isFreshSearch) |
80 |
|
{ |
81 |
0 |
offSet = 0; |
82 |
0 |
UniProtFTSRestClient c = UniProtFTSRestClient.getInstance(); |
83 |
0 |
c.clearCursors(); |
84 |
0 |
c.setCursorPage(0); |
85 |
0 |
c.setCursor(0, ""); |
86 |
|
} |
87 |
0 |
new Thread() |
88 |
|
{ |
|
|
| 0% |
Uncovered Elements: 47 (47) |
Complexity: 9 |
Complexity Density: 0.24 |
|
89 |
0 |
@Override... |
90 |
|
public void run() |
91 |
|
{ |
92 |
0 |
reset(); |
93 |
0 |
String searchInput = getTypedText(); |
94 |
0 |
if (searchInput.length() > 0) |
95 |
|
{ |
96 |
0 |
setSearchInProgress(true); |
97 |
0 |
long startTime = System.currentTimeMillis(); |
98 |
0 |
searchInput = getTypedText(); |
99 |
0 |
String searchTarget = ((FTSDataColumnI) cmb_searchTarget |
100 |
|
.getSelectedItem()).getAltCode(); |
101 |
0 |
wantedFields = UniProtFTSRestClient.getInstance() |
102 |
|
.getAllDefaultDisplayedFTSDataColumns(); |
103 |
0 |
String searchTerm = decodeSearchTerm(searchInput, searchTarget); |
104 |
|
|
105 |
0 |
FTSRestRequest request = new FTSRestRequest(); |
106 |
0 |
request.setFieldToSearchBy(searchTarget); |
107 |
0 |
request.setSearchTerm(searchTerm); |
108 |
0 |
request.setOffSet(offSet); |
109 |
0 |
request.setWantedFields(wantedFields); |
110 |
0 |
UniProtFTSRestClient uniProtRestClient = UniProtFTSRestClient |
111 |
|
.getInstance(); |
112 |
0 |
FTSRestResponse resultList; |
113 |
0 |
try |
114 |
|
{ |
115 |
0 |
resultList = uniProtRestClient.executeRequest(request, cursor); |
116 |
|
} catch (Exception e) |
117 |
|
{ |
118 |
0 |
setErrorMessage(e.getMessage()); |
119 |
0 |
checkForErrors(); |
120 |
0 |
setSearchInProgress(false); |
121 |
0 |
return; |
122 |
|
} |
123 |
|
|
124 |
0 |
if (resultList.getSearchSummary() != null |
125 |
|
&& resultList.getSearchSummary().size() > 0) |
126 |
|
{ |
127 |
0 |
getResultTable().setModel(FTSRestResponse.getTableModel(request, |
128 |
|
resultList.getSearchSummary())); |
129 |
0 |
FTSRestResponse.configureTableColumn(getResultTable(), |
130 |
|
wantedFields, tempUserPrefs); |
131 |
0 |
getResultTable().setVisible(true); |
132 |
|
} |
133 |
|
|
134 |
0 |
long endTime = System.currentTimeMillis(); |
135 |
0 |
totalResultSetCount = resultList.getNumberOfItemsFound(); |
136 |
0 |
resultSetCount = resultList.getSearchSummary() == null ? 0 |
137 |
|
: resultList.getSearchSummary().size(); |
138 |
0 |
String result = (resultSetCount > 0) |
139 |
|
? MessageManager.getString("label.results") |
140 |
|
: MessageManager.getString("label.result"); |
141 |
0 |
if (isPaginationEnabled() && resultSetCount > 0) |
142 |
|
{ |
143 |
0 |
updateSearchFrameTitle( |
144 |
|
defaultFTSFrameTitle + " - " + result + " " |
145 |
|
+ totalNumberformatter |
146 |
|
.format(Integer.valueOf(offSet + 1)) |
147 |
|
+ " to " |
148 |
|
+ totalNumberformatter.format(Integer |
149 |
|
.valueOf(offSet + resultSetCount)) |
150 |
|
+ " of " |
151 |
|
+ totalNumberformatter.format( |
152 |
|
Integer.valueOf(totalResultSetCount)) |
153 |
|
+ " " + " (" + (endTime - startTime) |
154 |
|
+ " milli secs)"); |
155 |
|
} |
156 |
|
else |
157 |
|
{ |
158 |
0 |
updateSearchFrameTitle(defaultFTSFrameTitle + " - " |
159 |
|
+ resultSetCount + " " + result + " (" |
160 |
|
+ (endTime - startTime) + " milli secs)"); |
161 |
|
} |
162 |
0 |
setSearchInProgress(false); |
163 |
0 |
refreshPaginatorState(); |
164 |
0 |
updateSummaryTableSelections(); |
165 |
|
} |
166 |
0 |
txt_search.updateCache(); |
167 |
|
} |
168 |
|
}.start(); |
169 |
|
|
170 |
|
} |
171 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 5 |
Complexity Density: 0.38 |
|
172 |
0 |
public String decodeSearchTerm(String enteredText, String targetField)... |
173 |
|
{ |
174 |
0 |
int searchTargetLength = targetField.equalsIgnoreCase("Search All") ? 0 |
175 |
|
: targetField.length() + 1; |
176 |
0 |
String searchTarget = targetField.equalsIgnoreCase("Search All") ? "" |
177 |
|
: targetField + ":"; |
178 |
0 |
String foundSearchTerms = enteredText; |
179 |
0 |
StringBuilder foundSearchTermsBuilder = new StringBuilder(); |
180 |
0 |
if (enteredText.contains(";")) |
181 |
|
{ |
182 |
0 |
String[] searchTerms = enteredText.split(";"); |
183 |
0 |
for (String searchTerm : searchTerms) |
184 |
|
{ |
185 |
0 |
foundSearchTermsBuilder.append(searchTarget).append(searchTerm) |
186 |
|
.append(" OR "); |
187 |
|
} |
188 |
0 |
int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR "); |
189 |
0 |
foundSearchTerms = foundSearchTermsBuilder.toString(); |
190 |
0 |
if (foundSearchTerms.contains(" OR ")) |
191 |
|
{ |
192 |
0 |
foundSearchTerms = foundSearchTerms.substring(searchTargetLength, |
193 |
|
endIndex); |
194 |
|
} |
195 |
|
} |
196 |
0 |
return foundSearchTerms; |
197 |
|
} |
198 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
199 |
0 |
@Override... |
200 |
|
public boolean isPaginationEnabled() |
201 |
|
{ |
202 |
0 |
return true; |
203 |
|
} |
204 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 2 |
Complexity Density: 0.11 |
|
205 |
0 |
@Override... |
206 |
|
public void okAction() |
207 |
|
{ |
208 |
0 |
disableActionButtons(); |
209 |
0 |
StringBuilder selectedIds = new StringBuilder(); |
210 |
0 |
HashSet<String> selectedIdsSet = new HashSet<>(); |
211 |
0 |
int primaryKeyColIndex = 0; |
212 |
0 |
try |
213 |
|
{ |
214 |
0 |
primaryKeyColIndex = getFTSRestClient() |
215 |
|
.getPrimaryKeyColumIndex(wantedFields, false); |
216 |
|
} catch (Exception e) |
217 |
|
{ |
218 |
0 |
e.printStackTrace(); |
219 |
|
} |
220 |
0 |
int[] selectedRows = getResultTable().getSelectedRows(); |
221 |
0 |
for (int summaryRow : selectedRows) |
222 |
|
{ |
223 |
0 |
String idStr = getResultTable() |
224 |
|
.getValueAt(summaryRow, primaryKeyColIndex).toString(); |
225 |
0 |
selectedIdsSet.add(idStr); |
226 |
|
} |
227 |
0 |
selectedIdsSet.addAll(paginatorCart); |
228 |
0 |
for (String selectedId : selectedIdsSet) |
229 |
|
{ |
230 |
0 |
selectedIds.append(selectedId).append(";"); |
231 |
|
} |
232 |
|
|
233 |
0 |
String ids = selectedIds.toString(); |
234 |
0 |
seqFetcher.setQuery(ids); |
235 |
0 |
Thread worker = new Thread(seqFetcher); |
236 |
0 |
worker.start(); |
237 |
0 |
delayAndEnableActionButtons(); |
238 |
|
} |
239 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
240 |
0 |
@Override... |
241 |
|
public FTSRestClientI getFTSRestClient() |
242 |
|
{ |
243 |
0 |
return UniProtFTSRestClient.getInstance(); |
244 |
|
} |
245 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
246 |
0 |
@Override... |
247 |
|
public String getFTSFrameTitle() |
248 |
|
{ |
249 |
0 |
return defaultFTSFrameTitle; |
250 |
|
} |
251 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
252 |
0 |
@Override... |
253 |
|
public Map<String, Integer> getTempUserPrefs() |
254 |
|
{ |
255 |
0 |
return tempUserPrefs; |
256 |
|
} |
257 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
258 |
0 |
@Override... |
259 |
|
public String getCacheKey() |
260 |
|
{ |
261 |
0 |
return UNIPROT_FTS_CACHE_KEY; |
262 |
|
} |
263 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
264 |
0 |
@Override... |
265 |
|
public String getAutosearchPreference() |
266 |
|
{ |
267 |
0 |
return UNIPROT_AUTOSEARCH; |
268 |
|
} |
269 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
270 |
0 |
@Override... |
271 |
|
protected void showHelp() |
272 |
|
{ |
273 |
0 |
try |
274 |
|
{ |
275 |
0 |
Help.showHelpWindow(HelpId.UniprotFts); |
276 |
|
} catch (HelpSetException e1) |
277 |
|
{ |
278 |
0 |
e1.printStackTrace(); |
279 |
|
} |
280 |
|
} |
281 |
|
|
282 |
|
|
283 |
|
|
284 |
|
|
285 |
|
|
286 |
|
|
287 |
|
|
288 |
|
|
289 |
|
|
290 |
|
|
291 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
292 |
0 |
@Override... |
293 |
|
public void refreshPaginatorState() |
294 |
|
{ |
295 |
0 |
UniProtFTSRestClient c = UniProtFTSRestClient.getInstance(); |
296 |
0 |
setNextPageButtonEnabled(c.getNextCursor() != null); |
297 |
0 |
setPrevPageButtonEnabled(c.getPrevCursor() != null); |
298 |
|
} |
299 |
|
|
|
|
| 0% |
Uncovered Elements: 14 (14) |
Complexity: 3 |
Complexity Density: 0.3 |
|
300 |
0 |
@Override... |
301 |
|
public void prevPageAction() |
302 |
|
{ |
303 |
0 |
updatePaginatorCart(); |
304 |
0 |
UniProtFTSRestClient c = UniProtFTSRestClient.getInstance(); |
305 |
0 |
String prevCursor = c.getPrevCursor(); |
306 |
0 |
if (prevCursor != null) |
307 |
|
{ |
308 |
0 |
if (offSet >= pageLimit) |
309 |
|
{ |
310 |
0 |
offSet -= pageLimit; |
311 |
|
} |
312 |
|
else |
313 |
|
{ |
314 |
|
|
315 |
|
|
316 |
0 |
Console.warn( |
317 |
|
"UniprotFTSPanel: prevCursor exists but offset < pageLimit. This probably shouldn't be happening."); |
318 |
|
} |
319 |
0 |
c.setPrevCursorPage(); |
320 |
0 |
searchAction(prevCursor, false); |
321 |
|
} |
322 |
|
else |
323 |
|
{ |
324 |
0 |
refreshPaginatorState(); |
325 |
|
} |
326 |
|
} |
327 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 2 |
Complexity Density: 0.29 |
|
328 |
0 |
@Override... |
329 |
|
public void nextPageAction() |
330 |
|
{ |
331 |
0 |
UniProtFTSRestClient c = UniProtFTSRestClient.getInstance(); |
332 |
0 |
String nextCursor = c.getNextCursor(); |
333 |
0 |
if (nextCursor != null) |
334 |
|
{ |
335 |
0 |
offSet += pageLimit; |
336 |
0 |
c.setNextCursorPage(); |
337 |
0 |
searchAction(nextCursor, false); |
338 |
|
} |
339 |
|
else |
340 |
|
{ |
341 |
0 |
refreshPaginatorState(); |
342 |
|
} |
343 |
|
} |
344 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
345 |
0 |
public String getDbName()... |
346 |
|
{ |
347 |
0 |
return "UniProt"; |
348 |
|
} |
349 |
|
} |