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 jalview.fts.api.FTSDataColumnI; |
25 |
|
import jalview.fts.api.FTSRestClientI; |
26 |
|
import jalview.fts.core.FTSRestRequest; |
27 |
|
import jalview.fts.core.FTSRestResponse; |
28 |
|
import jalview.fts.core.GFTSPanel; |
29 |
|
import jalview.gui.Help; |
30 |
|
import jalview.gui.Help.HelpId; |
31 |
|
import jalview.gui.SequenceFetcher; |
32 |
|
import jalview.util.MessageManager; |
33 |
|
|
34 |
|
import java.util.HashMap; |
35 |
|
import java.util.HashSet; |
36 |
|
import java.util.Map; |
37 |
|
|
38 |
|
import javax.help.HelpSetException; |
39 |
|
|
40 |
|
@SuppressWarnings("serial") |
|
|
| 37.2% |
Uncovered Elements: 91 (145) |
Complexity: 32 |
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.format(Integer.valueOf(offSet + 1)); |
129 |
0 |
String f2 = totalNumberformatter |
130 |
|
.format(Integer.valueOf(offSet + resultSetCount)); |
131 |
0 |
String f3 = totalNumberformatter |
132 |
|
.format(Integer.valueOf(totalResultSetCount)); |
133 |
0 |
updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result |
134 |
|
+ " " + f1 + " to " + f2 + " of " + f3 + " " + " (" |
135 |
|
+ (endTime - startTime) + " milli secs)"); |
136 |
|
} |
137 |
|
else |
138 |
|
{ |
139 |
0 |
updateSearchFrameTitle(defaultFTSFrameTitle + " - " |
140 |
|
+ resultSetCount + " " + result + " (" |
141 |
|
+ (endTime - startTime) + " milli secs)"); |
142 |
|
} |
143 |
|
|
144 |
0 |
setSearchInProgress(false); |
145 |
0 |
refreshPaginatorState(); |
146 |
0 |
updateSummaryTableSelections(); |
147 |
|
} |
148 |
0 |
txt_search.updateCache(); |
149 |
|
} |
150 |
|
}.start(); |
151 |
|
} |
152 |
|
|
|
|
| 87% |
Uncovered Elements: 3 (23) |
Complexity: 5 |
Complexity Density: 0.33 |
|
153 |
2 |
public static String decodeSearchTerm(String enteredText,... |
154 |
|
String targetField) |
155 |
|
{ |
156 |
2 |
String foundSearchTerms = enteredText; |
157 |
2 |
StringBuilder foundSearchTermsBuilder = new StringBuilder(); |
158 |
2 |
if (enteredText.contains(";")) |
159 |
|
{ |
160 |
1 |
String[] searchTerms = enteredText.split(";"); |
161 |
1 |
for (String searchTerm : searchTerms) |
162 |
|
{ |
163 |
3 |
if (searchTerm.contains(":")) |
164 |
|
{ |
165 |
1 |
foundSearchTermsBuilder.append(targetField).append(":") |
166 |
|
.append(searchTerm.split(":")[0]).append(" OR "); |
167 |
|
} |
168 |
|
else |
169 |
|
{ |
170 |
2 |
foundSearchTermsBuilder.append(targetField).append(":") |
171 |
|
.append(searchTerm).append(" OR "); |
172 |
|
} |
173 |
|
} |
174 |
1 |
int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR "); |
175 |
1 |
foundSearchTerms = foundSearchTermsBuilder.toString(); |
176 |
1 |
if (foundSearchTerms.contains(" OR ")) |
177 |
|
{ |
178 |
1 |
foundSearchTerms = foundSearchTerms |
179 |
|
.substring(targetField.length() + 1, endIndex); |
180 |
|
} |
181 |
|
} |
182 |
1 |
else if (enteredText.contains(":")) |
183 |
|
{ |
184 |
0 |
foundSearchTerms = foundSearchTerms.split(":")[0]; |
185 |
|
} |
186 |
2 |
return foundSearchTerms; |
187 |
|
} |
188 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 2 |
Complexity Density: 0.1 |
|
189 |
0 |
@Override... |
190 |
|
public void okAction() |
191 |
|
{ |
192 |
|
|
193 |
0 |
disableActionButtons(); |
194 |
0 |
StringBuilder selectedIds = new StringBuilder(); |
195 |
0 |
HashSet<String> selectedIdsSet = new HashSet<>(); |
196 |
0 |
int primaryKeyColIndex = 0; |
197 |
0 |
try |
198 |
|
{ |
199 |
0 |
primaryKeyColIndex = getFTSRestClient() |
200 |
|
.getPrimaryKeyColumIndex(wantedFields, false); |
201 |
|
} catch (Exception e) |
202 |
|
{ |
203 |
0 |
e.printStackTrace(); |
204 |
|
} |
205 |
0 |
int[] selectedRows = getResultTable().getSelectedRows(); |
206 |
0 |
String searchTerm = getTypedText(); |
207 |
0 |
for (int summaryRow : selectedRows) |
208 |
|
{ |
209 |
0 |
String idStr = getResultTable() |
210 |
|
.getValueAt(summaryRow, primaryKeyColIndex).toString(); |
211 |
0 |
selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm)); |
212 |
|
} |
213 |
|
|
214 |
0 |
for (String idStr : paginatorCart) |
215 |
|
{ |
216 |
0 |
selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm)); |
217 |
|
} |
218 |
|
|
219 |
0 |
for (String selectedId : selectedIdsSet) |
220 |
|
{ |
221 |
0 |
selectedIds.append(selectedId).append(";"); |
222 |
|
} |
223 |
|
|
224 |
0 |
String ids = selectedIds.toString(); |
225 |
0 |
seqFetcher.setQuery(ids); |
226 |
0 |
Thread worker = new Thread(seqFetcher); |
227 |
0 |
worker.start(); |
228 |
0 |
delayAndEnableActionButtons(); |
229 |
|
} |
230 |
|
|
|
|
| 87.5% |
Uncovered Elements: 2 (16) |
Complexity: 4 |
Complexity Density: 0.4 |
|
231 |
3 |
public static String getPDBIdwithSpecifiedChain(String pdbId,... |
232 |
|
String searchTerm) |
233 |
|
{ |
234 |
3 |
String pdbIdWithChainCode = ""; |
235 |
3 |
if (searchTerm.contains(";")) |
236 |
|
{ |
237 |
2 |
String[] foundTerms = searchTerm.split(";"); |
238 |
2 |
for (String foundTerm : foundTerms) |
239 |
|
{ |
240 |
6 |
if (foundTerm.contains(pdbId)) |
241 |
|
{ |
242 |
2 |
pdbIdWithChainCode = foundTerm; |
243 |
|
} |
244 |
|
} |
245 |
|
} |
246 |
1 |
else if (searchTerm.contains(pdbId)) |
247 |
|
{ |
248 |
1 |
pdbIdWithChainCode = searchTerm; |
249 |
|
} |
250 |
|
else |
251 |
|
{ |
252 |
0 |
pdbIdWithChainCode = pdbId; |
253 |
|
} |
254 |
3 |
return pdbIdWithChainCode; |
255 |
|
} |
256 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
257 |
3 |
@Override... |
258 |
|
public FTSRestClientI getFTSRestClient() |
259 |
|
{ |
260 |
3 |
return PDBFTSRestClient.getInstance(); |
261 |
|
} |
262 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
263 |
2 |
@Override... |
264 |
|
public String getFTSFrameTitle() |
265 |
|
{ |
266 |
2 |
return defaultFTSFrameTitle; |
267 |
|
} |
268 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
269 |
1 |
@Override... |
270 |
|
public boolean isPaginationEnabled() |
271 |
|
{ |
272 |
1 |
return true; |
273 |
|
} |
274 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
275 |
4 |
@Override... |
276 |
|
public Map<String, Integer> getTempUserPrefs() |
277 |
|
{ |
278 |
4 |
return tempUserPrefs; |
279 |
|
} |
280 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
281 |
1 |
@Override... |
282 |
|
public String getCacheKey() |
283 |
|
{ |
284 |
1 |
return PDB_FTS_CACHE_KEY; |
285 |
|
} |
286 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
287 |
1 |
@Override... |
288 |
|
public String getAutosearchPreference() |
289 |
|
{ |
290 |
1 |
return PDB_AUTOSEARCH; |
291 |
|
} |
292 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
293 |
0 |
@Override... |
294 |
|
protected void showHelp() |
295 |
|
{ |
296 |
0 |
try |
297 |
|
{ |
298 |
0 |
Help.showHelpWindow(HelpId.PdbFts); |
299 |
|
} catch (HelpSetException e1) |
300 |
|
{ |
301 |
0 |
e1.printStackTrace(); |
302 |
|
} |
303 |
|
} |
304 |
|
} |