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.Help;
30 import jalview.gui.Help.HelpId;
31 import jalview.gui.SequenceFetcher;
32 import jalview.util.MessageManager;
34 import java.util.HashMap;
35 import java.util.HashSet;
38 import javax.help.HelpSetException;
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.format(Integer.valueOf(offSet + 1));
129 String f2 = totalNumberformatter
130 .format(Integer.valueOf(offSet + resultSetCount));
131 String f3 = totalNumberformatter
132 .format(Integer.valueOf(totalResultSetCount));
133 updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result
134 + " " + f1 + " to " + f2 + " of " + f3 + " " + " ("
135 + (endTime - startTime) + " milli secs)");
139 updateSearchFrameTitle(defaultFTSFrameTitle + " - "
140 + resultSetCount + " " + result + " ("
141 + (endTime - startTime) + " milli secs)");
144 setSearchInProgress(false);
145 refreshPaginatorState();
146 updateSummaryTableSelections();
148 txt_search.updateCache();
153 public static String decodeSearchTerm(String enteredText,
156 String foundSearchTerms = enteredText;
157 StringBuilder foundSearchTermsBuilder = new StringBuilder();
158 if (enteredText.contains(";"))
160 String[] searchTerms = enteredText.split(";");
161 for (String searchTerm : searchTerms)
163 if (searchTerm.contains(":"))
165 foundSearchTermsBuilder.append(targetField).append(":")
166 .append(searchTerm.split(":")[0]).append(" OR ");
170 foundSearchTermsBuilder.append(targetField).append(":")
171 .append(searchTerm).append(" OR ");
174 int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR ");
175 foundSearchTerms = foundSearchTermsBuilder.toString();
176 if (foundSearchTerms.contains(" OR "))
178 foundSearchTerms = foundSearchTerms
179 .substring(targetField.length() + 1, endIndex);
182 else if (enteredText.contains(":"))
184 foundSearchTerms = foundSearchTerms.split(":")[0];
186 return foundSearchTerms;
190 public void okAction()
192 // mainFrame.dispose();
193 disableActionButtons();
194 StringBuilder selectedIds = new StringBuilder();
195 HashSet<String> selectedIdsSet = new HashSet<>();
196 int primaryKeyColIndex = 0;
199 primaryKeyColIndex = getFTSRestClient()
200 .getPrimaryKeyColumIndex(wantedFields, false);
201 } catch (Exception e)
205 int[] selectedRows = getResultTable().getSelectedRows();
206 String searchTerm = getTypedText();
207 for (int summaryRow : selectedRows)
209 String idStr = getResultTable()
210 .getValueAt(summaryRow, primaryKeyColIndex).toString();
211 selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm));
214 for (String idStr : paginatorCart)
216 selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm));
219 for (String selectedId : selectedIdsSet)
221 selectedIds.append(selectedId).append(";");
224 String ids = selectedIds.toString();
225 seqFetcher.setQuery(ids);
226 Thread worker = new Thread(seqFetcher);
228 delayAndEnableActionButtons();
231 public static String getPDBIdwithSpecifiedChain(String pdbId,
234 String pdbIdWithChainCode = "";
235 if (searchTerm.contains(";"))
237 String[] foundTerms = searchTerm.split(";");
238 for (String foundTerm : foundTerms)
240 if (foundTerm.contains(pdbId))
242 pdbIdWithChainCode = foundTerm;
246 else if (searchTerm.contains(pdbId))
248 pdbIdWithChainCode = searchTerm;
252 pdbIdWithChainCode = pdbId;
254 return pdbIdWithChainCode;
258 public FTSRestClientI getFTSRestClient()
260 return PDBFTSRestClient.getInstance();
264 public String getFTSFrameTitle()
266 return defaultFTSFrameTitle;
270 public boolean isPaginationEnabled()
276 public Map<String, Integer> getTempUserPrefs()
278 return tempUserPrefs;
282 public String getCacheKey()
284 return PDB_FTS_CACHE_KEY;
288 public String getAutosearchPreference()
290 return PDB_AUTOSEARCH;
294 protected void showHelp()
298 Help.showHelpWindow(HelpId.PdbFts);
299 } catch (HelpSetException e1)
301 e1.printStackTrace();