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 java.util.HashMap;
25 import java.util.HashSet;
28 import javax.help.HelpSetException;
30 import jalview.fts.api.FTSDataColumnI;
31 import jalview.fts.api.FTSRestClientI;
32 import jalview.fts.core.FTSRestRequest;
33 import jalview.fts.core.FTSRestResponse;
34 import jalview.fts.core.GFTSPanel;
35 import jalview.gui.Help;
36 import jalview.gui.Help.HelpId;
37 import jalview.gui.SequenceFetcher;
38 import jalview.util.MessageManager;
40 @SuppressWarnings("serial")
41 public class PDBFTSPanel extends GFTSPanel
43 private static String defaultFTSFrameTitle = MessageManager
44 .getString("label.pdb_sequence_fetcher");
46 private static Map<String, Integer> tempUserPrefs = new HashMap<>();
48 private static final String PDB_FTS_CACHE_KEY = "CACHE.PDB_FTS";
50 private static final String PDB_AUTOSEARCH = "FTS.PDB.AUTOSEARCH";
52 public PDBFTSPanel(SequenceFetcher fetcher)
55 pageLimit = PDBFTSRestClient.getInstance().getDefaultResponsePageSize();
56 this.seqFetcher = fetcher;
57 this.progressIndicator = (fetcher == null) ? null
58 : fetcher.getProgressIndicator();
62 public void searchAction(boolean isFreshSearch)
64 mainFrame.requestFocusInWindow();
75 boolean allowEmptySequence = false;
76 if (getTypedText().length() > 0)
78 setSearchInProgress(true);
79 long startTime = System.currentTimeMillis();
81 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
82 .getSelectedItem()).getCode();
83 wantedFields = PDBFTSRestClient.getInstance()
84 .getAllDefaultDisplayedFTSDataColumns();
85 String searchTerm = decodeSearchTerm(getTypedText(),
88 FTSRestRequest request = new FTSRestRequest();
89 request.setAllowEmptySeq(allowEmptySequence);
90 request.setResponseSize(100);
91 request.setFieldToSearchBy("(" + searchTarget + ":");
92 request.setSearchTerm(searchTerm + ")");
93 request.setOffSet(offSet);
94 request.setWantedFields(wantedFields);
95 FTSRestClientI pdbRestClient = PDBFTSRestClient.getInstance();
96 FTSRestResponse resultList;
99 resultList = pdbRestClient.executeRequest(request);
100 } catch (Exception e)
102 setErrorMessage(e.getMessage());
104 setSearchInProgress(false);
108 if (resultList.getSearchSummary() != null
109 && resultList.getSearchSummary().size() > 0)
111 getResultTable().setModel(FTSRestResponse.getTableModel(request,
112 resultList.getSearchSummary()));
113 FTSRestResponse.configureTableColumn(getResultTable(),
114 wantedFields, tempUserPrefs);
115 getResultTable().setVisible(true);
118 long endTime = System.currentTimeMillis();
119 totalResultSetCount = resultList.getNumberOfItemsFound();
120 resultSetCount = resultList.getSearchSummary() == null ? 0
121 : resultList.getSearchSummary().size();
122 String result = (resultSetCount > 0)
123 ? MessageManager.getString("label.results")
124 : MessageManager.getString("label.result");
126 if (isPaginationEnabled() && resultSetCount > 0)
128 String f1 = totalNumberformatter
129 .format(Integer.valueOf(offSet + 1));
130 String f2 = totalNumberformatter
131 .format(Integer.valueOf(offSet + resultSetCount));
132 String f3 = totalNumberformatter
133 .format(Integer.valueOf(totalResultSetCount));
134 updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result
135 + " " + f1 + " to " + f2 + " of " + f3 + " " + " ("
136 + (endTime - startTime) + " milli secs)");
140 updateSearchFrameTitle(defaultFTSFrameTitle + " - "
141 + resultSetCount + " " + result + " ("
142 + (endTime - startTime) + " milli secs)");
145 setSearchInProgress(false);
146 refreshPaginatorState();
147 updateSummaryTableSelections();
149 txt_search.updateCache();
154 public static String decodeSearchTerm(String enteredText,
157 String foundSearchTerms = enteredText;
158 StringBuilder foundSearchTermsBuilder = new StringBuilder();
159 if (enteredText.contains(";"))
161 String[] searchTerms = enteredText.split(";");
162 for (String searchTerm : searchTerms)
164 if (searchTerm.contains(":"))
166 foundSearchTermsBuilder.append(targetField).append(":")
167 .append(searchTerm.split(":")[0]).append(" OR ");
171 foundSearchTermsBuilder.append(targetField).append(":")
172 .append(searchTerm).append(" OR ");
175 int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR ");
176 foundSearchTerms = foundSearchTermsBuilder.toString();
177 if (foundSearchTerms.contains(" OR "))
179 foundSearchTerms = foundSearchTerms
180 .substring(targetField.length() + 1, endIndex);
183 else if (enteredText.contains(":"))
185 foundSearchTerms = foundSearchTerms.split(":")[0];
187 return foundSearchTerms;
191 public void okAction()
193 // mainFrame.dispose();
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 String searchTerm = getTypedText();
208 for (int summaryRow : selectedRows)
210 String idStr = getResultTable()
211 .getValueAt(summaryRow, primaryKeyColIndex).toString();
212 selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm));
215 for (String idStr : paginatorCart)
217 selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm));
220 for (String selectedId : selectedIdsSet)
222 selectedIds.append(selectedId).append(";");
225 String ids = selectedIds.toString();
226 seqFetcher.setQuery(ids);
227 Thread worker = new Thread(seqFetcher);
229 delayAndEnableActionButtons();
232 public static String getPDBIdwithSpecifiedChain(String pdbId,
235 String pdbIdWithChainCode = "";
236 if (searchTerm.contains(";"))
238 String[] foundTerms = searchTerm.split(";");
239 for (String foundTerm : foundTerms)
241 if (foundTerm.contains(pdbId))
243 pdbIdWithChainCode = foundTerm;
247 else if (searchTerm.contains(pdbId))
249 pdbIdWithChainCode = searchTerm;
253 pdbIdWithChainCode = pdbId;
255 return pdbIdWithChainCode;
259 public FTSRestClientI getFTSRestClient()
261 return PDBFTSRestClient.getInstance();
265 public String getFTSFrameTitle()
267 return defaultFTSFrameTitle;
271 public boolean isPaginationEnabled()
277 public Map<String, Integer> getTempUserPrefs()
279 return tempUserPrefs;
283 public String getCacheKey()
285 return PDB_FTS_CACHE_KEY;
289 public String getAutosearchPreference()
291 return PDB_AUTOSEARCH;
295 protected void showHelp()
299 Help.showHelpWindow(HelpId.PdbFts);
300 } catch (HelpSetException e1)
302 e1.printStackTrace();
306 public String getDbName()