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.api.structures.JalviewStructureDisplayI;
25 import jalview.bin.Cache;
26 import jalview.bin.Jalview;
27 import jalview.datamodel.DBRefEntry;
28 import jalview.datamodel.DBRefSource;
29 import jalview.datamodel.PDBEntry;
30 import jalview.datamodel.SequenceI;
31 import jalview.fts.api.FTSData;
32 import jalview.fts.api.FTSDataColumnI;
33 import jalview.fts.api.FTSRestClientI;
34 import jalview.fts.core.FTSDataColumnPreferences;
35 import jalview.fts.core.FTSRestRequest;
36 import jalview.fts.core.FTSRestResponse;
37 import jalview.fts.service.pdb.PDBFTSRestClient;
38 import jalview.gui.structurechooser.PDBStructureChooserQuerySource;
39 import jalview.gui.structurechooser.StructureChooserQuerySource;
40 import jalview.io.DataSourceType;
41 import jalview.jbgui.FilterOption;
42 import jalview.jbgui.GStructureChooser;
43 import jalview.structure.StructureMapping;
44 import jalview.structure.StructureSelectionManager;
45 import jalview.util.MessageManager;
46 import jalview.ws.DBRefFetcher;
47 import jalview.ws.sifts.SiftsSettings;
49 import java.awt.event.ItemEvent;
50 import java.util.ArrayList;
51 import java.util.Collection;
52 import java.util.HashSet;
53 import java.util.LinkedHashSet;
54 import java.util.List;
55 import java.util.Objects;
57 import java.util.Vector;
59 import javax.swing.JCheckBox;
60 import javax.swing.JComboBox;
61 import javax.swing.JLabel;
62 import javax.swing.JTable;
63 import javax.swing.SwingUtilities;
64 import javax.swing.table.AbstractTableModel;
67 * Provides the behaviors for the Structure chooser Panel
72 @SuppressWarnings("serial")
73 public class StructureChooser extends GStructureChooser
74 implements IProgressIndicator
76 private static final String AUTOSUPERIMPOSE = "AUTOSUPERIMPOSE";
78 private SequenceI selectedSequence;
80 private SequenceI[] selectedSequences;
82 private IProgressIndicator progressIndicator;
84 private Collection<FTSData> discoveredStructuresSet;
86 private StructureChooserQuerySource data;
89 protected FTSDataColumnPreferences getFTSDocFieldPrefs()
91 return data.getDocFieldPrefs();
94 private String selectedPdbFileName;
96 private boolean isValidPBDEntry;
98 private boolean cachedPDBExists;
100 private Collection<FTSData> lastDiscoveredStructuresSet;
102 private static StructureViewer lastTargetedView = null;
104 public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
107 // which FTS engine to use
108 data = StructureChooserQuerySource
109 .getQuerySourceFor(selectedSeqs);
113 this.selectedSequence = selectedSeq;
114 this.selectedSequences = selectedSeqs;
115 this.progressIndicator = (ap == null) ? null : ap.alignFrame;
121 * Initializes parameters used by the Structure Chooser Panel
123 protected void init()
125 if (!Jalview.isHeadlessMode())
127 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
130 chk_superpose.setSelected(Cache.getDefault(AUTOSUPERIMPOSE, true));
132 // ensure a filter option is in force for search
133 populateFilterComboBox(true, cachedPDBExists);
134 Thread discoverPDBStructuresThread = new Thread(new Runnable()
139 // looks for any existing structures already loaded
140 // for the sequences (the cached ones)
141 // then queries the StructureChooserQuerySource to
142 // discover more structures.
144 // Possible optimisation is to only begin querying
145 // the structure chooser if there are no cached structures.
147 long startTime = System.currentTimeMillis();
148 updateProgressIndicator(MessageManager
149 .getString("status.loading_cached_pdb_entries"), startTime);
150 loadLocalCachedPDBEntries();
151 updateProgressIndicator(null, startTime);
152 updateProgressIndicator(MessageManager.getString(
153 "status.searching_for_pdb_structures"), startTime);
154 fetchStructuresMetaData();
155 // revise filter options if no results were found
156 populateFilterComboBox(isStructuresDiscovered(), cachedPDBExists);
157 discoverStructureViews();
158 updateProgressIndicator(null, startTime);
159 mainFrame.setVisible(true);
163 discoverPDBStructuresThread.start();
167 * Builds a drop-down choice list of existing structure viewers to which new
168 * structures may be added. If this list is empty then it, and the 'Add'
169 * button, are hidden.
171 private void discoverStructureViews()
173 if (Desktop.instance != null)
175 targetView.removeAllItems();
176 if (lastTargetedView != null && !lastTargetedView.isVisible())
178 lastTargetedView = null;
180 int linkedViewsAt = 0;
181 for (StructureViewerBase view : Desktop.instance
182 .getStructureViewers(null, null))
184 StructureViewer viewHandler = (lastTargetedView != null
185 && lastTargetedView.sview == view) ? lastTargetedView
186 : StructureViewer.reconfigure(view);
188 if (view.isLinkedWith(ap))
190 targetView.insertItemAt(viewHandler, linkedViewsAt++);
194 targetView.addItem(viewHandler);
199 * show option to Add to viewer if at least 1 viewer found
201 targetView.setVisible(false);
202 if (targetView.getItemCount() > 0)
204 targetView.setVisible(true);
205 if (lastTargetedView != null)
207 targetView.setSelectedItem(lastTargetedView);
211 targetView.setSelectedIndex(0);
214 btn_add.setVisible(targetView.isVisible());
219 * Updates the progress indicator with the specified message
222 * displayed message for the operation
224 * unique handle for this indicator
226 protected void updateProgressIndicator(String message, long id)
228 if (progressIndicator != null)
230 progressIndicator.setProgressBar(message, id);
235 * Retrieve meta-data for all the structure(s) for a given sequence(s) in a
238 void fetchStructuresMetaData()
240 long startTime = System.currentTimeMillis();
241 Collection<FTSDataColumnI> wantedFields = data.getDocFieldPrefs()
242 .getStructureSummaryFields();
244 discoveredStructuresSet = new LinkedHashSet<>();
245 HashSet<String> errors = new HashSet<>();
247 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
250 for (SequenceI seq : selectedSequences)
253 FTSRestResponse resultList;
256 resultList = data.fetchStructuresMetaData(seq, wantedFields,
257 selectedFilterOpt, !chk_invertFilter.isSelected());
258 // null response means the FTSengine didn't yield a query for this
259 // consider designing a special exception if we really wanted to be OOCrazy
260 if (resultList==null)
264 } catch (Exception e)
267 errors.add(e.getMessage());
270 if (resultList.getSearchSummary() != null
271 && !resultList.getSearchSummary().isEmpty())
273 discoveredStructuresSet.addAll(resultList.getSearchSummary());
277 int noOfStructuresFound = 0;
278 String totalTime = (System.currentTimeMillis() - startTime)
280 if (discoveredStructuresSet != null
281 && !discoveredStructuresSet.isEmpty())
284 .setModel(data.getTableModel(discoveredStructuresSet));
286 noOfStructuresFound = discoveredStructuresSet.size();
287 lastDiscoveredStructuresSet=discoveredStructuresSet;
288 mainFrame.setTitle(MessageManager.formatMessage(
289 "label.structure_chooser_no_of_structures",
290 noOfStructuresFound, totalTime));
294 mainFrame.setTitle(MessageManager
295 .getString("label.structure_chooser_manual_association"));
296 if (errors.size() > 0)
298 StringBuilder errorMsg = new StringBuilder();
299 for (String error : errors)
301 errorMsg.append(error).append("\n");
303 JvOptionPane.showMessageDialog(this, errorMsg.toString(),
304 MessageManager.getString("label.pdb_web-service_error"),
305 JvOptionPane.ERROR_MESSAGE);
310 protected void loadLocalCachedPDBEntries()
312 ArrayList<CachedPDB> entries = new ArrayList<>();
313 for (SequenceI seq : selectedSequences)
315 if (seq.getDatasetSequence() != null
316 && seq.getDatasetSequence().getAllPDBEntries() != null)
318 for (PDBEntry pdbEntry : seq.getDatasetSequence()
321 if (pdbEntry.getFile() != null)
323 entries.add(new CachedPDB(seq, pdbEntry));
328 cachedPDBExists = !entries.isEmpty();
329 PDBEntryTableModel tableModelx = new PDBEntryTableModel(entries);
330 tbl_local_pdb.setModel(tableModelx);
334 * Filters a given list of discovered structures based on supplied argument
336 * @param fieldToFilterBy
337 * the field to filter by
339 void filterResultSet(final String fieldToFilterBy)
341 Thread filterThread = new Thread(new Runnable()
347 long startTime = System.currentTimeMillis();
348 lbl_loading.setVisible(true);
349 Collection<FTSDataColumnI> wantedFields = data.getDocFieldPrefs()
350 .getStructureSummaryFields();
351 Collection<FTSData> filteredResponse = new HashSet<>();
352 HashSet<String> errors = new HashSet<>();
354 for (SequenceI seq : selectedSequences)
357 FTSRestResponse resultList;
360 resultList = data.selectFirstRankedQuery(seq, discoveredStructuresSet,wantedFields,
361 fieldToFilterBy, !chk_invertFilter.isSelected());
363 } catch (Exception e)
366 errors.add(e.getMessage());
369 if (resultList.getSearchSummary() != null
370 && !resultList.getSearchSummary().isEmpty())
372 filteredResponse.addAll(resultList.getSearchSummary());
376 String totalTime = (System.currentTimeMillis() - startTime)
378 if (!filteredResponse.isEmpty())
380 final int filterResponseCount = filteredResponse.size();
381 Collection<FTSData> reorderedStructuresSet = new LinkedHashSet<>();
382 reorderedStructuresSet.addAll(filteredResponse);
383 reorderedStructuresSet.addAll(discoveredStructuresSet);
385 .setModel(data.getTableModel(reorderedStructuresSet));
387 FTSRestResponse.configureTableColumn(getResultTable(),
388 wantedFields, tempUserPrefs);
389 getResultTable().getColumn("Ref Sequence").setPreferredWidth(120);
390 getResultTable().getColumn("Ref Sequence").setMinWidth(100);
391 getResultTable().getColumn("Ref Sequence").setMaxWidth(200);
392 // Update table selection model here
393 getResultTable().addRowSelectionInterval(0,
394 filterResponseCount - 1);
395 mainFrame.setTitle(MessageManager.formatMessage(
396 "label.structure_chooser_filter_time", totalTime));
400 mainFrame.setTitle(MessageManager.formatMessage(
401 "label.structure_chooser_filter_time", totalTime));
402 if (errors.size() > 0)
404 StringBuilder errorMsg = new StringBuilder();
405 for (String error : errors)
407 errorMsg.append(error).append("\n");
409 JvOptionPane.showMessageDialog(null, errorMsg.toString(),
410 MessageManager.getString("label.pdb_web-service_error"),
411 JvOptionPane.ERROR_MESSAGE);
415 lbl_loading.setVisible(false);
417 validateSelections();
420 filterThread.start();
424 * Handles action event for btn_pdbFromFile
427 protected void pdbFromFile_actionPerformed()
429 // TODO: JAL-3048 not needed for Jalview-JS until JSmol dep and
432 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
433 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
434 chooser.setFileView(new jalview.io.JalviewFileView());
435 chooser.setDialogTitle(
436 MessageManager.formatMessage("label.select_pdb_file_for",
437 selectedSequence.getDisplayId(false)));
438 chooser.setToolTipText(MessageManager.formatMessage(
439 "label.load_pdb_file_associate_with_sequence",
440 selectedSequence.getDisplayId(false)));
442 int value = chooser.showOpenDialog(null);
443 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
445 selectedPdbFileName = chooser.getSelectedFile().getPath();
446 jalview.bin.Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName);
447 validateSelections();
452 * Populates the filter combo-box options dynamically depending on discovered
455 protected void populateFilterComboBox(boolean haveData,
456 boolean cachedPDBExist)
458 populateFilterComboBox(haveData, cachedPDBExist, null);
461 * Populates the filter combo-box options dynamically depending on discovered
464 protected void populateFilterComboBox(boolean haveData,
465 boolean cachedPDBExist, FilterOption lastSel)
469 * temporarily suspend the change listener behaviour
471 cmb_filterOption.removeItemListener(this);
473 cmb_filterOption.removeAllItems();
476 List<FilterOption> filters = data.getAvailableFilterOptions(VIEWS_FILTER);
477 data.updateAvailableFilterOptions(VIEWS_FILTER, filters, lastDiscoveredStructuresSet);
479 for (FilterOption filter:filters)
481 if (lastSel!=null && filter.equals(lastSel)) {
485 cmb_filterOption.addItem(filter);
488 cmb_filterOption.addItem(
489 new FilterOption(MessageManager.getString("label.enter_pdb_id"),
490 "-", VIEWS_ENTER_ID, false,null));
491 cmb_filterOption.addItem(
492 new FilterOption(MessageManager.getString("label.from_file"),
493 "-", VIEWS_FROM_FILE, false,null));
497 FilterOption cachedOption = new FilterOption(
498 MessageManager.getString("label.cached_structures"), "-",
499 VIEWS_LOCAL_PDB, false,null);
500 cmb_filterOption.addItem(cachedOption);
502 cmb_filterOption.setSelectedItem(cachedOption);
507 cmb_filterOption.setSelectedIndex(selSet);
509 cmb_filterOption.addItemListener(this);
513 * Updates the displayed view based on the selected filter option
515 protected void updateCurrentView()
517 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
519 layout_switchableViews.show(pnl_switchableViews,
520 selectedFilterOpt.getView());
521 String filterTitle = mainFrame.getTitle();
522 mainFrame.setTitle(frameTitle);
523 chk_invertFilter.setVisible(false);
524 if (selectedFilterOpt.getView() == VIEWS_FILTER)
526 mainFrame.setTitle(filterTitle);
527 // TDB Query has no invert as yet
528 chk_invertFilter.setVisible(selectedFilterOpt.getQuerySource() instanceof PDBStructureChooserQuerySource);
530 if (data!=selectedFilterOpt.getQuerySource() || data.needsRefetch(selectedFilterOpt))
532 data = selectedFilterOpt.getQuerySource();
533 // rebuild the views completely, since prefs will also change
537 filterResultSet(selectedFilterOpt.getValue());
540 else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
541 || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
543 mainFrame.setTitle(MessageManager
544 .getString("label.structure_chooser_manual_association"));
545 idInputAssSeqPanel.loadCmbAssSeq();
546 fileChooserAssSeqPanel.loadCmbAssSeq();
548 validateSelections();
552 * Validates user selection and enables the 'Add' and 'New View' buttons if
553 * all parameters are correct (the Add button will only be visible if there is
554 * at least one existing structure viewer open). This basically means at least
555 * one structure selected and no error messages.
557 * The 'Superpose Structures' option is enabled if either more than one
558 * structure is selected, or the 'Add' to existing view option is enabled, and
559 * disabled if the only option is to open a new view of a single structure.
562 protected void validateSelections()
564 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
566 btn_add.setEnabled(false);
567 String currentView = selectedFilterOpt.getView();
568 int selectedCount = 0;
569 if (currentView == VIEWS_FILTER)
571 selectedCount = getResultTable().getSelectedRows().length;
572 if (selectedCount > 0)
574 btn_add.setEnabled(true);
577 else if (currentView == VIEWS_LOCAL_PDB)
579 selectedCount = tbl_local_pdb.getSelectedRows().length;
580 if (selectedCount > 0)
582 btn_add.setEnabled(true);
585 else if (currentView == VIEWS_ENTER_ID)
587 validateAssociationEnterPdb();
589 else if (currentView == VIEWS_FROM_FILE)
591 validateAssociationFromFile();
594 btn_newView.setEnabled(btn_add.isEnabled());
597 * enable 'Superpose' option if more than one structure is selected,
598 * or there are view(s) available to add structure(s) to
601 .setEnabled(selectedCount > 1 || targetView.getItemCount() > 0);
605 * Validates inputs from the Manual PDB entry panel
607 protected void validateAssociationEnterPdb()
609 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel
610 .getCmb_assSeq().getSelectedItem();
611 lbl_pdbManualFetchStatus.setIcon(errorImage);
612 lbl_pdbManualFetchStatus.setToolTipText("");
613 if (txt_search.getText().length() > 0)
615 lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip(true,
616 MessageManager.formatMessage("info.no_pdb_entry_found_for",
617 txt_search.getText())));
620 if (errorWarning.length() > 0)
622 lbl_pdbManualFetchStatus.setIcon(warningImage);
623 lbl_pdbManualFetchStatus.setToolTipText(
624 JvSwingUtils.wrapTooltip(true, errorWarning.toString()));
627 if (selectedSequences.length == 1 || !assSeqOpt.getName()
628 .equalsIgnoreCase("-Select Associated Seq-"))
630 txt_search.setEnabled(true);
633 btn_add.setEnabled(true);
634 lbl_pdbManualFetchStatus.setToolTipText("");
635 lbl_pdbManualFetchStatus.setIcon(goodImage);
640 txt_search.setEnabled(false);
641 lbl_pdbManualFetchStatus.setIcon(errorImage);
646 * Validates inputs for the manual PDB file selection options
648 protected void validateAssociationFromFile()
650 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
651 .getCmb_assSeq().getSelectedItem();
652 lbl_fromFileStatus.setIcon(errorImage);
653 if (selectedSequences.length == 1 || (assSeqOpt != null && !assSeqOpt
654 .getName().equalsIgnoreCase("-Select Associated Seq-")))
656 btn_pdbFromFile.setEnabled(true);
657 if (selectedPdbFileName != null && selectedPdbFileName.length() > 0)
659 btn_add.setEnabled(true);
660 lbl_fromFileStatus.setIcon(goodImage);
665 btn_pdbFromFile.setEnabled(false);
666 lbl_fromFileStatus.setIcon(errorImage);
671 protected void cmbAssSeqStateChanged()
673 validateSelections();
677 * Handles the state change event for the 'filter' combo-box and 'invert'
681 protected void stateChanged(ItemEvent e)
683 if (e.getSource() instanceof JCheckBox)
689 if (e.getStateChange() == ItemEvent.SELECTED)
698 * select structures for viewing by their PDB IDs
701 * @return true if structures were found and marked as selected
703 public boolean selectStructure(String... pdbids)
705 boolean found = false;
707 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
709 String currentView = selectedFilterOpt.getView();
710 JTable restable = (currentView == VIEWS_FILTER) ? getResultTable()
711 : (currentView == VIEWS_LOCAL_PDB) ? tbl_local_pdb : null;
713 if (restable == null)
715 // can't select (enter PDB ID, or load file - need to also select which
716 // sequence to associate with)
720 int pdbIdColIndex = restable.getColumn("PDB Id").getModelIndex();
721 for (int r = 0; r < restable.getRowCount(); r++)
723 for (int p = 0; p < pdbids.length; p++)
725 if (String.valueOf(restable.getValueAt(r, pdbIdColIndex))
726 .equalsIgnoreCase(pdbids[p]))
728 restable.setRowSelectionInterval(r, r);
737 * Handles the 'New View' action
740 protected void newView_ActionPerformed()
742 targetView.setSelectedItem(null);
743 showStructures(false);
747 * Handles the 'Add to existing viewer' action
750 protected void add_ActionPerformed()
752 showStructures(false);
756 * structure viewer opened by this dialog, or null
758 private StructureViewer sViewer = null;
760 public void showStructures(boolean waitUntilFinished)
763 final StructureSelectionManager ssm = ap.getStructureSelectionManager();
765 final int preferredHeight = pnl_filter.getHeight();
767 Runnable viewStruc = new Runnable()
772 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
774 String currentView = selectedFilterOpt.getView();
775 JTable restable = (currentView == VIEWS_FILTER) ? getResultTable()
778 if (currentView == VIEWS_FILTER)
780 int[] selectedRows = restable.getSelectedRows();
781 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
782 List<SequenceI> selectedSeqsToView = new ArrayList<>();
783 pdbEntriesToView = data.collectSelectedRows(restable,selectedRows,selectedSeqsToView);
785 SequenceI[] selectedSeqs = selectedSeqsToView
786 .toArray(new SequenceI[selectedSeqsToView.size()]);
787 sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
790 else if (currentView == VIEWS_LOCAL_PDB)
792 int[] selectedRows = tbl_local_pdb.getSelectedRows();
793 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
795 int pdbIdColIndex = tbl_local_pdb.getColumn("PDB Id")
797 int refSeqColIndex = tbl_local_pdb.getColumn("Ref Sequence")
799 List<SequenceI> selectedSeqsToView = new ArrayList<>();
800 for (int row : selectedRows)
802 PDBEntry pdbEntry = (PDBEntry) tbl_local_pdb.getValueAt(row,
804 pdbEntriesToView[count++] = pdbEntry;
805 SequenceI selectedSeq = (SequenceI) tbl_local_pdb
806 .getValueAt(row, refSeqColIndex);
807 selectedSeqsToView.add(selectedSeq);
809 SequenceI[] selectedSeqs = selectedSeqsToView
810 .toArray(new SequenceI[selectedSeqsToView.size()]);
811 sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
814 else if (currentView == VIEWS_ENTER_ID)
816 SequenceI userSelectedSeq = ((AssociateSeqOptions) idInputAssSeqPanel
817 .getCmb_assSeq().getSelectedItem()).getSequence();
818 if (userSelectedSeq != null)
820 selectedSequence = userSelectedSeq;
822 String pdbIdStr = txt_search.getText();
823 PDBEntry pdbEntry = selectedSequence.getPDBEntry(pdbIdStr);
824 if (pdbEntry == null)
826 pdbEntry = new PDBEntry();
827 if (pdbIdStr.split(":").length > 1)
829 pdbEntry.setId(pdbIdStr.split(":")[0]);
830 pdbEntry.setChainCode(pdbIdStr.split(":")[1].toUpperCase());
834 pdbEntry.setId(pdbIdStr);
836 pdbEntry.setType(PDBEntry.Type.PDB);
837 selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
840 PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
841 sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
843 { selectedSequence });
845 else if (currentView == VIEWS_FROM_FILE)
847 SequenceI userSelectedSeq = ((AssociateSeqOptions) fileChooserAssSeqPanel
848 .getCmb_assSeq().getSelectedItem()).getSequence();
849 if (userSelectedSeq != null)
851 selectedSequence = userSelectedSeq;
853 PDBEntry fileEntry = new AssociatePdbFileWithSeq()
854 .associatePdbWithSeq(selectedPdbFileName,
855 DataSourceType.FILE, selectedSequence, true,
858 sViewer = launchStructureViewer(ssm, new PDBEntry[] { fileEntry },
860 { selectedSequence });
862 SwingUtilities.invokeLater(new Runnable()
867 closeAction(preferredHeight);
873 Thread runner = new Thread(viewStruc);
875 if (waitUntilFinished)
877 while (sViewer == null ? runner.isAlive()
878 : (sViewer.sview == null ? true
879 : !sViewer.sview.hasMapping()))
884 } catch (InterruptedException ie)
893 * Answers a structure viewer (new or existing) configured to superimpose
894 * added structures or not according to the user's choice
899 StructureViewer getTargetedStructureViewer(StructureSelectionManager ssm)
901 Object sv = targetView.getSelectedItem();
903 return sv == null ? new StructureViewer(ssm) : (StructureViewer) sv;
907 * Adds PDB structures to a new or existing structure viewer
910 * @param pdbEntriesToView
915 private StructureViewer launchStructureViewer(
916 StructureSelectionManager ssm, final PDBEntry[] pdbEntriesToView,
917 final AlignmentPanel alignPanel, SequenceI[] sequences)
919 long progressId = sequences.hashCode();
920 setProgressBar(MessageManager
921 .getString("status.launching_3d_structure_viewer"), progressId);
922 final StructureViewer theViewer = getTargetedStructureViewer(ssm);
923 boolean superimpose = chk_superpose.isSelected();
924 theViewer.setSuperpose(superimpose);
927 * remember user's choice of superimpose or not
929 Cache.setProperty(AUTOSUPERIMPOSE,
930 Boolean.valueOf(superimpose).toString());
932 setProgressBar(null, progressId);
933 if (SiftsSettings.isMapWithSifts())
935 List<SequenceI> seqsWithoutSourceDBRef = new ArrayList<>();
937 // TODO: skip PDBEntry:Sequence pairs where PDBEntry doesn't look like a
938 // real PDB ID. For moment, we can also safely do this if there is already
939 // a known mapping between the PDBEntry and the sequence.
940 for (SequenceI seq : sequences)
942 PDBEntry pdbe = pdbEntriesToView[p++];
943 if (pdbe != null && pdbe.getFile() != null)
945 StructureMapping[] smm = ssm.getMapping(pdbe.getFile());
946 if (smm != null && smm.length > 0)
948 for (StructureMapping sm : smm)
950 if (sm.getSequence() == seq)
957 if (seq.getPrimaryDBRefs().isEmpty())
959 seqsWithoutSourceDBRef.add(seq);
963 if (!seqsWithoutSourceDBRef.isEmpty())
965 int y = seqsWithoutSourceDBRef.size();
966 setProgressBar(MessageManager.formatMessage(
967 "status.fetching_dbrefs_for_sequences_without_valid_refs",
969 SequenceI[] seqWithoutSrcDBRef = seqsWithoutSourceDBRef
970 .toArray(new SequenceI[y]);
971 DBRefFetcher dbRefFetcher = new DBRefFetcher(seqWithoutSrcDBRef);
972 dbRefFetcher.fetchDBRefs(true);
974 setProgressBar("Fetch complete.", progressId); // todo i18n
977 if (pdbEntriesToView.length > 1)
980 MessageManager.getString(
981 "status.fetching_3d_structures_for_selected_entries"),
983 theViewer.viewStructures(pdbEntriesToView, sequences, alignPanel);
987 setProgressBar(MessageManager.formatMessage(
988 "status.fetching_3d_structures_for",
989 pdbEntriesToView[0].getId()), progressId);
990 theViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
992 setProgressBar(null, progressId);
993 // remember the last viewer we used...
994 lastTargetedView = theViewer;
999 * Populates the combo-box used in associating manually fetched structures to
1000 * a unique sequence when more than one sequence selection is made.
1003 protected void populateCmbAssociateSeqOptions(
1004 JComboBox<AssociateSeqOptions> cmb_assSeq,
1005 JLabel lbl_associateSeq)
1007 cmb_assSeq.removeAllItems();
1009 new AssociateSeqOptions("-Select Associated Seq-", null));
1010 lbl_associateSeq.setVisible(false);
1011 if (selectedSequences.length > 1)
1013 for (SequenceI seq : selectedSequences)
1015 cmb_assSeq.addItem(new AssociateSeqOptions(seq));
1020 String seqName = selectedSequence.getDisplayId(false);
1021 seqName = seqName.length() <= 40 ? seqName : seqName.substring(0, 39);
1022 lbl_associateSeq.setText(seqName);
1023 lbl_associateSeq.setVisible(true);
1024 cmb_assSeq.setVisible(false);
1028 protected boolean isStructuresDiscovered()
1030 return discoveredStructuresSet != null
1031 && !discoveredStructuresSet.isEmpty();
1034 protected int PDB_ID_MIN = 3;// or: (Jalview.isJS() ? 3 : 1); // Bob proposes
1036 // Doing a search for "1" or "1c" is valuable?
1037 // Those work but are enormously slow.
1040 protected void txt_search_ActionPerformed()
1042 String text = txt_search.getText().trim();
1043 if (text.length() >= PDB_ID_MIN)
1050 errorWarning.setLength(0);
1051 isValidPBDEntry = false;
1052 if (text.length() > 0)
1054 // TODO move this pdb id search into the PDB specific
1056 // for moment, it will work fine as is because it is self-contained
1057 String searchTerm = text.toLowerCase();
1058 searchTerm = searchTerm.split(":")[0];
1059 // System.out.println(">>>>> search term : " + searchTerm);
1060 List<FTSDataColumnI> wantedFields = new ArrayList<>();
1061 FTSRestRequest pdbRequest = new FTSRestRequest();
1062 pdbRequest.setAllowEmptySeq(false);
1063 pdbRequest.setResponseSize(1);
1064 pdbRequest.setFieldToSearchBy("(pdb_id:");
1065 pdbRequest.setWantedFields(wantedFields);
1066 pdbRequest.setSearchTerm(searchTerm + ")");
1067 pdbRequest.setAssociatedSequence(selectedSequence);
1068 FTSRestClientI pdbRestClient = PDBFTSRestClient.getInstance();
1069 wantedFields.add(pdbRestClient.getPrimaryKeyColumn());
1070 FTSRestResponse resultList;
1073 resultList = pdbRestClient.executeRequest(pdbRequest);
1074 } catch (Exception e)
1076 errorWarning.append(e.getMessage());
1080 validateSelections();
1082 if (resultList.getSearchSummary() != null
1083 && resultList.getSearchSummary().size() > 0)
1085 isValidPBDEntry = true;
1088 validateSelections();
1094 protected void tabRefresh()
1096 if (selectedSequences != null)
1098 Thread refreshThread = new Thread(new Runnable()
1103 fetchStructuresMetaData();
1104 //populateFilterComboBox(true, cachedPDBExists);
1107 ((FilterOption) cmb_filterOption.getSelectedItem())
1111 refreshThread.start();
1115 public class PDBEntryTableModel extends AbstractTableModel
1117 String[] columns = { "Ref Sequence", "PDB Id", "Chain", "Type",
1120 private List<CachedPDB> pdbEntries;
1122 public PDBEntryTableModel(List<CachedPDB> pdbEntries)
1124 this.pdbEntries = new ArrayList<>(pdbEntries);
1128 public String getColumnName(int columnIndex)
1130 return columns[columnIndex];
1134 public int getRowCount()
1136 return pdbEntries.size();
1140 public int getColumnCount()
1142 return columns.length;
1146 public boolean isCellEditable(int row, int column)
1152 public Object getValueAt(int rowIndex, int columnIndex)
1154 Object value = "??";
1155 CachedPDB entry = pdbEntries.get(rowIndex);
1156 switch (columnIndex)
1159 value = entry.getSequence();
1162 value = entry.getPdbEntry();
1165 value = entry.getPdbEntry().getChainCode() == null ? "_"
1166 : entry.getPdbEntry().getChainCode();
1169 value = entry.getPdbEntry().getType();
1172 value = entry.getPdbEntry().getFile();
1179 public Class<?> getColumnClass(int columnIndex)
1181 return columnIndex == 0 ? SequenceI.class : PDBEntry.class;
1184 public CachedPDB getPDBEntryAt(int row)
1186 return pdbEntries.get(row);
1191 private class CachedPDB
1193 private SequenceI sequence;
1195 private PDBEntry pdbEntry;
1197 public CachedPDB(SequenceI sequence, PDBEntry pdbEntry)
1199 this.sequence = sequence;
1200 this.pdbEntry = pdbEntry;
1203 public SequenceI getSequence()
1208 public PDBEntry getPdbEntry()
1215 private IProgressIndicator progressBar;
1218 public void setProgressBar(String message, long id)
1220 progressBar.setProgressBar(message, id);
1224 public void registerHandler(long id, IProgressIndicatorHandler handler)
1226 progressBar.registerHandler(id, handler);
1230 public boolean operationInProgress()
1232 return progressBar.operationInProgress();
1235 public JalviewStructureDisplayI getOpenedStructureViewer()
1237 return sViewer == null ? null : sViewer.sview;
1241 protected void setFTSDocFieldPrefs(FTSDataColumnPreferences newPrefs)
1243 data.setDocFieldPrefs(newPrefs);