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.io.DataSourceType;
36 import jalview.jbgui.GStructureChooser;
37 import jalview.structure.StructureMapping;
38 import jalview.structure.StructureSelectionManager;
39 import jalview.util.MessageManager;
40 import jalview.ws.DBRefFetcher;
41 import jalview.ws.sifts.SiftsSettings;
43 import java.awt.event.ItemEvent;
44 import java.util.ArrayList;
45 import java.util.Collection;
46 import java.util.HashSet;
47 import java.util.LinkedHashSet;
48 import java.util.List;
49 import java.util.Objects;
51 import java.util.Vector;
53 import javax.swing.JCheckBox;
54 import javax.swing.JComboBox;
55 import javax.swing.JLabel;
56 import javax.swing.table.AbstractTableModel;
59 * Provides the behaviors for the Structure chooser Panel
64 @SuppressWarnings("serial")
65 public class StructureChooser extends GStructureChooser
66 implements IProgressIndicator
68 private static int MAX_QLENGTH = 7820;
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 private boolean cachedPDBExists;
88 public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
92 this.selectedSequence = selectedSeq;
93 this.selectedSequences = selectedSeqs;
94 this.progressIndicator = (ap == null) ? null : ap.alignFrame;
99 * Initializes parameters used by the Structure Chooser Panel
103 if (!Jalview.isHeadlessMode())
105 progressBar = new ProgressBar(this.statusPanel, this.statusBar);
108 // ensure a filter option is in force for search
109 populateFilterComboBox(true, cachedPDBExists);
110 Thread discoverPDBStructuresThread = new Thread(new Runnable()
115 long startTime = System.currentTimeMillis();
116 updateProgressIndicator(MessageManager
117 .getString("status.loading_cached_pdb_entries"), startTime);
118 loadLocalCachedPDBEntries();
119 updateProgressIndicator(null, startTime);
120 updateProgressIndicator(MessageManager.getString(
121 "status.searching_for_pdb_structures"), startTime);
122 fetchStructuresMetaData();
123 // revise filter options if no results were found
124 populateFilterComboBox(isStructuresDiscovered(), cachedPDBExists);
125 updateProgressIndicator(null, startTime);
126 mainFrame.setVisible(true);
130 discoverPDBStructuresThread.start();
134 * Updates the progress indicator with the specified message
137 * displayed message for the operation
139 * unique handle for this indicator
141 public void updateProgressIndicator(String message, long id)
143 if (progressIndicator != null)
145 progressIndicator.setProgressBar(message, id);
150 * Retrieve meta-data for all the structure(s) for a given sequence(s) in a
153 public void fetchStructuresMetaData()
155 long startTime = System.currentTimeMillis();
156 pdbRestCleint = PDBFTSRestClient.getInstance();
157 Collection<FTSDataColumnI> wantedFields = pdbDocFieldPrefs
158 .getStructureSummaryFields();
160 discoveredStructuresSet = new LinkedHashSet<FTSData>();
161 HashSet<String> errors = new HashSet<String>();
162 for (SequenceI seq : selectedSequences)
164 FTSRestRequest pdbRequest = new FTSRestRequest();
165 pdbRequest.setAllowEmptySeq(false);
166 pdbRequest.setResponseSize(500);
167 pdbRequest.setFieldToSearchBy("(");
168 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
170 pdbRequest.setFieldToSortBy(selectedFilterOpt.getValue(),
171 !chk_invertFilter.isSelected());
172 pdbRequest.setWantedFields(wantedFields);
173 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
174 pdbRequest.setAssociatedSequence(seq);
175 FTSRestResponse resultList;
178 resultList = pdbRestCleint.executeRequest(pdbRequest);
179 } catch (Exception e)
182 errors.add(e.getMessage());
185 lastPdbRequest = pdbRequest;
186 if (resultList.getSearchSummary() != null
187 && !resultList.getSearchSummary().isEmpty())
189 discoveredStructuresSet.addAll(resultList.getSearchSummary());
193 int noOfStructuresFound = 0;
194 String totalTime = (System.currentTimeMillis() - startTime)
196 if (discoveredStructuresSet != null
197 && !discoveredStructuresSet.isEmpty())
199 getResultTable().setModel(FTSRestResponse
200 .getTableModel(lastPdbRequest, discoveredStructuresSet));
201 noOfStructuresFound = discoveredStructuresSet.size();
202 mainFrame.setTitle(MessageManager.formatMessage(
203 "label.structure_chooser_no_of_structures",
204 noOfStructuresFound, totalTime));
208 mainFrame.setTitle(MessageManager
209 .getString("label.structure_chooser_manual_association"));
210 if (errors.size() > 0)
212 StringBuilder errorMsg = new StringBuilder();
213 for (String error : errors)
215 errorMsg.append(error).append("\n");
217 JvOptionPane.showMessageDialog(this, errorMsg.toString(),
218 MessageManager.getString("label.pdb_web-service_error"),
219 JvOptionPane.ERROR_MESSAGE);
224 public void loadLocalCachedPDBEntries()
226 ArrayList<CachedPDB> entries = new ArrayList<CachedPDB>();
227 for (SequenceI seq : selectedSequences)
229 if (seq.getDatasetSequence() != null
230 && seq.getDatasetSequence().getAllPDBEntries() != null)
232 for (PDBEntry pdbEntry : seq.getDatasetSequence()
235 if (pdbEntry.getFile() != null)
237 entries.add(new CachedPDB(seq, pdbEntry));
242 cachedPDBExists = !entries.isEmpty();
243 PDBEntryTableModel tableModelx = new PDBEntryTableModel(entries);
244 tbl_local_pdb.setModel(tableModelx);
248 * Builds a query string for a given sequences using its DBRef entries
251 * the sequences to build a query for
252 * @return the built query string
255 public static String buildQuery(SequenceI seq)
257 boolean isPDBRefsFound = false;
258 boolean isUniProtRefsFound = false;
259 StringBuilder queryBuilder = new StringBuilder();
260 Set<String> seqRefs = new LinkedHashSet<String>();
262 if (seq.getAllPDBEntries() != null
263 && queryBuilder.length() < MAX_QLENGTH)
265 for (PDBEntry entry : seq.getAllPDBEntries())
267 if (isValidSeqName(entry.getId()))
269 queryBuilder.append("pdb_id:").append(entry.getId().toLowerCase())
271 isPDBRefsFound = true;
276 if (seq.getDBRefs() != null && seq.getDBRefs().length != 0)
278 for (DBRefEntry dbRef : seq.getDBRefs())
280 if (isValidSeqName(getDBRefId(dbRef))
281 && queryBuilder.length() < MAX_QLENGTH)
283 if (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT))
285 queryBuilder.append("uniprot_accession:")
286 .append(getDBRefId(dbRef)).append(" OR ");
287 queryBuilder.append("uniprot_id:").append(getDBRefId(dbRef))
289 isUniProtRefsFound = true;
291 else if (dbRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
294 queryBuilder.append("pdb_id:")
295 .append(getDBRefId(dbRef).toLowerCase()).append(" OR ");
296 isPDBRefsFound = true;
300 seqRefs.add(getDBRefId(dbRef));
306 if (!isPDBRefsFound && !isUniProtRefsFound)
308 String seqName = seq.getName();
309 seqName = sanitizeSeqName(seqName);
310 String[] names = seqName.toLowerCase().split("\\|");
311 for (String name : names)
313 // System.out.println("Found name : " + name);
315 if (isValidSeqName(name))
321 for (String seqRef : seqRefs)
323 queryBuilder.append("text:").append(seqRef).append(" OR ");
327 int endIndex = queryBuilder.lastIndexOf(" OR ");
328 if (queryBuilder.toString().length() < 6)
332 String query = queryBuilder.toString().substring(0, endIndex);
337 * Remove the following special characters from input string +, -, &, !, (, ),
338 * {, }, [, ], ^, ", ~, *, ?, :, \
343 static String sanitizeSeqName(String seqName)
345 Objects.requireNonNull(seqName);
346 return seqName.replaceAll("\\[\\d*\\]", "")
347 .replaceAll("[^\\dA-Za-z|_]", "").replaceAll("\\s+", "+");
351 * Ensures sequence ref names are not less than 3 characters and does not
352 * contain a database name
357 public static boolean isValidSeqName(String seqName)
359 // System.out.println("seqName : " + seqName);
360 String ignoreList = "pdb,uniprot,swiss-prot";
361 if (seqName.length() < 3)
365 if (seqName.contains(":"))
369 seqName = seqName.toLowerCase();
370 for (String ignoredEntry : ignoreList.split(","))
372 if (seqName.contains(ignoredEntry))
380 public static String getDBRefId(DBRefEntry dbRef)
382 String ref = dbRef.getAccessionId().replaceAll("GO:", "");
387 * Filters a given list of discovered structures based on supplied argument
389 * @param fieldToFilterBy
390 * the field to filter by
392 public void filterResultSet(final String fieldToFilterBy)
394 Thread filterThread = new Thread(new Runnable()
399 long startTime = System.currentTimeMillis();
400 pdbRestCleint = PDBFTSRestClient.getInstance();
401 lbl_loading.setVisible(true);
402 Collection<FTSDataColumnI> wantedFields = pdbDocFieldPrefs
403 .getStructureSummaryFields();
404 Collection<FTSData> filteredResponse = new HashSet<FTSData>();
405 HashSet<String> errors = new HashSet<String>();
407 for (SequenceI seq : selectedSequences)
409 FTSRestRequest pdbRequest = new FTSRestRequest();
410 if (fieldToFilterBy.equalsIgnoreCase("uniprot_coverage"))
412 pdbRequest.setAllowEmptySeq(false);
413 pdbRequest.setResponseSize(1);
414 pdbRequest.setFieldToSearchBy("(");
415 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
416 pdbRequest.setWantedFields(wantedFields);
417 pdbRequest.setAssociatedSequence(seq);
418 pdbRequest.setFacet(true);
419 pdbRequest.setFacetPivot(fieldToFilterBy + ",entry_entity");
420 pdbRequest.setFacetPivotMinCount(1);
424 pdbRequest.setAllowEmptySeq(false);
425 pdbRequest.setResponseSize(1);
426 pdbRequest.setFieldToSearchBy("(");
427 pdbRequest.setFieldToSortBy(fieldToFilterBy,
428 !chk_invertFilter.isSelected());
429 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
430 pdbRequest.setWantedFields(wantedFields);
431 pdbRequest.setAssociatedSequence(seq);
433 FTSRestResponse resultList;
436 resultList = pdbRestCleint.executeRequest(pdbRequest);
437 } catch (Exception e)
440 errors.add(e.getMessage());
443 lastPdbRequest = pdbRequest;
444 if (resultList.getSearchSummary() != null
445 && !resultList.getSearchSummary().isEmpty())
447 filteredResponse.addAll(resultList.getSearchSummary());
451 String totalTime = (System.currentTimeMillis() - startTime)
453 if (!filteredResponse.isEmpty())
455 final int filterResponseCount = filteredResponse.size();
456 Collection<FTSData> reorderedStructuresSet = new LinkedHashSet<FTSData>();
457 reorderedStructuresSet.addAll(filteredResponse);
458 reorderedStructuresSet.addAll(discoveredStructuresSet);
459 getResultTable().setModel(FTSRestResponse
460 .getTableModel(lastPdbRequest, reorderedStructuresSet));
462 FTSRestResponse.configureTableColumn(getResultTable(),
463 wantedFields, tempUserPrefs);
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 JvOptionPane.showMessageDialog(null, errorMsg.toString(),
485 MessageManager.getString("label.pdb_web-service_error"),
486 JvOptionPane.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(
508 MessageManager.formatMessage("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
527 protected void populateFilterComboBox(boolean haveData,
528 boolean cachedPDBExists)
531 * temporarily suspend the change listener behaviour
533 cmb_filterOption.removeItemListener(this);
535 cmb_filterOption.removeAllItems();
538 cmb_filterOption.addItem(new FilterOption("Best Quality",
539 "overall_quality", VIEWS_FILTER, false));
540 cmb_filterOption.addItem(new FilterOption("Best Resolution",
541 "resolution", VIEWS_FILTER, false));
542 cmb_filterOption.addItem(new FilterOption("Most Protein Chain",
543 "number_of_protein_chains", VIEWS_FILTER, false));
544 cmb_filterOption.addItem(new FilterOption("Most Bound Molecules",
545 "number_of_bound_molecules", VIEWS_FILTER, false));
546 cmb_filterOption.addItem(new FilterOption("Most Polymer Residues",
547 "number_of_polymer_residues", VIEWS_FILTER, true));
549 cmb_filterOption.addItem(
550 new FilterOption("Enter PDB Id", "-", VIEWS_ENTER_ID, false));
551 cmb_filterOption.addItem(
552 new FilterOption("From File", "-", VIEWS_FROM_FILE, false));
556 FilterOption cachedOption = new FilterOption("Cached PDB Entries",
557 "-", VIEWS_LOCAL_PDB, false);
558 cmb_filterOption.addItem(cachedOption);
559 cmb_filterOption.setSelectedItem(cachedOption);
562 cmb_filterOption.addItemListener(this);
566 * Updates the displayed view based on the selected filter option
568 protected void updateCurrentView()
570 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
572 layout_switchableViews.show(pnl_switchableViews,
573 selectedFilterOpt.getView());
574 String filterTitle = mainFrame.getTitle();
575 mainFrame.setTitle(frameTitle);
576 chk_invertFilter.setVisible(false);
577 if (selectedFilterOpt.getView() == VIEWS_FILTER)
579 mainFrame.setTitle(filterTitle);
580 chk_invertFilter.setVisible(true);
581 filterResultSet(selectedFilterOpt.getValue());
583 else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
584 || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
586 mainFrame.setTitle(MessageManager
587 .getString("label.structure_chooser_manual_association"));
588 idInputAssSeqPanel.loadCmbAssSeq();
589 fileChooserAssSeqPanel.loadCmbAssSeq();
591 validateSelections();
595 * Validates user selection and activates the view button if all parameters
599 public void validateSelections()
601 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
603 btn_view.setEnabled(false);
604 String currentView = selectedFilterOpt.getView();
605 if (currentView == VIEWS_FILTER)
607 if (getResultTable().getSelectedRows().length > 0)
609 btn_view.setEnabled(true);
612 else if (currentView == VIEWS_LOCAL_PDB)
614 if (tbl_local_pdb.getSelectedRows().length > 0)
616 btn_view.setEnabled(true);
619 else if (currentView == VIEWS_ENTER_ID)
621 validateAssociationEnterPdb();
623 else if (currentView == VIEWS_FROM_FILE)
625 validateAssociationFromFile();
630 * Validates inputs from the Manual PDB entry panel
632 public void validateAssociationEnterPdb()
634 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel
635 .getCmb_assSeq().getSelectedItem();
636 lbl_pdbManualFetchStatus.setIcon(errorImage);
637 lbl_pdbManualFetchStatus.setToolTipText("");
638 if (txt_search.getText().length() > 0)
640 lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip(true,
641 MessageManager.formatMessage("info.no_pdb_entry_found_for",
642 txt_search.getText())));
645 if (errorWarning.length() > 0)
647 lbl_pdbManualFetchStatus.setIcon(warningImage);
648 lbl_pdbManualFetchStatus.setToolTipText(
649 JvSwingUtils.wrapTooltip(true, errorWarning.toString()));
652 if (selectedSequences.length == 1 || !assSeqOpt.getName()
653 .equalsIgnoreCase("-Select Associated Seq-"))
655 txt_search.setEnabled(true);
658 btn_view.setEnabled(true);
659 lbl_pdbManualFetchStatus.setToolTipText("");
660 lbl_pdbManualFetchStatus.setIcon(goodImage);
665 txt_search.setEnabled(false);
666 lbl_pdbManualFetchStatus.setIcon(errorImage);
671 * Validates inputs for the manual PDB file selection options
673 public void validateAssociationFromFile()
675 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
676 .getCmb_assSeq().getSelectedItem();
677 lbl_fromFileStatus.setIcon(errorImage);
678 if (selectedSequences.length == 1 || (assSeqOpt != null && !assSeqOpt
679 .getName().equalsIgnoreCase("-Select Associated Seq-")))
681 btn_pdbFromFile.setEnabled(true);
682 if (selectedPdbFileName != null && selectedPdbFileName.length() > 0)
684 btn_view.setEnabled(true);
685 lbl_fromFileStatus.setIcon(goodImage);
690 btn_pdbFromFile.setEnabled(false);
691 lbl_fromFileStatus.setIcon(errorImage);
696 public void cmbAssSeqStateChanged()
698 validateSelections();
702 * Handles the state change event for the 'filter' combo-box and 'invert'
706 protected void stateChanged(ItemEvent e)
708 if (e.getSource() instanceof JCheckBox)
714 if (e.getStateChange() == ItemEvent.SELECTED)
723 * Handles action event for btn_ok
726 public void ok_ActionPerformed()
728 final long progressSessionId = System.currentTimeMillis();
729 final StructureSelectionManager ssm = ap.getStructureSelectionManager();
730 final int preferredHeight = pnl_filter.getHeight();
731 ssm.setProgressIndicator(this);
732 ssm.setProgressSessionId(progressSessionId);
733 new Thread(new Runnable()
738 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
740 String currentView = selectedFilterOpt.getView();
741 if (currentView == VIEWS_FILTER)
743 int pdbIdColIndex = getResultTable().getColumn("PDB Id")
745 int refSeqColIndex = getResultTable().getColumn("Ref Sequence")
747 int[] selectedRows = getResultTable().getSelectedRows();
748 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
750 List<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
751 for (int row : selectedRows)
753 String pdbIdStr = getResultTable()
754 .getValueAt(row, pdbIdColIndex).toString();
755 SequenceI selectedSeq = (SequenceI) getResultTable()
756 .getValueAt(row, refSeqColIndex);
757 selectedSeqsToView.add(selectedSeq);
758 PDBEntry pdbEntry = selectedSeq.getPDBEntry(pdbIdStr);
759 if (pdbEntry == null)
761 pdbEntry = getFindEntry(pdbIdStr,
762 selectedSeq.getAllPDBEntries());
764 if (pdbEntry == null)
766 pdbEntry = new PDBEntry();
767 pdbEntry.setId(pdbIdStr);
768 pdbEntry.setType(PDBEntry.Type.PDB);
769 selectedSeq.getDatasetSequence().addPDBId(pdbEntry);
771 pdbEntriesToView[count++] = pdbEntry;
773 SequenceI[] selectedSeqs = selectedSeqsToView
774 .toArray(new SequenceI[selectedSeqsToView.size()]);
775 launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
777 else if (currentView == VIEWS_LOCAL_PDB)
779 int[] selectedRows = tbl_local_pdb.getSelectedRows();
780 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
782 int pdbIdColIndex = tbl_local_pdb.getColumn("PDB Id")
784 int refSeqColIndex = tbl_local_pdb.getColumn("Ref Sequence")
786 List<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
787 for (int row : selectedRows)
789 PDBEntry pdbEntry = (PDBEntry) tbl_local_pdb.getValueAt(row,
791 pdbEntriesToView[count++] = pdbEntry;
792 SequenceI selectedSeq = (SequenceI) tbl_local_pdb
793 .getValueAt(row, refSeqColIndex);
794 selectedSeqsToView.add(selectedSeq);
796 SequenceI[] selectedSeqs = selectedSeqsToView
797 .toArray(new SequenceI[selectedSeqsToView.size()]);
798 launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
800 else if (currentView == VIEWS_ENTER_ID)
802 SequenceI userSelectedSeq = ((AssociateSeqOptions) idInputAssSeqPanel
803 .getCmb_assSeq().getSelectedItem()).getSequence();
804 if (userSelectedSeq != null)
806 selectedSequence = userSelectedSeq;
809 String pdbIdStr = txt_search.getText();
810 PDBEntry pdbEntry = selectedSequence.getPDBEntry(pdbIdStr);
811 if (pdbEntry == null)
813 pdbEntry = new PDBEntry();
814 if (pdbIdStr.split(":").length > 1)
816 pdbEntry.setId(pdbIdStr.split(":")[0]);
817 pdbEntry.setChainCode(pdbIdStr.split(":")[1].toUpperCase());
821 pdbEntry.setId(pdbIdStr);
823 pdbEntry.setType(PDBEntry.Type.PDB);
824 selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
827 PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
828 launchStructureViewer(ssm, pdbEntriesToView, ap,
830 { selectedSequence });
832 else if (currentView == VIEWS_FROM_FILE)
834 SequenceI userSelectedSeq = ((AssociateSeqOptions) fileChooserAssSeqPanel
835 .getCmb_assSeq().getSelectedItem()).getSequence();
836 if (userSelectedSeq != null)
838 selectedSequence = userSelectedSeq;
840 PDBEntry fileEntry = new AssociatePdbFileWithSeq()
841 .associatePdbWithSeq(selectedPdbFileName,
842 DataSourceType.FILE, selectedSequence, true,
845 launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
847 { selectedSequence });
849 closeAction(preferredHeight);
854 private PDBEntry getFindEntry(String id, Vector<PDBEntry> pdbEntries)
856 Objects.requireNonNull(id);
857 Objects.requireNonNull(pdbEntries);
858 PDBEntry foundEntry = null;
859 for (PDBEntry entry : pdbEntries)
861 if (entry.getId().equalsIgnoreCase(id))
869 private void launchStructureViewer(StructureSelectionManager ssm,
870 final PDBEntry[] pdbEntriesToView,
871 final AlignmentPanel alignPanel, SequenceI[] sequences)
873 ssm.setProgressBar(MessageManager
874 .getString("status.launching_3d_structure_viewer"));
875 final StructureViewer sViewer = new StructureViewer(ssm);
877 if (SiftsSettings.isMapWithSifts())
879 List<SequenceI> seqsWithoutSourceDBRef = new ArrayList<SequenceI>();
881 // TODO: skip PDBEntry:Sequence pairs where PDBEntry doesn't look like a
882 // real PDB ID. For moment, we can also safely do this if there is already
883 // a known mapping between the PDBEntry and the sequence.
884 for (SequenceI seq : sequences)
886 PDBEntry pdbe = pdbEntriesToView[p++];
887 if (pdbe != null && pdbe.getFile() != null)
889 StructureMapping[] smm = ssm.getMapping(pdbe.getFile());
890 if (smm != null && smm.length > 0)
892 for (StructureMapping sm : smm)
894 if (sm.getSequence() == seq)
901 if (seq.getPrimaryDBRefs().size() == 0)
903 seqsWithoutSourceDBRef.add(seq);
907 if (!seqsWithoutSourceDBRef.isEmpty())
909 int y = seqsWithoutSourceDBRef.size();
910 ssm.setProgressBar(null);
911 ssm.setProgressBar(MessageManager.formatMessage(
912 "status.fetching_dbrefs_for_sequences_without_valid_refs",
914 SequenceI[] seqWithoutSrcDBRef = new SequenceI[y];
916 for (SequenceI fSeq : seqsWithoutSourceDBRef)
918 seqWithoutSrcDBRef[x++] = fSeq;
920 DBRefFetcher dbRefFetcher = new DBRefFetcher(seqWithoutSrcDBRef);
921 dbRefFetcher.fetchDBRefs(true);
924 if (pdbEntriesToView.length > 1)
926 ArrayList<SequenceI[]> seqsMap = new ArrayList<SequenceI[]>();
927 for (SequenceI seq : sequences)
929 seqsMap.add(new SequenceI[] { seq });
931 SequenceI[][] collatedSeqs = seqsMap.toArray(new SequenceI[0][0]);
932 ssm.setProgressBar(null);
933 ssm.setProgressBar(MessageManager.getString(
934 "status.fetching_3d_structures_for_selected_entries"));
935 sViewer.viewStructures(pdbEntriesToView, collatedSeqs, alignPanel);
939 ssm.setProgressBar(null);
940 ssm.setProgressBar(MessageManager.formatMessage(
941 "status.fetching_3d_structures_for",
942 pdbEntriesToView[0].getId()));
943 sViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
948 * Populates the combo-box used in associating manually fetched structures to
949 * a unique sequence when more than one sequence selection is made.
952 public void populateCmbAssociateSeqOptions(
953 JComboBox<AssociateSeqOptions> cmb_assSeq,
954 JLabel lbl_associateSeq)
956 cmb_assSeq.removeAllItems();
958 new AssociateSeqOptions("-Select Associated Seq-", null));
959 lbl_associateSeq.setVisible(false);
960 if (selectedSequences.length > 1)
962 for (SequenceI seq : selectedSequences)
964 cmb_assSeq.addItem(new AssociateSeqOptions(seq));
969 String seqName = selectedSequence.getDisplayId(false);
970 seqName = seqName.length() <= 40 ? seqName : seqName.substring(0, 39);
971 lbl_associateSeq.setText(seqName);
972 lbl_associateSeq.setVisible(true);
973 cmb_assSeq.setVisible(false);
977 public boolean isStructuresDiscovered()
979 return discoveredStructuresSet != null
980 && !discoveredStructuresSet.isEmpty();
983 public Collection<FTSData> getDiscoveredStructuresSet()
985 return discoveredStructuresSet;
989 protected void txt_search_ActionPerformed()
996 errorWarning.setLength(0);
997 isValidPBDEntry = false;
998 if (txt_search.getText().length() > 0)
1000 String searchTerm = txt_search.getText().toLowerCase();
1001 searchTerm = searchTerm.split(":")[0];
1002 // System.out.println(">>>>> search term : " + searchTerm);
1003 List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
1004 FTSRestRequest pdbRequest = new FTSRestRequest();
1005 pdbRequest.setAllowEmptySeq(false);
1006 pdbRequest.setResponseSize(1);
1007 pdbRequest.setFieldToSearchBy("(pdb_id:");
1008 pdbRequest.setWantedFields(wantedFields);
1009 pdbRequest.setSearchTerm(searchTerm + ")");
1010 pdbRequest.setAssociatedSequence(selectedSequence);
1011 pdbRestCleint = PDBFTSRestClient.getInstance();
1012 wantedFields.add(pdbRestCleint.getPrimaryKeyColumn());
1013 FTSRestResponse resultList;
1016 resultList = pdbRestCleint.executeRequest(pdbRequest);
1017 } catch (Exception e)
1019 errorWarning.append(e.getMessage());
1023 validateSelections();
1025 if (resultList.getSearchSummary() != null
1026 && resultList.getSearchSummary().size() > 0)
1028 isValidPBDEntry = true;
1031 validateSelections();
1037 public void tabRefresh()
1039 if (selectedSequences != null)
1041 Thread refreshThread = new Thread(new Runnable()
1046 fetchStructuresMetaData();
1048 ((FilterOption) cmb_filterOption.getSelectedItem())
1052 refreshThread.start();
1056 public class PDBEntryTableModel extends AbstractTableModel
1058 String[] columns = { "Ref Sequence", "PDB Id", "Chain", "Type",
1061 private List<CachedPDB> pdbEntries;
1063 public PDBEntryTableModel(List<CachedPDB> pdbEntries)
1065 this.pdbEntries = new ArrayList<CachedPDB>(pdbEntries);
1069 public String getColumnName(int columnIndex)
1071 return columns[columnIndex];
1075 public int getRowCount()
1077 return pdbEntries.size();
1081 public int getColumnCount()
1083 return columns.length;
1087 public boolean isCellEditable(int row, int column)
1093 public Object getValueAt(int rowIndex, int columnIndex)
1095 Object value = "??";
1096 CachedPDB entry = pdbEntries.get(rowIndex);
1097 switch (columnIndex)
1100 value = entry.getSequence();
1103 value = entry.getPdbEntry();
1106 value = entry.getPdbEntry().getChainCode() == null ? "_"
1107 : entry.getPdbEntry().getChainCode();
1110 value = entry.getPdbEntry().getType();
1113 value = entry.getPdbEntry().getFile();
1120 public Class<?> getColumnClass(int columnIndex)
1122 return columnIndex == 0 ? SequenceI.class : PDBEntry.class;
1125 public CachedPDB getPDBEntryAt(int row)
1127 return pdbEntries.get(row);
1132 private class CachedPDB
1134 private SequenceI sequence;
1136 private PDBEntry pdbEntry;
1138 public CachedPDB(SequenceI sequence, PDBEntry pdbEntry)
1140 this.sequence = sequence;
1141 this.pdbEntry = pdbEntry;
1144 public SequenceI getSequence()
1149 public PDBEntry getPdbEntry()
1156 private IProgressIndicator progressBar;
1159 public void setProgressBar(String message, long id)
1161 progressBar.setProgressBar(message, id);
1165 public void registerHandler(long id, IProgressIndicatorHandler handler)
1167 progressBar.registerHandler(id, handler);
1171 public boolean operationInProgress()
1173 return progressBar.operationInProgress();