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.pdb; |
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.fts.api.FTSDataColumnI; |
31 |
|
import jalview.fts.api.FTSRestClientI; |
32 |
|
import jalview.fts.core.FTSRestRequest; |
33 |
|
import jalview.fts.core.FTSRestResponse; |
34 |
|
import jalview.fts.core.GFTSPanel; |
35 |
|
import jalview.gui.Help; |
36 |
|
import jalview.gui.Help.HelpId; |
37 |
|
import jalview.gui.SequenceFetcher; |
38 |
|
import jalview.util.MessageManager; |
39 |
|
|
40 |
|
@SuppressWarnings("serial") |
|
|
| 38.1% |
Uncovered Elements: 91 (147) |
Complexity: 33 |
Complexity Density: 0.31 |
|
41 |
|
public class PDBFTSPanel extends GFTSPanel |
42 |
|
{ |
43 |
|
private static String defaultFTSFrameTitle = MessageManager |
44 |
|
.getString("label.pdb_sequence_fetcher"); |
45 |
|
|
46 |
|
private static Map<String, Integer> tempUserPrefs = new HashMap<>(); |
47 |
|
|
48 |
|
private static final String PDB_FTS_CACHE_KEY = "CACHE.PDB_FTS"; |
49 |
|
|
50 |
|
private static final String PDB_AUTOSEARCH = "FTS.PDB.AUTOSEARCH"; |
51 |
|
|
|
|
| 83.3% |
Uncovered Elements: 1 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
52 |
1 |
public PDBFTSPanel(SequenceFetcher fetcher)... |
53 |
|
{ |
54 |
1 |
super(fetcher); |
55 |
1 |
pageLimit = PDBFTSRestClient.getInstance().getDefaultResponsePageSize(); |
56 |
1 |
this.seqFetcher = fetcher; |
57 |
1 |
this.progressIndicator = (fetcher == null) ? null |
58 |
|
: fetcher.getProgressIndicator(); |
59 |
|
} |
60 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
61 |
0 |
@Override... |
62 |
|
public void searchAction(boolean isFreshSearch) |
63 |
|
{ |
64 |
0 |
mainFrame.requestFocusInWindow(); |
65 |
0 |
if (isFreshSearch) |
66 |
|
{ |
67 |
0 |
offSet = 0; |
68 |
|
} |
69 |
0 |
new Thread() |
70 |
|
{ |
|
|
| 0% |
Uncovered Elements: 51 (51) |
Complexity: 9 |
Complexity Density: 0.22 |
|
71 |
0 |
@Override... |
72 |
|
public void run() |
73 |
|
{ |
74 |
0 |
reset(); |
75 |
0 |
boolean allowEmptySequence = false; |
76 |
0 |
if (getTypedText().length() > 0) |
77 |
|
{ |
78 |
0 |
setSearchInProgress(true); |
79 |
0 |
long startTime = System.currentTimeMillis(); |
80 |
|
|
81 |
0 |
String searchTarget = ((FTSDataColumnI) cmb_searchTarget |
82 |
|
.getSelectedItem()).getCode(); |
83 |
0 |
wantedFields = PDBFTSRestClient.getInstance() |
84 |
|
.getAllDefaultDisplayedFTSDataColumns(); |
85 |
0 |
String searchTerm = decodeSearchTerm(getTypedText(), |
86 |
|
searchTarget); |
87 |
|
|
88 |
0 |
FTSRestRequest request = new FTSRestRequest(); |
89 |
0 |
request.setAllowEmptySeq(allowEmptySequence); |
90 |
0 |
request.setResponseSize(100); |
91 |
0 |
request.setFieldToSearchBy("(" + searchTarget + ":"); |
92 |
0 |
request.setSearchTerm(searchTerm + ")"); |
93 |
0 |
request.setOffSet(offSet); |
94 |
0 |
request.setWantedFields(wantedFields); |
95 |
0 |
FTSRestClientI pdbRestClient = PDBFTSRestClient.getInstance(); |
96 |
0 |
FTSRestResponse resultList; |
97 |
0 |
try |
98 |
|
{ |
99 |
0 |
resultList = pdbRestClient.executeRequest(request); |
100 |
|
} catch (Exception e) |
101 |
|
{ |
102 |
0 |
setErrorMessage(e.getMessage()); |
103 |
0 |
checkForErrors(); |
104 |
0 |
setSearchInProgress(false); |
105 |
0 |
return; |
106 |
|
} |
107 |
|
|
108 |
0 |
if (resultList.getSearchSummary() != null |
109 |
|
&& resultList.getSearchSummary().size() > 0) |
110 |
|
{ |
111 |
0 |
getResultTable().setModel(FTSRestResponse.getTableModel(request, |
112 |
|
resultList.getSearchSummary())); |
113 |
0 |
FTSRestResponse.configureTableColumn(getResultTable(), |
114 |
|
wantedFields, tempUserPrefs); |
115 |
0 |
getResultTable().setVisible(true); |
116 |
|
} |
117 |
|
|
118 |
0 |
long endTime = System.currentTimeMillis(); |
119 |
0 |
totalResultSetCount = resultList.getNumberOfItemsFound(); |
120 |
0 |
resultSetCount = resultList.getSearchSummary() == null ? 0 |
121 |
|
: resultList.getSearchSummary().size(); |
122 |
0 |
String result = (resultSetCount > 0) |
123 |
|
? MessageManager.getString("label.results") |
124 |
|
: MessageManager.getString("label.result"); |
125 |
|
|
126 |
0 |
if (isPaginationEnabled() && resultSetCount > 0) |
127 |
|
{ |
128 |
0 |
String f1 = totalNumberformatter |
129 |
|
.format(Integer.valueOf(offSet + 1)); |
130 |
0 |
String f2 = totalNumberformatter |
131 |
|
.format(Integer.valueOf(offSet + resultSetCount)); |
132 |
0 |
String f3 = totalNumberformatter |
133 |
|
.format(Integer.valueOf(totalResultSetCount)); |
134 |
0 |
updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result |
135 |
|
+ " " + f1 + " to " + f2 + " of " + f3 + " " + " (" |
136 |
|
+ (endTime - startTime) + " milli secs)"); |
137 |
|
} |
138 |
|
else |
139 |
|
{ |
140 |
0 |
updateSearchFrameTitle(defaultFTSFrameTitle + " - " |
141 |
|
+ resultSetCount + " " + result + " (" |
142 |
|
+ (endTime - startTime) + " milli secs)"); |
143 |
|
} |
144 |
|
|
145 |
0 |
setSearchInProgress(false); |
146 |
0 |
refreshPaginatorState(); |
147 |
0 |
updateSummaryTableSelections(); |
148 |
|
} |
149 |
0 |
txt_search.updateCache(); |
150 |
|
} |
151 |
|
}.start(); |
152 |
|
} |
153 |
|
|
|
|
| 87% |
Uncovered Elements: 3 (23) |
Complexity: 5 |
Complexity Density: 0.33 |
|
154 |
2 |
public static String decodeSearchTerm(String enteredText,... |
155 |
|
String targetField) |
156 |
|
{ |
157 |
2 |
String foundSearchTerms = enteredText; |
158 |
2 |
StringBuilder foundSearchTermsBuilder = new StringBuilder(); |
159 |
2 |
if (enteredText.contains(";")) |
160 |
|
{ |
161 |
1 |
String[] searchTerms = enteredText.split(";"); |
162 |
1 |
for (String searchTerm : searchTerms) |
163 |
|
{ |
164 |
3 |
if (searchTerm.contains(":")) |
165 |
|
{ |
166 |
1 |
foundSearchTermsBuilder.append(targetField).append(":") |
167 |
|
.append(searchTerm.split(":")[0]).append(" OR "); |
168 |
|
} |
169 |
|
else |
170 |
|
{ |
171 |
2 |
foundSearchTermsBuilder.append(targetField).append(":") |
172 |
|
.append(searchTerm).append(" OR "); |
173 |
|
} |
174 |
|
} |
175 |
1 |
int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR "); |
176 |
1 |
foundSearchTerms = foundSearchTermsBuilder.toString(); |
177 |
1 |
if (foundSearchTerms.contains(" OR ")) |
178 |
|
{ |
179 |
1 |
foundSearchTerms = foundSearchTerms |
180 |
|
.substring(targetField.length() + 1, endIndex); |
181 |
|
} |
182 |
|
} |
183 |
1 |
else if (enteredText.contains(":")) |
184 |
|
{ |
185 |
0 |
foundSearchTerms = foundSearchTerms.split(":")[0]; |
186 |
|
} |
187 |
2 |
return foundSearchTerms; |
188 |
|
} |
189 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 2 |
Complexity Density: 0.1 |
|
190 |
0 |
@Override... |
191 |
|
public void okAction() |
192 |
|
{ |
193 |
|
|
194 |
0 |
disableActionButtons(); |
195 |
0 |
StringBuilder selectedIds = new StringBuilder(); |
196 |
0 |
HashSet<String> selectedIdsSet = new HashSet<>(); |
197 |
0 |
int primaryKeyColIndex = 0; |
198 |
0 |
try |
199 |
|
{ |
200 |
0 |
primaryKeyColIndex = getFTSRestClient() |
201 |
|
.getPrimaryKeyColumIndex(wantedFields, false); |
202 |
|
} catch (Exception e) |
203 |
|
{ |
204 |
0 |
e.printStackTrace(); |
205 |
|
} |
206 |
0 |
int[] selectedRows = getResultTable().getSelectedRows(); |
207 |
0 |
String searchTerm = getTypedText(); |
208 |
0 |
for (int summaryRow : selectedRows) |
209 |
|
{ |
210 |
0 |
String idStr = getResultTable() |
211 |
|
.getValueAt(summaryRow, primaryKeyColIndex).toString(); |
212 |
0 |
selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm)); |
213 |
|
} |
214 |
|
|
215 |
0 |
for (String idStr : paginatorCart) |
216 |
|
{ |
217 |
0 |
selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm)); |
218 |
|
} |
219 |
|
|
220 |
0 |
for (String selectedId : selectedIdsSet) |
221 |
|
{ |
222 |
0 |
selectedIds.append(selectedId).append(";"); |
223 |
|
} |
224 |
|
|
225 |
0 |
String ids = selectedIds.toString(); |
226 |
0 |
seqFetcher.setQuery(ids); |
227 |
0 |
Thread worker = new Thread(seqFetcher); |
228 |
0 |
worker.start(); |
229 |
0 |
delayAndEnableActionButtons(); |
230 |
|
} |
231 |
|
|
|
|
| 87.5% |
Uncovered Elements: 2 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
232 |
3 |
public static String getPDBIdwithSpecifiedChain(String pdbId,... |
233 |
|
String searchTerm) |
234 |
|
{ |
235 |
3 |
String pdbIdWithChainCode = ""; |
236 |
3 |
if (searchTerm.contains(";")) |
237 |
|
{ |
238 |
2 |
String[] foundTerms = searchTerm.split(";"); |
239 |
2 |
for (String foundTerm : foundTerms) |
240 |
|
{ |
241 |
6 |
if (foundTerm.contains(pdbId)) |
242 |
|
{ |
243 |
2 |
pdbIdWithChainCode = foundTerm; |
244 |
|
} |
245 |
|
} |
246 |
|
} |
247 |
1 |
else if (searchTerm.contains(pdbId)) |
248 |
|
{ |
249 |
1 |
pdbIdWithChainCode = searchTerm; |
250 |
|
} |
251 |
|
else |
252 |
|
{ |
253 |
0 |
pdbIdWithChainCode = pdbId; |
254 |
|
} |
255 |
3 |
return pdbIdWithChainCode; |
256 |
|
} |
257 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
258 |
3 |
@Override... |
259 |
|
public FTSRestClientI getFTSRestClient() |
260 |
|
{ |
261 |
3 |
return PDBFTSRestClient.getInstance(); |
262 |
|
} |
263 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
264 |
2 |
@Override... |
265 |
|
public String getFTSFrameTitle() |
266 |
|
{ |
267 |
2 |
return defaultFTSFrameTitle; |
268 |
|
} |
269 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
270 |
1 |
@Override... |
271 |
|
public boolean isPaginationEnabled() |
272 |
|
{ |
273 |
1 |
return true; |
274 |
|
} |
275 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
276 |
8 |
@Override... |
277 |
|
public Map<String, Integer> getTempUserPrefs() |
278 |
|
{ |
279 |
8 |
return tempUserPrefs; |
280 |
|
} |
281 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
282 |
1 |
@Override... |
283 |
|
public String getCacheKey() |
284 |
|
{ |
285 |
1 |
return PDB_FTS_CACHE_KEY; |
286 |
|
} |
287 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
288 |
1 |
@Override... |
289 |
|
public String getAutosearchPreference() |
290 |
|
{ |
291 |
1 |
return PDB_AUTOSEARCH; |
292 |
|
} |
293 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
294 |
0 |
@Override... |
295 |
|
protected void showHelp() |
296 |
|
{ |
297 |
0 |
try |
298 |
|
{ |
299 |
0 |
Help.showHelpWindow(HelpId.PdbFts); |
300 |
|
} catch (HelpSetException e1) |
301 |
|
{ |
302 |
0 |
e1.printStackTrace(); |
303 |
|
} |
304 |
|
} |
305 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
306 |
1 |
public String getDbName()... |
307 |
|
{ |
308 |
1 |
return "PDB"; |
309 |
|
} |
310 |
|
} |