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 // Update table selection model here
462 tbl_summary.addRowSelectionInterval(0, filterResponseCount - 1);
463 mainFrame.setTitle(MessageManager.formatMessage(
464 "label.structure_chooser_filter_time", totalTime));
468 mainFrame.setTitle(MessageManager.formatMessage(
469 "label.structure_chooser_filter_time", totalTime));
470 if (errors.size() > 0)
472 StringBuilder errorMsg = new StringBuilder();
473 for (String error : errors)
475 errorMsg.append(error).append("\n");
477 JOptionPane.showMessageDialog(
480 MessageManager.getString("label.pdb_web-service_error"),
481 JOptionPane.ERROR_MESSAGE);
485 lbl_loading.setVisible(false);
487 validateSelections();
490 filterThread.start();
494 * Handles action event for btn_pdbFromFile
497 public void pdbFromFile_actionPerformed()
499 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
500 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
501 chooser.setFileView(new jalview.io.JalviewFileView());
502 chooser.setDialogTitle(MessageManager.formatMessage(
503 "label.select_pdb_file_for",
504 selectedSequence.getDisplayId(false)));
505 chooser.setToolTipText(MessageManager.formatMessage(
506 "label.load_pdb_file_associate_with_sequence",
507 selectedSequence.getDisplayId(false)));
509 int value = chooser.showOpenDialog(null);
510 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
512 selectedPdbFileName = chooser.getSelectedFile().getPath();
513 jalview.bin.Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName);
514 validateSelections();
519 * Populates the filter combo-box options dynamically depending on discovered
523 protected void populateFilterComboBox()
525 if (isStructuresDiscovered())
527 cmb_filterOption.addItem(new FilterOption("Best Quality",
528 PDBDocField.OVERALL_QUALITY.getCode(), VIEWS_FILTER));
529 cmb_filterOption.addItem(new FilterOption("Most UniProt Coverage",
530 PDBDocField.UNIPROT_COVERAGE.getCode(), VIEWS_FILTER));
531 cmb_filterOption.addItem(new FilterOption("Best Resolution",
532 PDBDocField.RESOLUTION.getCode(), VIEWS_FILTER));
533 cmb_filterOption.addItem(new FilterOption("Most Protein Chain",
534 PDBDocField.PROTEIN_CHAIN_COUNT.getCode(), VIEWS_FILTER));
535 cmb_filterOption.addItem(new FilterOption("Most Bound Molecules",
536 PDBDocField.BOUND_MOLECULE_COUNT.getCode(), VIEWS_FILTER));
537 cmb_filterOption.addItem(new FilterOption("Most Polymer Residues",
538 PDBDocField.POLYMER_RESIDUE_COUNT.getCode(), VIEWS_FILTER));
540 cmb_filterOption.addItem(new FilterOption("Enter PDB Id", "-",
542 cmb_filterOption.addItem(new FilterOption("From File", "-",
544 cmb_filterOption.addItem(new FilterOption("Cached PDB Entries", "-",
549 * Updates the displayed view based on the selected filter option
552 protected void updateCurrentView()
554 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
556 layout_switchableViews.show(pnl_switchableViews,
557 selectedFilterOpt.getView());
558 String filterTitle = mainFrame.getTitle();
559 mainFrame.setTitle(frameTitle);
560 chk_invertFilter.setVisible(false);
561 if (selectedFilterOpt.getView() == VIEWS_FILTER)
563 mainFrame.setTitle(filterTitle);
564 chk_invertFilter.setVisible(true);
565 filterResultSet(selectedFilterOpt.getValue());
567 else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
568 || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
570 mainFrame.setTitle(MessageManager
571 .getString("label.structure_chooser_manual_association"));
572 idInputAssSeqPanel.loadCmbAssSeq();
573 fileChooserAssSeqPanel.loadCmbAssSeq();
575 validateSelections();
579 * Validates user selection and activates the view button if all parameters
583 public void validateSelections()
585 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
587 btn_view.setEnabled(false);
588 String currentView = selectedFilterOpt.getView();
589 if (currentView == VIEWS_FILTER)
591 if (tbl_summary.getSelectedRows().length > 0)
593 btn_view.setEnabled(true);
596 else if (currentView == VIEWS_LOCAL_PDB)
598 if (tbl_local_pdb.getSelectedRows().length > 0)
600 btn_view.setEnabled(true);
603 else if (currentView == VIEWS_ENTER_ID)
605 validateAssociationEnterPdb();
607 else if (currentView == VIEWS_FROM_FILE)
609 validateAssociationFromFile();
614 * Validates inputs from the Manual PDB entry panel
616 public void validateAssociationEnterPdb()
618 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel
619 .getCmb_assSeq().getSelectedItem();
620 lbl_pdbManualFetchStatus.setIcon(errorImage);
621 lbl_pdbManualFetchStatus.setToolTipText("");
622 if (txt_search.getText().length() > 0)
624 lbl_pdbManualFetchStatus
625 .setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
626 .formatMessage("info.no_pdb_entry_found_for",
627 txt_search.getText())));
630 if (errorWarning.length() > 0)
632 lbl_pdbManualFetchStatus.setIcon(warningImage);
633 lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip(
634 true, errorWarning.toString()));
637 if (selectedSequences.length == 1
638 || !assSeqOpt.getName().equalsIgnoreCase(
639 "-Select Associated Seq-"))
641 txt_search.setEnabled(true);
644 btn_view.setEnabled(true);
645 lbl_pdbManualFetchStatus.setToolTipText("");
646 lbl_pdbManualFetchStatus.setIcon(goodImage);
651 txt_search.setEnabled(false);
652 lbl_pdbManualFetchStatus.setIcon(errorImage);
657 * Validates inputs for the manual PDB file selection options
659 public void validateAssociationFromFile()
661 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
662 .getCmb_assSeq().getSelectedItem();
663 lbl_fromFileStatus.setIcon(errorImage);
664 if (selectedSequences.length == 1
665 || (assSeqOpt != null && !assSeqOpt.getName().equalsIgnoreCase(
666 "-Select Associated Seq-")))
668 btn_pdbFromFile.setEnabled(true);
669 if (selectedPdbFileName != null && selectedPdbFileName.length() > 0)
671 btn_view.setEnabled(true);
672 lbl_fromFileStatus.setIcon(goodImage);
677 btn_pdbFromFile.setEnabled(false);
678 lbl_fromFileStatus.setIcon(errorImage);
683 public void cmbAssSeqStateChanged()
685 validateSelections();
689 * Handles the state change event for the 'filter' combo-box and 'invert'
693 protected void stateChanged(ItemEvent e)
695 if (e.getSource() instanceof JCheckBox)
701 if (e.getStateChange() == ItemEvent.SELECTED)
710 * Handles action event for btn_ok
713 public void ok_ActionPerformed()
715 final long progressSessionId = System.currentTimeMillis();
716 final StructureSelectionManager ssm = ap.getStructureSelectionManager();
717 ssm.setProgressIndicator(this);
718 ssm.setProgressSessionId(progressSessionId);
719 new Thread(new Runnable()
724 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
726 String currentView = selectedFilterOpt.getView();
727 if (currentView == VIEWS_FILTER)
729 int pdbIdColIndex = tbl_summary.getColumn(
730 PDBRestClient.PDBDocField.PDB_ID.getName()).getModelIndex();
731 int refSeqColIndex = tbl_summary.getColumn("Ref Sequence")
733 int[] selectedRows = tbl_summary.getSelectedRows();
734 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
736 ArrayList<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
737 for (int row : selectedRows)
739 String pdbIdStr = tbl_summary.getValueAt(row, pdbIdColIndex)
741 SequenceI selectedSeq = (SequenceI) tbl_summary.getValueAt(row,
743 selectedSeqsToView.add(selectedSeq);
744 PDBEntry pdbEntry = selectedSeq.getPDBEntry(pdbIdStr);
745 if (pdbEntry == null)
747 pdbEntry = getFindEntry(pdbIdStr,
748 selectedSeq.getAllPDBEntries());
750 if (pdbEntry == null)
752 pdbEntry = new PDBEntry();
753 pdbEntry.setId(pdbIdStr);
754 pdbEntry.setType(PDBEntry.Type.PDB);
755 selectedSeq.getDatasetSequence().addPDBId(pdbEntry);
757 pdbEntriesToView[count++] = pdbEntry;
759 SequenceI[] selectedSeqs = selectedSeqsToView
760 .toArray(new SequenceI[selectedSeqsToView.size()]);
761 launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
763 else if (currentView == VIEWS_LOCAL_PDB)
765 int[] selectedRows = tbl_local_pdb.getSelectedRows();
766 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
768 int pdbIdColIndex = tbl_local_pdb.getColumn(
769 PDBRestClient.PDBDocField.PDB_ID.getName()).getModelIndex();
770 int refSeqColIndex = tbl_local_pdb.getColumn("Ref Sequence")
772 ArrayList<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
773 for (int row : selectedRows)
775 PDBEntry pdbEntry = (PDBEntry) tbl_local_pdb.getValueAt(row,
777 pdbEntriesToView[count++] = pdbEntry;
778 SequenceI selectedSeq = (SequenceI) tbl_local_pdb.getValueAt(row,
780 selectedSeqsToView.add(selectedSeq);
782 SequenceI[] selectedSeqs = selectedSeqsToView
783 .toArray(new SequenceI[selectedSeqsToView.size()]);
784 launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
786 else if (currentView == VIEWS_ENTER_ID)
788 SequenceI userSelectedSeq = ((AssociateSeqOptions) idInputAssSeqPanel
789 .getCmb_assSeq().getSelectedItem()).getSequence();
790 if (userSelectedSeq != null)
792 selectedSequence = userSelectedSeq;
795 String pdbIdStr = txt_search.getText();
796 PDBEntry pdbEntry = selectedSequence.getPDBEntry(pdbIdStr);
797 if (pdbEntry == null)
799 pdbEntry = new PDBEntry();
800 pdbEntry.setId(pdbIdStr);
801 pdbEntry.setType(PDBEntry.Type.PDB);
802 selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
805 PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
806 launchStructureViewer(ssm, pdbEntriesToView, ap,
807 new SequenceI[] { selectedSequence });
809 else if (currentView == VIEWS_FROM_FILE)
811 SequenceI userSelectedSeq = ((AssociateSeqOptions) fileChooserAssSeqPanel
812 .getCmb_assSeq().getSelectedItem()).getSequence();
813 if (userSelectedSeq != null)
815 selectedSequence = userSelectedSeq;
817 PDBEntry fileEntry = new AssociatePdbFileWithSeq()
818 .associatePdbWithSeq(selectedPdbFileName,
819 jalview.io.AppletFormatAdapter.FILE,
820 selectedSequence, true, Desktop.instance);
822 launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
823 new SequenceI[] { selectedSequence });
830 private PDBEntry getFindEntry(String id, Vector<PDBEntry> pdbEntries)
832 Objects.requireNonNull(id);
833 Objects.requireNonNull(pdbEntries);
834 PDBEntry foundEntry = null;
835 for (PDBEntry entry : pdbEntries)
837 if (entry.getId().equalsIgnoreCase(id))
845 private void launchStructureViewer(StructureSelectionManager ssm,
846 final PDBEntry[] pdbEntriesToView,
847 final AlignmentPanel alignPanel, SequenceI[] sequences)
849 ssm.setProgressBar("Launching PDB structure viewer..");
850 final StructureViewer sViewer = new StructureViewer(ssm);
852 if (SiftsSettings.isMapWithSifts())
854 for (SequenceI seq : sequences)
856 if (seq.getSourceDBRef() == null)
858 ssm.setProgressBar(null);
859 ssm.setProgressBar("Fetching Database refs..");
860 new jalview.ws.DBRefFetcher(sequences, null, null, null, false)
866 if (pdbEntriesToView.length > 1)
868 ArrayList<SequenceI[]> seqsMap = new ArrayList<SequenceI[]>();
869 for (SequenceI seq : sequences)
871 seqsMap.add(new SequenceI[] { seq });
873 SequenceI[][] collatedSeqs = seqsMap.toArray(new SequenceI[0][0]);
874 ssm.setProgressBar(null);
875 ssm.setProgressBar("Fetching PDB Structures for selected entries..");
876 sViewer.viewStructures(pdbEntriesToView, collatedSeqs, alignPanel);
880 ssm.setProgressBar(null);
881 ssm.setProgressBar("Fetching PDB Structure for "
882 + pdbEntriesToView[0].getId());
883 sViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
888 * Populates the combo-box used in associating manually fetched structures to
889 * a unique sequence when more than one sequence selection is made.
892 public void populateCmbAssociateSeqOptions(
893 JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq)
895 cmb_assSeq.removeAllItems();
896 cmb_assSeq.addItem(new AssociateSeqOptions("-Select Associated Seq-",
898 lbl_associateSeq.setVisible(false);
899 if (selectedSequences.length > 1)
901 for (SequenceI seq : selectedSequences)
903 cmb_assSeq.addItem(new AssociateSeqOptions(seq));
908 String seqName = selectedSequence.getDisplayId(false);
909 seqName = seqName.length() <= 40 ? seqName : seqName.substring(0, 39);
910 lbl_associateSeq.setText(seqName);
911 lbl_associateSeq.setVisible(true);
912 cmb_assSeq.setVisible(false);
916 public boolean isStructuresDiscovered()
918 return structuresDiscovered;
921 public void setStructuresDiscovered(boolean structuresDiscovered)
923 this.structuresDiscovered = structuresDiscovered;
926 public Collection<PDBResponseSummary> getDiscoveredStructuresSet()
928 return discoveredStructuresSet;
932 protected void txt_search_ActionPerformed()
939 errorWarning.setLength(0);
940 isValidPBDEntry = false;
941 if (txt_search.getText().length() > 0)
943 List<PDBDocField> wantedFields = new ArrayList<PDBDocField>();
944 wantedFields.add(PDBDocField.PDB_ID);
945 PDBRestRequest pdbRequest = new PDBRestRequest();
946 pdbRequest.setAllowEmptySeq(false);
947 pdbRequest.setResponseSize(1);
948 pdbRequest.setFieldToSearchBy("(pdb_id:");
949 pdbRequest.setWantedFields(wantedFields);
951 .setSearchTerm(txt_search.getText().toLowerCase() + ")");
952 pdbRequest.setAssociatedSequence(selectedSequence);
953 pdbRestCleint = new PDBRestClient();
954 PDBRestResponse resultList;
957 resultList = pdbRestCleint.executeRequest(pdbRequest);
958 } catch (Exception e)
960 errorWarning.append(e.getMessage());
964 validateSelections();
966 if (resultList.getSearchSummary() != null
967 && resultList.getSearchSummary().size() > 0)
969 isValidPBDEntry = true;
972 validateSelections();
978 public void tabRefresh()
980 if (selectedSequences != null)
982 Thread refreshThread = new Thread(new Runnable()
987 fetchStructuresMetaData();
988 filterResultSet(((FilterOption) cmb_filterOption
989 .getSelectedItem()).getValue());
992 refreshThread.start();
996 public class PDBEntryTableModel extends AbstractTableModel
998 String[] columns = { "Ref Sequence", "PDB Id", "Chain", "Type", "File" };
1000 private List<CachedPDB> pdbEntries;
1002 public PDBEntryTableModel(List<CachedPDB> pdbEntries)
1004 this.pdbEntries = new ArrayList<CachedPDB>(pdbEntries);
1008 public String getColumnName(int columnIndex)
1010 return columns[columnIndex];
1014 public int getRowCount()
1016 return pdbEntries.size();
1020 public int getColumnCount()
1022 return columns.length;
1026 public boolean isCellEditable(int row, int column)
1032 public Object getValueAt(int rowIndex, int columnIndex)
1034 Object value = "??";
1035 CachedPDB entry = pdbEntries.get(rowIndex);
1036 switch (columnIndex)
1039 value = entry.getSequence();
1042 value = entry.getPdbEntry();
1045 value = entry.getPdbEntry().getChainCode() == null ? "_" : entry
1046 .getPdbEntry().getChainCode();
1049 value = entry.getPdbEntry().getType();
1052 value = entry.getPdbEntry().getFile();
1059 public Class<?> getColumnClass(int columnIndex)
1061 return columnIndex == 0 ? SequenceI.class : PDBEntry.class;
1064 public CachedPDB getPDBEntryAt(int row)
1066 return pdbEntries.get(row);
1071 private class CachedPDB
1073 private SequenceI sequence;
1075 private PDBEntry pdbEntry;
1077 public CachedPDB(SequenceI sequence, PDBEntry pdbEntry)
1079 this.sequence = sequence;
1080 this.pdbEntry = pdbEntry;
1083 public SequenceI getSequence()
1088 public PDBEntry getPdbEntry()
1095 private IProgressIndicator progressBar;
1098 public void setProgressBar(String message, long id)
1100 progressBar.setProgressBar(message, id);
1104 public void registerHandler(long id, IProgressIndicatorHandler handler)
1106 progressBar.registerHandler(id, handler);
1110 public boolean operationInProgress()
1112 return progressBar.operationInProgress();