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.
24 import jalview.bin.Jalview;
25 import jalview.datamodel.DBRefEntry;
26 import jalview.datamodel.DBRefSource;
27 import jalview.datamodel.PDBEntry;
28 import jalview.datamodel.SequenceI;
29 import jalview.jbgui.GStructureChooser;
30 import jalview.jbgui.PDBDocFieldPreferences;
31 import jalview.structure.StructureSelectionManager;
32 import jalview.util.MessageManager;
33 import jalview.ws.dbsources.PDBRestClient;
34 import jalview.ws.dbsources.PDBRestClient.PDBDocField;
35 import jalview.ws.sifts.SiftsSettings;
36 import jalview.ws.uimodel.PDBRestRequest;
37 import jalview.ws.uimodel.PDBRestResponse;
38 import jalview.ws.uimodel.PDBRestResponse.PDBResponseSummary;
40 import java.awt.event.ItemEvent;
41 import java.util.ArrayList;
42 import java.util.Collection;
43 import java.util.HashSet;
44 import java.util.LinkedHashSet;
45 import java.util.List;
47 import javax.swing.JCheckBox;
48 import javax.swing.JComboBox;
49 import javax.swing.JLabel;
50 import javax.swing.JOptionPane;
51 import javax.swing.table.AbstractTableModel;
54 * Provides the behaviors for the Structure chooser Panel
59 @SuppressWarnings("serial")
60 public class StructureChooser extends GStructureChooser implements
63 private boolean structuresDiscovered = false;
65 private SequenceI selectedSequence;
67 private SequenceI[] selectedSequences;
69 private IProgressIndicator progressIndicator;
71 private Collection<PDBResponseSummary> discoveredStructuresSet;
73 private PDBRestRequest lastPdbRequest;
75 private PDBRestClient pdbRestCleint;
77 private String selectedPdbFileName;
79 private boolean isValidPBDEntry;
81 public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
85 this.selectedSequence = selectedSeq;
86 this.selectedSequences = selectedSeqs;
87 this.progressIndicator = (ap == null) ? null : ap.alignFrame;
92 * Initializes parameters used by the Structure Chooser Panel
96 if (!Jalview.isHeadlessMode())
98 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
101 Thread discoverPDBStructuresThread = new Thread(new Runnable()
106 long startTime = System.currentTimeMillis();
107 updateProgressIndicator(MessageManager
108 .getString("status.loading_cached_pdb_entries"), startTime);
109 loadLocalCachedPDBEntries();
110 updateProgressIndicator(null, startTime);
111 updateProgressIndicator(MessageManager
112 .getString("status.searching_for_pdb_structures"),
114 fetchStructuresMetaData();
115 populateFilterComboBox();
116 updateProgressIndicator(null, startTime);
117 mainFrame.setVisible(true);
121 discoverPDBStructuresThread.start();
125 * Updates the progress indicator with the specified message
128 * displayed message for the operation
130 * unique handle for this indicator
132 public void updateProgressIndicator(String message, long id)
134 if (progressIndicator != null)
136 progressIndicator.setProgressBar(message, id);
141 * Retrieve meta-data for all the structure(s) for a given sequence(s) in a
144 public void fetchStructuresMetaData()
146 long startTime = System.currentTimeMillis();
147 Collection<PDBDocField> wantedFields = PDBDocFieldPreferences
148 .getStructureSummaryFields();
150 discoveredStructuresSet = new LinkedHashSet<PDBResponseSummary>();
151 HashSet<String> errors = new HashSet<String>();
152 for (SequenceI seq : selectedSequences)
154 PDBRestRequest pdbRequest = new PDBRestRequest();
155 pdbRequest.setAllowEmptySeq(false);
156 pdbRequest.setResponseSize(500);
157 pdbRequest.setFieldToSearchBy("(");
158 pdbRequest.setWantedFields(wantedFields);
159 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
160 pdbRequest.setAssociatedSequence(seq);
161 pdbRestCleint = new PDBRestClient();
162 PDBRestResponse resultList;
165 resultList = pdbRestCleint.executeRequest(pdbRequest);
166 } catch (Exception e)
169 errors.add(e.getMessage());
172 lastPdbRequest = pdbRequest;
173 if (resultList.getSearchSummary() != null
174 && !resultList.getSearchSummary().isEmpty())
176 discoveredStructuresSet.addAll(resultList.getSearchSummary());
180 int noOfStructuresFound = 0;
181 String totalTime = (System.currentTimeMillis() - startTime)
183 if (discoveredStructuresSet != null
184 && !discoveredStructuresSet.isEmpty())
186 tbl_summary.setModel(PDBRestResponse.getTableModel(lastPdbRequest,
187 discoveredStructuresSet));
188 structuresDiscovered = true;
189 noOfStructuresFound = discoveredStructuresSet.size();
190 mainFrame.setTitle(MessageManager.formatMessage(
191 "label.structure_chooser_no_of_structures",
192 noOfStructuresFound, totalTime));
196 mainFrame.setTitle(MessageManager
197 .getString("label.structure_chooser_manual_association"));
198 if (errors.size() > 0)
200 StringBuilder errorMsg = new StringBuilder();
201 for (String error : errors)
203 errorMsg.append(error).append("\n");
205 JOptionPane.showMessageDialog(this, errorMsg.toString(),
206 MessageManager.getString("label.pdb_web-service_error"),
207 JOptionPane.ERROR_MESSAGE);
212 public void loadLocalCachedPDBEntries()
214 ArrayList<CachedPDB> entries = new ArrayList<CachedPDB>();
215 for (SequenceI seq : selectedSequences)
217 if (seq.getDatasetSequence() != null
218 && seq.getDatasetSequence().getAllPDBEntries() != null)
220 for (PDBEntry pdbEntry : seq.getDatasetSequence()
223 if (pdbEntry.getFile() != null)
225 entries.add(new CachedPDB(seq, pdbEntry));
231 PDBEntryTableModel tableModelx = new PDBEntryTableModel(entries);
232 tbl_local_pdb.setModel(tableModelx);
236 * Builds a query string for a given sequences using its DBRef entries
239 * the sequences to build a query for
240 * @return the built query string
243 public static String buildQuery(SequenceI seq)
245 boolean isPDBRefsFound = false;
246 boolean isUniProtRefsFound = false;
247 StringBuilder queryBuilder = new StringBuilder();
248 HashSet<String> seqRefs = new LinkedHashSet<String>();
250 if (seq.getAllPDBEntries() != null)
252 for (PDBEntry entry : seq.getAllPDBEntries())
254 if (isValidSeqName(entry.getId()))
256 queryBuilder.append(PDBRestClient.PDBDocField.PDB_ID.getCode())
258 .append(entry.getId().toLowerCase())
260 isPDBRefsFound = true;
261 // seqRefs.add(entry.getId());
266 if (seq.getDBRefs() != null && seq.getDBRefs().length != 0)
268 for (DBRefEntry dbRef : seq.getDBRefs())
270 if (isValidSeqName(getDBRefId(dbRef)))
272 if (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT))
275 .append(PDBRestClient.PDBDocField.UNIPROT_ACCESSION
276 .getCode()).append(":")
277 .append(getDBRefId(dbRef))
280 .append(PDBRestClient.PDBDocField.UNIPROT_ID.getCode())
282 .append(getDBRefId(dbRef)).append(" OR ");
283 isUniProtRefsFound = true;
285 else if (dbRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
288 queryBuilder.append(PDBRestClient.PDBDocField.PDB_ID.getCode())
289 .append(":").append(getDBRefId(dbRef).toLowerCase())
291 isPDBRefsFound = true;
295 seqRefs.add(getDBRefId(dbRef));
301 if (!isPDBRefsFound && !isUniProtRefsFound)
303 String seqName = seq.getName();
304 String[] names = seqName.toLowerCase().split("\\|");
305 for (String name : names)
307 // System.out.println("Found name : " + name);
309 if (isValidSeqName(name))
315 for (String seqRef : seqRefs)
317 queryBuilder.append("text:").append(seqRef).append(" OR ");
321 int endIndex = queryBuilder.lastIndexOf(" OR ");
322 if (queryBuilder.toString().length() < 6)
326 String query = queryBuilder.toString().substring(0, endIndex);
331 * Ensures sequence ref names are not less than 3 characters and does not
332 * contain a database name
337 public static boolean isValidSeqName(String seqName)
339 // System.out.println("seqName : " + seqName);
340 String ignoreList = "pdb,uniprot,swiss-prot";
341 if (seqName.length() < 3)
345 if (seqName.contains(":"))
349 seqName = seqName.toLowerCase();
350 for (String ignoredEntry : ignoreList.split(","))
352 if (seqName.contains(ignoredEntry))
360 public static String getDBRefId(DBRefEntry dbRef)
362 String ref = dbRef.getAccessionId().replaceAll("GO:", "");
367 * Filters a given list of discovered structures based on supplied argument
369 * @param fieldToFilterBy
370 * the field to filter by
372 public void filterResultSet(final String fieldToFilterBy)
374 Thread filterThread = new Thread(new Runnable()
379 long startTime = System.currentTimeMillis();
380 lbl_loading.setVisible(true);
381 Collection<PDBDocField> wantedFields = PDBDocFieldPreferences
382 .getStructureSummaryFields();
383 Collection<PDBResponseSummary> filteredResponse = new HashSet<PDBResponseSummary>();
384 HashSet<String> errors = new HashSet<String>();
385 for (SequenceI seq : selectedSequences)
387 PDBRestRequest pdbRequest = new PDBRestRequest();
388 pdbRequest.setAllowEmptySeq(false);
389 pdbRequest.setResponseSize(1);
390 pdbRequest.setFieldToSearchBy("(");
391 pdbRequest.setFieldToSortBy(fieldToFilterBy,
392 !chk_invertFilter.isSelected());
393 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
394 pdbRequest.setWantedFields(wantedFields);
395 pdbRequest.setAssociatedSequence(seq);
396 pdbRestCleint = new PDBRestClient();
397 PDBRestResponse resultList;
400 resultList = pdbRestCleint.executeRequest(pdbRequest);
401 } catch (Exception e)
404 errors.add(e.getMessage());
407 lastPdbRequest = pdbRequest;
408 if (resultList.getSearchSummary() != null
409 && !resultList.getSearchSummary().isEmpty())
411 filteredResponse.addAll(resultList.getSearchSummary());
415 String totalTime = (System.currentTimeMillis() - startTime)
417 if (!filteredResponse.isEmpty())
419 final int filterResponseCount = filteredResponse.size();
420 Collection<PDBResponseSummary> reorderedStructuresSet = new LinkedHashSet<PDBResponseSummary>();
421 reorderedStructuresSet.addAll(filteredResponse);
422 reorderedStructuresSet.addAll(discoveredStructuresSet);
423 tbl_summary.setModel(PDBRestResponse.getTableModel(
424 lastPdbRequest, reorderedStructuresSet));
426 // Update table selection model here
427 tbl_summary.addRowSelectionInterval(0, filterResponseCount - 1);
428 mainFrame.setTitle(MessageManager.formatMessage(
429 "label.structure_chooser_filter_time", totalTime));
433 mainFrame.setTitle(MessageManager.formatMessage(
434 "label.structure_chooser_filter_time", totalTime));
435 if (errors.size() > 0)
437 StringBuilder errorMsg = new StringBuilder();
438 for (String error : errors)
440 errorMsg.append(error).append("\n");
442 JOptionPane.showMessageDialog(
445 MessageManager.getString("label.pdb_web-service_error"),
446 JOptionPane.ERROR_MESSAGE);
450 lbl_loading.setVisible(false);
452 validateSelections();
455 filterThread.start();
459 * Handles action event for btn_pdbFromFile
462 public void pdbFromFile_actionPerformed()
464 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
465 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
466 chooser.setFileView(new jalview.io.JalviewFileView());
467 chooser.setDialogTitle(MessageManager.formatMessage(
468 "label.select_pdb_file_for",
469 selectedSequence.getDisplayId(false)));
470 chooser.setToolTipText(MessageManager.formatMessage(
471 "label.load_pdb_file_associate_with_sequence",
472 selectedSequence.getDisplayId(false)));
474 int value = chooser.showOpenDialog(null);
475 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
477 selectedPdbFileName = chooser.getSelectedFile().getPath();
478 jalview.bin.Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName);
479 validateSelections();
484 * Populates the filter combo-box options dynamically depending on discovered
488 protected void populateFilterComboBox()
490 if (isStructuresDiscovered())
492 cmb_filterOption.addItem(new FilterOption("Best Quality",
493 PDBDocField.OVERALL_QUALITY.getCode(), VIEWS_FILTER));
494 cmb_filterOption.addItem(new FilterOption("Best UniProt Coverage",
495 PDBDocField.UNIPROT_COVERAGE.getCode(), VIEWS_FILTER));
496 cmb_filterOption.addItem(new FilterOption("Highest Resolution",
497 PDBDocField.RESOLUTION.getCode(), VIEWS_FILTER));
498 cmb_filterOption.addItem(new FilterOption("Highest Protein Chain",
499 PDBDocField.PROTEIN_CHAIN_COUNT.getCode(), VIEWS_FILTER));
500 cmb_filterOption.addItem(new FilterOption("Highest Bound Molecules",
501 PDBDocField.BOUND_MOLECULE_COUNT.getCode(), VIEWS_FILTER));
502 cmb_filterOption.addItem(new FilterOption("Highest Polymer Residues",
503 PDBDocField.POLYMER_RESIDUE_COUNT.getCode(), VIEWS_FILTER));
505 cmb_filterOption.addItem(new FilterOption("Enter PDB Id", "-",
507 cmb_filterOption.addItem(new FilterOption("From File", "-",
509 cmb_filterOption.addItem(new FilterOption("Cached PDB Entries", "-",
514 * Updates the displayed view based on the selected filter option
517 protected void updateCurrentView()
519 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
521 layout_switchableViews.show(pnl_switchableViews,
522 selectedFilterOpt.getView());
523 String filterTitle = mainFrame.getTitle();
524 mainFrame.setTitle(frameTitle);
525 chk_invertFilter.setVisible(false);
526 if (selectedFilterOpt.getView() == VIEWS_FILTER)
528 mainFrame.setTitle(filterTitle);
529 chk_invertFilter.setVisible(true);
530 filterResultSet(selectedFilterOpt.getValue());
532 else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
533 || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
535 mainFrame.setTitle(MessageManager
536 .getString("label.structure_chooser_manual_association"));
537 idInputAssSeqPanel.loadCmbAssSeq();
538 fileChooserAssSeqPanel.loadCmbAssSeq();
540 validateSelections();
544 * Validates user selection and activates the view button if all parameters
548 public void validateSelections()
550 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
552 btn_view.setEnabled(false);
553 String currentView = selectedFilterOpt.getView();
554 if (currentView == VIEWS_FILTER)
556 if (tbl_summary.getSelectedRows().length > 0)
558 btn_view.setEnabled(true);
561 else if (currentView == VIEWS_LOCAL_PDB)
563 if (tbl_local_pdb.getSelectedRows().length > 0)
565 btn_view.setEnabled(true);
568 else if (currentView == VIEWS_ENTER_ID)
570 validateAssociationEnterPdb();
572 else if (currentView == VIEWS_FROM_FILE)
574 validateAssociationFromFile();
579 * Validates inputs from the Manual PDB entry panel
581 public void validateAssociationEnterPdb()
583 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel
584 .getCmb_assSeq().getSelectedItem();
585 lbl_pdbManualFetchStatus.setIcon(errorImage);
586 lbl_pdbManualFetchStatus.setToolTipText("");
587 if (txt_search.getText().length() > 0)
589 lbl_pdbManualFetchStatus
590 .setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
591 .formatMessage("info.no_pdb_entry_found_for",
592 txt_search.getText())));
595 if (errorWarning.length() > 0)
597 lbl_pdbManualFetchStatus.setIcon(warningImage);
598 lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip(
599 true, errorWarning.toString()));
602 if (selectedSequences.length == 1
603 || !assSeqOpt.getName().equalsIgnoreCase(
604 "-Select Associated Seq-"))
606 txt_search.setEnabled(true);
609 btn_view.setEnabled(true);
610 lbl_pdbManualFetchStatus.setToolTipText("");
611 lbl_pdbManualFetchStatus.setIcon(goodImage);
616 txt_search.setEnabled(false);
617 lbl_pdbManualFetchStatus.setIcon(errorImage);
622 * Validates inputs for the manual PDB file selection options
624 public void validateAssociationFromFile()
626 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
627 .getCmb_assSeq().getSelectedItem();
628 lbl_fromFileStatus.setIcon(errorImage);
629 if (selectedSequences.length == 1
630 || (assSeqOpt != null && !assSeqOpt.getName().equalsIgnoreCase(
631 "-Select Associated Seq-")))
633 btn_pdbFromFile.setEnabled(true);
634 if (selectedPdbFileName != null && selectedPdbFileName.length() > 0)
636 btn_view.setEnabled(true);
637 lbl_fromFileStatus.setIcon(goodImage);
642 btn_pdbFromFile.setEnabled(false);
643 lbl_fromFileStatus.setIcon(errorImage);
648 public void cmbAssSeqStateChanged()
650 validateSelections();
654 * Handles the state change event for the 'filter' combo-box and 'invert'
658 protected void stateChanged(ItemEvent e)
660 if (e.getSource() instanceof JCheckBox)
666 if (e.getStateChange() == ItemEvent.SELECTED)
675 * Handles action event for btn_ok
678 public void ok_ActionPerformed()
680 final long progressSessionId = System.currentTimeMillis();
681 final StructureSelectionManager ssm = ap.getStructureSelectionManager();
682 ssm.setProgressIndicator(this);
683 ssm.setProgressSessionId(progressSessionId);
684 new Thread(new Runnable()
689 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
691 String currentView = selectedFilterOpt.getView();
692 if (currentView == VIEWS_FILTER)
694 int pdbIdColIndex = tbl_summary.getColumn(
695 PDBRestClient.PDBDocField.PDB_ID.getName()).getModelIndex();
696 int refSeqColIndex = tbl_summary.getColumn("Ref Sequence")
698 int[] selectedRows = tbl_summary.getSelectedRows();
699 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
701 ArrayList<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
702 for (int row : selectedRows)
704 String pdbIdStr = tbl_summary.getValueAt(row, pdbIdColIndex)
706 SequenceI selectedSeq = (SequenceI) tbl_summary.getValueAt(row,
708 selectedSeqsToView.add(selectedSeq);
709 PDBEntry pdbEntry = selectedSeq.getPDBEntry(pdbIdStr);
710 if (pdbEntry == null)
712 pdbEntry = new PDBEntry();
713 pdbEntry.setId(pdbIdStr);
714 pdbEntry.setType(PDBEntry.Type.PDB);
715 selectedSeq.getDatasetSequence().addPDBId(pdbEntry);
717 pdbEntriesToView[count++] = pdbEntry;
719 SequenceI[] selectedSeqs = selectedSeqsToView
720 .toArray(new SequenceI[selectedSeqsToView.size()]);
721 launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
723 else if (currentView == VIEWS_LOCAL_PDB)
725 int[] selectedRows = tbl_local_pdb.getSelectedRows();
726 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
728 int pdbIdColIndex = tbl_local_pdb.getColumn(
729 PDBRestClient.PDBDocField.PDB_ID.getName()).getModelIndex();
730 int refSeqColIndex = tbl_local_pdb.getColumn("Ref Sequence")
732 ArrayList<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
733 for (int row : selectedRows)
735 PDBEntry pdbEntry = (PDBEntry) tbl_local_pdb.getValueAt(row,
737 pdbEntriesToView[count++] = pdbEntry;
738 SequenceI selectedSeq = (SequenceI) tbl_local_pdb.getValueAt(row,
740 selectedSeqsToView.add(selectedSeq);
742 SequenceI[] selectedSeqs = selectedSeqsToView
743 .toArray(new SequenceI[selectedSeqsToView.size()]);
744 launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
746 else if (currentView == VIEWS_ENTER_ID)
748 SequenceI userSelectedSeq = ((AssociateSeqOptions) idInputAssSeqPanel
749 .getCmb_assSeq().getSelectedItem()).getSequence();
750 if (userSelectedSeq != null)
752 selectedSequence = userSelectedSeq;
755 String pdbIdStr = txt_search.getText();
756 PDBEntry pdbEntry = selectedSequence.getPDBEntry(pdbIdStr);
757 if (pdbEntry == null)
759 pdbEntry = new PDBEntry();
760 pdbEntry.setId(pdbIdStr);
761 pdbEntry.setType(PDBEntry.Type.PDB);
762 selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
765 PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
766 launchStructureViewer(ssm, pdbEntriesToView, ap,
767 new SequenceI[] { selectedSequence });
769 else if (currentView == VIEWS_FROM_FILE)
771 SequenceI userSelectedSeq = ((AssociateSeqOptions) fileChooserAssSeqPanel
772 .getCmb_assSeq().getSelectedItem()).getSequence();
773 if (userSelectedSeq != null)
775 selectedSequence = userSelectedSeq;
777 PDBEntry fileEntry = new AssociatePdbFileWithSeq()
778 .associatePdbWithSeq(selectedPdbFileName,
779 jalview.io.AppletFormatAdapter.FILE,
780 selectedSequence, true, Desktop.instance);
782 launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
783 new SequenceI[] { selectedSequence });
790 private void launchStructureViewer(StructureSelectionManager ssm,
791 final PDBEntry[] pdbEntriesToView,
792 final AlignmentPanel alignPanel, SequenceI[] sequences)
794 ssm.setProgressBar("Launching PDB structure viewer..");
795 final StructureViewer sViewer = new StructureViewer(ssm);
797 if (SiftsSettings.isMapWithSifts())
799 for (SequenceI seq : sequences)
801 if (seq.getSourceDBRef() == null)
803 ssm.setProgressBar(null);
804 ssm.setProgressBar("Fetching Database refs..");
805 new jalview.ws.DBRefFetcher(sequences, null, null, null, false)
811 if (pdbEntriesToView.length > 1)
813 ArrayList<SequenceI[]> seqsMap = new ArrayList<SequenceI[]>();
814 for (SequenceI seq : sequences)
816 seqsMap.add(new SequenceI[] { seq });
818 SequenceI[][] collatedSeqs = seqsMap.toArray(new SequenceI[0][0]);
819 ssm.setProgressBar(null);
820 ssm.setProgressBar("Fetching PDB Structures for selected entries..");
821 sViewer.viewStructures(pdbEntriesToView, collatedSeqs, alignPanel);
825 ssm.setProgressBar(null);
826 ssm.setProgressBar("Fetching PDB Structure for "
827 + pdbEntriesToView[0].getId());
828 sViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
833 * Populates the combo-box used in associating manually fetched structures to
834 * a unique sequence when more than one sequence selection is made.
837 public void populateCmbAssociateSeqOptions(
838 JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq)
840 cmb_assSeq.removeAllItems();
841 cmb_assSeq.addItem(new AssociateSeqOptions("-Select Associated Seq-",
843 lbl_associateSeq.setVisible(false);
844 if (selectedSequences.length > 1)
846 for (SequenceI seq : selectedSequences)
848 cmb_assSeq.addItem(new AssociateSeqOptions(seq));
853 String seqName = selectedSequence.getDisplayId(false);
854 seqName = seqName.length() <= 40 ? seqName : seqName.substring(0, 39);
855 lbl_associateSeq.setText(seqName);
856 lbl_associateSeq.setVisible(true);
857 cmb_assSeq.setVisible(false);
861 public boolean isStructuresDiscovered()
863 return structuresDiscovered;
866 public void setStructuresDiscovered(boolean structuresDiscovered)
868 this.structuresDiscovered = structuresDiscovered;
871 public Collection<PDBResponseSummary> getDiscoveredStructuresSet()
873 return discoveredStructuresSet;
877 protected void txt_search_ActionPerformed()
884 errorWarning.setLength(0);
885 isValidPBDEntry = false;
886 if (txt_search.getText().length() > 0)
888 List<PDBDocField> wantedFields = new ArrayList<PDBDocField>();
889 wantedFields.add(PDBDocField.PDB_ID);
890 PDBRestRequest pdbRequest = new PDBRestRequest();
891 pdbRequest.setAllowEmptySeq(false);
892 pdbRequest.setResponseSize(1);
893 pdbRequest.setFieldToSearchBy("(pdb_id:");
894 pdbRequest.setWantedFields(wantedFields);
895 pdbRequest.setSearchTerm(txt_search.getText() + ")");
896 pdbRequest.setAssociatedSequence(selectedSequence);
897 pdbRestCleint = new PDBRestClient();
898 PDBRestResponse resultList;
901 resultList = pdbRestCleint.executeRequest(pdbRequest);
902 } catch (Exception e)
904 errorWarning.append(e.getMessage());
908 validateSelections();
910 if (resultList.getSearchSummary() != null
911 && resultList.getSearchSummary().size() > 0)
913 isValidPBDEntry = true;
916 validateSelections();
922 public void tabRefresh()
924 if (selectedSequences != null)
926 Thread refreshThread = new Thread(new Runnable()
931 fetchStructuresMetaData();
932 filterResultSet(((FilterOption) cmb_filterOption
933 .getSelectedItem()).getValue());
936 refreshThread.start();
940 public class PDBEntryTableModel extends AbstractTableModel
942 String[] columns = { "Ref Sequence", "PDB Id", "Chain", "Type", "File" };
944 private List<CachedPDB> pdbEntries;
946 public PDBEntryTableModel(List<CachedPDB> pdbEntries)
948 this.pdbEntries = new ArrayList<CachedPDB>(pdbEntries);
952 public String getColumnName(int columnIndex)
954 return columns[columnIndex];
958 public int getRowCount()
960 return pdbEntries.size();
964 public int getColumnCount()
966 return columns.length;
970 public boolean isCellEditable(int row, int column)
976 public Object getValueAt(int rowIndex, int columnIndex)
979 CachedPDB entry = pdbEntries.get(rowIndex);
983 value = entry.getSequence();
986 value = entry.getPdbEntry();
989 value = entry.getPdbEntry().getChainCode() == null ? "_" : entry
990 .getPdbEntry().getChainCode();
993 value = entry.getPdbEntry().getType();
996 value = entry.getPdbEntry().getFile();
1003 public Class<?> getColumnClass(int columnIndex)
1005 return columnIndex == 0 ? SequenceI.class : PDBEntry.class;
1008 public CachedPDB getPDBEntryAt(int row)
1010 return pdbEntries.get(row);
1015 private class CachedPDB
1017 private SequenceI sequence;
1019 private PDBEntry pdbEntry;
1021 public CachedPDB(SequenceI sequence, PDBEntry pdbEntry)
1023 this.sequence = sequence;
1024 this.pdbEntry = pdbEntry;
1027 public SequenceI getSequence()
1032 public PDBEntry getPdbEntry()
1039 private IProgressIndicator progressBar;
1042 public void setProgressBar(String message, long id)
1044 progressBar.setProgressBar(message, id);
1048 public void registerHandler(long id, IProgressIndicatorHandler handler)
1050 progressBar.registerHandler(id, handler);
1054 public boolean operationInProgress()
1056 return progressBar.operationInProgress();