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