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.HashSet;
34 @SuppressWarnings("serial")
35 public class PDBFTSPanel extends GFTSPanel
37 private static String defaultFTSFrameTitle = MessageManager
38 .getString("label.pdb_sequence_fetcher");
40 private String ftsFrameTitle = defaultFTSFrameTitle;
42 public PDBFTSPanel(SequenceFetcher seqFetcher)
44 this.seqFetcher = seqFetcher;
45 this.progressIdicator = (seqFetcher == null) ? null : seqFetcher
46 .getProgressIndicator();
51 public void searchAction()
58 ftsFrameTitle = defaultFTSFrameTitle;
60 boolean allowEmptySequence = false;
61 if (getTypedText().length() > 0)
63 setSearchInProgress(true);
64 long startTime = System.currentTimeMillis();
66 String searchTarget = ((FTSDataColumnI) cmb_searchTarget
67 .getSelectedItem()).getCode();
68 wantedFields = PDBFTSRestClient.getInstance()
69 .getAllDefaulDisplayedDataColumns();
70 String searchTerm = decodeSearchTerm(txt_search.getText(),
73 FTSRestRequest request = new FTSRestRequest();
74 request.setAllowEmptySeq(allowEmptySequence);
75 request.setResponseSize(100);
76 request.setFieldToSearchBy("(" + searchTarget + ":");
77 request.setSearchTerm(searchTerm + ")");
78 request.setWantedFields(wantedFields);
79 FTSRestClientI pdbRestCleint = PDBFTSRestClient.getInstance();
80 FTSRestResponse resultList;
83 resultList = pdbRestCleint.executeRequest(request);
86 setErrorMessage(e.getMessage());
91 if (resultList.getSearchSummary() != null
92 && resultList.getSearchSummary().size() > 0)
94 getResultTable().setModel(
95 FTSRestResponse.getTableModel(request,
96 resultList.getSearchSummary()));
97 FTSRestResponse.configureTableColumn(getResultTable(),
99 getResultTable().setVisible(true);
102 long endTime = System.currentTimeMillis();
103 int resultSetCount = resultList.getNumberOfItemsFound();
104 String result = (resultSetCount > 1) ? MessageManager
105 .getString("label.results") : MessageManager
106 .getString("label.result");
107 updateSearchFrameTitle(defaultFTSFrameTitle + " - "
108 + resultSetCount + " " + result + " ("
109 + (endTime - startTime) + " milli secs)");
110 setSearchInProgress(false);
116 public static String decodeSearchTerm(String enteredText,
119 String foundSearchTerms = enteredText;
120 StringBuilder foundSearchTermsBuilder = new StringBuilder();
121 if (enteredText.contains(";"))
123 String[] searchTerms = enteredText.split(";");
124 for (String searchTerm : searchTerms)
126 if (searchTerm.contains(":"))
128 foundSearchTermsBuilder.append(targetField).append(":")
129 .append(searchTerm.split(":")[0]).append(" OR ");
133 foundSearchTermsBuilder.append(targetField).append(":")
134 .append(searchTerm).append(" OR ");
137 int endIndex = foundSearchTermsBuilder.lastIndexOf(" OR ");
138 foundSearchTerms = foundSearchTermsBuilder.toString();
139 if (foundSearchTerms.contains(" OR "))
141 foundSearchTerms = foundSearchTerms.substring(
142 targetField.length() + 1, endIndex);
145 else if (enteredText.contains(":"))
147 foundSearchTerms = foundSearchTerms.split(":")[0];
149 return foundSearchTerms;
153 public void okAction()
155 // mainFrame.dispose();
156 disableActionButtons();
157 StringBuilder selectedIds = new StringBuilder();
158 HashSet<String> selectedIdsSet = new HashSet<String>();
159 int primaryKeyColIndex = 0;
162 primaryKeyColIndex = getFTSRestClient().getPrimaryKeyColumIndex(
165 } catch (Exception e)
167 // TODO Auto-generated catch block
170 int[] selectedRows = getResultTable().getSelectedRows();
171 for (int summaryRow : selectedRows)
173 String idStr = getResultTable().getValueAt(summaryRow,
176 String searchTerm = txt_search.getText();
177 selectedIdsSet.add(getPDBIdwithSpecifiedChain(idStr, searchTerm));
180 for (String selectedId : selectedIdsSet)
182 selectedIds.append(selectedId).append(";");
185 String ids = selectedIds.toString();
186 // System.out.println(">>>>>>>>>>>>>>>> selected Ids: " + ids);
187 seqFetcher.getTextArea().setText(ids);
188 Thread worker = new Thread(seqFetcher);
190 delayAndEnableActionButtons();
194 public static String getPDBIdwithSpecifiedChain(String pdbId,
197 String pdbIdWithChainCode = "";
198 if (searchTerm.contains(";"))
200 String[] foundTerms = searchTerm.split(";");
201 for (String foundTerm : foundTerms)
203 if (foundTerm.contains(pdbId))
205 pdbIdWithChainCode = foundTerm;
209 else if (searchTerm.contains(pdbId))
211 pdbIdWithChainCode = searchTerm;
215 pdbIdWithChainCode = pdbId;
217 return pdbIdWithChainCode;
223 public FTSRestClientI getFTSRestClient()
225 return PDBFTSRestClient.getInstance();
229 public String getFTSFrameTitle()
231 return ftsFrameTitle;
236 public void prevPageAction()
238 // TODO pagination not yet implemented for PDB FTS
243 public void nextPageAction()
245 // TODO pagination not yet implemented for PDB FTS
250 public boolean isPaginationEnabled()