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;
46 import java.util.Objects;
47 import java.util.Vector;
49 import javax.swing.JCheckBox;
50 import javax.swing.JComboBox;
51 import javax.swing.JLabel;
52 import javax.swing.JOptionPane;
53 import javax.swing.table.AbstractTableModel;
56 * Provides the behaviors for the Structure chooser Panel
61 @SuppressWarnings("serial")
62 public class StructureChooser extends GStructureChooser implements
65 private boolean structuresDiscovered = false;
67 private SequenceI selectedSequence;
69 private SequenceI[] selectedSequences;
71 private IProgressIndicator progressIndicator;
73 private Collection<PDBResponseSummary> discoveredStructuresSet;
75 private PDBRestRequest lastPdbRequest;
77 private PDBRestClient pdbRestCleint;
79 private String selectedPdbFileName;
81 private boolean isValidPBDEntry;
83 public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
87 this.selectedSequence = selectedSeq;
88 this.selectedSequences = selectedSeqs;
89 this.progressIndicator = (ap == null) ? null : ap.alignFrame;
94 * Initializes parameters used by the Structure Chooser Panel
98 if (!Jalview.isHeadlessMode())
100 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
103 Thread discoverPDBStructuresThread = new Thread(new Runnable()
108 long startTime = System.currentTimeMillis();
109 updateProgressIndicator(MessageManager
110 .getString("status.loading_cached_pdb_entries"), startTime);
111 loadLocalCachedPDBEntries();
112 updateProgressIndicator(null, startTime);
113 updateProgressIndicator(MessageManager
114 .getString("status.searching_for_pdb_structures"),
116 fetchStructuresMetaData();
117 populateFilterComboBox();
118 updateProgressIndicator(null, startTime);
119 mainFrame.setVisible(true);
123 discoverPDBStructuresThread.start();
127 * Updates the progress indicator with the specified message
130 * displayed message for the operation
132 * unique handle for this indicator
134 public void updateProgressIndicator(String message, long id)
136 if (progressIndicator != null)
138 progressIndicator.setProgressBar(message, id);
143 * Retrieve meta-data for all the structure(s) for a given sequence(s) in a
146 public void fetchStructuresMetaData()
148 long startTime = System.currentTimeMillis();
149 Collection<PDBDocField> wantedFields = PDBDocFieldPreferences
150 .getStructureSummaryFields();
152 discoveredStructuresSet = new LinkedHashSet<PDBResponseSummary>();
153 HashSet<String> errors = new HashSet<String>();
154 for (SequenceI seq : selectedSequences)
156 PDBRestRequest pdbRequest = new PDBRestRequest();
157 pdbRequest.setAllowEmptySeq(false);
158 pdbRequest.setResponseSize(500);
159 pdbRequest.setFieldToSearchBy("(");
160 pdbRequest.setWantedFields(wantedFields);
161 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
162 pdbRequest.setAssociatedSequence(seq);
163 pdbRestCleint = new PDBRestClient();
164 PDBRestResponse resultList;
167 resultList = pdbRestCleint.executeRequest(pdbRequest);
168 } catch (Exception e)
171 errors.add(e.getMessage());
174 lastPdbRequest = pdbRequest;
175 if (resultList.getSearchSummary() != null
176 && !resultList.getSearchSummary().isEmpty())
178 discoveredStructuresSet.addAll(resultList.getSearchSummary());
182 int noOfStructuresFound = 0;
183 String totalTime = (System.currentTimeMillis() - startTime)
185 if (discoveredStructuresSet != null
186 && !discoveredStructuresSet.isEmpty())
188 tbl_summary.setModel(PDBRestResponse.getTableModel(lastPdbRequest,
189 discoveredStructuresSet));
190 structuresDiscovered = true;
191 noOfStructuresFound = discoveredStructuresSet.size();
192 mainFrame.setTitle(MessageManager.formatMessage(
193 "label.structure_chooser_no_of_structures",
194 noOfStructuresFound, totalTime));
198 mainFrame.setTitle(MessageManager
199 .getString("label.structure_chooser_manual_association"));
200 if (errors.size() > 0)
202 StringBuilder errorMsg = new StringBuilder();
203 for (String error : errors)
205 errorMsg.append(error).append("\n");
207 JOptionPane.showMessageDialog(this, errorMsg.toString(),
208 MessageManager.getString("label.pdb_web-service_error"),
209 JOptionPane.ERROR_MESSAGE);
214 public void loadLocalCachedPDBEntries()
216 ArrayList<CachedPDB> entries = new ArrayList<CachedPDB>();
217 for (SequenceI seq : selectedSequences)
219 if (seq.getDatasetSequence() != null
220 && seq.getDatasetSequence().getAllPDBEntries() != null)
222 for (PDBEntry pdbEntry : seq.getDatasetSequence()
225 if (pdbEntry.getFile() != null)
227 entries.add(new CachedPDB(seq, pdbEntry));
233 PDBEntryTableModel tableModelx = new PDBEntryTableModel(entries);
234 tbl_local_pdb.setModel(tableModelx);
238 * Builds a query string for a given sequences using its DBRef entries
241 * the sequences to build a query for
242 * @return the built query string
245 public static String buildQuery(SequenceI seq)
247 boolean isPDBRefsFound = false;
248 boolean isUniProtRefsFound = false;
249 StringBuilder queryBuilder = new StringBuilder();
250 HashSet<String> seqRefs = new LinkedHashSet<String>();
252 if (seq.getAllPDBEntries() != null)
254 for (PDBEntry entry : seq.getAllPDBEntries())
256 if (isValidSeqName(entry.getId()))
258 queryBuilder.append(PDBRestClient.PDBDocField.PDB_ID.getCode())
260 .append(entry.getId().toLowerCase())
262 isPDBRefsFound = true;
263 // seqRefs.add(entry.getId());
268 if (seq.getDBRefs() != null && seq.getDBRefs().length != 0)
270 for (DBRefEntry dbRef : seq.getDBRefs())
272 if (isValidSeqName(getDBRefId(dbRef)))
274 if (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT))
277 .append(PDBRestClient.PDBDocField.UNIPROT_ACCESSION
278 .getCode()).append(":")
279 .append(getDBRefId(dbRef))
282 .append(PDBRestClient.PDBDocField.UNIPROT_ID.getCode())
284 .append(getDBRefId(dbRef)).append(" OR ");
285 isUniProtRefsFound = true;
287 else if (dbRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
290 queryBuilder.append(PDBRestClient.PDBDocField.PDB_ID.getCode())
291 .append(":").append(getDBRefId(dbRef).toLowerCase())
293 isPDBRefsFound = true;
297 seqRefs.add(getDBRefId(dbRef));
303 if (!isPDBRefsFound && !isUniProtRefsFound)
305 String seqName = seq.getName();
306 seqName = sanitizeSeqName(seqName);
307 String[] names = seqName.toLowerCase().split("\\|");
308 for (String name : names)
310 // System.out.println("Found name : " + name);
312 if (isValidSeqName(name))
318 for (String seqRef : seqRefs)
320 queryBuilder.append("text:").append(seqRef).append(" OR ");
324 int endIndex = queryBuilder.lastIndexOf(" OR ");
325 if (queryBuilder.toString().length() < 6)
329 String query = queryBuilder.toString().substring(0, endIndex);
334 * Remove the following special characters from input string +, -, &, |, !, (,
335 * ), {, }, [, ], ^, ", ~, *, ?, :, \
340 private static String sanitizeSeqName(String seqName)
342 Objects.requireNonNull(seqName);
343 return seqName.replaceAll("\\[\\d*\\]", "")
344 .replaceAll("[^\\dA-Za-z|]", "").replaceAll("\\s+", "+");
349 * Ensures sequence ref names are not less than 3 characters and does not
350 * contain a database name
355 public static boolean isValidSeqName(String seqName)
357 // System.out.println("seqName : " + seqName);
358 String ignoreList = "pdb,uniprot,swiss-prot";
359 if (seqName.length() < 3)
363 if (seqName.contains(":"))
367 seqName = seqName.toLowerCase();
368 for (String ignoredEntry : ignoreList.split(","))
370 if (seqName.contains(ignoredEntry))
378 public static String getDBRefId(DBRefEntry dbRef)
380 String ref = dbRef.getAccessionId().replaceAll("GO:", "");
385 * Filters a given list of discovered structures based on supplied argument
387 * @param fieldToFilterBy
388 * the field to filter by
390 public void filterResultSet(final String fieldToFilterBy)
392 Thread filterThread = new Thread(new Runnable()
397 long startTime = System.currentTimeMillis();
398 lbl_loading.setVisible(true);
399 Collection<PDBDocField> wantedFields = PDBDocFieldPreferences
400 .getStructureSummaryFields();
401 Collection<PDBResponseSummary> filteredResponse = new HashSet<PDBResponseSummary>();
402 HashSet<String> errors = new HashSet<String>();
404 for (SequenceI seq : selectedSequences)
406 PDBRestRequest pdbRequest = new PDBRestRequest();
407 if (fieldToFilterBy.equalsIgnoreCase("uniprot_coverage"))
409 System.out.println(">>>>>> Filtering with uniprot coverate");
410 pdbRequest.setAllowEmptySeq(false);
411 pdbRequest.setResponseSize(1);
412 pdbRequest.setFieldToSearchBy("(");
413 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
414 pdbRequest.setWantedFields(wantedFields);
415 pdbRequest.setAssociatedSequence(seq);
416 pdbRequest.setFacet(true);
417 pdbRequest.setFacetPivot(fieldToFilterBy + ",entry_entity");
418 pdbRequest.setFacetPivotMinCount(1);
422 pdbRequest.setAllowEmptySeq(false);
423 pdbRequest.setResponseSize(1);
424 pdbRequest.setFieldToSearchBy("(");
425 pdbRequest.setFieldToSortBy(fieldToFilterBy,
426 !chk_invertFilter.isSelected());
427 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
428 pdbRequest.setWantedFields(wantedFields);
429 pdbRequest.setAssociatedSequence(seq);
431 pdbRestCleint = new PDBRestClient();
432 PDBRestResponse resultList;
435 resultList = pdbRestCleint.executeRequest(pdbRequest);
436 } catch (Exception e)
439 errors.add(e.getMessage());
442 lastPdbRequest = pdbRequest;
443 if (resultList.getSearchSummary() != null
444 && !resultList.getSearchSummary().isEmpty())
446 filteredResponse.addAll(resultList.getSearchSummary());
450 String totalTime = (System.currentTimeMillis() - startTime)
452 if (!filteredResponse.isEmpty())
454 final int filterResponseCount = filteredResponse.size();
455 Collection<PDBResponseSummary> reorderedStructuresSet = new LinkedHashSet<PDBResponseSummary>();
456 reorderedStructuresSet.addAll(filteredResponse);
457 reorderedStructuresSet.addAll(discoveredStructuresSet);
458 tbl_summary.setModel(PDBRestResponse.getTableModel(
459 lastPdbRequest, reorderedStructuresSet));
461 PDBRestResponse.configureTableColumn(tbl_summary, wantedFields);
462 tbl_summary.getColumn("Ref Sequence").setPreferredWidth(120);
463 tbl_summary.getColumn("Ref Sequence").setMinWidth(100);
464 tbl_summary.getColumn("Ref Sequence").setMaxWidth(200);
465 // Update table selection model here
466 tbl_summary.addRowSelectionInterval(0, filterResponseCount - 1);
467 mainFrame.setTitle(MessageManager.formatMessage(
468 "label.structure_chooser_filter_time", totalTime));
472 mainFrame.setTitle(MessageManager.formatMessage(
473 "label.structure_chooser_filter_time", totalTime));
474 if (errors.size() > 0)
476 StringBuilder errorMsg = new StringBuilder();
477 for (String error : errors)
479 errorMsg.append(error).append("\n");
481 JOptionPane.showMessageDialog(
484 MessageManager.getString("label.pdb_web-service_error"),
485 JOptionPane.ERROR_MESSAGE);
489 lbl_loading.setVisible(false);
491 validateSelections();
494 filterThread.start();
498 * Handles action event for btn_pdbFromFile
501 public void pdbFromFile_actionPerformed()
503 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
504 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
505 chooser.setFileView(new jalview.io.JalviewFileView());
506 chooser.setDialogTitle(MessageManager.formatMessage(
507 "label.select_pdb_file_for",
508 selectedSequence.getDisplayId(false)));
509 chooser.setToolTipText(MessageManager.formatMessage(
510 "label.load_pdb_file_associate_with_sequence",
511 selectedSequence.getDisplayId(false)));
513 int value = chooser.showOpenDialog(null);
514 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
516 selectedPdbFileName = chooser.getSelectedFile().getPath();
517 jalview.bin.Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName);
518 validateSelections();
523 * Populates the filter combo-box options dynamically depending on discovered
527 protected void populateFilterComboBox()
529 if (isStructuresDiscovered())
531 cmb_filterOption.addItem(new FilterOption("Best Quality",
532 PDBDocField.OVERALL_QUALITY.getCode(), VIEWS_FILTER));
533 cmb_filterOption.addItem(new FilterOption("Most UniProt Coverage",
534 PDBDocField.UNIPROT_COVERAGE.getCode(), VIEWS_FILTER));
535 cmb_filterOption.addItem(new FilterOption("Best Resolution",
536 PDBDocField.RESOLUTION.getCode(), VIEWS_FILTER));
537 cmb_filterOption.addItem(new FilterOption("Most Protein Chain",
538 PDBDocField.PROTEIN_CHAIN_COUNT.getCode(), VIEWS_FILTER));
539 cmb_filterOption.addItem(new FilterOption("Most Bound Molecules",
540 PDBDocField.BOUND_MOLECULE_COUNT.getCode(), VIEWS_FILTER));
541 cmb_filterOption.addItem(new FilterOption("Most Polymer Residues",
542 PDBDocField.POLYMER_RESIDUE_COUNT.getCode(), VIEWS_FILTER));
544 cmb_filterOption.addItem(new FilterOption("Enter PDB Id", "-",
546 cmb_filterOption.addItem(new FilterOption("From File", "-",
548 cmb_filterOption.addItem(new FilterOption("Cached PDB Entries", "-",
553 * Updates the displayed view based on the selected filter option
556 protected void updateCurrentView()
558 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
560 layout_switchableViews.show(pnl_switchableViews,
561 selectedFilterOpt.getView());
562 String filterTitle = mainFrame.getTitle();
563 mainFrame.setTitle(frameTitle);
564 chk_invertFilter.setVisible(false);
565 if (selectedFilterOpt.getView() == VIEWS_FILTER)
567 mainFrame.setTitle(filterTitle);
568 chk_invertFilter.setVisible(true);
569 filterResultSet(selectedFilterOpt.getValue());
571 else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
572 || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
574 mainFrame.setTitle(MessageManager
575 .getString("label.structure_chooser_manual_association"));
576 idInputAssSeqPanel.loadCmbAssSeq();
577 fileChooserAssSeqPanel.loadCmbAssSeq();
579 validateSelections();
583 * Validates user selection and activates the view button if all parameters
587 public void validateSelections()
589 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
591 btn_view.setEnabled(false);
592 String currentView = selectedFilterOpt.getView();
593 if (currentView == VIEWS_FILTER)
595 if (tbl_summary.getSelectedRows().length > 0)
597 btn_view.setEnabled(true);
600 else if (currentView == VIEWS_LOCAL_PDB)
602 if (tbl_local_pdb.getSelectedRows().length > 0)
604 btn_view.setEnabled(true);
607 else if (currentView == VIEWS_ENTER_ID)
609 validateAssociationEnterPdb();
611 else if (currentView == VIEWS_FROM_FILE)
613 validateAssociationFromFile();
618 * Validates inputs from the Manual PDB entry panel
620 public void validateAssociationEnterPdb()
622 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel
623 .getCmb_assSeq().getSelectedItem();
624 lbl_pdbManualFetchStatus.setIcon(errorImage);
625 lbl_pdbManualFetchStatus.setToolTipText("");
626 if (txt_search.getText().length() > 0)
628 lbl_pdbManualFetchStatus
629 .setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
630 .formatMessage("info.no_pdb_entry_found_for",
631 txt_search.getText())));
634 if (errorWarning.length() > 0)
636 lbl_pdbManualFetchStatus.setIcon(warningImage);
637 lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip(
638 true, errorWarning.toString()));
641 if (selectedSequences.length == 1
642 || !assSeqOpt.getName().equalsIgnoreCase(
643 "-Select Associated Seq-"))
645 txt_search.setEnabled(true);
648 btn_view.setEnabled(true);
649 lbl_pdbManualFetchStatus.setToolTipText("");
650 lbl_pdbManualFetchStatus.setIcon(goodImage);
655 txt_search.setEnabled(false);
656 lbl_pdbManualFetchStatus.setIcon(errorImage);
661 * Validates inputs for the manual PDB file selection options
663 public void validateAssociationFromFile()
665 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
666 .getCmb_assSeq().getSelectedItem();
667 lbl_fromFileStatus.setIcon(errorImage);
668 if (selectedSequences.length == 1
669 || (assSeqOpt != null && !assSeqOpt.getName().equalsIgnoreCase(
670 "-Select Associated Seq-")))
672 btn_pdbFromFile.setEnabled(true);
673 if (selectedPdbFileName != null && selectedPdbFileName.length() > 0)
675 btn_view.setEnabled(true);
676 lbl_fromFileStatus.setIcon(goodImage);
681 btn_pdbFromFile.setEnabled(false);
682 lbl_fromFileStatus.setIcon(errorImage);
687 public void cmbAssSeqStateChanged()
689 validateSelections();
693 * Handles the state change event for the 'filter' combo-box and 'invert'
697 protected void stateChanged(ItemEvent e)
699 if (e.getSource() instanceof JCheckBox)
705 if (e.getStateChange() == ItemEvent.SELECTED)
714 * Handles action event for btn_ok
717 public void ok_ActionPerformed()
719 final long progressSessionId = System.currentTimeMillis();
720 final StructureSelectionManager ssm = ap.getStructureSelectionManager();
721 ssm.setProgressIndicator(this);
722 ssm.setProgressSessionId(progressSessionId);
723 new Thread(new Runnable()
728 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
730 String currentView = selectedFilterOpt.getView();
731 if (currentView == VIEWS_FILTER)
733 int pdbIdColIndex = tbl_summary.getColumn(
734 PDBRestClient.PDBDocField.PDB_ID.getName()).getModelIndex();
735 int refSeqColIndex = tbl_summary.getColumn("Ref Sequence")
737 int[] selectedRows = tbl_summary.getSelectedRows();
738 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
740 ArrayList<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
741 for (int row : selectedRows)
743 String pdbIdStr = tbl_summary.getValueAt(row, pdbIdColIndex)
745 SequenceI selectedSeq = (SequenceI) tbl_summary.getValueAt(row,
747 selectedSeqsToView.add(selectedSeq);
748 PDBEntry pdbEntry = selectedSeq.getPDBEntry(pdbIdStr);
749 if (pdbEntry == null)
751 pdbEntry = getFindEntry(pdbIdStr,
752 selectedSeq.getAllPDBEntries());
754 if (pdbEntry == null)
756 pdbEntry = new PDBEntry();
757 pdbEntry.setId(pdbIdStr);
758 pdbEntry.setType(PDBEntry.Type.PDB);
759 selectedSeq.getDatasetSequence().addPDBId(pdbEntry);
761 pdbEntriesToView[count++] = pdbEntry;
763 SequenceI[] selectedSeqs = selectedSeqsToView
764 .toArray(new SequenceI[selectedSeqsToView.size()]);
765 launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
767 else if (currentView == VIEWS_LOCAL_PDB)
769 int[] selectedRows = tbl_local_pdb.getSelectedRows();
770 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
772 int pdbIdColIndex = tbl_local_pdb.getColumn(
773 PDBRestClient.PDBDocField.PDB_ID.getName()).getModelIndex();
774 int refSeqColIndex = tbl_local_pdb.getColumn("Ref Sequence")
776 ArrayList<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
777 for (int row : selectedRows)
779 PDBEntry pdbEntry = (PDBEntry) tbl_local_pdb.getValueAt(row,
781 pdbEntriesToView[count++] = pdbEntry;
782 SequenceI selectedSeq = (SequenceI) tbl_local_pdb.getValueAt(row,
784 selectedSeqsToView.add(selectedSeq);
786 SequenceI[] selectedSeqs = selectedSeqsToView
787 .toArray(new SequenceI[selectedSeqsToView.size()]);
788 launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
790 else if (currentView == VIEWS_ENTER_ID)
792 SequenceI userSelectedSeq = ((AssociateSeqOptions) idInputAssSeqPanel
793 .getCmb_assSeq().getSelectedItem()).getSequence();
794 if (userSelectedSeq != null)
796 selectedSequence = userSelectedSeq;
799 String pdbIdStr = txt_search.getText();
800 PDBEntry pdbEntry = selectedSequence.getPDBEntry(pdbIdStr);
801 if (pdbEntry == null)
803 pdbEntry = new PDBEntry();
804 pdbEntry.setId(pdbIdStr);
805 pdbEntry.setType(PDBEntry.Type.PDB);
806 selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
809 PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
810 launchStructureViewer(ssm, pdbEntriesToView, ap,
811 new SequenceI[] { selectedSequence });
813 else if (currentView == VIEWS_FROM_FILE)
815 SequenceI userSelectedSeq = ((AssociateSeqOptions) fileChooserAssSeqPanel
816 .getCmb_assSeq().getSelectedItem()).getSequence();
817 if (userSelectedSeq != null)
819 selectedSequence = userSelectedSeq;
821 PDBEntry fileEntry = new AssociatePdbFileWithSeq()
822 .associatePdbWithSeq(selectedPdbFileName,
823 jalview.io.AppletFormatAdapter.FILE,
824 selectedSequence, true, Desktop.instance);
826 launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
827 new SequenceI[] { selectedSequence });
834 private PDBEntry getFindEntry(String id, Vector<PDBEntry> pdbEntries)
836 Objects.requireNonNull(id);
837 Objects.requireNonNull(pdbEntries);
838 PDBEntry foundEntry = null;
839 for (PDBEntry entry : pdbEntries)
841 if (entry.getId().equalsIgnoreCase(id))
849 private void launchStructureViewer(StructureSelectionManager ssm,
850 final PDBEntry[] pdbEntriesToView,
851 final AlignmentPanel alignPanel, SequenceI[] sequences)
853 ssm.setProgressBar("Launching PDB structure viewer..");
854 final StructureViewer sViewer = new StructureViewer(ssm);
856 if (SiftsSettings.isMapWithSifts())
858 for (SequenceI seq : sequences)
860 if (seq.getSourceDBRef() == null)
862 ssm.setProgressBar(null);
863 ssm.setProgressBar("Fetching Database refs..");
864 new jalview.ws.DBRefFetcher(sequences, null, null, null, false)
870 if (pdbEntriesToView.length > 1)
872 ArrayList<SequenceI[]> seqsMap = new ArrayList<SequenceI[]>();
873 for (SequenceI seq : sequences)
875 seqsMap.add(new SequenceI[] { seq });
877 SequenceI[][] collatedSeqs = seqsMap.toArray(new SequenceI[0][0]);
878 ssm.setProgressBar(null);
879 ssm.setProgressBar("Fetching PDB Structures for selected entries..");
880 sViewer.viewStructures(pdbEntriesToView, collatedSeqs, alignPanel);
884 ssm.setProgressBar(null);
885 ssm.setProgressBar("Fetching PDB Structure for "
886 + pdbEntriesToView[0].getId());
887 sViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
892 * Populates the combo-box used in associating manually fetched structures to
893 * a unique sequence when more than one sequence selection is made.
896 public void populateCmbAssociateSeqOptions(
897 JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq)
899 cmb_assSeq.removeAllItems();
900 cmb_assSeq.addItem(new AssociateSeqOptions("-Select Associated Seq-",
902 lbl_associateSeq.setVisible(false);
903 if (selectedSequences.length > 1)
905 for (SequenceI seq : selectedSequences)
907 cmb_assSeq.addItem(new AssociateSeqOptions(seq));
912 String seqName = selectedSequence.getDisplayId(false);
913 seqName = seqName.length() <= 40 ? seqName : seqName.substring(0, 39);
914 lbl_associateSeq.setText(seqName);
915 lbl_associateSeq.setVisible(true);
916 cmb_assSeq.setVisible(false);
920 public boolean isStructuresDiscovered()
922 return structuresDiscovered;
925 public void setStructuresDiscovered(boolean structuresDiscovered)
927 this.structuresDiscovered = structuresDiscovered;
930 public Collection<PDBResponseSummary> getDiscoveredStructuresSet()
932 return discoveredStructuresSet;
936 protected void txt_search_ActionPerformed()
943 errorWarning.setLength(0);
944 isValidPBDEntry = false;
945 if (txt_search.getText().length() > 0)
947 List<PDBDocField> wantedFields = new ArrayList<PDBDocField>();
948 wantedFields.add(PDBDocField.PDB_ID);
949 PDBRestRequest pdbRequest = new PDBRestRequest();
950 pdbRequest.setAllowEmptySeq(false);
951 pdbRequest.setResponseSize(1);
952 pdbRequest.setFieldToSearchBy("(pdb_id:");
953 pdbRequest.setWantedFields(wantedFields);
955 .setSearchTerm(txt_search.getText().toLowerCase() + ")");
956 pdbRequest.setAssociatedSequence(selectedSequence);
957 pdbRestCleint = new PDBRestClient();
958 PDBRestResponse resultList;
961 resultList = pdbRestCleint.executeRequest(pdbRequest);
962 } catch (Exception e)
964 errorWarning.append(e.getMessage());
968 validateSelections();
970 if (resultList.getSearchSummary() != null
971 && resultList.getSearchSummary().size() > 0)
973 isValidPBDEntry = true;
976 validateSelections();
982 public void tabRefresh()
984 if (selectedSequences != null)
986 Thread refreshThread = new Thread(new Runnable()
991 fetchStructuresMetaData();
992 filterResultSet(((FilterOption) cmb_filterOption
993 .getSelectedItem()).getValue());
996 refreshThread.start();
1000 public class PDBEntryTableModel extends AbstractTableModel
1002 String[] columns = { "Ref Sequence", "PDB Id", "Chain", "Type", "File" };
1004 private List<CachedPDB> pdbEntries;
1006 public PDBEntryTableModel(List<CachedPDB> pdbEntries)
1008 this.pdbEntries = new ArrayList<CachedPDB>(pdbEntries);
1012 public String getColumnName(int columnIndex)
1014 return columns[columnIndex];
1018 public int getRowCount()
1020 return pdbEntries.size();
1024 public int getColumnCount()
1026 return columns.length;
1030 public boolean isCellEditable(int row, int column)
1036 public Object getValueAt(int rowIndex, int columnIndex)
1038 Object value = "??";
1039 CachedPDB entry = pdbEntries.get(rowIndex);
1040 switch (columnIndex)
1043 value = entry.getSequence();
1046 value = entry.getPdbEntry();
1049 value = entry.getPdbEntry().getChainCode() == null ? "_" : entry
1050 .getPdbEntry().getChainCode();
1053 value = entry.getPdbEntry().getType();
1056 value = entry.getPdbEntry().getFile();
1063 public Class<?> getColumnClass(int columnIndex)
1065 return columnIndex == 0 ? SequenceI.class : PDBEntry.class;
1068 public CachedPDB getPDBEntryAt(int row)
1070 return pdbEntries.get(row);
1075 private class CachedPDB
1077 private SequenceI sequence;
1079 private PDBEntry pdbEntry;
1081 public CachedPDB(SequenceI sequence, PDBEntry pdbEntry)
1083 this.sequence = sequence;
1084 this.pdbEntry = pdbEntry;
1087 public SequenceI getSequence()
1092 public PDBEntry getPdbEntry()
1099 private IProgressIndicator progressBar;
1102 public void setProgressBar(String message, long id)
1104 progressBar.setProgressBar(message, id);
1108 public void registerHandler(long id, IProgressIndicatorHandler handler)
1110 progressBar.registerHandler(id, handler);
1114 public boolean operationInProgress()
1116 return progressBar.operationInProgress();