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 String ftsFrameTitle = defaultFTSFrameTitle;
44 private static Map<String, Integer> tempUserPrefs = new HashMap<String, Integer>();
46 public PDBFTSPanel(SequenceFetcher seqFetcher)
49 pageLimit = PDBFTSRestClient.getInstance().getDefaultResponsePageSize();
50 this.seqFetcher = seqFetcher;
51 this.progressIndicator = (seqFetcher == null) ? null : seqFetcher
52 .getProgressIndicator();
57 public void searchAction(boolean isFreshSearch)
68 ftsFrameTitle = defaultFTSFrameTitle;
70 boolean allowEmptySequence = false;
71 if (getTypedText().length() > 0)
73 setSearchInProgress(true);
74 long startTime = System.currentTimeMillis();
76 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
77 .getSelectedItem()).getCode();
78 wantedFields = PDBFTSRestClient.getInstance()
79 .getAllDefaultDisplayedFTSDataColumns();
80 String searchTerm = decodeSearchTerm(txt_search.getText(),
83 FTSRestRequest request = new FTSRestRequest();
84 request.setAllowEmptySeq(allowEmptySequence);
85 request.setResponseSize(100);
86 request.setFieldToSearchBy("(" + searchTarget + ":");
87 request.setSearchTerm(searchTerm + ")");
88 request.setOffSet(offSet);
89 request.setWantedFields(wantedFields);
90 FTSRestClientI pdbRestCleint = PDBFTSRestClient.getInstance();
91 FTSRestResponse resultList;
94 resultList = pdbRestCleint.executeRequest(request);
97 setErrorMessage(e.getMessage());
102 if (resultList.getSearchSummary() != null
103 && resultList.getSearchSummary().size() > 0)
105 getResultTable().setModel(
106 FTSRestResponse.getTableModel(request,
107 resultList.getSearchSummary()));
108 FTSRestResponse.configureTableColumn(getResultTable(),
109 wantedFields, tempUserPrefs);
110 getResultTable().setVisible(true);
113 long endTime = System.currentTimeMillis();
114 totalResultSetCount = resultList.getNumberOfItemsFound();
115 resultSetCount = resultList.getSearchSummary() == null ? 0
116 : resultList.getSearchSummary().size();
117 String result = (resultSetCount > 0) ? MessageManager
118 .getString("label.results") : MessageManager
119 .getString("label.result");
121 if (isPaginationEnabled() && resultSetCount > 0)
123 updateSearchFrameTitle(defaultFTSFrameTitle + " - " + result
125 + totalNumberformatter.format((Number) (offSet + 1))
127 + totalNumberformatter
128 .format((Number) (offSet + resultSetCount))
130 + totalNumberformatter
131 .format((Number) totalResultSetCount)
132 + " " + " (" + (endTime - startTime) + " milli secs)");
136 updateSearchFrameTitle(defaultFTSFrameTitle + " - "
137 + resultSetCount + " " + result + " ("
138 + (endTime - startTime) + " milli secs)");
141 setSearchInProgress(false);
142 refreshPaginatorState();
143 updateSummaryTableSelections();
149 public static String decodeSearchTerm(String enteredText,
152 String foundSearchTerms = enteredText;
153 StringBuilder foundSearchTermsBuilder = new StringBuilder();
154 if (enteredText.contains(";"))
156 String[] searchTerms = enteredText.split(";");
157 for (String searchTerm : searchTerms)
159 if (searchTerm.contains(":"))
161 foundSearchTermsBuilder.append(targetField).append(":")
162 .append(searchTerm.split(":")[0]).append(" OR ");
166 foundSearchTermsBuilder.append(targetField).append(":")
167 .append(searchTerm).append(" OR ");
170 int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR ");
171 foundSearchTerms = foundSearchTermsBuilder.toString();
172 if (foundSearchTerms.contains(" OR "))
174 foundSearchTerms = foundSearchTerms.substring(
175 targetField.length() + 1, endIndex);
178 else if (enteredText.contains(":"))
180 foundSearchTerms = foundSearchTerms.split(":")[0];
182 return foundSearchTerms;
186 public void okAction()
188 // mainFrame.dispose();
189 disableActionButtons();
190 StringBuilder selectedIds = new StringBuilder();
191 HashSet<String> selectedIdsSet = new HashSet<String>();
192 int primaryKeyColIndex = 0;
195 primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex(
198 } catch (Exception e)
202 int[] selectedRows = getResultTable().getSelectedRows();
203 String searchTerm = txt_search.getText();
204 for (int summaryRow : selectedRows)
206 String idStr = getResultTable().getValueAt(summaryRow,
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();
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 ftsFrameTitle;
270 public boolean isPaginationEnabled()
276 public Map<String, Integer> getTempUserPrefs()
278 return tempUserPrefs;