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.StructureMapping;
37 import jalview.structure.StructureSelectionManager;
38 import jalview.util.MessageManager;
39 import jalview.ws.DBRefFetcher;
40 import jalview.ws.sifts.SiftsSettings;
42 import java.awt.event.ItemEvent;
43 import java.util.ArrayList;
44 import java.util.Collection;
45 import java.util.HashSet;
46 import java.util.LinkedHashSet;
47 import java.util.List;
48 import java.util.Objects;
50 import java.util.Vector;
52 import javax.swing.JCheckBox;
53 import javax.swing.JComboBox;
54 import javax.swing.JLabel;
55 import javax.swing.JOptionPane;
56 import javax.swing.table.AbstractTableModel;
59 * Provides the behaviors for the Structure chooser Panel
64 @SuppressWarnings("serial")
65 public class StructureChooser extends GStructureChooser implements
68 private boolean structuresDiscovered = false;
70 private SequenceI selectedSequence;
72 private SequenceI[] selectedSequences;
74 private IProgressIndicator progressIndicator;
76 private Collection<FTSData> discoveredStructuresSet;
78 private FTSRestRequest lastPdbRequest;
80 private FTSRestClientI pdbRestCleint;
82 private String selectedPdbFileName;
84 private boolean isValidPBDEntry;
86 public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
90 this.selectedSequence = selectedSeq;
91 this.selectedSequences = selectedSeqs;
92 this.progressIndicator = (ap == null) ? null : ap.alignFrame;
97 * Initializes parameters used by the Structure Chooser Panel
101 if (!Jalview.isHeadlessMode())
103 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
106 Thread discoverPDBStructuresThread = new Thread(new Runnable()
111 long startTime = System.currentTimeMillis();
112 updateProgressIndicator(MessageManager
113 .getString("status.loading_cached_pdb_entries"), startTime);
114 loadLocalCachedPDBEntries();
115 updateProgressIndicator(null, startTime);
116 updateProgressIndicator(MessageManager
117 .getString("status.searching_for_pdb_structures"),
119 fetchStructuresMetaData();
120 populateFilterComboBox();
121 updateProgressIndicator(null, startTime);
122 mainFrame.setVisible(true);
126 discoverPDBStructuresThread.start();
130 * Updates the progress indicator with the specified message
133 * displayed message for the operation
135 * unique handle for this indicator
137 public void updateProgressIndicator(String message, long id)
139 if (progressIndicator != null)
141 progressIndicator.setProgressBar(message, id);
146 * Retrieve meta-data for all the structure(s) for a given sequence(s) in a
149 public void fetchStructuresMetaData()
151 long startTime = System.currentTimeMillis();
152 pdbRestCleint = PDBFTSRestClient.getInstance();
153 Collection<FTSDataColumnI> wantedFields = pdbDocFieldPrefs
154 .getStructureSummaryFields();
156 discoveredStructuresSet = new LinkedHashSet<FTSData>();
157 HashSet<String> errors = new HashSet<String>();
158 for (SequenceI seq : selectedSequences)
160 FTSRestRequest pdbRequest = new FTSRestRequest();
161 pdbRequest.setAllowEmptySeq(false);
162 pdbRequest.setResponseSize(500);
163 pdbRequest.setFieldToSearchBy("(");
164 pdbRequest.setWantedFields(wantedFields);
165 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
166 pdbRequest.setAssociatedSequence(seq);
167 FTSRestResponse resultList;
170 resultList = pdbRestCleint.executeRequest(pdbRequest);
171 } catch (Exception e)
174 errors.add(e.getMessage());
177 lastPdbRequest = pdbRequest;
178 if (resultList.getSearchSummary() != null
179 && !resultList.getSearchSummary().isEmpty())
181 discoveredStructuresSet.addAll(resultList.getSearchSummary());
185 int noOfStructuresFound = 0;
186 String totalTime = (System.currentTimeMillis() - startTime)
188 if (discoveredStructuresSet != null
189 && !discoveredStructuresSet.isEmpty())
191 getResultTable().setModel(
192 FTSRestResponse.getTableModel(lastPdbRequest,
193 discoveredStructuresSet));
194 structuresDiscovered = true;
195 noOfStructuresFound = discoveredStructuresSet.size();
196 mainFrame.setTitle(MessageManager.formatMessage(
197 "label.structure_chooser_no_of_structures",
198 noOfStructuresFound, totalTime));
202 mainFrame.setTitle(MessageManager
203 .getString("label.structure_chooser_manual_association"));
204 if (errors.size() > 0)
206 StringBuilder errorMsg = new StringBuilder();
207 for (String error : errors)
209 errorMsg.append(error).append("\n");
211 JOptionPane.showMessageDialog(this, errorMsg.toString(),
212 MessageManager.getString("label.pdb_web-service_error"),
213 JOptionPane.ERROR_MESSAGE);
218 public void loadLocalCachedPDBEntries()
220 ArrayList<CachedPDB> entries = new ArrayList<CachedPDB>();
221 for (SequenceI seq : selectedSequences)
223 if (seq.getDatasetSequence() != null
224 && seq.getDatasetSequence().getAllPDBEntries() != null)
226 for (PDBEntry pdbEntry : seq.getDatasetSequence()
229 if (pdbEntry.getFile() != null)
231 entries.add(new CachedPDB(seq, pdbEntry));
237 PDBEntryTableModel tableModelx = new PDBEntryTableModel(entries);
238 tbl_local_pdb.setModel(tableModelx);
242 * Builds a query string for a given sequences using its DBRef entries
245 * the sequences to build a query for
246 * @return the built query string
249 public static String buildQuery(SequenceI seq)
251 boolean isPDBRefsFound = false;
252 boolean isUniProtRefsFound = false;
253 StringBuilder queryBuilder = new StringBuilder();
254 Set<String> seqRefs = new LinkedHashSet<String>();
256 if (seq.getAllPDBEntries() != null)
258 for (PDBEntry entry : seq.getAllPDBEntries())
260 if (isValidSeqName(entry.getId()))
262 queryBuilder.append("pdb_id:")
263 .append(entry.getId().toLowerCase())
265 isPDBRefsFound = true;
266 // seqRefs.add(entry.getId());
271 if (seq.getDBRefs() != null && seq.getDBRefs().length != 0)
273 for (DBRefEntry dbRef : seq.getDBRefs())
275 if (isValidSeqName(getDBRefId(dbRef)))
277 if (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT))
279 queryBuilder.append("uniprot_accession:")
280 .append(getDBRefId(dbRef))
282 queryBuilder.append("uniprot_id:").append(getDBRefId(dbRef))
284 isUniProtRefsFound = true;
286 else if (dbRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
289 queryBuilder.append("pdb_id:")
290 .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 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 = pdbDocFieldPrefs
400 .getStructureSummaryFields();
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 pdbRequest.setAllowEmptySeq(false);
410 pdbRequest.setResponseSize(1);
411 pdbRequest.setFieldToSearchBy("(");
412 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
413 pdbRequest.setWantedFields(wantedFields);
414 pdbRequest.setAssociatedSequence(seq);
415 pdbRequest.setFacet(true);
416 pdbRequest.setFacetPivot(fieldToFilterBy + ",entry_entity");
417 pdbRequest.setFacetPivotMinCount(1);
421 pdbRequest.setAllowEmptySeq(false);
422 pdbRequest.setResponseSize(1);
423 pdbRequest.setFieldToSearchBy("(");
424 pdbRequest.setFieldToSortBy(fieldToFilterBy,
425 !chk_invertFilter.isSelected());
426 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
427 pdbRequest.setWantedFields(wantedFields);
428 pdbRequest.setAssociatedSequence(seq);
430 FTSRestResponse resultList;
433 resultList = pdbRestCleint.executeRequest(pdbRequest);
434 } catch (Exception e)
437 errors.add(e.getMessage());
440 lastPdbRequest = pdbRequest;
441 if (resultList.getSearchSummary() != null
442 && !resultList.getSearchSummary().isEmpty())
444 filteredResponse.addAll(resultList.getSearchSummary());
448 String totalTime = (System.currentTimeMillis() - startTime)
450 if (!filteredResponse.isEmpty())
452 final int filterResponseCount = filteredResponse.size();
453 Collection<FTSData> reorderedStructuresSet = new LinkedHashSet<FTSData>();
454 reorderedStructuresSet.addAll(filteredResponse);
455 reorderedStructuresSet.addAll(discoveredStructuresSet);
456 getResultTable().setModel(
457 FTSRestResponse.getTableModel(
458 lastPdbRequest, reorderedStructuresSet));
460 FTSRestResponse.configureTableColumn(getResultTable(),
461 wantedFields, tempUserPrefs);
462 getResultTable().getColumn("Ref Sequence").setPreferredWidth(120);
463 getResultTable().getColumn("Ref Sequence").setMinWidth(100);
464 getResultTable().getColumn("Ref Sequence").setMaxWidth(200);
465 // Update table selection model here
466 getResultTable().addRowSelectionInterval(0,
467 filterResponseCount - 1);
468 mainFrame.setTitle(MessageManager.formatMessage(
469 "label.structure_chooser_filter_time", totalTime));
473 mainFrame.setTitle(MessageManager.formatMessage(
474 "label.structure_chooser_filter_time", totalTime));
475 if (errors.size() > 0)
477 StringBuilder errorMsg = new StringBuilder();
478 for (String error : errors)
480 errorMsg.append(error).append("\n");
482 JOptionPane.showMessageDialog(
485 MessageManager.getString("label.pdb_web-service_error"),
486 JOptionPane.ERROR_MESSAGE);
490 lbl_loading.setVisible(false);
492 validateSelections();
495 filterThread.start();
499 * Handles action event for btn_pdbFromFile
502 public void pdbFromFile_actionPerformed()
504 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
505 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
506 chooser.setFileView(new jalview.io.JalviewFileView());
507 chooser.setDialogTitle(MessageManager.formatMessage(
508 "label.select_pdb_file_for",
509 selectedSequence.getDisplayId(false)));
510 chooser.setToolTipText(MessageManager.formatMessage(
511 "label.load_pdb_file_associate_with_sequence",
512 selectedSequence.getDisplayId(false)));
514 int value = chooser.showOpenDialog(null);
515 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
517 selectedPdbFileName = chooser.getSelectedFile().getPath();
518 jalview.bin.Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName);
519 validateSelections();
524 * Populates the filter combo-box options dynamically depending on discovered
528 protected void populateFilterComboBox()
530 if (isStructuresDiscovered())
532 cmb_filterOption.addItem(new FilterOption("Best Quality",
533 "overall_quality", 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 (getResultTable().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 final int preferredHeight = pnl_filter.getHeight();
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 = getResultTable().getColumn("PDB Id")
735 int refSeqColIndex = getResultTable().getColumn("Ref Sequence")
737 int[] selectedRows = getResultTable().getSelectedRows();
738 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
740 ArrayList<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
741 for (int row : selectedRows)
743 String pdbIdStr = getResultTable().getValueAt(row,
744 pdbIdColIndex).toString();
745 SequenceI selectedSeq = (SequenceI) getResultTable()
746 .getValueAt(row, refSeqColIndex);
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(
783 row, refSeqColIndex);
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.setId(pdbIdStr.split(":")[0]);
807 pdbEntry.setChainCode(pdbIdStr.split(":")[1].toUpperCase());
811 pdbEntry.setId(pdbIdStr);
813 pdbEntry.setType(PDBEntry.Type.PDB);
814 selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
817 PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
818 launchStructureViewer(ssm, pdbEntriesToView, ap,
819 new SequenceI[] { selectedSequence });
821 else if (currentView == VIEWS_FROM_FILE)
823 SequenceI userSelectedSeq = ((AssociateSeqOptions) fileChooserAssSeqPanel
824 .getCmb_assSeq().getSelectedItem()).getSequence();
825 if (userSelectedSeq != null)
827 selectedSequence = userSelectedSeq;
829 PDBEntry fileEntry = new AssociatePdbFileWithSeq()
830 .associatePdbWithSeq(selectedPdbFileName,
831 jalview.io.AppletFormatAdapter.FILE,
832 selectedSequence, true, Desktop.instance);
834 launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
835 new SequenceI[] { selectedSequence });
837 closeAction(preferredHeight);
842 private PDBEntry getFindEntry(String id, Vector<PDBEntry> pdbEntries)
844 Objects.requireNonNull(id);
845 Objects.requireNonNull(pdbEntries);
846 PDBEntry foundEntry = null;
847 for (PDBEntry entry : pdbEntries)
849 if (entry.getId().equalsIgnoreCase(id))
857 private void launchStructureViewer(StructureSelectionManager ssm,
858 final PDBEntry[] pdbEntriesToView,
859 final AlignmentPanel alignPanel, SequenceI[] sequences)
861 ssm.setProgressBar(MessageManager
862 .getString("status.launching_3d_structure_viewer"));
863 final StructureViewer sViewer = new StructureViewer(ssm);
865 if (SiftsSettings.isMapWithSifts())
867 List<SequenceI> seqsWithoutSourceDBRef = new ArrayList<SequenceI>();
869 // TODO: skip PDBEntry:Sequence pairs where PDBEntry doesn't look like a
870 // real PDB ID. For moment, we can also safely do this if there is already
871 // a known mapping between the PDBEntry and the sequence.
872 for (SequenceI seq : sequences)
874 PDBEntry pdbe = pdbEntriesToView[p++];
875 if (pdbe != null && pdbe.getFile() != null)
877 StructureMapping[] smm = ssm.getMapping(pdbe.getFile());
878 if (smm != null && smm.length > 0)
880 for (StructureMapping sm : smm)
882 if (sm.getSequence() == seq)
889 if (seq.getPrimaryDBRefs().size() == 0)
891 seqsWithoutSourceDBRef.add(seq);
895 if (!seqsWithoutSourceDBRef.isEmpty())
897 int y = seqsWithoutSourceDBRef.size();
898 ssm.setProgressBar(null);
899 ssm.setProgressBar(MessageManager.formatMessage(
900 "status.fetching_dbrefs_for_sequences_without_valid_refs",
902 SequenceI[] seqWithoutSrcDBRef = new SequenceI[y];
904 for (SequenceI fSeq : seqsWithoutSourceDBRef)
906 seqWithoutSrcDBRef[x++] = fSeq;
908 DBRefFetcher dbRefFetcher = new DBRefFetcher(seqWithoutSrcDBRef);
909 dbRefFetcher.fetchDBRefs(true);
912 if (pdbEntriesToView.length > 1)
914 ArrayList<SequenceI[]> seqsMap = new ArrayList<SequenceI[]>();
915 for (SequenceI seq : sequences)
917 seqsMap.add(new SequenceI[] { seq });
919 SequenceI[][] collatedSeqs = seqsMap.toArray(new SequenceI[0][0]);
920 ssm.setProgressBar(null);
921 ssm.setProgressBar(MessageManager
922 .getString("status.fetching_3d_structures_for_selected_entries"));
923 sViewer.viewStructures(pdbEntriesToView, collatedSeqs, alignPanel);
927 ssm.setProgressBar(null);
928 ssm.setProgressBar(MessageManager.formatMessage(
929 "status.fetching_3d_structures_for",
930 pdbEntriesToView[0].getId()));
931 sViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
936 * Populates the combo-box used in associating manually fetched structures to
937 * a unique sequence when more than one sequence selection is made.
940 public void populateCmbAssociateSeqOptions(
941 JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq)
943 cmb_assSeq.removeAllItems();
944 cmb_assSeq.addItem(new AssociateSeqOptions("-Select Associated Seq-",
946 lbl_associateSeq.setVisible(false);
947 if (selectedSequences.length > 1)
949 for (SequenceI seq : selectedSequences)
951 cmb_assSeq.addItem(new AssociateSeqOptions(seq));
956 String seqName = selectedSequence.getDisplayId(false);
957 seqName = seqName.length() <= 40 ? seqName : seqName.substring(0, 39);
958 lbl_associateSeq.setText(seqName);
959 lbl_associateSeq.setVisible(true);
960 cmb_assSeq.setVisible(false);
964 public boolean isStructuresDiscovered()
966 return structuresDiscovered;
969 public void setStructuresDiscovered(boolean structuresDiscovered)
971 this.structuresDiscovered = structuresDiscovered;
974 public Collection<FTSData> getDiscoveredStructuresSet()
976 return discoveredStructuresSet;
980 protected void txt_search_ActionPerformed()
987 errorWarning.setLength(0);
988 isValidPBDEntry = false;
989 if (txt_search.getText().length() > 0)
991 String searchTerm = txt_search.getText().toLowerCase();
992 searchTerm = searchTerm.split(":")[0];
993 // System.out.println(">>>>> search term : " + searchTerm);
994 List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
995 FTSRestRequest pdbRequest = new FTSRestRequest();
996 pdbRequest.setAllowEmptySeq(false);
997 pdbRequest.setResponseSize(1);
998 pdbRequest.setFieldToSearchBy("(pdb_id:");
999 pdbRequest.setWantedFields(wantedFields);
1001 .setSearchTerm(searchTerm + ")");
1002 pdbRequest.setAssociatedSequence(selectedSequence);
1003 pdbRestCleint = PDBFTSRestClient.getInstance();
1004 wantedFields.add(pdbRestCleint.getPrimaryKeyColumn());
1005 FTSRestResponse resultList;
1008 resultList = pdbRestCleint.executeRequest(pdbRequest);
1009 } catch (Exception e)
1011 errorWarning.append(e.getMessage());
1015 validateSelections();
1017 if (resultList.getSearchSummary() != null
1018 && resultList.getSearchSummary().size() > 0)
1020 isValidPBDEntry = true;
1023 validateSelections();
1029 public void tabRefresh()
1031 if (selectedSequences != null)
1033 Thread refreshThread = new Thread(new Runnable()
1038 fetchStructuresMetaData();
1039 filterResultSet(((FilterOption) cmb_filterOption
1040 .getSelectedItem()).getValue());
1043 refreshThread.start();
1047 public class PDBEntryTableModel extends AbstractTableModel
1049 String[] columns = { "Ref Sequence", "PDB Id", "Chain", "Type", "File" };
1051 private List<CachedPDB> pdbEntries;
1053 public PDBEntryTableModel(List<CachedPDB> pdbEntries)
1055 this.pdbEntries = new ArrayList<CachedPDB>(pdbEntries);
1059 public String getColumnName(int columnIndex)
1061 return columns[columnIndex];
1065 public int getRowCount()
1067 return pdbEntries.size();
1071 public int getColumnCount()
1073 return columns.length;
1077 public boolean isCellEditable(int row, int column)
1083 public Object getValueAt(int rowIndex, int columnIndex)
1085 Object value = "??";
1086 CachedPDB entry = pdbEntries.get(rowIndex);
1087 switch (columnIndex)
1090 value = entry.getSequence();
1093 value = entry.getPdbEntry();
1096 value = entry.getPdbEntry().getChainCode() == null ? "_" : entry
1097 .getPdbEntry().getChainCode();
1100 value = entry.getPdbEntry().getType();
1103 value = entry.getPdbEntry().getFile();
1110 public Class<?> getColumnClass(int columnIndex)
1112 return columnIndex == 0 ? SequenceI.class : PDBEntry.class;
1115 public CachedPDB getPDBEntryAt(int row)
1117 return pdbEntries.get(row);
1122 private class CachedPDB
1124 private SequenceI sequence;
1126 private PDBEntry pdbEntry;
1128 public CachedPDB(SequenceI sequence, PDBEntry pdbEntry)
1130 this.sequence = sequence;
1131 this.pdbEntry = pdbEntry;
1134 public SequenceI getSequence()
1139 public PDBEntry getPdbEntry()
1146 private IProgressIndicator progressBar;
1149 public void setProgressBar(String message, long id)
1151 progressBar.setProgressBar(message, id);
1155 public void registerHandler(long id, IProgressIndicatorHandler handler)
1157 progressBar.registerHandler(id, handler);
1161 public boolean operationInProgress()
1163 return progressBar.operationInProgress();