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 = pdbDocFieldPrefs
152 .getStructureSummaryFields();
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 getResultTable().setModel(
190 FTSRestResponse.getTableModel(lastPdbRequest,
191 discoveredStructuresSet));
192 structuresDiscovered = true;
193 noOfStructuresFound = discoveredStructuresSet.size();
194 mainFrame.setTitle(MessageManager.formatMessage(
195 "label.structure_chooser_no_of_structures",
196 noOfStructuresFound, totalTime));
200 mainFrame.setTitle(MessageManager
201 .getString("label.structure_chooser_manual_association"));
202 if (errors.size() > 0)
204 StringBuilder errorMsg = new StringBuilder();
205 for (String error : errors)
207 errorMsg.append(error).append("\n");
209 JOptionPane.showMessageDialog(this, errorMsg.toString(),
210 MessageManager.getString("label.pdb_web-service_error"),
211 JOptionPane.ERROR_MESSAGE);
216 public void loadLocalCachedPDBEntries()
218 ArrayList<CachedPDB> entries = new ArrayList<CachedPDB>();
219 for (SequenceI seq : selectedSequences)
221 if (seq.getDatasetSequence() != null
222 && seq.getDatasetSequence().getAllPDBEntries() != null)
224 for (PDBEntry pdbEntry : seq.getDatasetSequence()
227 if (pdbEntry.getFile() != null)
229 entries.add(new CachedPDB(seq, pdbEntry));
235 PDBEntryTableModel tableModelx = new PDBEntryTableModel(entries);
236 tbl_local_pdb.setModel(tableModelx);
240 * Builds a query string for a given sequences using its DBRef entries
243 * the sequences to build a query for
244 * @return the built query string
247 public static String buildQuery(SequenceI seq)
249 boolean isPDBRefsFound = false;
250 boolean isUniProtRefsFound = false;
251 StringBuilder queryBuilder = new StringBuilder();
252 HashSet<String> seqRefs = new LinkedHashSet<String>();
254 if (seq.getAllPDBEntries() != null)
256 for (PDBEntry entry : seq.getAllPDBEntries())
258 if (isValidSeqName(entry.getId()))
260 queryBuilder.append("pdb_id")
262 .append(entry.getId().toLowerCase())
264 isPDBRefsFound = true;
265 // seqRefs.add(entry.getId());
270 if (seq.getDBRefs() != null && seq.getDBRefs().length != 0)
272 for (DBRefEntry dbRef : seq.getDBRefs())
274 if (isValidSeqName(getDBRefId(dbRef)))
276 if (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT))
279 .append("uniprot_accession").append(":")
280 .append(getDBRefId(dbRef))
283 .append("uniprot_id")
285 .append(getDBRefId(dbRef)).append(" OR ");
286 isUniProtRefsFound = true;
288 else if (dbRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
291 queryBuilder.append("pdb_id")
292 .append(":").append(getDBRefId(dbRef).toLowerCase())
294 isPDBRefsFound = true;
298 seqRefs.add(getDBRefId(dbRef));
304 if (!isPDBRefsFound && !isUniProtRefsFound)
306 String seqName = seq.getName();
307 seqName = sanitizeSeqName(seqName);
308 String[] names = seqName.toLowerCase().split("\\|");
309 for (String name : names)
311 // System.out.println("Found name : " + name);
313 if (isValidSeqName(name))
319 for (String seqRef : seqRefs)
321 queryBuilder.append("text:").append(seqRef).append(" OR ");
325 int endIndex = queryBuilder.lastIndexOf(" OR ");
326 if (queryBuilder.toString().length() < 6)
330 String query = queryBuilder.toString().substring(0, endIndex);
335 * Remove the following special characters from input string +, -, &, !, (, ),
336 * {, }, [, ], ^, ", ~, *, ?, :, \
341 static String sanitizeSeqName(String seqName)
343 Objects.requireNonNull(seqName);
344 return seqName.replaceAll("\\[\\d*\\]", "")
345 .replaceAll("[^\\dA-Za-z|_]", "").replaceAll("\\s+", "+");
350 * Ensures sequence ref names are not less than 3 characters and does not
351 * contain a database name
356 public static boolean isValidSeqName(String seqName)
358 // System.out.println("seqName : " + seqName);
359 String ignoreList = "pdb,uniprot,swiss-prot";
360 if (seqName.length() < 3)
364 if (seqName.contains(":"))
368 seqName = seqName.toLowerCase();
369 for (String ignoredEntry : ignoreList.split(","))
371 if (seqName.contains(ignoredEntry))
379 public static String getDBRefId(DBRefEntry dbRef)
381 String ref = dbRef.getAccessionId().replaceAll("GO:", "");
386 * Filters a given list of discovered structures based on supplied argument
388 * @param fieldToFilterBy
389 * the field to filter by
391 public void filterResultSet(final String fieldToFilterBy)
393 Thread filterThread = new Thread(new Runnable()
398 long startTime = System.currentTimeMillis();
399 pdbRestCleint = PDBFTSRestClient.getInstance();
400 lbl_loading.setVisible(true);
401 Collection<FTSDataColumnI> wantedFields = pdbDocFieldPrefs
402 .getStructureSummaryFields();
403 Collection<FTSData> filteredResponse = new HashSet<FTSData>();
404 HashSet<String> errors = new HashSet<String>();
406 for (SequenceI seq : selectedSequences)
408 FTSRestRequest pdbRequest = new FTSRestRequest();
409 if (fieldToFilterBy.equalsIgnoreCase("uniprot_coverage"))
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 getResultTable().setModel(
459 FTSRestResponse.getTableModel(
460 lastPdbRequest, reorderedStructuresSet));
462 FTSRestResponse.configureTableColumn(getResultTable(),
464 getResultTable().getColumn("Ref Sequence").setPreferredWidth(120);
465 getResultTable().getColumn("Ref Sequence").setMinWidth(100);
466 getResultTable().getColumn("Ref Sequence").setMaxWidth(200);
467 // Update table selection model here
468 getResultTable().addRowSelectionInterval(0,
469 filterResponseCount - 1);
470 mainFrame.setTitle(MessageManager.formatMessage(
471 "label.structure_chooser_filter_time", totalTime));
475 mainFrame.setTitle(MessageManager.formatMessage(
476 "label.structure_chooser_filter_time", totalTime));
477 if (errors.size() > 0)
479 StringBuilder errorMsg = new StringBuilder();
480 for (String error : errors)
482 errorMsg.append(error).append("\n");
484 JOptionPane.showMessageDialog(
487 MessageManager.getString("label.pdb_web-service_error"),
488 JOptionPane.ERROR_MESSAGE);
492 lbl_loading.setVisible(false);
494 validateSelections();
497 filterThread.start();
501 * Handles action event for btn_pdbFromFile
504 public void pdbFromFile_actionPerformed()
506 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
507 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
508 chooser.setFileView(new jalview.io.JalviewFileView());
509 chooser.setDialogTitle(MessageManager.formatMessage(
510 "label.select_pdb_file_for",
511 selectedSequence.getDisplayId(false)));
512 chooser.setToolTipText(MessageManager.formatMessage(
513 "label.load_pdb_file_associate_with_sequence",
514 selectedSequence.getDisplayId(false)));
516 int value = chooser.showOpenDialog(null);
517 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
519 selectedPdbFileName = chooser.getSelectedFile().getPath();
520 jalview.bin.Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName);
521 validateSelections();
526 * Populates the filter combo-box options dynamically depending on discovered
530 protected void populateFilterComboBox()
532 if (isStructuresDiscovered())
534 cmb_filterOption.addItem(new FilterOption("Best Quality",
535 "overall_quality", VIEWS_FILTER));
536 cmb_filterOption.addItem(new FilterOption("Best Resolution",
537 "resolution", VIEWS_FILTER));
538 cmb_filterOption.addItem(new FilterOption("Most Protein Chain",
539 "number_of_protein_chains", VIEWS_FILTER));
540 cmb_filterOption.addItem(new FilterOption("Most Bound Molecules",
541 "number_of_bound_molecules", VIEWS_FILTER));
542 cmb_filterOption.addItem(new FilterOption("Most Polymer Residues",
543 "number_of_polymer_residues", VIEWS_FILTER));
545 cmb_filterOption.addItem(new FilterOption("Enter PDB Id", "-",
547 cmb_filterOption.addItem(new FilterOption("From File", "-",
549 cmb_filterOption.addItem(new FilterOption("Cached PDB Entries", "-",
554 * Updates the displayed view based on the selected filter option
557 protected void updateCurrentView()
559 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
561 layout_switchableViews.show(pnl_switchableViews,
562 selectedFilterOpt.getView());
563 String filterTitle = mainFrame.getTitle();
564 mainFrame.setTitle(frameTitle);
565 chk_invertFilter.setVisible(false);
566 if (selectedFilterOpt.getView() == VIEWS_FILTER)
568 mainFrame.setTitle(filterTitle);
569 chk_invertFilter.setVisible(true);
570 filterResultSet(selectedFilterOpt.getValue());
572 else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
573 || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
575 mainFrame.setTitle(MessageManager
576 .getString("label.structure_chooser_manual_association"));
577 idInputAssSeqPanel.loadCmbAssSeq();
578 fileChooserAssSeqPanel.loadCmbAssSeq();
580 validateSelections();
584 * Validates user selection and activates the view button if all parameters
588 public void validateSelections()
590 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
592 btn_view.setEnabled(false);
593 String currentView = selectedFilterOpt.getView();
594 if (currentView == VIEWS_FILTER)
596 if (getResultTable().getSelectedRows().length > 0)
598 btn_view.setEnabled(true);
601 else if (currentView == VIEWS_LOCAL_PDB)
603 if (tbl_local_pdb.getSelectedRows().length > 0)
605 btn_view.setEnabled(true);
608 else if (currentView == VIEWS_ENTER_ID)
610 validateAssociationEnterPdb();
612 else if (currentView == VIEWS_FROM_FILE)
614 validateAssociationFromFile();
619 * Validates inputs from the Manual PDB entry panel
621 public void validateAssociationEnterPdb()
623 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel
624 .getCmb_assSeq().getSelectedItem();
625 lbl_pdbManualFetchStatus.setIcon(errorImage);
626 lbl_pdbManualFetchStatus.setToolTipText("");
627 if (txt_search.getText().length() > 0)
629 lbl_pdbManualFetchStatus
630 .setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
631 .formatMessage("info.no_pdb_entry_found_for",
632 txt_search.getText())));
635 if (errorWarning.length() > 0)
637 lbl_pdbManualFetchStatus.setIcon(warningImage);
638 lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip(
639 true, errorWarning.toString()));
642 if (selectedSequences.length == 1
643 || !assSeqOpt.getName().equalsIgnoreCase(
644 "-Select Associated Seq-"))
646 txt_search.setEnabled(true);
649 btn_view.setEnabled(true);
650 lbl_pdbManualFetchStatus.setToolTipText("");
651 lbl_pdbManualFetchStatus.setIcon(goodImage);
656 txt_search.setEnabled(false);
657 lbl_pdbManualFetchStatus.setIcon(errorImage);
662 * Validates inputs for the manual PDB file selection options
664 public void validateAssociationFromFile()
666 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
667 .getCmb_assSeq().getSelectedItem();
668 lbl_fromFileStatus.setIcon(errorImage);
669 if (selectedSequences.length == 1
670 || (assSeqOpt != null && !assSeqOpt.getName().equalsIgnoreCase(
671 "-Select Associated Seq-")))
673 btn_pdbFromFile.setEnabled(true);
674 if (selectedPdbFileName != null && selectedPdbFileName.length() > 0)
676 btn_view.setEnabled(true);
677 lbl_fromFileStatus.setIcon(goodImage);
682 btn_pdbFromFile.setEnabled(false);
683 lbl_fromFileStatus.setIcon(errorImage);
688 public void cmbAssSeqStateChanged()
690 validateSelections();
694 * Handles the state change event for the 'filter' combo-box and 'invert'
698 protected void stateChanged(ItemEvent e)
700 if (e.getSource() instanceof JCheckBox)
706 if (e.getStateChange() == ItemEvent.SELECTED)
715 * Handles action event for btn_ok
718 public void ok_ActionPerformed()
720 final StructureSelectionManager ssm = ap.getStructureSelectionManager();
721 new Thread(new Runnable()
726 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
728 String currentView = selectedFilterOpt.getView();
729 if (currentView == VIEWS_FILTER)
731 int pdbIdColIndex = getResultTable().getColumn("PDB Id")
733 int refSeqColIndex = getResultTable().getColumn("Ref Sequence")
735 int[] selectedRows = getResultTable().getSelectedRows();
736 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
738 ArrayList<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
739 for (int row : selectedRows)
741 String pdbIdStr = getResultTable().getValueAt(row,
744 SequenceI selectedSeq = (SequenceI) getResultTable()
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,
768 else if (currentView == VIEWS_LOCAL_PDB)
770 int[] selectedRows = tbl_local_pdb.getSelectedRows();
771 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
773 int pdbIdColIndex = tbl_local_pdb.getColumn("PDB Id")
775 int refSeqColIndex = tbl_local_pdb.getColumn("Ref Sequence")
777 ArrayList<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
778 for (int row : selectedRows)
780 PDBEntry pdbEntry = (PDBEntry) tbl_local_pdb.getValueAt(row,
782 pdbEntriesToView[count++] = pdbEntry;
783 SequenceI selectedSeq = (SequenceI) tbl_local_pdb.getValueAt(row,
785 selectedSeqsToView.add(selectedSeq);
787 SequenceI[] selectedSeqs = selectedSeqsToView
788 .toArray(new SequenceI[selectedSeqsToView.size()]);
789 launchStructureViewer(ssm, pdbEntriesToView, ap,
792 else if (currentView == VIEWS_ENTER_ID)
794 SequenceI userSelectedSeq = ((AssociateSeqOptions) idInputAssSeqPanel
795 .getCmb_assSeq().getSelectedItem()).getSequence();
796 if (userSelectedSeq != null)
798 selectedSequence = userSelectedSeq;
801 String pdbIdStr = txt_search.getText();
802 PDBEntry pdbEntry = selectedSequence.getPDBEntry(pdbIdStr);
803 if (pdbEntry == null)
805 pdbEntry = new PDBEntry();
806 if (pdbIdStr.split(":").length > 1)
808 pdbEntry.setChainCode(pdbIdStr.split(":")[1]);
810 pdbEntry.setId(pdbIdStr);
811 pdbEntry.setType(PDBEntry.Type.PDB);
812 selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
815 PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
816 launchStructureViewer(ssm, pdbEntriesToView, ap,
817 new SequenceI[] { selectedSequence });
819 else if (currentView == VIEWS_FROM_FILE)
821 SequenceI userSelectedSeq = ((AssociateSeqOptions) fileChooserAssSeqPanel
822 .getCmb_assSeq().getSelectedItem()).getSequence();
823 if (userSelectedSeq != null)
825 selectedSequence = userSelectedSeq;
827 PDBEntry fileEntry = new AssociatePdbFileWithSeq()
828 .associatePdbWithSeq(selectedPdbFileName,
829 jalview.io.AppletFormatAdapter.FILE,
830 selectedSequence, true, Desktop.instance);
832 launchStructureViewer(ssm,
833 new PDBEntry[] { fileEntry }, ap,
834 new SequenceI[] { selectedSequence });
841 private PDBEntry getFindEntry(String id, Vector<PDBEntry> pdbEntries)
843 Objects.requireNonNull(id);
844 Objects.requireNonNull(pdbEntries);
845 PDBEntry foundEntry = null;
846 for (PDBEntry entry : pdbEntries)
848 if (entry.getId().equalsIgnoreCase(id))
856 private void launchStructureViewer(StructureSelectionManager ssm,
857 final PDBEntry[] pdbEntriesToView,
858 final AlignmentPanel alignPanel, SequenceI[] sequences)
860 long progressId = sequences.hashCode();
861 setProgressBar(MessageManager
862 .getString("status.launching_3d_structure_viewer"), progressId);
863 final StructureViewer sViewer = new StructureViewer(ssm);
864 setProgressBar(null, progressId);
866 if (SiftsSettings.isMapWithSifts())
868 // TODO: prompt user if there are lots of sequences without dbrefs.
869 // It can take a long time if we need to fetch all dbrefs for all
871 ArrayList<SequenceI> seqsWithoutSourceDBRef = new ArrayList<SequenceI>();
872 for (SequenceI seq : sequences)
874 if (seq.getSourceDBRef() == null && seq.getDBRefs() == null)
876 seqsWithoutSourceDBRef.add(seq);
880 if (!seqsWithoutSourceDBRef.isEmpty())
882 int y = seqsWithoutSourceDBRef.size();
883 setProgressBar(MessageManager.formatMessage(
884 "status.fetching_dbrefs_for_sequences_without_valid_refs",
887 SequenceI[] seqWithoutSrcDBRef = new SequenceI[y];
889 for (SequenceI fSeq : seqsWithoutSourceDBRef)
891 seqWithoutSrcDBRef[x++] = fSeq;
893 new DBRefFetcher(seqWithoutSrcDBRef).fetchDBRefs(true);
894 setProgressBar("Fetch complete.", progressId); // todo i18n
897 if (pdbEntriesToView.length > 1)
899 ArrayList<SequenceI[]> seqsMap = new ArrayList<SequenceI[]>();
900 for (SequenceI seq : sequences)
902 seqsMap.add(new SequenceI[] { seq });
904 SequenceI[][] collatedSeqs = seqsMap.toArray(new SequenceI[0][0]);
905 <<<<<<< Updated upstream
906 ssm.setProgressBar(null);
907 ssm.setProgressBar(MessageManager
908 .getString("status.fetching_3d_structures_for_selected_entries"));
910 setProgressBar("Fetching structure data", progressId);
911 >>>>>>> Stashed changes
912 sViewer.viewStructures(pdbEntriesToView, collatedSeqs, alignPanel);
916 <<<<<<< Updated upstream
917 ssm.setProgressBar(null);
918 ssm.setProgressBar(MessageManager.formatMessage(
919 "status.fetching_3d_structures_for",
920 pdbEntriesToView[0].getId()));
923 "Fetching structure for " + pdbEntriesToView[0].getId(),
925 >>>>>>> Stashed changes
926 sViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
928 setProgressBar(null, progressId);
932 * Populates the combo-box used in associating manually fetched structures to
933 * a unique sequence when more than one sequence selection is made.
936 public void populateCmbAssociateSeqOptions(
937 JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq)
939 cmb_assSeq.removeAllItems();
940 cmb_assSeq.addItem(new AssociateSeqOptions("-Select Associated Seq-",
942 lbl_associateSeq.setVisible(false);
943 if (selectedSequences.length > 1)
945 for (SequenceI seq : selectedSequences)
947 cmb_assSeq.addItem(new AssociateSeqOptions(seq));
952 String seqName = selectedSequence.getDisplayId(false);
953 seqName = seqName.length() <= 40 ? seqName : seqName.substring(0, 39);
954 lbl_associateSeq.setText(seqName);
955 lbl_associateSeq.setVisible(true);
956 cmb_assSeq.setVisible(false);
960 public boolean isStructuresDiscovered()
962 return structuresDiscovered;
965 public void setStructuresDiscovered(boolean structuresDiscovered)
967 this.structuresDiscovered = structuresDiscovered;
970 public Collection<FTSData> getDiscoveredStructuresSet()
972 return discoveredStructuresSet;
976 protected void txt_search_ActionPerformed()
983 errorWarning.setLength(0);
984 isValidPBDEntry = false;
985 if (txt_search.getText().length() > 0)
987 String searchTerm = txt_search.getText().toLowerCase();
988 searchTerm = searchTerm.split(":")[0];
989 // System.out.println(">>>>> search term : " + searchTerm);
990 List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
991 FTSRestRequest pdbRequest = new FTSRestRequest();
992 pdbRequest.setAllowEmptySeq(false);
993 pdbRequest.setResponseSize(1);
994 pdbRequest.setFieldToSearchBy("(pdb_id:");
995 pdbRequest.setWantedFields(wantedFields);
997 .setSearchTerm(searchTerm + ")");
998 pdbRequest.setAssociatedSequence(selectedSequence);
999 pdbRestCleint = PDBFTSRestClient.getInstance();
1000 wantedFields.add(pdbRestCleint.getPrimaryKeyColumn());
1001 FTSRestResponse resultList;
1004 resultList = pdbRestCleint.executeRequest(pdbRequest);
1005 } catch (Exception e)
1007 errorWarning.append(e.getMessage());
1011 validateSelections();
1013 if (resultList.getSearchSummary() != null
1014 && resultList.getSearchSummary().size() > 0)
1016 isValidPBDEntry = true;
1019 validateSelections();
1025 public void tabRefresh()
1027 if (selectedSequences != null)
1029 Thread refreshThread = new Thread(new Runnable()
1034 fetchStructuresMetaData();
1035 filterResultSet(((FilterOption) cmb_filterOption
1036 .getSelectedItem()).getValue());
1039 refreshThread.start();
1043 public class PDBEntryTableModel extends AbstractTableModel
1045 String[] columns = { "Ref Sequence", "PDB Id", "Chain", "Type", "File" };
1047 private List<CachedPDB> pdbEntries;
1049 public PDBEntryTableModel(List<CachedPDB> pdbEntries)
1051 this.pdbEntries = new ArrayList<CachedPDB>(pdbEntries);
1055 public String getColumnName(int columnIndex)
1057 return columns[columnIndex];
1061 public int getRowCount()
1063 return pdbEntries.size();
1067 public int getColumnCount()
1069 return columns.length;
1073 public boolean isCellEditable(int row, int column)
1079 public Object getValueAt(int rowIndex, int columnIndex)
1081 Object value = "??";
1082 CachedPDB entry = pdbEntries.get(rowIndex);
1083 switch (columnIndex)
1086 value = entry.getSequence();
1089 value = entry.getPdbEntry();
1092 value = entry.getPdbEntry().getChainCode() == null ? "_" : entry
1093 .getPdbEntry().getChainCode();
1096 value = entry.getPdbEntry().getType();
1099 value = entry.getPdbEntry().getFile();
1106 public Class<?> getColumnClass(int columnIndex)
1108 return columnIndex == 0 ? SequenceI.class : PDBEntry.class;
1111 public CachedPDB getPDBEntryAt(int row)
1113 return pdbEntries.get(row);
1118 private class CachedPDB
1120 private SequenceI sequence;
1122 private PDBEntry pdbEntry;
1124 public CachedPDB(SequenceI sequence, PDBEntry pdbEntry)
1126 this.sequence = sequence;
1127 this.pdbEntry = pdbEntry;
1130 public SequenceI getSequence()
1135 public PDBEntry getPdbEntry()
1142 private IProgressIndicator progressBar;
1145 public void setProgressBar(String message, long id)
1147 progressBar.setProgressBar(message, id);
1151 public void registerHandler(long id, IProgressIndicatorHandler handler)
1153 progressBar.registerHandler(id, handler);
1157 public boolean operationInProgress()
1159 return progressBar.operationInProgress();