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();
56 public void searchAction(boolean isFreshSearch)
67 ftsFrameTitle = defaultFTSFrameTitle;
69 boolean allowEmptySequence = false;
70 if (getTypedText().length() > 0)
72 setSearchInProgress(true);
73 long startTime = System.currentTimeMillis();
75 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
76 .getSelectedItem()).getCode();
77 wantedFields = PDBFTSRestClient.getInstance()
78 .getAllDefaultDisplayedFTSDataColumns();
79 String searchTerm = decodeSearchTerm(txt_search.getText(),
82 FTSRestRequest request = new FTSRestRequest();
83 request.setAllowEmptySeq(allowEmptySequence);
84 request.setResponseSize(100);
85 request.setFieldToSearchBy("(" + searchTarget + ":");
86 request.setSearchTerm(searchTerm + ")");
87 request.setOffSet(offSet);
88 request.setWantedFields(wantedFields);
89 FTSRestClientI pdbRestCleint = PDBFTSRestClient.getInstance();
90 FTSRestResponse resultList;
93 resultList = pdbRestCleint.executeRequest(request);
96 setErrorMessage(e.getMessage());
101 if (resultList.getSearchSummary() != null
102 && resultList.getSearchSummary().size() > 0)
104 getResultTable().setModel(
105 FTSRestResponse.getTableModel(request,
106 resultList.getSearchSummary()));
107 FTSRestResponse.configureTableColumn(getResultTable(),
108 wantedFields, tempUserPrefs);
109 getResultTable().setVisible(true);
112 long endTime = System.currentTimeMillis();
113 totalResultSetCount = resultList.getNumberOfItemsFound();
114 resultSetCount = resultList.getSearchSummary() == null ? 0
115 : resultList.getSearchSummary().size();
116 String result = (resultSetCount > 0) ? MessageManager
117 .getString("label.results") : MessageManager
118 .getString("label.result");
120 if (isPaginationEnabled() && resultSetCount > 0)
122 updateSearchFrameTitle(defaultFTSFrameTitle
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();
150 public static String decodeSearchTerm(String enteredText,
153 String foundSearchTerms = enteredText;
154 StringBuilder foundSearchTermsBuilder = new StringBuilder();
155 if (enteredText.contains(";"))
157 String[] searchTerms = enteredText.split(";");
158 for (String searchTerm : searchTerms)
160 if (searchTerm.contains(":"))
162 foundSearchTermsBuilder.append(targetField).append(":")
163 .append(searchTerm.split(":")[0]).append(" OR ");
167 foundSearchTermsBuilder.append(targetField).append(":")
168 .append(searchTerm).append(" OR ");
171 int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR ");
172 foundSearchTerms = foundSearchTermsBuilder.toString();
173 if (foundSearchTerms.contains(" OR "))
175 foundSearchTerms = foundSearchTerms.substring(
176 targetField.length() + 1, endIndex);
179 else if (enteredText.contains(":"))
181 foundSearchTerms = foundSearchTerms.split(":")[0];
183 return foundSearchTerms;
187 public void okAction()
189 // mainFrame.dispose();
190 disableActionButtons();
191 StringBuilder selectedIds = new StringBuilder();
192 HashSet<String> selectedIdsSet = new HashSet<String>();
193 int primaryKeyColIndex = 0;
196 primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex(
197 wantedFields, false);
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,
207 primaryKeyColIndex).toString();
208 selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm));
211 for (String idStr : paginatorCart)
213 selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm));
216 for (String selectedId : selectedIdsSet)
218 selectedIds.append(selectedId).append(";");
221 String ids = selectedIds.toString();
222 // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids);
223 seqFetcher.getTextArea().setText(ids);
224 Thread worker = new Thread(seqFetcher);
226 delayAndEnableActionButtons();
229 public static String getPDBIdwithSpecifiedChain(String pdbId,
232 String pdbIdWithChainCode = "";
233 if (searchTerm.contains(";"))
235 String[] foundTerms = searchTerm.split(";");
236 for (String foundTerm : foundTerms)
238 if (foundTerm.contains(pdbId))
240 pdbIdWithChainCode = foundTerm;
244 else if (searchTerm.contains(pdbId))
246 pdbIdWithChainCode = searchTerm;
250 pdbIdWithChainCode = pdbId;
252 return pdbIdWithChainCode;
256 public FTSRestClientI getFTSRestClient()
258 return PDBFTSRestClient.getInstance();
262 public String getFTSFrameTitle()
264 return ftsFrameTitle;
268 public boolean isPaginationEnabled()
274 public Map<String, Integer> getTempUserPrefs()
276 return tempUserPrefs;