2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3
10 * of the License, or (at your option) any later version.
12 * Jalview is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19 * The Jalview Authors are detailed in the 'AUTHORS' file.
22 package jalview.fts.service.uniprot;
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;
32 import java.util.HashMap;
33 import java.util.HashSet;
36 @SuppressWarnings("serial")
37 public class UniprotFTSPanel extends GFTSPanel
40 private static String defaultFTSFrameTitle = MessageManager
41 .getString("label.uniprot_sequence_fetcher");
43 private static Map<String, Integer> tempUserPrefs = new HashMap<>();
45 private static final String UNIPROT_FTS_CACHE_KEY = "CACHE.UNIPROT_FTS";
47 private static final String UNIPROT_AUTOSEARCH = "FTS.UNIPROT.AUTOSEARCH";
50 * Constructor given an (optional) sequence fetcher panel to revert to on
51 * clicking the 'Back' button
55 public UniprotFTSPanel(SequenceFetcher fetcher)
58 pageLimit = UniProtFTSRestClient.getInstance()
59 .getDefaultResponsePageSize();
60 this.seqFetcher = fetcher;
61 this.progressIndicator = (fetcher == null) ? null
62 : fetcher.getProgressIndicator();
66 public void searchAction(boolean isFreshSearch)
68 mainFrame.requestFocusInWindow();
79 String searchInput = getTypedText();
80 if (searchInput.length() > 0)
82 setSearchInProgress(true);
83 long startTime = System.currentTimeMillis();
84 searchInput = getTypedText();
85 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
86 .getSelectedItem()).getAltCode();
87 wantedFields = UniProtFTSRestClient.getInstance()
88 .getAllDefaultDisplayedFTSDataColumns();
89 String searchTerm = decodeSearchTerm(searchInput, searchTarget);
91 FTSRestRequest request = new FTSRestRequest();
92 request.setFieldToSearchBy(searchTarget);
93 request.setSearchTerm(searchTerm);
94 request.setOffSet(offSet);
95 request.setWantedFields(wantedFields);
96 FTSRestClientI uniProtRestClient = UniProtFTSRestClient
98 FTSRestResponse resultList;
101 resultList = uniProtRestClient.executeRequest(request);
102 } catch (Exception e)
104 setErrorMessage(e.getMessage());
106 setSearchInProgress(false);
110 if (resultList.getSearchSummary() != null
111 && resultList.getSearchSummary().size() > 0)
113 getResultTable().setModel(FTSRestResponse.getTableModel(request,
114 resultList.getSearchSummary()));
115 FTSRestResponse.configureTableColumn(getResultTable(),
116 wantedFields, tempUserPrefs);
117 getResultTable().setVisible(true);
120 long endTime = System.currentTimeMillis();
121 totalResultSetCount = resultList.getNumberOfItemsFound();
122 resultSetCount = resultList.getSearchSummary() == null ? 0
123 : resultList.getSearchSummary().size();
124 String result = (resultSetCount > 0)
125 ? MessageManager.getString("label.results")
126 : MessageManager.getString("label.result");
127 if (isPaginationEnabled() && resultSetCount > 0)
129 updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result
131 + totalNumberformatter
132 .format(Integer.valueOf(offSet + 1))
134 + totalNumberformatter
136 .valueOf(offSet + resultSetCount))
138 + totalNumberformatter
139 .format(Integer.valueOf(totalResultSetCount))
140 + " " + " (" + (endTime - startTime) + " milli secs)");
144 updateSearchFrameTitle(defaultFTSFrameTitle + " - "
145 + resultSetCount + " " + result + " ("
146 + (endTime - startTime) + " milli secs)");
148 setSearchInProgress(false);
149 refreshPaginatorState();
150 updateSummaryTableSelections();
152 txt_search.updateCache();
158 public String decodeSearchTerm(String enteredText, String targetField)
160 int searchTargetLength = targetField.equalsIgnoreCase("Search All") ? 0
161 : targetField.length() + 1;
162 String searchTarget = targetField.equalsIgnoreCase("Search All") ? ""
164 String foundSearchTerms = enteredText;
165 StringBuilder foundSearchTermsBuilder = new StringBuilder();
166 if (enteredText.contains(";"))
168 String[] searchTerms = enteredText.split(";");
169 for (String searchTerm : searchTerms)
171 foundSearchTermsBuilder.append(searchTarget).append(searchTerm)
174 int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR ");
175 foundSearchTerms = foundSearchTermsBuilder.toString();
176 if (foundSearchTerms.contains(" OR "))
178 foundSearchTerms = foundSearchTerms.substring(searchTargetLength,
182 return foundSearchTerms;
186 public boolean isPaginationEnabled()
192 public void okAction()
194 disableActionButtons();
195 StringBuilder selectedIds = new StringBuilder();
196 HashSet<String> selectedIdsSet = new HashSet<>();
197 int primaryKeyColIndex = 0;
200 primaryKeyColIndex = getFTSRestClient()
201 .getPrimaryKeyColumIndex(wantedFields, false);
202 } catch (Exception e)
206 int[] selectedRows = getResultTable().getSelectedRows();
207 for (int summaryRow : selectedRows)
209 String idStr = getResultTable()
210 .getValueAt(summaryRow, primaryKeyColIndex).toString();
211 selectedIdsSet.add(idStr);
213 selectedIdsSet.addAll(paginatorCart);
214 for (String selectedId : selectedIdsSet)
216 selectedIds.append(selectedId).append(";");
219 String ids = selectedIds.toString();
220 seqFetcher.setQuery(ids);
221 Thread worker = new Thread(seqFetcher);
223 delayAndEnableActionButtons();
227 public FTSRestClientI getFTSRestClient()
229 return UniProtFTSRestClient.getInstance();
233 public String getFTSFrameTitle()
235 return defaultFTSFrameTitle;
239 public Map<String, Integer> getTempUserPrefs()
241 return tempUserPrefs;
245 public String getCacheKey()
247 return UNIPROT_FTS_CACHE_KEY;
251 public String getAutosearchPreference()
253 return UNIPROT_AUTOSEARCH;