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 static StructureViewer lastTargetedView = null;
102 public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
105 // which FTS engine to use
106 data = StructureChooserQuerySource
107 .getQuerySourceFor(selectedSeqs);
111 this.selectedSequence = selectedSeq;
112 this.selectedSequences = selectedSeqs;
113 this.progressIndicator = (ap == null) ? null : ap.alignFrame;
119 * Initializes parameters used by the Structure Chooser Panel
121 protected void init()
123 if (!Jalview.isHeadlessMode())
125 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
128 chk_superpose.setSelected(Cache.getDefault(AUTOSUPERIMPOSE, true));
130 // ensure a filter option is in force for search
131 populateFilterComboBox(true, cachedPDBExists);
132 Thread discoverPDBStructuresThread = new Thread(new Runnable()
137 // looks for any existing structures already loaded
138 // for the sequences (the cached ones)
139 // then queries the StructureChooserQuerySource to
140 // discover more structures.
142 // Possible optimisation is to only begin querying
143 // the structure chooser if there are no cached structures.
145 long startTime = System.currentTimeMillis();
146 updateProgressIndicator(MessageManager
147 .getString("status.loading_cached_pdb_entries"), startTime);
148 loadLocalCachedPDBEntries();
149 updateProgressIndicator(null, startTime);
150 updateProgressIndicator(MessageManager.getString(
151 "status.searching_for_pdb_structures"), startTime);
152 fetchStructuresMetaData();
153 // revise filter options if no results were found
154 populateFilterComboBox(isStructuresDiscovered(), cachedPDBExists);
155 discoverStructureViews();
156 updateProgressIndicator(null, startTime);
157 mainFrame.setVisible(true);
161 discoverPDBStructuresThread.start();
165 * Builds a drop-down choice list of existing structure viewers to which new
166 * structures may be added. If this list is empty then it, and the 'Add'
167 * button, are hidden.
169 private void discoverStructureViews()
171 if (Desktop.instance != null)
173 targetView.removeAllItems();
174 if (lastTargetedView != null && !lastTargetedView.isVisible())
176 lastTargetedView = null;
178 int linkedViewsAt = 0;
179 for (StructureViewerBase view : Desktop.instance
180 .getStructureViewers(null, null))
182 StructureViewer viewHandler = (lastTargetedView != null
183 && lastTargetedView.sview == view) ? lastTargetedView
184 : StructureViewer.reconfigure(view);
186 if (view.isLinkedWith(ap))
188 targetView.insertItemAt(viewHandler, linkedViewsAt++);
192 targetView.addItem(viewHandler);
197 * show option to Add to viewer if at least 1 viewer found
199 targetView.setVisible(false);
200 if (targetView.getItemCount() > 0)
202 targetView.setVisible(true);
203 if (lastTargetedView != null)
205 targetView.setSelectedItem(lastTargetedView);
209 targetView.setSelectedIndex(0);
212 btn_add.setVisible(targetView.isVisible());
217 * Updates the progress indicator with the specified message
220 * displayed message for the operation
222 * unique handle for this indicator
224 protected void updateProgressIndicator(String message, long id)
226 if (progressIndicator != null)
228 progressIndicator.setProgressBar(message, id);
233 * Retrieve meta-data for all the structure(s) for a given sequence(s) in a
236 void fetchStructuresMetaData()
238 long startTime = System.currentTimeMillis();
239 Collection<FTSDataColumnI> wantedFields = data.getDocFieldPrefs()
240 .getStructureSummaryFields();
242 discoveredStructuresSet = new LinkedHashSet<>();
243 HashSet<String> errors = new HashSet<>();
245 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
248 for (SequenceI seq : selectedSequences)
251 FTSRestResponse resultList;
254 resultList = data.fetchStructuresMetaData(seq, wantedFields,
255 selectedFilterOpt, !chk_invertFilter.isSelected());
256 // null response means the FTSengine didn't yield a query for this
257 // consider designing a special exception if we really wanted to be OOCrazy
258 if (resultList==null)
262 } catch (Exception e)
265 errors.add(e.getMessage());
268 if (resultList.getSearchSummary() != null
269 && !resultList.getSearchSummary().isEmpty())
271 discoveredStructuresSet.addAll(resultList.getSearchSummary());
275 int noOfStructuresFound = 0;
276 String totalTime = (System.currentTimeMillis() - startTime)
278 if (discoveredStructuresSet != null
279 && !discoveredStructuresSet.isEmpty())
282 .setModel(data.getTableModel(discoveredStructuresSet));
283 noOfStructuresFound = discoveredStructuresSet.size();
284 mainFrame.setTitle(MessageManager.formatMessage(
285 "label.structure_chooser_no_of_structures",
286 noOfStructuresFound, totalTime));
290 mainFrame.setTitle(MessageManager
291 .getString("label.structure_chooser_manual_association"));
292 if (errors.size() > 0)
294 StringBuilder errorMsg = new StringBuilder();
295 for (String error : errors)
297 errorMsg.append(error).append("\n");
299 JvOptionPane.showMessageDialog(this, errorMsg.toString(),
300 MessageManager.getString("label.pdb_web-service_error"),
301 JvOptionPane.ERROR_MESSAGE);
306 protected void loadLocalCachedPDBEntries()
308 ArrayList<CachedPDB> entries = new ArrayList<>();
309 for (SequenceI seq : selectedSequences)
311 if (seq.getDatasetSequence() != null
312 && seq.getDatasetSequence().getAllPDBEntries() != null)
314 for (PDBEntry pdbEntry : seq.getDatasetSequence()
317 if (pdbEntry.getFile() != null)
319 entries.add(new CachedPDB(seq, pdbEntry));
324 cachedPDBExists = !entries.isEmpty();
325 PDBEntryTableModel tableModelx = new PDBEntryTableModel(entries);
326 tbl_local_pdb.setModel(tableModelx);
330 * Filters a given list of discovered structures based on supplied argument
332 * @param fieldToFilterBy
333 * the field to filter by
335 void filterResultSet(final String fieldToFilterBy)
337 Thread filterThread = new Thread(new Runnable()
342 long startTime = System.currentTimeMillis();
343 lbl_loading.setVisible(true);
344 Collection<FTSDataColumnI> wantedFields = data.getDocFieldPrefs()
345 .getStructureSummaryFields();
346 Collection<FTSData> filteredResponse = new HashSet<>();
347 HashSet<String> errors = new HashSet<>();
349 for (SequenceI seq : selectedSequences)
352 FTSRestResponse resultList;
355 resultList = data.selectFirstRankedQuery(seq, discoveredStructuresSet,wantedFields,
356 fieldToFilterBy, !chk_invertFilter.isSelected());
358 } catch (Exception e)
361 errors.add(e.getMessage());
364 if (resultList.getSearchSummary() != null
365 && !resultList.getSearchSummary().isEmpty())
367 filteredResponse.addAll(resultList.getSearchSummary());
371 String totalTime = (System.currentTimeMillis() - startTime)
373 if (!filteredResponse.isEmpty())
375 final int filterResponseCount = filteredResponse.size();
376 Collection<FTSData> reorderedStructuresSet = new LinkedHashSet<>();
377 reorderedStructuresSet.addAll(filteredResponse);
378 reorderedStructuresSet.addAll(discoveredStructuresSet);
380 .setModel(data.getTableModel(reorderedStructuresSet));
382 FTSRestResponse.configureTableColumn(getResultTable(),
383 wantedFields, tempUserPrefs);
384 getResultTable().getColumn("Ref Sequence").setPreferredWidth(120);
385 getResultTable().getColumn("Ref Sequence").setMinWidth(100);
386 getResultTable().getColumn("Ref Sequence").setMaxWidth(200);
387 // Update table selection model here
388 getResultTable().addRowSelectionInterval(0,
389 filterResponseCount - 1);
390 mainFrame.setTitle(MessageManager.formatMessage(
391 "label.structure_chooser_filter_time", totalTime));
395 mainFrame.setTitle(MessageManager.formatMessage(
396 "label.structure_chooser_filter_time", totalTime));
397 if (errors.size() > 0)
399 StringBuilder errorMsg = new StringBuilder();
400 for (String error : errors)
402 errorMsg.append(error).append("\n");
404 JvOptionPane.showMessageDialog(null, errorMsg.toString(),
405 MessageManager.getString("label.pdb_web-service_error"),
406 JvOptionPane.ERROR_MESSAGE);
410 lbl_loading.setVisible(false);
412 validateSelections();
415 filterThread.start();
419 * Handles action event for btn_pdbFromFile
422 protected void pdbFromFile_actionPerformed()
424 // TODO: JAL-3048 not needed for Jalview-JS until JSmol dep and
427 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
428 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
429 chooser.setFileView(new jalview.io.JalviewFileView());
430 chooser.setDialogTitle(
431 MessageManager.formatMessage("label.select_pdb_file_for",
432 selectedSequence.getDisplayId(false)));
433 chooser.setToolTipText(MessageManager.formatMessage(
434 "label.load_pdb_file_associate_with_sequence",
435 selectedSequence.getDisplayId(false)));
437 int value = chooser.showOpenDialog(null);
438 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
440 selectedPdbFileName = chooser.getSelectedFile().getPath();
441 jalview.bin.Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName);
442 validateSelections();
447 * Populates the filter combo-box options dynamically depending on discovered
450 protected void populateFilterComboBox(boolean haveData,
451 boolean cachedPDBExist)
454 * temporarily suspend the change listener behaviour
456 cmb_filterOption.removeItemListener(this);
458 cmb_filterOption.removeAllItems();
461 List<FilterOption> filters = data.getAvailableFilterOptions(VIEWS_FILTER);
462 for (FilterOption filter:filters)
464 cmb_filterOption.addItem(filter);
467 cmb_filterOption.addItem(
468 new FilterOption(MessageManager.getString("label.enter_pdb_id"),
469 "-", VIEWS_ENTER_ID, false,null));
470 cmb_filterOption.addItem(
471 new FilterOption(MessageManager.getString("label.from_file"),
472 "-", VIEWS_FROM_FILE, false,null));
476 FilterOption cachedOption = new FilterOption(
477 MessageManager.getString("label.cached_structures"), "-",
478 VIEWS_LOCAL_PDB, false,null);
479 cmb_filterOption.addItem(cachedOption);
480 cmb_filterOption.setSelectedItem(cachedOption);
483 cmb_filterOption.addItemListener(this);
487 * Updates the displayed view based on the selected filter option
489 protected void updateCurrentView()
491 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
493 layout_switchableViews.show(pnl_switchableViews,
494 selectedFilterOpt.getView());
495 String filterTitle = mainFrame.getTitle();
496 mainFrame.setTitle(frameTitle);
497 chk_invertFilter.setVisible(false);
498 if (selectedFilterOpt.getView() == VIEWS_FILTER)
500 mainFrame.setTitle(filterTitle);
501 chk_invertFilter.setVisible(true);
503 if (data!=selectedFilterOpt.getQuerySource() || data.needsRefetch(selectedFilterOpt))
505 data = selectedFilterOpt.getQuerySource();
506 // rebuild the views completely, since prefs will also change
510 filterResultSet(selectedFilterOpt.getValue());
513 else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
514 || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
516 mainFrame.setTitle(MessageManager
517 .getString("label.structure_chooser_manual_association"));
518 idInputAssSeqPanel.loadCmbAssSeq();
519 fileChooserAssSeqPanel.loadCmbAssSeq();
521 validateSelections();
525 * Validates user selection and enables the 'Add' and 'New View' buttons if
526 * all parameters are correct (the Add button will only be visible if there is
527 * at least one existing structure viewer open). This basically means at least
528 * one structure selected and no error messages.
530 * The 'Superpose Structures' option is enabled if either more than one
531 * structure is selected, or the 'Add' to existing view option is enabled, and
532 * disabled if the only option is to open a new view of a single structure.
535 protected void validateSelections()
537 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
539 btn_add.setEnabled(false);
540 String currentView = selectedFilterOpt.getView();
541 int selectedCount = 0;
542 if (currentView == VIEWS_FILTER)
544 selectedCount = getResultTable().getSelectedRows().length;
545 if (selectedCount > 0)
547 btn_add.setEnabled(true);
550 else if (currentView == VIEWS_LOCAL_PDB)
552 selectedCount = tbl_local_pdb.getSelectedRows().length;
553 if (selectedCount > 0)
555 btn_add.setEnabled(true);
558 else if (currentView == VIEWS_ENTER_ID)
560 validateAssociationEnterPdb();
562 else if (currentView == VIEWS_FROM_FILE)
564 validateAssociationFromFile();
567 btn_newView.setEnabled(btn_add.isEnabled());
570 * enable 'Superpose' option if more than one structure is selected,
571 * or there are view(s) available to add structure(s) to
574 .setEnabled(selectedCount > 1 || targetView.getItemCount() > 0);
578 * Validates inputs from the Manual PDB entry panel
580 protected void validateAssociationEnterPdb()
582 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel
583 .getCmb_assSeq().getSelectedItem();
584 lbl_pdbManualFetchStatus.setIcon(errorImage);
585 lbl_pdbManualFetchStatus.setToolTipText("");
586 if (txt_search.getText().length() > 0)
588 lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip(true,
589 MessageManager.formatMessage("info.no_pdb_entry_found_for",
590 txt_search.getText())));
593 if (errorWarning.length() > 0)
595 lbl_pdbManualFetchStatus.setIcon(warningImage);
596 lbl_pdbManualFetchStatus.setToolTipText(
597 JvSwingUtils.wrapTooltip(true, errorWarning.toString()));
600 if (selectedSequences.length == 1 || !assSeqOpt.getName()
601 .equalsIgnoreCase("-Select Associated Seq-"))
603 txt_search.setEnabled(true);
606 btn_add.setEnabled(true);
607 lbl_pdbManualFetchStatus.setToolTipText("");
608 lbl_pdbManualFetchStatus.setIcon(goodImage);
613 txt_search.setEnabled(false);
614 lbl_pdbManualFetchStatus.setIcon(errorImage);
619 * Validates inputs for the manual PDB file selection options
621 protected void validateAssociationFromFile()
623 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
624 .getCmb_assSeq().getSelectedItem();
625 lbl_fromFileStatus.setIcon(errorImage);
626 if (selectedSequences.length == 1 || (assSeqOpt != null && !assSeqOpt
627 .getName().equalsIgnoreCase("-Select Associated Seq-")))
629 btn_pdbFromFile.setEnabled(true);
630 if (selectedPdbFileName != null && selectedPdbFileName.length() > 0)
632 btn_add.setEnabled(true);
633 lbl_fromFileStatus.setIcon(goodImage);
638 btn_pdbFromFile.setEnabled(false);
639 lbl_fromFileStatus.setIcon(errorImage);
644 protected void cmbAssSeqStateChanged()
646 validateSelections();
650 * Handles the state change event for the 'filter' combo-box and 'invert'
654 protected void stateChanged(ItemEvent e)
656 if (e.getSource() instanceof JCheckBox)
662 if (e.getStateChange() == ItemEvent.SELECTED)
671 * select structures for viewing by their PDB IDs
674 * @return true if structures were found and marked as selected
676 public boolean selectStructure(String... pdbids)
678 boolean found = false;
680 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
682 String currentView = selectedFilterOpt.getView();
683 JTable restable = (currentView == VIEWS_FILTER) ? getResultTable()
684 : (currentView == VIEWS_LOCAL_PDB) ? tbl_local_pdb : null;
686 if (restable == null)
688 // can't select (enter PDB ID, or load file - need to also select which
689 // sequence to associate with)
693 int pdbIdColIndex = restable.getColumn("PDB Id").getModelIndex();
694 for (int r = 0; r < restable.getRowCount(); r++)
696 for (int p = 0; p < pdbids.length; p++)
698 if (String.valueOf(restable.getValueAt(r, pdbIdColIndex))
699 .equalsIgnoreCase(pdbids[p]))
701 restable.setRowSelectionInterval(r, r);
710 * Handles the 'New View' action
713 protected void newView_ActionPerformed()
715 targetView.setSelectedItem(null);
716 showStructures(false);
720 * Handles the 'Add to existing viewer' action
723 protected void add_ActionPerformed()
725 showStructures(false);
729 * structure viewer opened by this dialog, or null
731 private StructureViewer sViewer = null;
733 public void showStructures(boolean waitUntilFinished)
736 final StructureSelectionManager ssm = ap.getStructureSelectionManager();
738 final int preferredHeight = pnl_filter.getHeight();
740 Runnable viewStruc = new Runnable()
745 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
747 String currentView = selectedFilterOpt.getView();
748 JTable restable = (currentView == VIEWS_FILTER) ? getResultTable()
751 if (currentView == VIEWS_FILTER)
753 int[] selectedRows = restable.getSelectedRows();
754 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
755 List<SequenceI> selectedSeqsToView = new ArrayList<>();
756 pdbEntriesToView = data.collectSelectedRows(restable,selectedRows,selectedSeqsToView);
758 SequenceI[] selectedSeqs = selectedSeqsToView
759 .toArray(new SequenceI[selectedSeqsToView.size()]);
760 sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
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("PDB Id")
770 int refSeqColIndex = tbl_local_pdb.getColumn("Ref Sequence")
772 List<SequenceI> selectedSeqsToView = new ArrayList<>();
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
779 .getValueAt(row, refSeqColIndex);
780 selectedSeqsToView.add(selectedSeq);
782 SequenceI[] selectedSeqs = selectedSeqsToView
783 .toArray(new SequenceI[selectedSeqsToView.size()]);
784 sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
787 else if (currentView == VIEWS_ENTER_ID)
789 SequenceI userSelectedSeq = ((AssociateSeqOptions) idInputAssSeqPanel
790 .getCmb_assSeq().getSelectedItem()).getSequence();
791 if (userSelectedSeq != null)
793 selectedSequence = userSelectedSeq;
795 String pdbIdStr = txt_search.getText();
796 PDBEntry pdbEntry = selectedSequence.getPDBEntry(pdbIdStr);
797 if (pdbEntry == null)
799 pdbEntry = new PDBEntry();
800 if (pdbIdStr.split(":").length > 1)
802 pdbEntry.setId(pdbIdStr.split(":")[0]);
803 pdbEntry.setChainCode(pdbIdStr.split(":")[1].toUpperCase());
807 pdbEntry.setId(pdbIdStr);
809 pdbEntry.setType(PDBEntry.Type.PDB);
810 selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
813 PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
814 sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
816 { selectedSequence });
818 else if (currentView == VIEWS_FROM_FILE)
820 SequenceI userSelectedSeq = ((AssociateSeqOptions) fileChooserAssSeqPanel
821 .getCmb_assSeq().getSelectedItem()).getSequence();
822 if (userSelectedSeq != null)
824 selectedSequence = userSelectedSeq;
826 PDBEntry fileEntry = new AssociatePdbFileWithSeq()
827 .associatePdbWithSeq(selectedPdbFileName,
828 DataSourceType.FILE, selectedSequence, true,
831 sViewer = launchStructureViewer(ssm, new PDBEntry[] { fileEntry },
833 { selectedSequence });
835 SwingUtilities.invokeLater(new Runnable()
840 closeAction(preferredHeight);
846 Thread runner = new Thread(viewStruc);
848 if (waitUntilFinished)
850 while (sViewer == null ? runner.isAlive()
851 : (sViewer.sview == null ? true
852 : !sViewer.sview.hasMapping()))
857 } catch (InterruptedException ie)
866 * Answers a structure viewer (new or existing) configured to superimpose
867 * added structures or not according to the user's choice
872 StructureViewer getTargetedStructureViewer(StructureSelectionManager ssm)
874 Object sv = targetView.getSelectedItem();
876 return sv == null ? new StructureViewer(ssm) : (StructureViewer) sv;
880 * Adds PDB structures to a new or existing structure viewer
883 * @param pdbEntriesToView
888 private StructureViewer launchStructureViewer(
889 StructureSelectionManager ssm, final PDBEntry[] pdbEntriesToView,
890 final AlignmentPanel alignPanel, SequenceI[] sequences)
892 long progressId = sequences.hashCode();
893 setProgressBar(MessageManager
894 .getString("status.launching_3d_structure_viewer"), progressId);
895 final StructureViewer theViewer = getTargetedStructureViewer(ssm);
896 boolean superimpose = chk_superpose.isSelected();
897 theViewer.setSuperpose(superimpose);
900 * remember user's choice of superimpose or not
902 Cache.setProperty(AUTOSUPERIMPOSE,
903 Boolean.valueOf(superimpose).toString());
905 setProgressBar(null, progressId);
906 if (SiftsSettings.isMapWithSifts())
908 List<SequenceI> seqsWithoutSourceDBRef = new ArrayList<>();
910 // TODO: skip PDBEntry:Sequence pairs where PDBEntry doesn't look like a
911 // real PDB ID. For moment, we can also safely do this if there is already
912 // a known mapping between the PDBEntry and the sequence.
913 for (SequenceI seq : sequences)
915 PDBEntry pdbe = pdbEntriesToView[p++];
916 if (pdbe != null && pdbe.getFile() != null)
918 StructureMapping[] smm = ssm.getMapping(pdbe.getFile());
919 if (smm != null && smm.length > 0)
921 for (StructureMapping sm : smm)
923 if (sm.getSequence() == seq)
930 if (seq.getPrimaryDBRefs().isEmpty())
932 seqsWithoutSourceDBRef.add(seq);
936 if (!seqsWithoutSourceDBRef.isEmpty())
938 int y = seqsWithoutSourceDBRef.size();
939 setProgressBar(MessageManager.formatMessage(
940 "status.fetching_dbrefs_for_sequences_without_valid_refs",
942 SequenceI[] seqWithoutSrcDBRef = seqsWithoutSourceDBRef
943 .toArray(new SequenceI[y]);
944 DBRefFetcher dbRefFetcher = new DBRefFetcher(seqWithoutSrcDBRef);
945 dbRefFetcher.fetchDBRefs(true);
947 setProgressBar("Fetch complete.", progressId); // todo i18n
950 if (pdbEntriesToView.length > 1)
953 MessageManager.getString(
954 "status.fetching_3d_structures_for_selected_entries"),
956 theViewer.viewStructures(pdbEntriesToView, sequences, alignPanel);
960 setProgressBar(MessageManager.formatMessage(
961 "status.fetching_3d_structures_for",
962 pdbEntriesToView[0].getId()), progressId);
963 theViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
965 setProgressBar(null, progressId);
966 // remember the last viewer we used...
967 lastTargetedView = theViewer;
972 * Populates the combo-box used in associating manually fetched structures to
973 * a unique sequence when more than one sequence selection is made.
976 protected void populateCmbAssociateSeqOptions(
977 JComboBox<AssociateSeqOptions> cmb_assSeq,
978 JLabel lbl_associateSeq)
980 cmb_assSeq.removeAllItems();
982 new AssociateSeqOptions("-Select Associated Seq-", null));
983 lbl_associateSeq.setVisible(false);
984 if (selectedSequences.length > 1)
986 for (SequenceI seq : selectedSequences)
988 cmb_assSeq.addItem(new AssociateSeqOptions(seq));
993 String seqName = selectedSequence.getDisplayId(false);
994 seqName = seqName.length() <= 40 ? seqName : seqName.substring(0, 39);
995 lbl_associateSeq.setText(seqName);
996 lbl_associateSeq.setVisible(true);
997 cmb_assSeq.setVisible(false);
1001 protected boolean isStructuresDiscovered()
1003 return discoveredStructuresSet != null
1004 && !discoveredStructuresSet.isEmpty();
1007 protected int PDB_ID_MIN = 3;// or: (Jalview.isJS() ? 3 : 1); // Bob proposes
1009 // Doing a search for "1" or "1c" is valuable?
1010 // Those work but are enormously slow.
1013 protected void txt_search_ActionPerformed()
1015 String text = txt_search.getText().trim();
1016 if (text.length() >= PDB_ID_MIN)
1023 errorWarning.setLength(0);
1024 isValidPBDEntry = false;
1025 if (text.length() > 0)
1027 // TODO move this pdb id search into the PDB specific
1029 // for moment, it will work fine as is because it is self-contained
1030 String searchTerm = text.toLowerCase();
1031 searchTerm = searchTerm.split(":")[0];
1032 // System.out.println(">>>>> search term : " + searchTerm);
1033 List<FTSDataColumnI> wantedFields = new ArrayList<>();
1034 FTSRestRequest pdbRequest = new FTSRestRequest();
1035 pdbRequest.setAllowEmptySeq(false);
1036 pdbRequest.setResponseSize(1);
1037 pdbRequest.setFieldToSearchBy("(pdb_id:");
1038 pdbRequest.setWantedFields(wantedFields);
1039 pdbRequest.setSearchTerm(searchTerm + ")");
1040 pdbRequest.setAssociatedSequence(selectedSequence);
1041 FTSRestClientI pdbRestClient = PDBFTSRestClient.getInstance();
1042 wantedFields.add(pdbRestClient.getPrimaryKeyColumn());
1043 FTSRestResponse resultList;
1046 resultList = pdbRestClient.executeRequest(pdbRequest);
1047 } catch (Exception e)
1049 errorWarning.append(e.getMessage());
1053 validateSelections();
1055 if (resultList.getSearchSummary() != null
1056 && resultList.getSearchSummary().size() > 0)
1058 isValidPBDEntry = true;
1061 validateSelections();
1067 protected void tabRefresh()
1069 if (selectedSequences != null)
1071 Thread refreshThread = new Thread(new Runnable()
1076 fetchStructuresMetaData();
1078 ((FilterOption) cmb_filterOption.getSelectedItem())
1082 refreshThread.start();
1086 public class PDBEntryTableModel extends AbstractTableModel
1088 String[] columns = { "Ref Sequence", "PDB Id", "Chain", "Type",
1091 private List<CachedPDB> pdbEntries;
1093 public PDBEntryTableModel(List<CachedPDB> pdbEntries)
1095 this.pdbEntries = new ArrayList<>(pdbEntries);
1099 public String getColumnName(int columnIndex)
1101 return columns[columnIndex];
1105 public int getRowCount()
1107 return pdbEntries.size();
1111 public int getColumnCount()
1113 return columns.length;
1117 public boolean isCellEditable(int row, int column)
1123 public Object getValueAt(int rowIndex, int columnIndex)
1125 Object value = "??";
1126 CachedPDB entry = pdbEntries.get(rowIndex);
1127 switch (columnIndex)
1130 value = entry.getSequence();
1133 value = entry.getPdbEntry();
1136 value = entry.getPdbEntry().getChainCode() == null ? "_"
1137 : entry.getPdbEntry().getChainCode();
1140 value = entry.getPdbEntry().getType();
1143 value = entry.getPdbEntry().getFile();
1150 public Class<?> getColumnClass(int columnIndex)
1152 return columnIndex == 0 ? SequenceI.class : PDBEntry.class;
1155 public CachedPDB getPDBEntryAt(int row)
1157 return pdbEntries.get(row);
1162 private class CachedPDB
1164 private SequenceI sequence;
1166 private PDBEntry pdbEntry;
1168 public CachedPDB(SequenceI sequence, PDBEntry pdbEntry)
1170 this.sequence = sequence;
1171 this.pdbEntry = pdbEntry;
1174 public SequenceI getSequence()
1179 public PDBEntry getPdbEntry()
1186 private IProgressIndicator progressBar;
1189 public void setProgressBar(String message, long id)
1191 progressBar.setProgressBar(message, id);
1195 public void registerHandler(long id, IProgressIndicatorHandler handler)
1197 progressBar.registerHandler(id, handler);
1201 public boolean operationInProgress()
1203 return progressBar.operationInProgress();
1206 public JalviewStructureDisplayI getOpenedStructureViewer()
1208 return sViewer == null ? null : sViewer.sview;
1212 protected void setFTSDocFieldPrefs(FTSDataColumnPreferences newPrefs)
1214 data.setDocFieldPrefs(newPrefs);