2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
3 * Copyright (C) 2014 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.
24 import jalview.jbgui.GPDBSearchPanel;
25 import jalview.jbgui.PDBDocFieldPreferences;
26 import jalview.util.MessageManager;
27 import jalview.ws.dbsources.PDBRestClient;
28 import jalview.ws.dbsources.PDBRestClient.PDBDocField;
29 import jalview.ws.uimodel.PDBRestRequest;
30 import jalview.ws.uimodel.PDBRestResponse;
32 import java.util.ArrayList;
33 import java.util.Collection;
34 import java.util.Collections;
35 import java.util.Comparator;
36 import java.util.List;
38 @SuppressWarnings("serial")
39 public class PDBSearchPanel extends GPDBSearchPanel
41 private SequenceFetcher seqFetcher;
43 private IProgressIndicator progressIdicator;
45 private Collection<PDBDocField> wantedFields;
47 public PDBSearchPanel(SequenceFetcher seqFetcher)
49 this.seqFetcher = seqFetcher;
50 this.progressIdicator = (seqFetcher == null) ? null : seqFetcher
51 .getProgressIndicator();
56 * Action performed when an input is detected on txt_search field.
59 public void txt_search_ActionPerformed()
61 boolean allowEmptySequence = false;
62 mainFrame.setTitle(MessageManager
63 .getString("label.pdb_sequence_getcher"));
64 if (txt_search.getText().trim().length() > 0)
66 long startTime = System.currentTimeMillis();
68 String searchTarget = ((PDBDocField) cmb_searchTarget
69 .getSelectedItem()).getCode();
71 wantedFields = PDBDocFieldPreferences
72 .getSearchSummaryFields();
74 PDBRestRequest request = new PDBRestRequest();
75 request.setAllowEmptySeq(allowEmptySequence);
76 request.setResponseSize(100);
77 request.setFieldToSearchBy(searchTarget + ":");
78 request.setSearchTerm(txt_search.getText());
79 request.setWantedFields(wantedFields);
81 PDBRestClient pdbRestCleint = new PDBRestClient();
82 PDBRestResponse resultList = pdbRestCleint.executeRequest(request);
83 if (resultList.getSearchSummary() != null)
85 tbl_summary.setModel(PDBRestResponse.getTableModel(request,
86 resultList.getSearchSummary()));
89 long endTime = System.currentTimeMillis();
90 int resultSetCount = resultList.getNumberOfItemsFound();
91 String result = (resultSetCount > 1) ? MessageManager
92 .getString("label.results") : MessageManager
93 .getString("label.result");
94 mainFrame.setTitle(frameTitle + " - " + resultSetCount + " " + result
95 + " (" + (endTime - startTime) + " milli secs)");
100 public void btn_ok_ActionPerformed()
102 loadSelectedPDBSequencesToAlignment();
106 public void btn_back_ActionPerformed()
109 new SequenceFetcher(progressIdicator);
113 public void btn_cancel_ActionPerformed()
119 * Add the discovered/selected sequences to a target alignment window
121 public void loadSelectedPDBSequencesToAlignment()
124 StringBuilder selectedIds = new StringBuilder();
125 int pdbIdCol = PDBRestClient.getPDBIdColumIndex(wantedFields, false);
126 int[] selectedRows = tbl_summary.getSelectedRows();
127 for (int summaryRow : selectedRows)
129 String pdbIdStr = tbl_summary.getValueAt(summaryRow, pdbIdCol)
131 selectedIds.append(";").append(pdbIdStr);
134 String ids = selectedIds.deleteCharAt(0).toString();
135 seqFetcher.textArea.setText(ids);
136 Thread worker = new Thread(seqFetcher);
141 * Populates search target combo-box options
143 public void populateCmbSearchTargetOptions()
145 List<PDBDocField> searchableTargets = new ArrayList<PDBDocField>();
146 searchableTargets.add(PDBDocField.PDB_ID);
147 searchableTargets.add(PDBDocField.PFAM_ACCESSION);
148 searchableTargets.add(PDBDocField.MOLECULE_TYPE);
149 searchableTargets.add(PDBDocField.MOLECULE_NAME);
150 searchableTargets.add(PDBDocField.UNIPROT_ACCESSION);
151 searchableTargets.add(PDBDocField.GENE_NAME);
152 searchableTargets.add(PDBDocField.GENUS);
153 searchableTargets.add(PDBDocField.ALL);
155 Collections.sort(searchableTargets, new Comparator<PDBDocField>()
158 public int compare(PDBDocField o1, PDBDocField o2)
160 return o1.getName().compareTo(o2.getName());
164 for (PDBDocField searchTarget : searchableTargets)
166 cmb_searchTarget.addItem(searchTarget);