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.fts.api.FTSData;
30 import jalview.fts.api.FTSDataColumnI;
31 import jalview.fts.api.FTSRestClientI;
32 import jalview.fts.core.FTSRestRequest;
33 import jalview.fts.core.FTSRestResponse;
34 import jalview.fts.service.pdb.PDBFTSRestClient;
35 import jalview.jbgui.GStructureChooser;
36 import jalview.structure.StructureSelectionManager;
37 import jalview.util.MessageManager;
38 import jalview.ws.sifts.SiftsSettings;
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<FTSData> discoveredStructuresSet;
75 private FTSRestRequest lastPdbRequest;
77 private FTSRestClientI 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 pdbRestCleint = PDBFTSRestClient.getInstance();
150 Collection<FTSDataColumnI> wantedFields = pdbRestCleint
151 .getAllDefaulDisplayedDataColumns();
153 discoveredStructuresSet = new LinkedHashSet<FTSData>();
154 HashSet<String> errors = new HashSet<String>();
155 for (SequenceI seq : selectedSequences)
157 FTSRestRequest pdbRequest = new FTSRestRequest();
158 pdbRequest.setAllowEmptySeq(false);
159 pdbRequest.setResponseSize(500);
160 pdbRequest.setFieldToSearchBy("(");
161 pdbRequest.setWantedFields(wantedFields);
162 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
163 pdbRequest.setAssociatedSequence(seq);
164 FTSRestResponse 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(FTSRestResponse.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("pdb_id")
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("uniprot_accession").append(":")
278 .append(getDBRefId(dbRef))
281 .append("uniprot_id")
283 .append(getDBRefId(dbRef)).append(" OR ");
284 isUniProtRefsFound = true;
286 else if (dbRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
289 queryBuilder.append("pdb_id")
290 .append(":").append(getDBRefId(dbRef).toLowerCase())
292 isPDBRefsFound = true;
296 seqRefs.add(getDBRefId(dbRef));
302 if (!isPDBRefsFound && !isUniProtRefsFound)
304 String seqName = seq.getName();
305 seqName = sanitizeSeqName(seqName);
306 String[] names = seqName.toLowerCase().split("\\|");
307 for (String name : names)
309 // System.out.println("Found name : " + name);
311 if (isValidSeqName(name))
317 for (String seqRef : seqRefs)
319 queryBuilder.append("text:").append(seqRef).append(" OR ");
323 int endIndex = queryBuilder.lastIndexOf(" OR ");
324 if (queryBuilder.toString().length() < 6)
328 String query = queryBuilder.toString().substring(0, endIndex);
333 * Remove the following special characters from input string +, -, &, |, !, (,
334 * ), {, }, [, ], ^, ", ~, *, ?, :, \
339 private static String sanitizeSeqName(String seqName)
341 Objects.requireNonNull(seqName);
342 return seqName.replaceAll("\\[\\d*\\]", "")
343 .replaceAll("[^\\dA-Za-z|]", "").replaceAll("\\s+", "+");
348 * Ensures sequence ref names are not less than 3 characters and does not
349 * contain a database name
354 public static boolean isValidSeqName(String seqName)
356 // System.out.println("seqName : " + seqName);
357 String ignoreList = "pdb,uniprot,swiss-prot";
358 if (seqName.length() < 3)
362 if (seqName.contains(":"))
366 seqName = seqName.toLowerCase();
367 for (String ignoredEntry : ignoreList.split(","))
369 if (seqName.contains(ignoredEntry))
377 public static String getDBRefId(DBRefEntry dbRef)
379 String ref = dbRef.getAccessionId().replaceAll("GO:", "");
384 * Filters a given list of discovered structures based on supplied argument
386 * @param fieldToFilterBy
387 * the field to filter by
389 public void filterResultSet(final String fieldToFilterBy)
391 Thread filterThread = new Thread(new Runnable()
396 long startTime = System.currentTimeMillis();
397 pdbRestCleint = PDBFTSRestClient.getInstance();
398 lbl_loading.setVisible(true);
399 Collection<FTSDataColumnI> wantedFields = pdbRestCleint
400 .getAllDefaulDisplayedDataColumns();
401 Collection<FTSData> filteredResponse = new HashSet<FTSData>();
402 HashSet<String> errors = new HashSet<String>();
404 for (SequenceI seq : selectedSequences)
406 FTSRestRequest pdbRequest = new FTSRestRequest();
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 FTSRestResponse resultList;
434 resultList = pdbRestCleint.executeRequest(pdbRequest);
435 } catch (Exception e)
438 errors.add(e.getMessage());
441 lastPdbRequest = pdbRequest;
442 if (resultList.getSearchSummary() != null
443 && !resultList.getSearchSummary().isEmpty())
445 filteredResponse.addAll(resultList.getSearchSummary());
449 String totalTime = (System.currentTimeMillis() - startTime)
451 if (!filteredResponse.isEmpty())
453 final int filterResponseCount = filteredResponse.size();
454 Collection<FTSData> reorderedStructuresSet = new LinkedHashSet<FTSData>();
455 reorderedStructuresSet.addAll(filteredResponse);
456 reorderedStructuresSet.addAll(discoveredStructuresSet);
457 tbl_summary.setModel(FTSRestResponse.getTableModel(
458 lastPdbRequest, reorderedStructuresSet));
460 FTSRestResponse.configureTableColumn(tbl_summary, wantedFields);
461 tbl_summary.getColumn("Ref Sequence").setPreferredWidth(120);
462 tbl_summary.getColumn("Ref Sequence").setMinWidth(100);
463 tbl_summary.getColumn("Ref Sequence").setMaxWidth(200);
464 // Update table selection model here
465 tbl_summary.addRowSelectionInterval(0, filterResponseCount - 1);
466 mainFrame.setTitle(MessageManager.formatMessage(
467 "label.structure_chooser_filter_time", totalTime));
471 mainFrame.setTitle(MessageManager.formatMessage(
472 "label.structure_chooser_filter_time", totalTime));
473 if (errors.size() > 0)
475 StringBuilder errorMsg = new StringBuilder();
476 for (String error : errors)
478 errorMsg.append(error).append("\n");
480 JOptionPane.showMessageDialog(
483 MessageManager.getString("label.pdb_web-service_error"),
484 JOptionPane.ERROR_MESSAGE);
488 lbl_loading.setVisible(false);
490 validateSelections();
493 filterThread.start();
497 * Handles action event for btn_pdbFromFile
500 public void pdbFromFile_actionPerformed()
502 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
503 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
504 chooser.setFileView(new jalview.io.JalviewFileView());
505 chooser.setDialogTitle(MessageManager.formatMessage(
506 "label.select_pdb_file_for",
507 selectedSequence.getDisplayId(false)));
508 chooser.setToolTipText(MessageManager.formatMessage(
509 "label.load_pdb_file_associate_with_sequence",
510 selectedSequence.getDisplayId(false)));
512 int value = chooser.showOpenDialog(null);
513 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
515 selectedPdbFileName = chooser.getSelectedFile().getPath();
516 jalview.bin.Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName);
517 validateSelections();
522 * Populates the filter combo-box options dynamically depending on discovered
526 protected void populateFilterComboBox()
528 if (isStructuresDiscovered())
530 cmb_filterOption.addItem(new FilterOption("Best Quality",
531 "overall_quality", VIEWS_FILTER));
532 cmb_filterOption.addItem(new FilterOption("Most UniProt Coverage",
533 "uniprot_coverage", VIEWS_FILTER));
534 cmb_filterOption.addItem(new FilterOption("Best Resolution",
535 "resolution", VIEWS_FILTER));
536 cmb_filterOption.addItem(new FilterOption("Most Protein Chain",
537 "number_of_protein_chains", VIEWS_FILTER));
538 cmb_filterOption.addItem(new FilterOption("Most Bound Molecules",
539 "number_of_bound_molecules", VIEWS_FILTER));
540 cmb_filterOption.addItem(new FilterOption("Most Polymer Residues",
541 "number_of_polymer_residues", VIEWS_FILTER));
543 cmb_filterOption.addItem(new FilterOption("Enter PDB Id", "-",
545 cmb_filterOption.addItem(new FilterOption("From File", "-",
547 cmb_filterOption.addItem(new FilterOption("Cached PDB Entries", "-",
552 * Updates the displayed view based on the selected filter option
555 protected void updateCurrentView()
557 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
559 layout_switchableViews.show(pnl_switchableViews,
560 selectedFilterOpt.getView());
561 String filterTitle = mainFrame.getTitle();
562 mainFrame.setTitle(frameTitle);
563 chk_invertFilter.setVisible(false);
564 if (selectedFilterOpt.getView() == VIEWS_FILTER)
566 mainFrame.setTitle(filterTitle);
567 chk_invertFilter.setVisible(true);
568 filterResultSet(selectedFilterOpt.getValue());
570 else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
571 || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
573 mainFrame.setTitle(MessageManager
574 .getString("label.structure_chooser_manual_association"));
575 idInputAssSeqPanel.loadCmbAssSeq();
576 fileChooserAssSeqPanel.loadCmbAssSeq();
578 validateSelections();
582 * Validates user selection and activates the view button if all parameters
586 public void validateSelections()
588 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
590 btn_view.setEnabled(false);
591 String currentView = selectedFilterOpt.getView();
592 if (currentView == VIEWS_FILTER)
594 if (tbl_summary.getSelectedRows().length > 0)
596 btn_view.setEnabled(true);
599 else if (currentView == VIEWS_LOCAL_PDB)
601 if (tbl_local_pdb.getSelectedRows().length > 0)
603 btn_view.setEnabled(true);
606 else if (currentView == VIEWS_ENTER_ID)
608 validateAssociationEnterPdb();
610 else if (currentView == VIEWS_FROM_FILE)
612 validateAssociationFromFile();
617 * Validates inputs from the Manual PDB entry panel
619 public void validateAssociationEnterPdb()
621 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel
622 .getCmb_assSeq().getSelectedItem();
623 lbl_pdbManualFetchStatus.setIcon(errorImage);
624 lbl_pdbManualFetchStatus.setToolTipText("");
625 if (txt_search.getText().length() > 0)
627 lbl_pdbManualFetchStatus
628 .setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
629 .formatMessage("info.no_pdb_entry_found_for",
630 txt_search.getText())));
633 if (errorWarning.length() > 0)
635 lbl_pdbManualFetchStatus.setIcon(warningImage);
636 lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip(
637 true, errorWarning.toString()));
640 if (selectedSequences.length == 1
641 || !assSeqOpt.getName().equalsIgnoreCase(
642 "-Select Associated Seq-"))
644 txt_search.setEnabled(true);
647 btn_view.setEnabled(true);
648 lbl_pdbManualFetchStatus.setToolTipText("");
649 lbl_pdbManualFetchStatus.setIcon(goodImage);
654 txt_search.setEnabled(false);
655 lbl_pdbManualFetchStatus.setIcon(errorImage);
660 * Validates inputs for the manual PDB file selection options
662 public void validateAssociationFromFile()
664 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
665 .getCmb_assSeq().getSelectedItem();
666 lbl_fromFileStatus.setIcon(errorImage);
667 if (selectedSequences.length == 1
668 || (assSeqOpt != null && !assSeqOpt.getName().equalsIgnoreCase(
669 "-Select Associated Seq-")))
671 btn_pdbFromFile.setEnabled(true);
672 if (selectedPdbFileName != null && selectedPdbFileName.length() > 0)
674 btn_view.setEnabled(true);
675 lbl_fromFileStatus.setIcon(goodImage);
680 btn_pdbFromFile.setEnabled(false);
681 lbl_fromFileStatus.setIcon(errorImage);
686 public void cmbAssSeqStateChanged()
688 validateSelections();
692 * Handles the state change event for the 'filter' combo-box and 'invert'
696 protected void stateChanged(ItemEvent e)
698 if (e.getSource() instanceof JCheckBox)
704 if (e.getStateChange() == ItemEvent.SELECTED)
713 * Handles action event for btn_ok
716 public void ok_ActionPerformed()
718 final long progressSessionId = System.currentTimeMillis();
719 final StructureSelectionManager ssm = ap.getStructureSelectionManager();
720 ssm.setProgressIndicator(this);
721 ssm.setProgressSessionId(progressSessionId);
722 new Thread(new Runnable()
727 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
729 String currentView = selectedFilterOpt.getView();
730 if (currentView == VIEWS_FILTER)
732 int pdbIdColIndex = tbl_summary.getColumn("PDB Id")
734 int refSeqColIndex = tbl_summary.getColumn("Ref Sequence")
736 int[] selectedRows = tbl_summary.getSelectedRows();
737 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
739 ArrayList<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
740 for (int row : selectedRows)
742 String pdbIdStr = tbl_summary.getValueAt(row, pdbIdColIndex)
744 SequenceI selectedSeq = (SequenceI) tbl_summary.getValueAt(row,
746 selectedSeqsToView.add(selectedSeq);
747 PDBEntry pdbEntry = selectedSeq.getPDBEntry(pdbIdStr);
748 if (pdbEntry == null)
750 pdbEntry = getFindEntry(pdbIdStr,
751 selectedSeq.getAllPDBEntries());
753 if (pdbEntry == null)
755 pdbEntry = new PDBEntry();
756 pdbEntry.setId(pdbIdStr);
757 pdbEntry.setType(PDBEntry.Type.PDB);
758 selectedSeq.getDatasetSequence().addPDBId(pdbEntry);
760 pdbEntriesToView[count++] = pdbEntry;
762 SequenceI[] selectedSeqs = selectedSeqsToView
763 .toArray(new SequenceI[selectedSeqsToView.size()]);
764 launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
766 else if (currentView == VIEWS_LOCAL_PDB)
768 int[] selectedRows = tbl_local_pdb.getSelectedRows();
769 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
771 int pdbIdColIndex = tbl_local_pdb.getColumn("PDB Id")
773 int refSeqColIndex = tbl_local_pdb.getColumn("Ref Sequence")
775 ArrayList<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
776 for (int row : selectedRows)
778 PDBEntry pdbEntry = (PDBEntry) tbl_local_pdb.getValueAt(row,
780 pdbEntriesToView[count++] = pdbEntry;
781 SequenceI selectedSeq = (SequenceI) tbl_local_pdb.getValueAt(row,
783 selectedSeqsToView.add(selectedSeq);
785 SequenceI[] selectedSeqs = selectedSeqsToView
786 .toArray(new SequenceI[selectedSeqsToView.size()]);
787 launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
789 else if (currentView == VIEWS_ENTER_ID)
791 SequenceI userSelectedSeq = ((AssociateSeqOptions) idInputAssSeqPanel
792 .getCmb_assSeq().getSelectedItem()).getSequence();
793 if (userSelectedSeq != null)
795 selectedSequence = userSelectedSeq;
798 String pdbIdStr = txt_search.getText();
799 PDBEntry pdbEntry = selectedSequence.getPDBEntry(pdbIdStr);
800 if (pdbEntry == null)
802 pdbEntry = new PDBEntry();
803 pdbEntry.setId(pdbIdStr);
804 pdbEntry.setType(PDBEntry.Type.PDB);
805 selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
808 PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
809 launchStructureViewer(ssm, pdbEntriesToView, ap,
810 new SequenceI[] { selectedSequence });
812 else if (currentView == VIEWS_FROM_FILE)
814 SequenceI userSelectedSeq = ((AssociateSeqOptions) fileChooserAssSeqPanel
815 .getCmb_assSeq().getSelectedItem()).getSequence();
816 if (userSelectedSeq != null)
818 selectedSequence = userSelectedSeq;
820 PDBEntry fileEntry = new AssociatePdbFileWithSeq()
821 .associatePdbWithSeq(selectedPdbFileName,
822 jalview.io.AppletFormatAdapter.FILE,
823 selectedSequence, true, Desktop.instance);
825 launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
826 new SequenceI[] { selectedSequence });
833 private PDBEntry getFindEntry(String id, Vector<PDBEntry> pdbEntries)
835 Objects.requireNonNull(id);
836 Objects.requireNonNull(pdbEntries);
837 PDBEntry foundEntry = null;
838 for (PDBEntry entry : pdbEntries)
840 if (entry.getId().equalsIgnoreCase(id))
848 private void launchStructureViewer(StructureSelectionManager ssm,
849 final PDBEntry[] pdbEntriesToView,
850 final AlignmentPanel alignPanel, SequenceI[] sequences)
852 ssm.setProgressBar("Launching PDB structure viewer..");
853 final StructureViewer sViewer = new StructureViewer(ssm);
855 if (SiftsSettings.isMapWithSifts())
857 for (SequenceI seq : sequences)
859 if (seq.getSourceDBRef() == null)
861 ssm.setProgressBar(null);
862 ssm.setProgressBar("Fetching Database refs..");
863 new jalview.ws.DBRefFetcher(sequences, null, null, null, false)
869 if (pdbEntriesToView.length > 1)
871 ArrayList<SequenceI[]> seqsMap = new ArrayList<SequenceI[]>();
872 for (SequenceI seq : sequences)
874 seqsMap.add(new SequenceI[] { seq });
876 SequenceI[][] collatedSeqs = seqsMap.toArray(new SequenceI[0][0]);
877 ssm.setProgressBar(null);
878 ssm.setProgressBar("Fetching PDB Structures for selected entries..");
879 sViewer.viewStructures(pdbEntriesToView, collatedSeqs, alignPanel);
883 ssm.setProgressBar(null);
884 ssm.setProgressBar("Fetching PDB Structure for "
885 + pdbEntriesToView[0].getId());
886 sViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
891 * Populates the combo-box used in associating manually fetched structures to
892 * a unique sequence when more than one sequence selection is made.
895 public void populateCmbAssociateSeqOptions(
896 JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq)
898 cmb_assSeq.removeAllItems();
899 cmb_assSeq.addItem(new AssociateSeqOptions("-Select Associated Seq-",
901 lbl_associateSeq.setVisible(false);
902 if (selectedSequences.length > 1)
904 for (SequenceI seq : selectedSequences)
906 cmb_assSeq.addItem(new AssociateSeqOptions(seq));
911 String seqName = selectedSequence.getDisplayId(false);
912 seqName = seqName.length() <= 40 ? seqName : seqName.substring(0, 39);
913 lbl_associateSeq.setText(seqName);
914 lbl_associateSeq.setVisible(true);
915 cmb_assSeq.setVisible(false);
919 public boolean isStructuresDiscovered()
921 return structuresDiscovered;
924 public void setStructuresDiscovered(boolean structuresDiscovered)
926 this.structuresDiscovered = structuresDiscovered;
929 public Collection<FTSData> getDiscoveredStructuresSet()
931 return discoveredStructuresSet;
935 protected void txt_search_ActionPerformed()
942 errorWarning.setLength(0);
943 isValidPBDEntry = false;
944 if (txt_search.getText().length() > 0)
946 List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
947 FTSRestRequest pdbRequest = new FTSRestRequest();
948 pdbRequest.setAllowEmptySeq(false);
949 pdbRequest.setResponseSize(1);
950 pdbRequest.setFieldToSearchBy("(pdb_id:");
951 pdbRequest.setWantedFields(wantedFields);
953 .setSearchTerm(txt_search.getText().toLowerCase() + ")");
954 pdbRequest.setAssociatedSequence(selectedSequence);
955 pdbRestCleint = PDBFTSRestClient.getInstance();
956 wantedFields.add(pdbRestCleint.getPrimaryKeyColumn());
957 FTSRestResponse resultList;
960 resultList = pdbRestCleint.executeRequest(pdbRequest);
961 } catch (Exception e)
963 errorWarning.append(e.getMessage());
967 validateSelections();
969 if (resultList.getSearchSummary() != null
970 && resultList.getSearchSummary().size() > 0)
972 isValidPBDEntry = true;
975 validateSelections();
981 public void tabRefresh()
983 if (selectedSequences != null)
985 Thread refreshThread = new Thread(new Runnable()
990 fetchStructuresMetaData();
991 filterResultSet(((FilterOption) cmb_filterOption
992 .getSelectedItem()).getValue());
995 refreshThread.start();
999 public class PDBEntryTableModel extends AbstractTableModel
1001 String[] columns = { "Ref Sequence", "PDB Id", "Chain", "Type", "File" };
1003 private List<CachedPDB> pdbEntries;
1005 public PDBEntryTableModel(List<CachedPDB> pdbEntries)
1007 this.pdbEntries = new ArrayList<CachedPDB>(pdbEntries);
1011 public String getColumnName(int columnIndex)
1013 return columns[columnIndex];
1017 public int getRowCount()
1019 return pdbEntries.size();
1023 public int getColumnCount()
1025 return columns.length;
1029 public boolean isCellEditable(int row, int column)
1035 public Object getValueAt(int rowIndex, int columnIndex)
1037 Object value = "??";
1038 CachedPDB entry = pdbEntries.get(rowIndex);
1039 switch (columnIndex)
1042 value = entry.getSequence();
1045 value = entry.getPdbEntry();
1048 value = entry.getPdbEntry().getChainCode() == null ? "_" : entry
1049 .getPdbEntry().getChainCode();
1052 value = entry.getPdbEntry().getType();
1055 value = entry.getPdbEntry().getFile();
1062 public Class<?> getColumnClass(int columnIndex)
1064 return columnIndex == 0 ? SequenceI.class : PDBEntry.class;
1067 public CachedPDB getPDBEntryAt(int row)
1069 return pdbEntries.get(row);
1074 private class CachedPDB
1076 private SequenceI sequence;
1078 private PDBEntry pdbEntry;
1080 public CachedPDB(SequenceI sequence, PDBEntry pdbEntry)
1082 this.sequence = sequence;
1083 this.pdbEntry = pdbEntry;
1086 public SequenceI getSequence()
1091 public PDBEntry getPdbEntry()
1098 private IProgressIndicator progressBar;
1101 public void setProgressBar(String message, long id)
1103 progressBar.setProgressBar(message, id);
1107 public void registerHandler(long id, IProgressIndicatorHandler handler)
1109 progressBar.registerHandler(id, handler);
1113 public boolean operationInProgress()
1115 return progressBar.operationInProgress();