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 implements
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
121 .getString("status.searching_for_pdb_structures"),
123 fetchStructuresMetaData();
124 // revise filter options if no results were found
125 populateFilterComboBox(isStructuresDiscovered(), cachedPDBExists);
126 updateProgressIndicator(null, startTime);
127 mainFrame.setVisible(true);
131 discoverPDBStructuresThread.start();
135 * Updates the progress indicator with the specified message
138 * displayed message for the operation
140 * unique handle for this indicator
142 public void updateProgressIndicator(String message, long id)
144 if (progressIndicator != null)
146 progressIndicator.setProgressBar(message, id);
151 * Retrieve meta-data for all the structure(s) for a given sequence(s) in a
154 public void fetchStructuresMetaData()
156 long startTime = System.currentTimeMillis();
157 pdbRestCleint = PDBFTSRestClient.getInstance();
158 Collection<FTSDataColumnI> wantedFields = pdbDocFieldPrefs
159 .getStructureSummaryFields();
161 discoveredStructuresSet = new LinkedHashSet<FTSData>();
162 HashSet<String> errors = new HashSet<String>();
163 for (SequenceI seq : selectedSequences)
165 FTSRestRequest pdbRequest = new FTSRestRequest();
166 pdbRequest.setAllowEmptySeq(false);
167 pdbRequest.setResponseSize(500);
168 pdbRequest.setFieldToSearchBy("(");
169 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
171 pdbRequest.setFieldToSortBy(selectedFilterOpt.getValue(),
172 !chk_invertFilter.isSelected());
173 pdbRequest.setWantedFields(wantedFields);
174 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
175 pdbRequest.setAssociatedSequence(seq);
176 FTSRestResponse resultList;
179 resultList = pdbRestCleint.executeRequest(pdbRequest);
180 } catch (Exception e)
183 errors.add(e.getMessage());
186 lastPdbRequest = pdbRequest;
187 if (resultList.getSearchSummary() != null
188 && !resultList.getSearchSummary().isEmpty())
190 discoveredStructuresSet.addAll(resultList.getSearchSummary());
194 int noOfStructuresFound = 0;
195 String totalTime = (System.currentTimeMillis() - startTime)
197 if (discoveredStructuresSet != null
198 && !discoveredStructuresSet.isEmpty())
200 getResultTable().setModel(
201 FTSRestResponse.getTableModel(lastPdbRequest,
202 discoveredStructuresSet));
203 noOfStructuresFound = discoveredStructuresSet.size();
204 mainFrame.setTitle(MessageManager.formatMessage(
205 "label.structure_chooser_no_of_structures",
206 noOfStructuresFound, totalTime));
210 mainFrame.setTitle(MessageManager
211 .getString("label.structure_chooser_manual_association"));
212 if (errors.size() > 0)
214 StringBuilder errorMsg = new StringBuilder();
215 for (String error : errors)
217 errorMsg.append(error).append("\n");
219 JvOptionPane.showMessageDialog(this, errorMsg.toString(),
220 MessageManager.getString("label.pdb_web-service_error"),
221 JvOptionPane.ERROR_MESSAGE);
226 public void loadLocalCachedPDBEntries()
228 ArrayList<CachedPDB> entries = new ArrayList<CachedPDB>();
229 for (SequenceI seq : selectedSequences)
231 if (seq.getDatasetSequence() != null
232 && seq.getDatasetSequence().getAllPDBEntries() != null)
234 for (PDBEntry pdbEntry : seq.getDatasetSequence()
237 if (pdbEntry.getFile() != null)
239 entries.add(new CachedPDB(seq, pdbEntry));
244 cachedPDBExists = !entries.isEmpty();
245 PDBEntryTableModel tableModelx = new PDBEntryTableModel(entries);
246 tbl_local_pdb.setModel(tableModelx);
250 * Builds a query string for a given sequences using its DBRef entries
253 * the sequences to build a query for
254 * @return the built query string
257 public static String buildQuery(SequenceI seq)
259 boolean isPDBRefsFound = false;
260 boolean isUniProtRefsFound = false;
261 StringBuilder queryBuilder = new StringBuilder();
262 Set<String> seqRefs = new LinkedHashSet<String>();
264 if (seq.getAllPDBEntries() != null
265 && queryBuilder.length() < MAX_QLENGTH)
267 for (PDBEntry entry : seq.getAllPDBEntries())
269 if (isValidSeqName(entry.getId()))
271 queryBuilder.append("pdb_id:")
272 .append(entry.getId().toLowerCase()).append(" OR ");
273 isPDBRefsFound = true;
278 if (seq.getDBRefs() != null && seq.getDBRefs().length != 0)
280 for (DBRefEntry dbRef : seq.getDBRefs())
282 if (isValidSeqName(getDBRefId(dbRef))
283 && queryBuilder.length() < MAX_QLENGTH)
285 if (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT))
287 queryBuilder.append("uniprot_accession:")
288 .append(getDBRefId(dbRef)).append(" OR ");
289 queryBuilder.append("uniprot_id:").append(getDBRefId(dbRef))
291 isUniProtRefsFound = true;
293 else if (dbRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
296 queryBuilder.append("pdb_id:")
297 .append(getDBRefId(dbRef).toLowerCase()).append(" OR ");
298 isPDBRefsFound = true;
302 seqRefs.add(getDBRefId(dbRef));
308 if (!isPDBRefsFound && !isUniProtRefsFound)
310 String seqName = seq.getName();
311 seqName = sanitizeSeqName(seqName);
312 String[] names = seqName.toLowerCase().split("\\|");
313 for (String name : names)
315 // System.out.println("Found name : " + name);
317 if (isValidSeqName(name))
323 for (String seqRef : seqRefs)
325 queryBuilder.append("text:").append(seqRef).append(" OR ");
329 int endIndex = queryBuilder.lastIndexOf(" OR ");
330 if (queryBuilder.toString().length() < 6)
334 String query = queryBuilder.toString().substring(0, endIndex);
339 * Remove the following special characters from input string +, -, &, !, (, ),
340 * {, }, [, ], ^, ", ~, *, ?, :, \
345 static String sanitizeSeqName(String seqName)
347 Objects.requireNonNull(seqName);
348 return seqName.replaceAll("\\[\\d*\\]", "")
349 .replaceAll("[^\\dA-Za-z|_]", "").replaceAll("\\s+", "+");
353 * Ensures sequence ref names are not less than 3 characters and does not
354 * contain a database name
359 public static boolean isValidSeqName(String seqName)
361 // System.out.println("seqName : " + seqName);
362 String ignoreList = "pdb,uniprot,swiss-prot";
363 if (seqName.length() < 3)
367 if (seqName.contains(":"))
371 seqName = seqName.toLowerCase();
372 for (String ignoredEntry : ignoreList.split(","))
374 if (seqName.contains(ignoredEntry))
382 public static String getDBRefId(DBRefEntry dbRef)
384 String ref = dbRef.getAccessionId().replaceAll("GO:", "");
389 * Filters a given list of discovered structures based on supplied argument
391 * @param fieldToFilterBy
392 * the field to filter by
394 public void filterResultSet(final String fieldToFilterBy)
396 Thread filterThread = new Thread(new Runnable()
401 long startTime = System.currentTimeMillis();
402 pdbRestCleint = PDBFTSRestClient.getInstance();
403 lbl_loading.setVisible(true);
404 Collection<FTSDataColumnI> wantedFields = pdbDocFieldPrefs
405 .getStructureSummaryFields();
406 Collection<FTSData> filteredResponse = new HashSet<FTSData>();
407 HashSet<String> errors = new HashSet<String>();
409 for (SequenceI seq : selectedSequences)
411 FTSRestRequest pdbRequest = new FTSRestRequest();
412 if (fieldToFilterBy.equalsIgnoreCase("uniprot_coverage"))
414 pdbRequest.setAllowEmptySeq(false);
415 pdbRequest.setResponseSize(1);
416 pdbRequest.setFieldToSearchBy("(");
417 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
418 pdbRequest.setWantedFields(wantedFields);
419 pdbRequest.setAssociatedSequence(seq);
420 pdbRequest.setFacet(true);
421 pdbRequest.setFacetPivot(fieldToFilterBy + ",entry_entity");
422 pdbRequest.setFacetPivotMinCount(1);
426 pdbRequest.setAllowEmptySeq(false);
427 pdbRequest.setResponseSize(1);
428 pdbRequest.setFieldToSearchBy("(");
429 pdbRequest.setFieldToSortBy(fieldToFilterBy,
430 !chk_invertFilter.isSelected());
431 pdbRequest.setSearchTerm(buildQuery(seq) + ")");
432 pdbRequest.setWantedFields(wantedFields);
433 pdbRequest.setAssociatedSequence(seq);
435 FTSRestResponse resultList;
438 resultList = pdbRestCleint.executeRequest(pdbRequest);
439 } catch (Exception e)
442 errors.add(e.getMessage());
445 lastPdbRequest = pdbRequest;
446 if (resultList.getSearchSummary() != null
447 && !resultList.getSearchSummary().isEmpty())
449 filteredResponse.addAll(resultList.getSearchSummary());
453 String totalTime = (System.currentTimeMillis() - startTime)
455 if (!filteredResponse.isEmpty())
457 final int filterResponseCount = filteredResponse.size();
458 Collection<FTSData> reorderedStructuresSet = new LinkedHashSet<FTSData>();
459 reorderedStructuresSet.addAll(filteredResponse);
460 reorderedStructuresSet.addAll(discoveredStructuresSet);
461 getResultTable().setModel(
462 FTSRestResponse.getTableModel(lastPdbRequest,
463 reorderedStructuresSet));
465 FTSRestResponse.configureTableColumn(getResultTable(),
466 wantedFields, tempUserPrefs);
467 getResultTable().getColumn("Ref Sequence").setPreferredWidth(120);
468 getResultTable().getColumn("Ref Sequence").setMinWidth(100);
469 getResultTable().getColumn("Ref Sequence").setMaxWidth(200);
470 // Update table selection model here
471 getResultTable().addRowSelectionInterval(0,
472 filterResponseCount - 1);
473 mainFrame.setTitle(MessageManager.formatMessage(
474 "label.structure_chooser_filter_time", totalTime));
478 mainFrame.setTitle(MessageManager.formatMessage(
479 "label.structure_chooser_filter_time", totalTime));
480 if (errors.size() > 0)
482 StringBuilder errorMsg = new StringBuilder();
483 for (String error : errors)
485 errorMsg.append(error).append("\n");
487 JvOptionPane.showMessageDialog(
490 MessageManager.getString("label.pdb_web-service_error"),
491 JvOptionPane.ERROR_MESSAGE);
495 lbl_loading.setVisible(false);
497 validateSelections();
500 filterThread.start();
504 * Handles action event for btn_pdbFromFile
507 public void pdbFromFile_actionPerformed()
509 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
510 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
511 chooser.setFileView(new jalview.io.JalviewFileView());
512 chooser.setDialogTitle(MessageManager.formatMessage(
513 "label.select_pdb_file_for",
514 selectedSequence.getDisplayId(false)));
515 chooser.setToolTipText(MessageManager.formatMessage(
516 "label.load_pdb_file_associate_with_sequence",
517 selectedSequence.getDisplayId(false)));
519 int value = chooser.showOpenDialog(null);
520 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
522 selectedPdbFileName = chooser.getSelectedFile().getPath();
523 jalview.bin.Cache.setProperty("LAST_DIRECTORY", selectedPdbFileName);
524 validateSelections();
529 * Populates the filter combo-box options dynamically depending on discovered
532 protected void populateFilterComboBox(boolean haveData,
533 boolean cachedPDBExists)
536 * temporarily suspend the change listener behaviour
538 cmb_filterOption.removeItemListener(this);
540 cmb_filterOption.removeAllItems();
543 cmb_filterOption.addItem(new FilterOption("Best Quality",
544 "overall_quality", VIEWS_FILTER, false));
545 cmb_filterOption.addItem(new FilterOption("Best Resolution",
546 "resolution", VIEWS_FILTER, false));
547 cmb_filterOption.addItem(new FilterOption("Most Protein Chain",
548 "number_of_protein_chains", VIEWS_FILTER, false));
549 cmb_filterOption.addItem(new FilterOption("Most Bound Molecules",
550 "number_of_bound_molecules", VIEWS_FILTER, false));
551 cmb_filterOption.addItem(new FilterOption("Most Polymer Residues",
552 "number_of_polymer_residues", VIEWS_FILTER, true));
554 cmb_filterOption.addItem(new FilterOption("Enter PDB Id", "-",
555 VIEWS_ENTER_ID, false));
556 cmb_filterOption.addItem(new FilterOption("From File", "-",
557 VIEWS_FROM_FILE, false));
561 FilterOption cachedOption = new FilterOption("Cached PDB Entries",
562 "-", VIEWS_LOCAL_PDB, false);
563 cmb_filterOption.addItem(cachedOption);
564 cmb_filterOption.setSelectedItem(cachedOption);
567 cmb_filterOption.addItemListener(this);
571 * Updates the displayed view based on the selected filter option
573 protected void updateCurrentView()
575 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
577 layout_switchableViews.show(pnl_switchableViews,
578 selectedFilterOpt.getView());
579 String filterTitle = mainFrame.getTitle();
580 mainFrame.setTitle(frameTitle);
581 chk_invertFilter.setVisible(false);
582 if (selectedFilterOpt.getView() == VIEWS_FILTER)
584 mainFrame.setTitle(filterTitle);
585 chk_invertFilter.setVisible(true);
586 filterResultSet(selectedFilterOpt.getValue());
588 else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
589 || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
591 mainFrame.setTitle(MessageManager
592 .getString("label.structure_chooser_manual_association"));
593 idInputAssSeqPanel.loadCmbAssSeq();
594 fileChooserAssSeqPanel.loadCmbAssSeq();
596 validateSelections();
600 * Validates user selection and activates the view button if all parameters
604 public void validateSelections()
606 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
608 btn_view.setEnabled(false);
609 String currentView = selectedFilterOpt.getView();
610 if (currentView == VIEWS_FILTER)
612 if (getResultTable().getSelectedRows().length > 0)
614 btn_view.setEnabled(true);
617 else if (currentView == VIEWS_LOCAL_PDB)
619 if (tbl_local_pdb.getSelectedRows().length > 0)
621 btn_view.setEnabled(true);
624 else if (currentView == VIEWS_ENTER_ID)
626 validateAssociationEnterPdb();
628 else if (currentView == VIEWS_FROM_FILE)
630 validateAssociationFromFile();
635 * Validates inputs from the Manual PDB entry panel
637 public void validateAssociationEnterPdb()
639 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) idInputAssSeqPanel
640 .getCmb_assSeq().getSelectedItem();
641 lbl_pdbManualFetchStatus.setIcon(errorImage);
642 lbl_pdbManualFetchStatus.setToolTipText("");
643 if (txt_search.getText().length() > 0)
645 lbl_pdbManualFetchStatus
646 .setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
647 .formatMessage("info.no_pdb_entry_found_for",
648 txt_search.getText())));
651 if (errorWarning.length() > 0)
653 lbl_pdbManualFetchStatus.setIcon(warningImage);
654 lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip(
655 true, errorWarning.toString()));
658 if (selectedSequences.length == 1
659 || !assSeqOpt.getName().equalsIgnoreCase(
660 "-Select Associated Seq-"))
662 txt_search.setEnabled(true);
665 btn_view.setEnabled(true);
666 lbl_pdbManualFetchStatus.setToolTipText("");
667 lbl_pdbManualFetchStatus.setIcon(goodImage);
672 txt_search.setEnabled(false);
673 lbl_pdbManualFetchStatus.setIcon(errorImage);
678 * Validates inputs for the manual PDB file selection options
680 public void validateAssociationFromFile()
682 AssociateSeqOptions assSeqOpt = (AssociateSeqOptions) fileChooserAssSeqPanel
683 .getCmb_assSeq().getSelectedItem();
684 lbl_fromFileStatus.setIcon(errorImage);
685 if (selectedSequences.length == 1
686 || (assSeqOpt != null && !assSeqOpt.getName().equalsIgnoreCase(
687 "-Select Associated Seq-")))
689 btn_pdbFromFile.setEnabled(true);
690 if (selectedPdbFileName != null && selectedPdbFileName.length() > 0)
692 btn_view.setEnabled(true);
693 lbl_fromFileStatus.setIcon(goodImage);
698 btn_pdbFromFile.setEnabled(false);
699 lbl_fromFileStatus.setIcon(errorImage);
704 public void cmbAssSeqStateChanged()
706 validateSelections();
710 * Handles the state change event for the 'filter' combo-box and 'invert'
714 protected void stateChanged(ItemEvent e)
716 if (e.getSource() instanceof JCheckBox)
722 if (e.getStateChange() == ItemEvent.SELECTED)
731 * Handles action event for btn_ok
734 public void ok_ActionPerformed()
736 final long progressSessionId = System.currentTimeMillis();
737 final StructureSelectionManager ssm = ap.getStructureSelectionManager();
738 final int preferredHeight = pnl_filter.getHeight();
739 ssm.setProgressIndicator(this);
740 ssm.setProgressSessionId(progressSessionId);
741 new Thread(new Runnable()
746 FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
748 String currentView = selectedFilterOpt.getView();
749 if (currentView == VIEWS_FILTER)
751 int pdbIdColIndex = getResultTable().getColumn("PDB Id")
753 int refSeqColIndex = getResultTable().getColumn("Ref Sequence")
755 int[] selectedRows = getResultTable().getSelectedRows();
756 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
758 List<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
759 for (int row : selectedRows)
761 String pdbIdStr = getResultTable().getValueAt(row,
762 pdbIdColIndex).toString();
763 SequenceI selectedSeq = (SequenceI) getResultTable()
764 .getValueAt(row, refSeqColIndex);
765 selectedSeqsToView.add(selectedSeq);
766 PDBEntry pdbEntry = selectedSeq.getPDBEntry(pdbIdStr);
767 if (pdbEntry == null)
769 pdbEntry = getFindEntry(pdbIdStr,
770 selectedSeq.getAllPDBEntries());
772 if (pdbEntry == null)
774 pdbEntry = new PDBEntry();
775 pdbEntry.setId(pdbIdStr);
776 pdbEntry.setType(PDBEntry.Type.PDB);
777 selectedSeq.getDatasetSequence().addPDBId(pdbEntry);
779 pdbEntriesToView[count++] = pdbEntry;
781 SequenceI[] selectedSeqs = selectedSeqsToView
782 .toArray(new SequenceI[selectedSeqsToView.size()]);
783 launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
785 else if (currentView == VIEWS_LOCAL_PDB)
787 int[] selectedRows = tbl_local_pdb.getSelectedRows();
788 PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
790 int pdbIdColIndex = tbl_local_pdb.getColumn("PDB Id")
792 int refSeqColIndex = tbl_local_pdb.getColumn("Ref Sequence")
794 List<SequenceI> selectedSeqsToView = new ArrayList<SequenceI>();
795 for (int row : selectedRows)
797 PDBEntry pdbEntry = (PDBEntry) tbl_local_pdb.getValueAt(row,
799 pdbEntriesToView[count++] = pdbEntry;
800 SequenceI selectedSeq = (SequenceI) tbl_local_pdb.getValueAt(
801 row, refSeqColIndex);
802 selectedSeqsToView.add(selectedSeq);
804 SequenceI[] selectedSeqs = selectedSeqsToView
805 .toArray(new SequenceI[selectedSeqsToView.size()]);
806 launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
808 else if (currentView == VIEWS_ENTER_ID)
810 SequenceI userSelectedSeq = ((AssociateSeqOptions) idInputAssSeqPanel
811 .getCmb_assSeq().getSelectedItem()).getSequence();
812 if (userSelectedSeq != null)
814 selectedSequence = userSelectedSeq;
817 String pdbIdStr = txt_search.getText();
818 PDBEntry pdbEntry = selectedSequence.getPDBEntry(pdbIdStr);
819 if (pdbEntry == null)
821 pdbEntry = new PDBEntry();
822 if (pdbIdStr.split(":").length > 1)
824 pdbEntry.setId(pdbIdStr.split(":")[0]);
825 pdbEntry.setChainCode(pdbIdStr.split(":")[1].toUpperCase());
829 pdbEntry.setId(pdbIdStr);
831 pdbEntry.setType(PDBEntry.Type.PDB);
832 selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
835 PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
836 launchStructureViewer(ssm, pdbEntriesToView, ap,
837 new SequenceI[] { selectedSequence });
839 else if (currentView == VIEWS_FROM_FILE)
841 SequenceI userSelectedSeq = ((AssociateSeqOptions) fileChooserAssSeqPanel
842 .getCmb_assSeq().getSelectedItem()).getSequence();
843 if (userSelectedSeq != null)
845 selectedSequence = userSelectedSeq;
847 PDBEntry fileEntry = new AssociatePdbFileWithSeq()
848 .associatePdbWithSeq(selectedPdbFileName,
850 selectedSequence, true, Desktop.instance);
852 launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
853 new SequenceI[] { selectedSequence });
855 closeAction(preferredHeight);
860 private PDBEntry getFindEntry(String id, Vector<PDBEntry> pdbEntries)
862 Objects.requireNonNull(id);
863 Objects.requireNonNull(pdbEntries);
864 PDBEntry foundEntry = null;
865 for (PDBEntry entry : pdbEntries)
867 if (entry.getId().equalsIgnoreCase(id))
875 private void launchStructureViewer(StructureSelectionManager ssm,
876 final PDBEntry[] pdbEntriesToView,
877 final AlignmentPanel alignPanel, SequenceI[] sequences)
879 ssm.setProgressBar(MessageManager
880 .getString("status.launching_3d_structure_viewer"));
881 final StructureViewer sViewer = new StructureViewer(ssm);
883 if (SiftsSettings.isMapWithSifts())
885 List<SequenceI> seqsWithoutSourceDBRef = new ArrayList<SequenceI>();
887 // TODO: skip PDBEntry:Sequence pairs where PDBEntry doesn't look like a
888 // real PDB ID. For moment, we can also safely do this if there is already
889 // a known mapping between the PDBEntry and the sequence.
890 for (SequenceI seq : sequences)
892 PDBEntry pdbe = pdbEntriesToView[p++];
893 if (pdbe != null && pdbe.getFile() != null)
895 StructureMapping[] smm = ssm.getMapping(pdbe.getFile());
896 if (smm != null && smm.length > 0)
898 for (StructureMapping sm : smm)
900 if (sm.getSequence() == seq)
907 if (seq.getPrimaryDBRefs().size() == 0)
909 seqsWithoutSourceDBRef.add(seq);
913 if (!seqsWithoutSourceDBRef.isEmpty())
915 int y = seqsWithoutSourceDBRef.size();
916 ssm.setProgressBar(null);
917 ssm.setProgressBar(MessageManager.formatMessage(
918 "status.fetching_dbrefs_for_sequences_without_valid_refs",
920 SequenceI[] seqWithoutSrcDBRef = new SequenceI[y];
922 for (SequenceI fSeq : seqsWithoutSourceDBRef)
924 seqWithoutSrcDBRef[x++] = fSeq;
926 DBRefFetcher dbRefFetcher = new DBRefFetcher(seqWithoutSrcDBRef);
927 dbRefFetcher.fetchDBRefs(true);
930 if (pdbEntriesToView.length > 1)
932 ArrayList<SequenceI[]> seqsMap = new ArrayList<SequenceI[]>();
933 for (SequenceI seq : sequences)
935 seqsMap.add(new SequenceI[] { seq });
937 SequenceI[][] collatedSeqs = seqsMap.toArray(new SequenceI[0][0]);
938 ssm.setProgressBar(null);
939 ssm.setProgressBar(MessageManager
940 .getString("status.fetching_3d_structures_for_selected_entries"));
941 sViewer.viewStructures(pdbEntriesToView, collatedSeqs, alignPanel);
945 ssm.setProgressBar(null);
946 ssm.setProgressBar(MessageManager.formatMessage(
947 "status.fetching_3d_structures_for",
948 pdbEntriesToView[0].getId()));
949 sViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
954 * Populates the combo-box used in associating manually fetched structures to
955 * a unique sequence when more than one sequence selection is made.
958 public void populateCmbAssociateSeqOptions(
959 JComboBox<AssociateSeqOptions> cmb_assSeq, JLabel lbl_associateSeq)
961 cmb_assSeq.removeAllItems();
962 cmb_assSeq.addItem(new AssociateSeqOptions("-Select Associated Seq-",
964 lbl_associateSeq.setVisible(false);
965 if (selectedSequences.length > 1)
967 for (SequenceI seq : selectedSequences)
969 cmb_assSeq.addItem(new AssociateSeqOptions(seq));
974 String seqName = selectedSequence.getDisplayId(false);
975 seqName = seqName.length() <= 40 ? seqName : seqName.substring(0, 39);
976 lbl_associateSeq.setText(seqName);
977 lbl_associateSeq.setVisible(true);
978 cmb_assSeq.setVisible(false);
982 public boolean isStructuresDiscovered()
984 return discoveredStructuresSet != null
985 && !discoveredStructuresSet.isEmpty();
988 public Collection<FTSData> getDiscoveredStructuresSet()
990 return discoveredStructuresSet;
994 protected void txt_search_ActionPerformed()
1001 errorWarning.setLength(0);
1002 isValidPBDEntry = false;
1003 if (txt_search.getText().length() > 0)
1005 String searchTerm = txt_search.getText().toLowerCase();
1006 searchTerm = searchTerm.split(":")[0];
1007 // System.out.println(">>>>> search term : " + searchTerm);
1008 List<FTSDataColumnI> wantedFields = new ArrayList<FTSDataColumnI>();
1009 FTSRestRequest pdbRequest = new FTSRestRequest();
1010 pdbRequest.setAllowEmptySeq(false);
1011 pdbRequest.setResponseSize(1);
1012 pdbRequest.setFieldToSearchBy("(pdb_id:");
1013 pdbRequest.setWantedFields(wantedFields);
1014 pdbRequest.setSearchTerm(searchTerm + ")");
1015 pdbRequest.setAssociatedSequence(selectedSequence);
1016 pdbRestCleint = PDBFTSRestClient.getInstance();
1017 wantedFields.add(pdbRestCleint.getPrimaryKeyColumn());
1018 FTSRestResponse resultList;
1021 resultList = pdbRestCleint.executeRequest(pdbRequest);
1022 } catch (Exception e)
1024 errorWarning.append(e.getMessage());
1028 validateSelections();
1030 if (resultList.getSearchSummary() != null
1031 && resultList.getSearchSummary().size() > 0)
1033 isValidPBDEntry = true;
1036 validateSelections();
1042 public void tabRefresh()
1044 if (selectedSequences != null)
1046 Thread refreshThread = new Thread(new Runnable()
1051 fetchStructuresMetaData();
1052 filterResultSet(((FilterOption) cmb_filterOption
1053 .getSelectedItem()).getValue());
1056 refreshThread.start();
1060 public class PDBEntryTableModel extends AbstractTableModel
1062 String[] columns = { "Ref Sequence", "PDB Id", "Chain", "Type", "File" };
1064 private List<CachedPDB> pdbEntries;
1066 public PDBEntryTableModel(List<CachedPDB> pdbEntries)
1068 this.pdbEntries = new ArrayList<CachedPDB>(pdbEntries);
1072 public String getColumnName(int columnIndex)
1074 return columns[columnIndex];
1078 public int getRowCount()
1080 return pdbEntries.size();
1084 public int getColumnCount()
1086 return columns.length;
1090 public boolean isCellEditable(int row, int column)
1096 public Object getValueAt(int rowIndex, int columnIndex)
1098 Object value = "??";
1099 CachedPDB entry = pdbEntries.get(rowIndex);
1100 switch (columnIndex)
1103 value = entry.getSequence();
1106 value = entry.getPdbEntry();
1109 value = entry.getPdbEntry().getChainCode() == null ? "_" : entry
1110 .getPdbEntry().getChainCode();
1113 value = entry.getPdbEntry().getType();
1116 value = entry.getPdbEntry().getFile();
1123 public Class<?> getColumnClass(int columnIndex)
1125 return columnIndex == 0 ? SequenceI.class : PDBEntry.class;
1128 public CachedPDB getPDBEntryAt(int row)
1130 return pdbEntries.get(row);
1135 private class CachedPDB
1137 private SequenceI sequence;
1139 private PDBEntry pdbEntry;
1141 public CachedPDB(SequenceI sequence, PDBEntry pdbEntry)
1143 this.sequence = sequence;
1144 this.pdbEntry = pdbEntry;
1147 public SequenceI getSequence()
1152 public PDBEntry getPdbEntry()
1159 private IProgressIndicator progressBar;
1162 public void setProgressBar(String message, long id)
1164 progressBar.setProgressBar(message, id);
1168 public void registerHandler(long id, IProgressIndicatorHandler handler)
1170 progressBar.registerHandler(id, handler);
1174 public boolean operationInProgress()
1176 return progressBar.operationInProgress();