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.DBRefFetcher;
39 import jalview.ws.sifts.SiftsSettings;
41 import java.awt.event.ItemEvent;
42 import java.util.ArrayList;
43 import java.util.Collection;
44 import java.util.HashSet;
45 import java.util.LinkedHashSet;
46 import java.util.List;
47 import java.util.Objects;
48 import java.util.Vector;
50 import javax.swing.JCheckBox;
51 import javax.swing.JComboBox;
52 import javax.swing.JLabel;
53 import javax.swing.JOptionPane;
54 import javax.swing.table.AbstractTableModel;
57 * Provides the behaviors for the Structure chooser Panel
62 @SuppressWarnings("serial")
63 public class StructureChooser extends GStructureChooser implements
66 private boolean structuresDiscovered = false;
68 private SequenceI selectedSequence;
70 private SequenceI[] selectedSequences;
72 private IProgressIndicator progressIndicator;
74 private Collection<FTSData> discoveredStructuresSet;
76 private FTSRestRequest lastPdbRequest;
78 private FTSRestClientI pdbRestCleint;
80 private String selectedPdbFileName;
82 private boolean isValidPBDEntry;
84 public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
88 this.selectedSequence = selectedSeq;
89 this.selectedSequences = selectedSeqs;
90 this.progressIndicator = (ap == null) ? null : ap.alignFrame;
95 * Initializes parameters used by the Structure Chooser Panel
99 if (!Jalview.isHeadlessMode())
101 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
104 Thread discoverPDBStructuresThread = new Thread(new Runnable()
109 long startTime = System.currentTimeMillis();
110 updateProgressIndicator(MessageManager
111 .getString("status.loading_cached_pdb_entries"), startTime);
112 loadLocalCachedPDBEntries();
113 updateProgressIndicator(null, startTime);
114 updateProgressIndicator(MessageManager
115 .getString("status.searching_for_pdb_structures"),
117 fetchStructuresMetaData();
118 populateFilterComboBox();
119 updateProgressIndicator(null, startTime);
120 mainFrame.setVisible(true);
124 discoverPDBStructuresThread.start();
128 * Updates the progress indicator with the specified message
131 * displayed message for the operation
133 * unique handle for this indicator
135 public void updateProgressIndicator(String message, long id)
137 if (progressIndicator != null)
139 progressIndicator.setProgressBar(message, id);
144 * Retrieve meta-data for all the structure(s) for a given sequence(s) in a
147 public void fetchStructuresMetaData()
149 long startTime = System.currentTimeMillis();
150 pdbRestCleint = PDBFTSRestClient.getInstance();
151 Collection<FTSDataColumnI> wantedFields = pdbRestCleint
152 .getAllDefaulDisplayedDataColumns();
154 discoveredStructuresSet = new LinkedHashSet<FTSData>();
155 HashSet<String> errors = new HashSet<String>();
156 for (SequenceI seq : selectedSequences)
158 FTSRestRequest pdbRequest = new FTSRestRequest();
159 pdbRequest.setAllowEmptySeq(false);
160 pdbRequest.setResponseSize(500);
161 pdbRequest.setFieldToSearchBy("(");
162 pdbRequest.setWantedFields(wantedFields);
163 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
164 pdbRequest.setAssociatedSequence(seq);
165 FTSRestResponse resultList;
168 resultList = pdbRestCleint.executeRequest(pdbRequest);
169 } catch (Exception e)
172 errors.add(e.getMessage());
175 lastPdbRequest = pdbRequest;
176 if (resultList.getSearchSummary() != null
177 && !resultList.getSearchSummary().isEmpty())
179 discoveredStructuresSet.addAll(resultList.getSearchSummary());
183 int noOfStructuresFound = 0;
184 String totalTime = (System.currentTimeMillis() - startTime)
186 if (discoveredStructuresSet != null
187 && !discoveredStructuresSet.isEmpty())
189 tbl_summary.setModel(FTSRestResponse.getTableModel(lastPdbRequest,
190 discoveredStructuresSet));
191 structuresDiscovered = true;
192 noOfStructuresFound = discoveredStructuresSet.size();
193 mainFrame.setTitle(MessageManager.formatMessage(
194 "label.structure_chooser_no_of_structures",
195 noOfStructuresFound, totalTime));
199 mainFrame.setTitle(MessageManager
200 .getString("label.structure_chooser_manual_association"));
201 if (errors.size() > 0)
203 StringBuilder errorMsg = new StringBuilder();
204 for (String error : errors)
206 errorMsg.append(error).append("\n");
208 JOptionPane.showMessageDialog(this, errorMsg.toString(),
209 MessageManager.getString("label.pdb_web-service_error"),
210 JOptionPane.ERROR_MESSAGE);
215 public void loadLocalCachedPDBEntries()
217 ArrayList<CachedPDB> entries = new ArrayList<CachedPDB>();
218 for (SequenceI seq : selectedSequences)
220 if (seq.getDatasetSequence() != null
221 && seq.getDatasetSequence().getAllPDBEntries() != null)
223 for (PDBEntry pdbEntry : seq.getDatasetSequence()
226 if (pdbEntry.getFile() != null)
228 entries.add(new CachedPDB(seq, pdbEntry));
234 PDBEntryTableModel tableModelx = new PDBEntryTableModel(entries);
235 tbl_local_pdb.setModel(tableModelx);
239 * Builds a query string for a given sequences using its DBRef entries
242 * the sequences to build a query for
243 * @return the built query string
246 public static String buildQuery(SequenceI seq)
248 boolean isPDBRefsFound = false;
249 boolean isUniProtRefsFound = false;
250 StringBuilder queryBuilder = new StringBuilder();
251 HashSet<String> seqRefs = new LinkedHashSet<String>();
253 if (seq.getAllPDBEntries() != null)
255 for (PDBEntry entry : seq.getAllPDBEntries())
257 if (isValidSeqName(entry.getId()))
259 queryBuilder.append("pdb_id")
261 .append(entry.getId().toLowerCase())
263 isPDBRefsFound = true;
264 // seqRefs.add(entry.getId());
269 if (seq.getDBRefs() != null && seq.getDBRefs().length != 0)
271 for (DBRefEntry dbRef : seq.getDBRefs())
273 if (isValidSeqName(getDBRefId(dbRef)))
275 if (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT))
278 .append("uniprot_accession").append(":")
279 .append(getDBRefId(dbRef))
282 .append("uniprot_id")
284 .append(getDBRefId(dbRef)).append(" OR ");
285 isUniProtRefsFound = true;
287 else if (dbRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
290 queryBuilder.append("pdb_id")
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 pdbRestCleint = PDBFTSRestClient.getInstance();
399 lbl_loading.setVisible(true);
400 Collection<FTSDataColumnI> wantedFields = pdbRestCleint
401 .getAllDefaulDisplayedDataColumns();
402 Collection<FTSData> filteredResponse = new HashSet<FTSData>();
403 HashSet<String> errors = new HashSet<String>();
405 for (SequenceI seq : selectedSequences)
407 FTSRestRequest pdbRequest = new FTSRestRequest();
408 if (fieldToFilterBy.equalsIgnoreCase("uniprot_coverage"))
410 System.out.println(">>>>>> Filtering with uniprot coverate");
411 pdbRequest.setAllowEmptySeq(false);
412 pdbRequest.setResponseSize(1);
413 pdbRequest.setFieldToSearchBy("(");
414 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
415 pdbRequest.setWantedFields(wantedFields);
416 pdbRequest.setAssociatedSequence(seq);
417 pdbRequest.setFacet(true);
418 pdbRequest.setFacetPivot(fieldToFilterBy + ",entry_entity");
419 pdbRequest.setFacetPivotMinCount(1);
423 pdbRequest.setAllowEmptySeq(false);
424 pdbRequest.setResponseSize(1);
425 pdbRequest.setFieldToSearchBy("(");
426 pdbRequest.setFieldToSortBy(fieldToFilterBy,
427 !chk_invertFilter.isSelected());
428 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
429 pdbRequest.setWantedFields(wantedFields);
430 pdbRequest.setAssociatedSequence(seq);
432 FTSRestResponse 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<FTSData> reorderedStructuresSet = new LinkedHashSet<FTSData>();
456 reorderedStructuresSet.addAll(filteredResponse);
457 reorderedStructuresSet.addAll(discoveredStructuresSet);
458 tbl_summary.setModel(FTSRestResponse.getTableModel(
459 lastPdbRequest, reorderedStructuresSet));
461 FTSRestResponse.configureTableColumn(tbl_summary, wantedFields);
462 tbl_summary.getColumn("Ref Sequence").setPreferredWidth(120);
463 tbl_summary.getColumn("Ref Sequence").setMinWidth(100);
464 tbl_summary.getColumn("Ref Sequence").setMaxWidth(200);
465 // Update table selection model here
466 tbl_summary.addRowSelectionInterval(0, filterResponseCount - 1);
467 mainFrame.setTitle(MessageManager.formatMessage(
468 "label.structure_chooser_filter_time", totalTime));
472 mainFrame.setTitle(MessageManager.formatMessage(
473 "label.structure_chooser_filter_time", totalTime));
474 if (errors.size() > 0)
476 StringBuilder errorMsg = new StringBuilder();
477 for (String error : errors)
479 errorMsg.append(error).append("\n");
481 JOptionPane.showMessageDialog(
484 MessageManager.getString("label.pdb_web-service_error"),
485 JOptionPane.ERROR_MESSAGE);
489 lbl_loading.setVisible(false);
491 validateSelections();
494 filterThread.start();
498 * Handles action event for btn_pdbFromFile
501 public void pdbFromFile_actionPerformed()
503 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
504 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
505 chooser.setFileView(new jalview.io.JalviewFileView());
506 chooser.setDialogTitle(MessageManager.formatMessage(
507 "label.select_pdb_file_for",
508 selectedSequence.getDisplayId(false)));
509 chooser.setToolTipText(MessageManager.formatMessage(
510 "label.load_pdb_file_associate_with_sequence",
511 selectedSequence.getDisplayId(false)));
513 int value = chooser.showOpenDialog(null);
514 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
516 selectedPdbFileName = chooser.getSelectedFile().getPath();
517 jalview.bin.Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName);
518 validateSelections();
523 * Populates the filter combo-box options dynamically depending on discovered
527 protected void populateFilterComboBox()
529 if (isStructuresDiscovered())
531 cmb_filterOption.addItem(new FilterOption("Best Quality",
532 "overall_quality", VIEWS_FILTER));
533 cmb_filterOption.addItem(new FilterOption("Most UniProt Coverage",
534 "uniprot_coverage", VIEWS_FILTER));
535 cmb_filterOption.addItem(new FilterOption("Best Resolution",
536 "resolution", VIEWS_FILTER));
537 cmb_filterOption.addItem(new FilterOption("Most Protein Chain",
538 "number_of_protein_chains", VIEWS_FILTER));
539 cmb_filterOption.addItem(new FilterOption("Most Bound Molecules",
540 "number_of_bound_molecules", VIEWS_FILTER));
541 cmb_filterOption.addItem(new FilterOption("Most Polymer Residues",
542 "number_of_polymer_residues", VIEWS_FILTER));
544 cmb_filterOption.addItem(new FilterOption("Enter PDB Id", "-",
546 cmb_filterOption.addItem(new FilterOption("From File", "-",
548 cmb_filterOption.addItem(new FilterOption("Cached PDB Entries", "-",
553 * Updates the displayed view based on the selected filter option
556 protected void updateCurrentView()
558 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
560 layout_switchableViews.show(pnl_switchableViews,
561 selectedFilterOpt.getView());
562 String filterTitle = mainFrame.getTitle();
563 mainFrame.setTitle(frameTitle);
564 chk_invertFilter.setVisible(false);
565 if (selectedFilterOpt.getView() == VIEWS_FILTER)
567 mainFrame.setTitle(filterTitle);
568 chk_invertFilter.setVisible(true);
569 filterResultSet(selectedFilterOpt.getValue());
571 else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
572 || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
574 mainFrame.setTitle(MessageManager
575 .getString("label.structure_chooser_manual_association"));
576 idInputAssSeqPanel.loadCmbAssSeq();
577 fileChooserAssSeqPanel.loadCmbAssSeq();
579 validateSelections();
583 * Validates user selection and activates the view button if all parameters
587 public void validateSelections()
589 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
591 btn_view.setEnabled(false);
592 String currentView = selectedFilterOpt.getView();
593 if (currentView == VIEWS_FILTER)
595 if (tbl_summary.getSelectedRows().length > 0)
597 btn_view.setEnabled(true);
600 else if (currentView == VIEWS_LOCAL_PDB)
602 if (tbl_local_pdb.getSelectedRows().length > 0)
604 btn_view.setEnabled(true);
607 else if (currentView == VIEWS_ENTER_ID)
609 validateAssociationEnterPdb();
611 else if (currentView == VIEWS_FROM_FILE)
613 validateAssociationFromFile();
618 * Validates inputs from the Manual PDB entry panel
620 public void validateAssociationEnterPdb()
622 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel
623 .getCmb_assSeq().getSelectedItem();
624 lbl_pdbManualFetchStatus.setIcon(errorImage);
625 lbl_pdbManualFetchStatus.setToolTipText("");
626 if (txt_search.getText().length() > 0)
628 lbl_pdbManualFetchStatus
629 .setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
630 .formatMessage("info.no_pdb_entry_found_for",
631 txt_search.getText())));
634 if (errorWarning.length() > 0)
636 lbl_pdbManualFetchStatus.setIcon(warningImage);
637 lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip(
638 true, errorWarning.toString()));
641 if (selectedSequences.length == 1
642 || !assSeqOpt.getName().equalsIgnoreCase(
643 "-Select Associated Seq-"))
645 txt_search.setEnabled(true);
648 btn_view.setEnabled(true);
649 lbl_pdbManualFetchStatus.setToolTipText("");
650 lbl_pdbManualFetchStatus.setIcon(goodImage);
655 txt_search.setEnabled(false);
656 lbl_pdbManualFetchStatus.setIcon(errorImage);
661 * Validates inputs for the manual PDB file selection options
663 public void validateAssociationFromFile()
665 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
666 .getCmb_assSeq().getSelectedItem();
667 lbl_fromFileStatus.setIcon(errorImage);
668 if (selectedSequences.length == 1
669 || (assSeqOpt != null && !assSeqOpt.getName().equalsIgnoreCase(
670 "-Select Associated Seq-")))
672 btn_pdbFromFile.setEnabled(true);
673 if (selectedPdbFileName != null && selectedPdbFileName.length() > 0)
675 btn_view.setEnabled(true);
676 lbl_fromFileStatus.setIcon(goodImage);
681 btn_pdbFromFile.setEnabled(false);
682 lbl_fromFileStatus.setIcon(errorImage);
687 public void cmbAssSeqStateChanged()
689 validateSelections();
693 * Handles the state change event for the 'filter' combo-box and 'invert'
697 protected void stateChanged(ItemEvent e)
699 if (e.getSource() instanceof JCheckBox)
705 if (e.getStateChange() == ItemEvent.SELECTED)
714 * Handles action event for btn_ok
717 public void ok_ActionPerformed()
719 final long progressSessionId = System.currentTimeMillis();
720 final StructureSelectionManager ssm = ap.getStructureSelectionManager();
721 ssm.setProgressIndicator(this);
722 ssm.setProgressSessionId(progressSessionId);
723 new Thread(new Runnable()
728 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
730 String currentView = selectedFilterOpt.getView();
731 if (currentView == VIEWS_FILTER)
733 int pdbIdColIndex = tbl_summary.getColumn("PDB Id")
735 int refSeqColIndex = tbl_summary.getColumn("Ref Sequence")
737 int[] selectedRows = tbl_summary.getSelectedRows();
738 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
740 ArrayList<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
741 for (int row : selectedRows)
743 String pdbIdStr = tbl_summary.getValueAt(row, pdbIdColIndex)
745 SequenceI selectedSeq = (SequenceI) tbl_summary.getValueAt(row,
747 selectedSeqsToView.add(selectedSeq);
748 PDBEntry pdbEntry = selectedSeq.getPDBEntry(pdbIdStr);
749 if (pdbEntry == null)
751 pdbEntry = getFindEntry(pdbIdStr,
752 selectedSeq.getAllPDBEntries());
754 if (pdbEntry == null)
756 pdbEntry = new PDBEntry();
757 pdbEntry.setId(pdbIdStr);
758 pdbEntry.setType(PDBEntry.Type.PDB);
759 selectedSeq.getDatasetSequence().addPDBId(pdbEntry);
761 pdbEntriesToView[count++] = pdbEntry;
763 SequenceI[] selectedSeqs = selectedSeqsToView
764 .toArray(new SequenceI[selectedSeqsToView.size()]);
765 launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
767 else if (currentView == VIEWS_LOCAL_PDB)
769 int[] selectedRows = tbl_local_pdb.getSelectedRows();
770 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
772 int pdbIdColIndex = tbl_local_pdb.getColumn("PDB Id")
774 int refSeqColIndex = tbl_local_pdb.getColumn("Ref Sequence")
776 ArrayList<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
777 for (int row : selectedRows)
779 PDBEntry pdbEntry = (PDBEntry) tbl_local_pdb.getValueAt(row,
781 pdbEntriesToView[count++] = pdbEntry;
782 SequenceI selectedSeq = (SequenceI) tbl_local_pdb.getValueAt(row,
784 selectedSeqsToView.add(selectedSeq);
786 SequenceI[] selectedSeqs = selectedSeqsToView
787 .toArray(new SequenceI[selectedSeqsToView.size()]);
788 launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
790 else if (currentView == VIEWS_ENTER_ID)
792 SequenceI userSelectedSeq = ((AssociateSeqOptions) idInputAssSeqPanel
793 .getCmb_assSeq().getSelectedItem()).getSequence();
794 if (userSelectedSeq != null)
796 selectedSequence = userSelectedSeq;
799 String pdbIdStr = txt_search.getText();
800 PDBEntry pdbEntry = selectedSequence.getPDBEntry(pdbIdStr);
801 if (pdbEntry == null)
803 pdbEntry = new PDBEntry();
804 if (pdbIdStr.split(":").length > 1)
806 pdbEntry.setChainCode(pdbIdStr.split(":")[1]);
808 pdbEntry.setId(pdbIdStr);
809 pdbEntry.setType(PDBEntry.Type.PDB);
810 selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
813 PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
814 launchStructureViewer(ssm, pdbEntriesToView, ap,
815 new SequenceI[] { selectedSequence });
817 else if (currentView == VIEWS_FROM_FILE)
819 SequenceI userSelectedSeq = ((AssociateSeqOptions) fileChooserAssSeqPanel
820 .getCmb_assSeq().getSelectedItem()).getSequence();
821 if (userSelectedSeq != null)
823 selectedSequence = userSelectedSeq;
825 PDBEntry fileEntry = new AssociatePdbFileWithSeq()
826 .associatePdbWithSeq(selectedPdbFileName,
827 jalview.io.AppletFormatAdapter.FILE,
828 selectedSequence, true, Desktop.instance);
830 launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
831 new SequenceI[] { selectedSequence });
838 private PDBEntry getFindEntry(String id, Vector<PDBEntry> pdbEntries)
840 Objects.requireNonNull(id);
841 Objects.requireNonNull(pdbEntries);
842 PDBEntry foundEntry = null;
843 for (PDBEntry entry : pdbEntries)
845 if (entry.getId().equalsIgnoreCase(id))
853 private void launchStructureViewer(StructureSelectionManager ssm,
854 final PDBEntry[] pdbEntriesToView,
855 final AlignmentPanel alignPanel, SequenceI[] sequences)
857 ssm.setProgressBar("Launching PDB structure viewer..");
858 final StructureViewer sViewer = new StructureViewer(ssm);
860 if (SiftsSettings.isMapWithSifts())
862 for (SequenceI seq : sequences)
864 if (seq.getSourceDBRef() == null)
866 ssm.setProgressBar(null);
867 ssm.setProgressBar("Fetching Database refs..");
868 new DBRefFetcher(sequences).fetchDBRefs(true);
873 if (pdbEntriesToView.length > 1)
875 ArrayList<SequenceI[]> seqsMap = new ArrayList<SequenceI[]>();
876 for (SequenceI seq : sequences)
878 seqsMap.add(new SequenceI[] { seq });
880 SequenceI[][] collatedSeqs = seqsMap.toArray(new SequenceI[0][0]);
881 ssm.setProgressBar(null);
882 ssm.setProgressBar("Fetching PDB Structures for selected entries..");
883 sViewer.viewStructures(pdbEntriesToView, collatedSeqs, alignPanel);
887 ssm.setProgressBar(null);
888 ssm.setProgressBar("Fetching PDB Structure for "
889 + pdbEntriesToView[0].getId());
890 sViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
895 * Populates the combo-box used in associating manually fetched structures to
896 * a unique sequence when more than one sequence selection is made.
899 public void populateCmbAssociateSeqOptions(
900 JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq)
902 cmb_assSeq.removeAllItems();
903 cmb_assSeq.addItem(new AssociateSeqOptions("-Select Associated Seq-",
905 lbl_associateSeq.setVisible(false);
906 if (selectedSequences.length > 1)
908 for (SequenceI seq : selectedSequences)
910 cmb_assSeq.addItem(new AssociateSeqOptions(seq));
915 String seqName = selectedSequence.getDisplayId(false);
916 seqName = seqName.length() <= 40 ? seqName : seqName.substring(0, 39);
917 lbl_associateSeq.setText(seqName);
918 lbl_associateSeq.setVisible(true);
919 cmb_assSeq.setVisible(false);
923 public boolean isStructuresDiscovered()
925 return structuresDiscovered;
928 public void setStructuresDiscovered(boolean structuresDiscovered)
930 this.structuresDiscovered = structuresDiscovered;
933 public Collection<FTSData> getDiscoveredStructuresSet()
935 return discoveredStructuresSet;
939 protected void txt_search_ActionPerformed()
946 errorWarning.setLength(0);
947 isValidPBDEntry = false;
948 if (txt_search.getText().length() > 0)
950 String searchTerm = txt_search.getText().toLowerCase();
951 searchTerm = searchTerm.split(":")[0];
952 System.out.println(">>>>> search term : " + searchTerm);
953 List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
954 FTSRestRequest pdbRequest = new FTSRestRequest();
955 pdbRequest.setAllowEmptySeq(false);
956 pdbRequest.setResponseSize(1);
957 pdbRequest.setFieldToSearchBy("(pdb_id:");
958 pdbRequest.setWantedFields(wantedFields);
960 .setSearchTerm(searchTerm + ")");
961 pdbRequest.setAssociatedSequence(selectedSequence);
962 pdbRestCleint = PDBFTSRestClient.getInstance();
963 wantedFields.add(pdbRestCleint.getPrimaryKeyColumn());
964 FTSRestResponse resultList;
967 resultList = pdbRestCleint.executeRequest(pdbRequest);
968 } catch (Exception e)
970 errorWarning.append(e.getMessage());
974 validateSelections();
976 if (resultList.getSearchSummary() != null
977 && resultList.getSearchSummary().size() > 0)
979 isValidPBDEntry = true;
982 validateSelections();
988 public void tabRefresh()
990 if (selectedSequences != null)
992 Thread refreshThread = new Thread(new Runnable()
997 fetchStructuresMetaData();
998 filterResultSet(((FilterOption) cmb_filterOption
999 .getSelectedItem()).getValue());
1002 refreshThread.start();
1006 public class PDBEntryTableModel extends AbstractTableModel
1008 String[] columns = { "Ref Sequence", "PDB Id", "Chain", "Type", "File" };
1010 private List<CachedPDB> pdbEntries;
1012 public PDBEntryTableModel(List<CachedPDB> pdbEntries)
1014 this.pdbEntries = new ArrayList<CachedPDB>(pdbEntries);
1018 public String getColumnName(int columnIndex)
1020 return columns[columnIndex];
1024 public int getRowCount()
1026 return pdbEntries.size();
1030 public int getColumnCount()
1032 return columns.length;
1036 public boolean isCellEditable(int row, int column)
1042 public Object getValueAt(int rowIndex, int columnIndex)
1044 Object value = "??";
1045 CachedPDB entry = pdbEntries.get(rowIndex);
1046 switch (columnIndex)
1049 value = entry.getSequence();
1052 value = entry.getPdbEntry();
1055 value = entry.getPdbEntry().getChainCode() == null ? "_" : entry
1056 .getPdbEntry().getChainCode();
1059 value = entry.getPdbEntry().getType();
1062 value = entry.getPdbEntry().getFile();
1069 public Class<?> getColumnClass(int columnIndex)
1071 return columnIndex == 0 ? SequenceI.class : PDBEntry.class;
1074 public CachedPDB getPDBEntryAt(int row)
1076 return pdbEntries.get(row);
1081 private class CachedPDB
1083 private SequenceI sequence;
1085 private PDBEntry pdbEntry;
1087 public CachedPDB(SequenceI sequence, PDBEntry pdbEntry)
1089 this.sequence = sequence;
1090 this.pdbEntry = pdbEntry;
1093 public SequenceI getSequence()
1098 public PDBEntry getPdbEntry()
1105 private IProgressIndicator progressBar;
1108 public void setProgressBar(String message, long id)
1110 progressBar.setProgressBar(message, id);
1114 public void registerHandler(long id, IProgressIndicatorHandler handler)
1116 progressBar.registerHandler(id, handler);
1120 public boolean operationInProgress()
1122 return progressBar.operationInProgress();