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>();
387 // PDBDocField fiterField = PDBRestClient
388 // .getPDBDocFieldByCode(fieldToFilterBy);
389 // if (!wantedFields.contains(fiterField))
391 // wantedFields.add(fiterField);
393 // } catch (Exception e)
395 // e.printStackTrace();
398 for (SequenceI seq : selectedSequences)
400 PDBRestRequest pdbRequest = new PDBRestRequest();
401 if (fieldToFilterBy.equalsIgnoreCase("uniprot_coverage"))
403 System.out.println(">>>>>> Filtering with uniprot coverate");
404 pdbRequest.setAllowEmptySeq(false);
405 pdbRequest.setResponseSize(1);
406 pdbRequest.setFieldToSearchBy("(");
407 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
408 pdbRequest.setWantedFields(wantedFields);
409 pdbRequest.setAssociatedSequence(seq);
410 pdbRequest.setFacet(true);
411 pdbRequest.setFacetPivot(fieldToFilterBy + ",entry_entity");
412 pdbRequest.setFacetPivotMinCount(1);
416 pdbRequest.setAllowEmptySeq(false);
417 pdbRequest.setResponseSize(1);
418 pdbRequest.setFieldToSearchBy("(");
419 pdbRequest.setFieldToSortBy(fieldToFilterBy,
420 !chk_invertFilter.isSelected());
421 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
422 pdbRequest.setWantedFields(wantedFields);
423 pdbRequest.setAssociatedSequence(seq);
425 pdbRestCleint = new PDBRestClient();
426 PDBRestResponse resultList;
429 resultList = pdbRestCleint.executeRequest(pdbRequest);
430 } catch (Exception e)
433 errors.add(e.getMessage());
436 lastPdbRequest = pdbRequest;
437 if (resultList.getSearchSummary() != null
438 && !resultList.getSearchSummary().isEmpty())
440 filteredResponse.addAll(resultList.getSearchSummary());
444 String totalTime = (System.currentTimeMillis() - startTime)
446 if (!filteredResponse.isEmpty())
448 final int filterResponseCount = filteredResponse.size();
449 Collection<PDBResponseSummary> reorderedStructuresSet = new LinkedHashSet<PDBResponseSummary>();
450 reorderedStructuresSet.addAll(filteredResponse);
451 reorderedStructuresSet.addAll(discoveredStructuresSet);
452 tbl_summary.setModel(PDBRestResponse.getTableModel(
453 lastPdbRequest, reorderedStructuresSet));
455 // Update table selection model here
456 tbl_summary.addRowSelectionInterval(0, filterResponseCount - 1);
457 mainFrame.setTitle(MessageManager.formatMessage(
458 "label.structure_chooser_filter_time", totalTime));
462 mainFrame.setTitle(MessageManager.formatMessage(
463 "label.structure_chooser_filter_time", totalTime));
464 if (errors.size() > 0)
466 StringBuilder errorMsg = new StringBuilder();
467 for (String error : errors)
469 errorMsg.append(error).append("\n");
471 JOptionPane.showMessageDialog(
474 MessageManager.getString("label.pdb_web-service_error"),
475 JOptionPane.ERROR_MESSAGE);
479 lbl_loading.setVisible(false);
481 validateSelections();
484 filterThread.start();
488 * Handles action event for btn_pdbFromFile
491 public void pdbFromFile_actionPerformed()
493 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
494 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
495 chooser.setFileView(new jalview.io.JalviewFileView());
496 chooser.setDialogTitle(MessageManager.formatMessage(
497 "label.select_pdb_file_for",
498 selectedSequence.getDisplayId(false)));
499 chooser.setToolTipText(MessageManager.formatMessage(
500 "label.load_pdb_file_associate_with_sequence",
501 selectedSequence.getDisplayId(false)));
503 int value = chooser.showOpenDialog(null);
504 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
506 selectedPdbFileName = chooser.getSelectedFile().getPath();
507 jalview.bin.Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName);
508 validateSelections();
513 * Populates the filter combo-box options dynamically depending on discovered
517 protected void populateFilterComboBox()
519 if (isStructuresDiscovered())
521 cmb_filterOption.addItem(new FilterOption("Best Quality",
522 PDBDocField.OVERALL_QUALITY.getCode(), VIEWS_FILTER));
523 cmb_filterOption.addItem(new FilterOption("Most UniProt Coverage",
524 PDBDocField.UNIPROT_COVERAGE.getCode(), VIEWS_FILTER));
525 cmb_filterOption.addItem(new FilterOption("Best Resolution",
526 PDBDocField.RESOLUTION.getCode(), VIEWS_FILTER));
527 cmb_filterOption.addItem(new FilterOption("Most Protein Chain",
528 PDBDocField.PROTEIN_CHAIN_COUNT.getCode(), VIEWS_FILTER));
529 cmb_filterOption.addItem(new FilterOption("Most Bound Molecules",
530 PDBDocField.BOUND_MOLECULE_COUNT.getCode(), VIEWS_FILTER));
531 cmb_filterOption.addItem(new FilterOption("Most Polymer Residues",
532 PDBDocField.POLYMER_RESIDUE_COUNT.getCode(), VIEWS_FILTER));
534 cmb_filterOption.addItem(new FilterOption("Enter PDB Id", "-",
536 cmb_filterOption.addItem(new FilterOption("From File", "-",
538 cmb_filterOption.addItem(new FilterOption("Cached PDB Entries", "-",
543 * Updates the displayed view based on the selected filter option
546 protected void updateCurrentView()
548 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
550 layout_switchableViews.show(pnl_switchableViews,
551 selectedFilterOpt.getView());
552 String filterTitle = mainFrame.getTitle();
553 mainFrame.setTitle(frameTitle);
554 chk_invertFilter.setVisible(false);
555 if (selectedFilterOpt.getView() == VIEWS_FILTER)
557 mainFrame.setTitle(filterTitle);
558 chk_invertFilter.setVisible(true);
559 filterResultSet(selectedFilterOpt.getValue());
561 else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
562 || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
564 mainFrame.setTitle(MessageManager
565 .getString("label.structure_chooser_manual_association"));
566 idInputAssSeqPanel.loadCmbAssSeq();
567 fileChooserAssSeqPanel.loadCmbAssSeq();
569 validateSelections();
573 * Validates user selection and activates the view button if all parameters
577 public void validateSelections()
579 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
581 btn_view.setEnabled(false);
582 String currentView = selectedFilterOpt.getView();
583 if (currentView == VIEWS_FILTER)
585 if (tbl_summary.getSelectedRows().length > 0)
587 btn_view.setEnabled(true);
590 else if (currentView == VIEWS_LOCAL_PDB)
592 if (tbl_local_pdb.getSelectedRows().length > 0)
594 btn_view.setEnabled(true);
597 else if (currentView == VIEWS_ENTER_ID)
599 validateAssociationEnterPdb();
601 else if (currentView == VIEWS_FROM_FILE)
603 validateAssociationFromFile();
608 * Validates inputs from the Manual PDB entry panel
610 public void validateAssociationEnterPdb()
612 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel
613 .getCmb_assSeq().getSelectedItem();
614 lbl_pdbManualFetchStatus.setIcon(errorImage);
615 lbl_pdbManualFetchStatus.setToolTipText("");
616 if (txt_search.getText().length() > 0)
618 lbl_pdbManualFetchStatus
619 .setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
620 .formatMessage("info.no_pdb_entry_found_for",
621 txt_search.getText())));
624 if (errorWarning.length() > 0)
626 lbl_pdbManualFetchStatus.setIcon(warningImage);
627 lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip(
628 true, errorWarning.toString()));
631 if (selectedSequences.length == 1
632 || !assSeqOpt.getName().equalsIgnoreCase(
633 "-Select Associated Seq-"))
635 txt_search.setEnabled(true);
638 btn_view.setEnabled(true);
639 lbl_pdbManualFetchStatus.setToolTipText("");
640 lbl_pdbManualFetchStatus.setIcon(goodImage);
645 txt_search.setEnabled(false);
646 lbl_pdbManualFetchStatus.setIcon(errorImage);
651 * Validates inputs for the manual PDB file selection options
653 public void validateAssociationFromFile()
655 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
656 .getCmb_assSeq().getSelectedItem();
657 lbl_fromFileStatus.setIcon(errorImage);
658 if (selectedSequences.length == 1
659 || (assSeqOpt != null && !assSeqOpt.getName().equalsIgnoreCase(
660 "-Select Associated Seq-")))
662 btn_pdbFromFile.setEnabled(true);
663 if (selectedPdbFileName != null && selectedPdbFileName.length() > 0)
665 btn_view.setEnabled(true);
666 lbl_fromFileStatus.setIcon(goodImage);
671 btn_pdbFromFile.setEnabled(false);
672 lbl_fromFileStatus.setIcon(errorImage);
677 public void cmbAssSeqStateChanged()
679 validateSelections();
683 * Handles the state change event for the 'filter' combo-box and 'invert'
687 protected void stateChanged(ItemEvent e)
689 if (e.getSource() instanceof JCheckBox)
695 if (e.getStateChange() == ItemEvent.SELECTED)
704 * Handles action event for btn_ok
707 public void ok_ActionPerformed()
709 final long progressSessionId = System.currentTimeMillis();
710 final StructureSelectionManager ssm = ap.getStructureSelectionManager();
711 ssm.setProgressIndicator(this);
712 ssm.setProgressSessionId(progressSessionId);
713 new Thread(new Runnable()
718 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
720 String currentView = selectedFilterOpt.getView();
721 if (currentView == VIEWS_FILTER)
723 int pdbIdColIndex = tbl_summary.getColumn(
724 PDBRestClient.PDBDocField.PDB_ID.getName()).getModelIndex();
725 int refSeqColIndex = tbl_summary.getColumn("Ref Sequence")
727 int[] selectedRows = tbl_summary.getSelectedRows();
728 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
730 ArrayList<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
731 for (int row : selectedRows)
733 String pdbIdStr = tbl_summary.getValueAt(row, pdbIdColIndex)
735 SequenceI selectedSeq = (SequenceI) tbl_summary.getValueAt(row,
737 selectedSeqsToView.add(selectedSeq);
738 PDBEntry pdbEntry = selectedSeq.getPDBEntry(pdbIdStr);
739 if (pdbEntry == null)
741 pdbEntry = new PDBEntry();
742 pdbEntry.setId(pdbIdStr);
743 pdbEntry.setType(PDBEntry.Type.PDB);
744 selectedSeq.getDatasetSequence().addPDBId(pdbEntry);
746 pdbEntriesToView[count++] = pdbEntry;
748 SequenceI[] selectedSeqs = selectedSeqsToView
749 .toArray(new SequenceI[selectedSeqsToView.size()]);
750 launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
752 else if (currentView == VIEWS_LOCAL_PDB)
754 int[] selectedRows = tbl_local_pdb.getSelectedRows();
755 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
757 int pdbIdColIndex = tbl_local_pdb.getColumn(
758 PDBRestClient.PDBDocField.PDB_ID.getName()).getModelIndex();
759 int refSeqColIndex = tbl_local_pdb.getColumn("Ref Sequence")
761 ArrayList<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
762 for (int row : selectedRows)
764 PDBEntry pdbEntry = (PDBEntry) tbl_local_pdb.getValueAt(row,
766 pdbEntriesToView[count++] = pdbEntry;
767 SequenceI selectedSeq = (SequenceI) tbl_local_pdb.getValueAt(row,
769 selectedSeqsToView.add(selectedSeq);
771 SequenceI[] selectedSeqs = selectedSeqsToView
772 .toArray(new SequenceI[selectedSeqsToView.size()]);
773 launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
775 else if (currentView == VIEWS_ENTER_ID)
777 SequenceI userSelectedSeq = ((AssociateSeqOptions) idInputAssSeqPanel
778 .getCmb_assSeq().getSelectedItem()).getSequence();
779 if (userSelectedSeq != null)
781 selectedSequence = userSelectedSeq;
784 String pdbIdStr = txt_search.getText();
785 PDBEntry pdbEntry = selectedSequence.getPDBEntry(pdbIdStr);
786 if (pdbEntry == null)
788 pdbEntry = new PDBEntry();
789 pdbEntry.setId(pdbIdStr);
790 pdbEntry.setType(PDBEntry.Type.PDB);
791 selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
794 PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
795 launchStructureViewer(ssm, pdbEntriesToView, ap,
796 new SequenceI[] { selectedSequence });
798 else if (currentView == VIEWS_FROM_FILE)
800 SequenceI userSelectedSeq = ((AssociateSeqOptions) fileChooserAssSeqPanel
801 .getCmb_assSeq().getSelectedItem()).getSequence();
802 if (userSelectedSeq != null)
804 selectedSequence = userSelectedSeq;
806 PDBEntry fileEntry = new AssociatePdbFileWithSeq()
807 .associatePdbWithSeq(selectedPdbFileName,
808 jalview.io.AppletFormatAdapter.FILE,
809 selectedSequence, true, Desktop.instance);
811 launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
812 new SequenceI[] { selectedSequence });
819 private void launchStructureViewer(StructureSelectionManager ssm,
820 final PDBEntry[] pdbEntriesToView,
821 final AlignmentPanel alignPanel, SequenceI[] sequences)
823 ssm.setProgressBar("Launching PDB structure viewer..");
824 final StructureViewer sViewer = new StructureViewer(ssm);
826 if (SiftsSettings.isMapWithSifts())
828 for (SequenceI seq : sequences)
830 if (seq.getSourceDBRef() == null)
832 ssm.setProgressBar(null);
833 ssm.setProgressBar("Fetching Database refs..");
834 new jalview.ws.DBRefFetcher(sequences, null, null, null, false)
840 if (pdbEntriesToView.length > 1)
842 ArrayList<SequenceI[]> seqsMap = new ArrayList<SequenceI[]>();
843 for (SequenceI seq : sequences)
845 seqsMap.add(new SequenceI[] { seq });
847 SequenceI[][] collatedSeqs = seqsMap.toArray(new SequenceI[0][0]);
848 ssm.setProgressBar(null);
849 ssm.setProgressBar("Fetching PDB Structures for selected entries..");
850 sViewer.viewStructures(pdbEntriesToView, collatedSeqs, alignPanel);
854 ssm.setProgressBar(null);
855 ssm.setProgressBar("Fetching PDB Structure for "
856 + pdbEntriesToView[0].getId());
857 sViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
862 * Populates the combo-box used in associating manually fetched structures to
863 * a unique sequence when more than one sequence selection is made.
866 public void populateCmbAssociateSeqOptions(
867 JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq)
869 cmb_assSeq.removeAllItems();
870 cmb_assSeq.addItem(new AssociateSeqOptions("-Select Associated Seq-",
872 lbl_associateSeq.setVisible(false);
873 if (selectedSequences.length > 1)
875 for (SequenceI seq : selectedSequences)
877 cmb_assSeq.addItem(new AssociateSeqOptions(seq));
882 String seqName = selectedSequence.getDisplayId(false);
883 seqName = seqName.length() <= 40 ? seqName : seqName.substring(0, 39);
884 lbl_associateSeq.setText(seqName);
885 lbl_associateSeq.setVisible(true);
886 cmb_assSeq.setVisible(false);
890 public boolean isStructuresDiscovered()
892 return structuresDiscovered;
895 public void setStructuresDiscovered(boolean structuresDiscovered)
897 this.structuresDiscovered = structuresDiscovered;
900 public Collection<PDBResponseSummary> getDiscoveredStructuresSet()
902 return discoveredStructuresSet;
906 protected void txt_search_ActionPerformed()
913 errorWarning.setLength(0);
914 isValidPBDEntry = false;
915 if (txt_search.getText().length() > 0)
917 List<PDBDocField> wantedFields = new ArrayList<PDBDocField>();
918 wantedFields.add(PDBDocField.PDB_ID);
919 PDBRestRequest pdbRequest = new PDBRestRequest();
920 pdbRequest.setAllowEmptySeq(false);
921 pdbRequest.setResponseSize(1);
922 pdbRequest.setFieldToSearchBy("(pdb_id:");
923 pdbRequest.setWantedFields(wantedFields);
924 pdbRequest.setSearchTerm(txt_search.getText() + ")");
925 pdbRequest.setAssociatedSequence(selectedSequence);
926 pdbRestCleint = new PDBRestClient();
927 PDBRestResponse resultList;
930 resultList = pdbRestCleint.executeRequest(pdbRequest);
931 } catch (Exception e)
933 errorWarning.append(e.getMessage());
937 validateSelections();
939 if (resultList.getSearchSummary() != null
940 && resultList.getSearchSummary().size() > 0)
942 isValidPBDEntry = true;
945 validateSelections();
951 public void tabRefresh()
953 if (selectedSequences != null)
955 Thread refreshThread = new Thread(new Runnable()
960 fetchStructuresMetaData();
961 filterResultSet(((FilterOption) cmb_filterOption
962 .getSelectedItem()).getValue());
965 refreshThread.start();
969 public class PDBEntryTableModel extends AbstractTableModel
971 String[] columns = { "Ref Sequence", "PDB Id", "Chain", "Type", "File" };
973 private List<CachedPDB> pdbEntries;
975 public PDBEntryTableModel(List<CachedPDB> pdbEntries)
977 this.pdbEntries = new ArrayList<CachedPDB>(pdbEntries);
981 public String getColumnName(int columnIndex)
983 return columns[columnIndex];
987 public int getRowCount()
989 return pdbEntries.size();
993 public int getColumnCount()
995 return columns.length;
999 public boolean isCellEditable(int row, int column)
1005 public Object getValueAt(int rowIndex, int columnIndex)
1007 Object value = "??";
1008 CachedPDB entry = pdbEntries.get(rowIndex);
1009 switch (columnIndex)
1012 value = entry.getSequence();
1015 value = entry.getPdbEntry();
1018 value = entry.getPdbEntry().getChainCode() == null ? "_" : entry
1019 .getPdbEntry().getChainCode();
1022 value = entry.getPdbEntry().getType();
1025 value = entry.getPdbEntry().getFile();
1032 public Class<?> getColumnClass(int columnIndex)
1034 return columnIndex == 0 ? SequenceI.class : PDBEntry.class;
1037 public CachedPDB getPDBEntryAt(int row)
1039 return pdbEntries.get(row);
1044 private class CachedPDB
1046 private SequenceI sequence;
1048 private PDBEntry pdbEntry;
1050 public CachedPDB(SequenceI sequence, PDBEntry pdbEntry)
1052 this.sequence = sequence;
1053 this.pdbEntry = pdbEntry;
1056 public SequenceI getSequence()
1061 public PDBEntry getPdbEntry()
1068 private IProgressIndicator progressBar;
1071 public void setProgressBar(String message, long id)
1073 progressBar.setProgressBar(message, id);
1077 public void registerHandler(long id, IProgressIndicatorHandler handler)
1079 progressBar.registerHandler(id, handler);
1083 public boolean operationInProgress()
1085 return progressBar.operationInProgress();