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.pdb;
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 PDBFTSPanel extends GFTSPanel
39 private static String defaultFTSFrameTitle = MessageManager
40 .getString("label.pdb_sequence_fetcher");
42 private static Map<String, Integer> tempUserPrefs = new HashMap<String, Integer>();
44 private static final String PDB_FTS_CACHE_KEY = "CACHE.PDB_FTS";
46 private static final String PDB_AUTOSEARCH = "FTS.PDB.AUTOSEARCH";
48 public PDBFTSPanel(SequenceFetcher fetcher)
51 pageLimit = PDBFTSRestClient.getInstance().getDefaultResponsePageSize();
52 this.seqFetcher = fetcher;
53 this.progressIndicator = (fetcher == null) ? null
54 : fetcher.getProgressIndicator();
58 public void searchAction(boolean isFreshSearch)
60 mainFrame.requestFocusInWindow();
71 boolean allowEmptySequence = false;
72 if (getTypedText().length() > 0)
74 setSearchInProgress(true);
75 long startTime = System.currentTimeMillis();
77 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
78 .getSelectedItem()).getCode();
79 wantedFields = PDBFTSRestClient.getInstance()
80 .getAllDefaultDisplayedFTSDataColumns();
81 String searchTerm = decodeSearchTerm(getTypedText(),
84 FTSRestRequest request = new FTSRestRequest();
85 request.setAllowEmptySeq(allowEmptySequence);
86 request.setResponseSize(100);
87 request.setFieldToSearchBy("(" + searchTarget + ":");
88 request.setSearchTerm(searchTerm + ")");
89 request.setOffSet(offSet);
90 request.setWantedFields(wantedFields);
91 FTSRestClientI pdbRestClient = PDBFTSRestClient.getInstance();
92 FTSRestResponse resultList;
95 resultList = pdbRestClient.executeRequest(request);
98 setErrorMessage(e.getMessage());
100 setSearchInProgress(false);
104 if (resultList.getSearchSummary() != null
105 && resultList.getSearchSummary().size() > 0)
107 getResultTable().setModel(FTSRestResponse.getTableModel(request,
108 resultList.getSearchSummary()));
109 FTSRestResponse.configureTableColumn(getResultTable(),
110 wantedFields, tempUserPrefs);
111 getResultTable().setVisible(true);
114 long endTime = System.currentTimeMillis();
115 totalResultSetCount = resultList.getNumberOfItemsFound();
116 resultSetCount = resultList.getSearchSummary() == null ? 0
117 : resultList.getSearchSummary().size();
118 String result = (resultSetCount > 0)
119 ? MessageManager.getString("label.results")
120 : MessageManager.getString("label.result");
122 if (isPaginationEnabled() && resultSetCount > 0)
124 updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result
126 + totalNumberformatter.format((Number) (offSet + 1))
128 + totalNumberformatter
129 .format((Number) (offSet + resultSetCount))
131 + totalNumberformatter
132 .format((Number) totalResultSetCount)
133 + " " + " (" + (endTime - startTime) + " milli secs)");
137 updateSearchFrameTitle(defaultFTSFrameTitle + " - "
138 + resultSetCount + " " + result + " ("
139 + (endTime - startTime) + " milli secs)");
142 setSearchInProgress(false);
143 refreshPaginatorState();
144 updateSummaryTableSelections();
146 txt_search.updateCache();
151 public static String decodeSearchTerm(String enteredText,
154 String foundSearchTerms = enteredText;
155 StringBuilder foundSearchTermsBuilder = new StringBuilder();
156 if (enteredText.contains(";"))
158 String[] searchTerms = enteredText.split(";");
159 for (String searchTerm : searchTerms)
161 if (searchTerm.contains(":"))
163 foundSearchTermsBuilder.append(targetField).append(":")
164 .append(searchTerm.split(":")[0]).append(" OR ");
168 foundSearchTermsBuilder.append(targetField).append(":")
169 .append(searchTerm).append(" OR ");
172 int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR ");
173 foundSearchTerms = foundSearchTermsBuilder.toString();
174 if (foundSearchTerms.contains(" OR "))
176 foundSearchTerms = foundSearchTerms
177 .substring(targetField.length() + 1, endIndex);
180 else if (enteredText.contains(":"))
182 foundSearchTerms = foundSearchTerms.split(":")[0];
184 return foundSearchTerms;
188 public void okAction()
190 // mainFrame.dispose();
191 disableActionButtons();
192 StringBuilder selectedIds = new StringBuilder();
193 HashSet<String> selectedIdsSet = new HashSet<String>();
194 int primaryKeyColIndex = 0;
197 primaryKeyColIndex = getFTSRestClient()
198 .getPrimaryKeyColumIndex(wantedFields, false);
199 } catch (Exception e)
203 int[] selectedRows = getResultTable().getSelectedRows();
204 String searchTerm = getTypedText();
205 for (int summaryRow : selectedRows)
207 String idStr = getResultTable()
208 .getValueAt(summaryRow, primaryKeyColIndex).toString();
209 selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm));
212 for (String idStr : paginatorCart)
214 selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm));
217 for (String selectedId : selectedIdsSet)
219 selectedIds.append(selectedId).append(";");
222 String ids = selectedIds.toString();
223 // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids);
224 seqFetcher.getTextArea().setText(ids);
225 Thread worker = new Thread(seqFetcher);
227 delayAndEnableActionButtons();
230 public static String getPDBIdwithSpecifiedChain(String pdbId,
233 String pdbIdWithChainCode = "";
234 if (searchTerm.contains(";"))
236 String[] foundTerms = searchTerm.split(";");
237 for (String foundTerm : foundTerms)
239 if (foundTerm.contains(pdbId))
241 pdbIdWithChainCode = foundTerm;
245 else if (searchTerm.contains(pdbId))
247 pdbIdWithChainCode = searchTerm;
251 pdbIdWithChainCode = pdbId;
253 return pdbIdWithChainCode;
257 public FTSRestClientI getFTSRestClient()
259 return PDBFTSRestClient.getInstance();
263 public String getFTSFrameTitle()
265 return defaultFTSFrameTitle;
269 public boolean isPaginationEnabled()
275 public Map<String, Integer> getTempUserPrefs()
277 return tempUserPrefs;
281 public String getCacheKey()
283 return PDB_FTS_CACHE_KEY;
287 public String getAutosearchPreference()
289 return PDB_AUTOSEARCH;