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 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") |
|
|
| 0% |
Uncovered Elements: 116 (116) |
Complexity: 26 |
Complexity Density: 0.31 |
|
37 |
|
public class UniprotFTSPanel extends GFTSPanel |
38 |
|
{ |
39 |
|
|
40 |
|
private static String defaultFTSFrameTitle = MessageManager |
41 |
|
.getString("label.uniprot_sequence_fetcher"); |
42 |
|
|
43 |
|
private static Map<String, Integer> tempUserPrefs = new HashMap<>(); |
44 |
|
|
45 |
|
private static final String UNIPROT_FTS_CACHE_KEY = "CACHE.UNIPROT_FTS"; |
46 |
|
|
47 |
|
private static final String UNIPROT_AUTOSEARCH = "FTS.UNIPROT.AUTOSEARCH"; |
48 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
49 |
0 |
public UniprotFTSPanel(SequenceFetcher fetcher)... |
50 |
|
{ |
51 |
0 |
super(fetcher); |
52 |
0 |
pageLimit = UniProtFTSRestClient.getInstance() |
53 |
|
.getDefaultResponsePageSize(); |
54 |
0 |
this.seqFetcher = fetcher; |
55 |
0 |
this.progressIndicator = (fetcher == null) ? null |
56 |
|
: fetcher.getProgressIndicator(); |
57 |
|
} |
58 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
59 |
0 |
@Override... |
60 |
|
public void searchAction(boolean isFreshSearch) |
61 |
|
{ |
62 |
0 |
mainFrame.requestFocusInWindow(); |
63 |
0 |
if (isFreshSearch) |
64 |
|
{ |
65 |
0 |
offSet = 0; |
66 |
|
} |
67 |
0 |
new Thread() |
68 |
|
{ |
|
|
| 0% |
Uncovered Elements: 47 (47) |
Complexity: 9 |
Complexity Density: 0.24 |
|
69 |
0 |
@Override... |
70 |
|
public void run() |
71 |
|
{ |
72 |
0 |
reset(); |
73 |
0 |
String searchInput = getTypedText(); |
74 |
0 |
if (searchInput.length() > 0) |
75 |
|
{ |
76 |
0 |
setSearchInProgress(true); |
77 |
0 |
long startTime = System.currentTimeMillis(); |
78 |
0 |
searchInput = getTypedText(); |
79 |
0 |
String searchTarget = ((FTSDataColumnI) cmb_searchTarget |
80 |
|
.getSelectedItem()).getAltCode(); |
81 |
0 |
wantedFields = UniProtFTSRestClient.getInstance() |
82 |
|
.getAllDefaultDisplayedFTSDataColumns(); |
83 |
0 |
String searchTerm = decodeSearchTerm(searchInput, searchTarget); |
84 |
|
|
85 |
0 |
FTSRestRequest request = new FTSRestRequest(); |
86 |
0 |
request.setFieldToSearchBy(searchTarget); |
87 |
0 |
request.setSearchTerm(searchTerm); |
88 |
0 |
request.setOffSet(offSet); |
89 |
0 |
request.setWantedFields(wantedFields); |
90 |
0 |
FTSRestClientI uniProtRestClient = UniProtFTSRestClient |
91 |
|
.getInstance(); |
92 |
0 |
FTSRestResponse resultList; |
93 |
0 |
try |
94 |
|
{ |
95 |
0 |
resultList = uniProtRestClient.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 |
0 |
if (isPaginationEnabled() && resultSetCount > 0) |
122 |
|
{ |
123 |
0 |
updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result |
124 |
|
+ " " |
125 |
|
+ totalNumberformatter.format((Number) (offSet + 1)) |
126 |
|
+ " to " |
127 |
|
+ totalNumberformatter |
128 |
|
.format((Number) (offSet + resultSetCount)) |
129 |
|
+ " of " |
130 |
|
+ totalNumberformatter |
131 |
|
.format((Number) totalResultSetCount) |
132 |
|
+ " " + " (" + (endTime - startTime) + " milli secs)"); |
133 |
|
} |
134 |
|
else |
135 |
|
{ |
136 |
0 |
updateSearchFrameTitle(defaultFTSFrameTitle + " - " |
137 |
|
+ resultSetCount + " " + result + " (" |
138 |
|
+ (endTime - startTime) + " milli secs)"); |
139 |
|
} |
140 |
0 |
setSearchInProgress(false); |
141 |
0 |
refreshPaginatorState(); |
142 |
0 |
updateSummaryTableSelections(); |
143 |
|
} |
144 |
0 |
txt_search.updateCache(); |
145 |
|
} |
146 |
|
}.start(); |
147 |
|
|
148 |
|
} |
149 |
|
|
|
|
| 0% |
Uncovered Elements: 21 (21) |
Complexity: 5 |
Complexity Density: 0.38 |
|
150 |
0 |
public String decodeSearchTerm(String enteredText, String targetField)... |
151 |
|
{ |
152 |
0 |
int searchTargetLength = targetField.equalsIgnoreCase("Search All") ? 0 |
153 |
|
: targetField.length() + 1; |
154 |
0 |
String searchTarget = targetField.equalsIgnoreCase("Search All") ? "" |
155 |
|
: targetField + ":"; |
156 |
0 |
String foundSearchTerms = enteredText; |
157 |
0 |
StringBuilder foundSearchTermsBuilder = new StringBuilder(); |
158 |
0 |
if (enteredText.contains(";")) |
159 |
|
{ |
160 |
0 |
String[] searchTerms = enteredText.split(";"); |
161 |
0 |
for (String searchTerm : searchTerms) |
162 |
|
{ |
163 |
0 |
foundSearchTermsBuilder.append(searchTarget).append(searchTerm) |
164 |
|
.append(" OR "); |
165 |
|
} |
166 |
0 |
int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR "); |
167 |
0 |
foundSearchTerms = foundSearchTermsBuilder.toString(); |
168 |
0 |
if (foundSearchTerms.contains(" OR ")) |
169 |
|
{ |
170 |
0 |
foundSearchTerms = foundSearchTerms.substring(searchTargetLength, |
171 |
|
endIndex); |
172 |
|
} |
173 |
|
} |
174 |
0 |
return foundSearchTerms; |
175 |
|
} |
176 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
177 |
0 |
@Override... |
178 |
|
public boolean isPaginationEnabled() |
179 |
|
{ |
180 |
0 |
return true; |
181 |
|
} |
182 |
|
|
|
|
| 0% |
Uncovered Elements: 19 (19) |
Complexity: 2 |
Complexity Density: 0.11 |
|
183 |
0 |
@Override... |
184 |
|
public void okAction() |
185 |
|
{ |
186 |
0 |
disableActionButtons(); |
187 |
0 |
StringBuilder selectedIds = new StringBuilder(); |
188 |
0 |
HashSet<String> selectedIdsSet = new HashSet<>(); |
189 |
0 |
int primaryKeyColIndex = 0; |
190 |
0 |
try |
191 |
|
{ |
192 |
0 |
primaryKeyColIndex = getFTSRestClient() |
193 |
|
.getPrimaryKeyColumIndex(wantedFields, false); |
194 |
|
} catch (Exception e) |
195 |
|
{ |
196 |
0 |
e.printStackTrace(); |
197 |
|
} |
198 |
0 |
int[] selectedRows = getResultTable().getSelectedRows(); |
199 |
0 |
for (int summaryRow : selectedRows) |
200 |
|
{ |
201 |
0 |
String idStr = getResultTable() |
202 |
|
.getValueAt(summaryRow, primaryKeyColIndex).toString(); |
203 |
0 |
selectedIdsSet.add(idStr); |
204 |
|
} |
205 |
0 |
selectedIdsSet.addAll(paginatorCart); |
206 |
0 |
for (String selectedId : selectedIdsSet) |
207 |
|
{ |
208 |
0 |
selectedIds.append(selectedId).append(";"); |
209 |
|
} |
210 |
|
|
211 |
0 |
String ids = selectedIds.toString(); |
212 |
|
|
213 |
0 |
seqFetcher.getTextArea().setText(ids); |
214 |
0 |
Thread worker = new Thread(seqFetcher); |
215 |
0 |
worker.start(); |
216 |
0 |
delayAndEnableActionButtons(); |
217 |
|
} |
218 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
219 |
0 |
@Override... |
220 |
|
public FTSRestClientI getFTSRestClient() |
221 |
|
{ |
222 |
0 |
return UniProtFTSRestClient.getInstance(); |
223 |
|
} |
224 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
225 |
0 |
@Override... |
226 |
|
public String getFTSFrameTitle() |
227 |
|
{ |
228 |
0 |
return defaultFTSFrameTitle; |
229 |
|
} |
230 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
231 |
0 |
@Override... |
232 |
|
public Map<String, Integer> getTempUserPrefs() |
233 |
|
{ |
234 |
0 |
return tempUserPrefs; |
235 |
|
} |
236 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
237 |
0 |
@Override... |
238 |
|
public String getCacheKey() |
239 |
|
{ |
240 |
0 |
return UNIPROT_FTS_CACHE_KEY; |
241 |
|
} |
242 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
243 |
0 |
@Override... |
244 |
|
public String getAutosearchPreference() |
245 |
|
{ |
246 |
0 |
return UNIPROT_AUTOSEARCH; |
247 |
|
} |
248 |
|
} |