+ if (restable == null)
+ {
+ // can't select (enter PDB ID, or load file - need to also select which
+ // sequence to associate with)
+ return false;
+ }
+
+ int pdbIdColIndex = restable.getColumn("PDB Id").getModelIndex();
+ for (int r = 0; r < restable.getRowCount(); r++)
+ {
+ for (int p = 0; p < pdbids.length; p++)
+ {
+ if (String.valueOf(restable.getValueAt(r, pdbIdColIndex))
+ .equalsIgnoreCase(pdbids[p]))
+ {
+ restable.setRowSelectionInterval(r, r);
+ found = true;
+ }
+ }
+ }
+ return found;
+ }
+ /**
+ * Handles action event for btn_ok
+ */
+ @Override
+ public void ok_ActionPerformed()
+ {
+ showStructures(false);
+ }
+
+ /**
+ * structure viewer opened by this dialog, or null
+ */
+ private StructureViewer sViewer = null;
+
+ public void showStructures(boolean waitUntilFinished)
+ {
+
+ final StructureSelectionManager ssm = ap.getStructureSelectionManager();
+
+ final int preferredHeight = pnl_filter.getHeight();
+
+ Runnable viewStruc = new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
+ .getSelectedItem());
+ String currentView = selectedFilterOpt.getView();
+ JTable restable = (currentView == VIEWS_FILTER) ? getResultTable()
+ : tbl_local_pdb;
+
+ if (currentView == VIEWS_FILTER)
+ {
+ int pdbIdColIndex = restable.getColumn("PDB Id")
+ .getModelIndex();
+ int refSeqColIndex = restable.getColumn("Ref Sequence")
+ .getModelIndex();
+ int[] selectedRows = restable.getSelectedRows();
+ PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
+ int count = 0;
+ List<SequenceI> selectedSeqsToView = new ArrayList<>();
+ for (int row : selectedRows)
+ {
+ String pdbIdStr = restable
+ .getValueAt(row, pdbIdColIndex).toString();
+ SequenceI selectedSeq = (SequenceI) restable
+ .getValueAt(row, refSeqColIndex);
+ selectedSeqsToView.add(selectedSeq);
+ PDBEntry pdbEntry = selectedSeq.getPDBEntry(pdbIdStr);
+ if (pdbEntry == null)
+ {
+ pdbEntry = getFindEntry(pdbIdStr,
+ selectedSeq.getAllPDBEntries());
+ }
+
+ if (pdbEntry == null)
+ {
+ pdbEntry = new PDBEntry();
+ pdbEntry.setId(pdbIdStr);
+ pdbEntry.setType(PDBEntry.Type.PDB);
+ selectedSeq.getDatasetSequence().addPDBId(pdbEntry);
+ }
+ pdbEntriesToView[count++] = pdbEntry;
+ }
+ SequenceI[] selectedSeqs = selectedSeqsToView
+ .toArray(new SequenceI[selectedSeqsToView.size()]);
+ sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
+ selectedSeqs);
+ }
+ else if (currentView == VIEWS_LOCAL_PDB)
+ {
+ int[] selectedRows = tbl_local_pdb.getSelectedRows();
+ PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
+ int count = 0;
+ int pdbIdColIndex = tbl_local_pdb.getColumn("PDB Id")
+ .getModelIndex();
+ int refSeqColIndex = tbl_local_pdb.getColumn("Ref Sequence")
+ .getModelIndex();
+ List<SequenceI> selectedSeqsToView = new ArrayList<>();
+ for (int row : selectedRows)
+ {
+ PDBEntry pdbEntry = (PDBEntry) tbl_local_pdb.getValueAt(row,
+ pdbIdColIndex);
+ pdbEntriesToView[count++] = pdbEntry;
+ SequenceI selectedSeq = (SequenceI) tbl_local_pdb
+ .getValueAt(row, refSeqColIndex);
+ selectedSeqsToView.add(selectedSeq);
+ }
+ SequenceI[] selectedSeqs = selectedSeqsToView
+ .toArray(new SequenceI[selectedSeqsToView.size()]);
+ sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
+ selectedSeqs);
+ }
+ else if (currentView == VIEWS_ENTER_ID)
+ {
+ SequenceI userSelectedSeq = ((AssociateSeqOptions) idInputAssSeqPanel
+ .getCmb_assSeq().getSelectedItem()).getSequence();
+ if (userSelectedSeq != null)
+ {
+ selectedSequence = userSelectedSeq;
+ }
+ String pdbIdStr = txt_search.getText();
+ PDBEntry pdbEntry = selectedSequence.getPDBEntry(pdbIdStr);
+ if (pdbEntry == null)
+ {
+ pdbEntry = new PDBEntry();
+ if (pdbIdStr.split(":").length > 1)
+ {
+ pdbEntry.setId(pdbIdStr.split(":")[0]);
+ pdbEntry.setChainCode(pdbIdStr.split(":")[1].toUpperCase());
+ }
+ else
+ {
+ pdbEntry.setId(pdbIdStr);
+ }
+ pdbEntry.setType(PDBEntry.Type.PDB);
+ selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
+ }
+
+ PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
+ sViewer = launchStructureViewer(ssm, pdbEntriesToView, ap,
+ new SequenceI[]
+ { selectedSequence });
+ }
+ else if (currentView == VIEWS_FROM_FILE)
+ {
+ SequenceI userSelectedSeq = ((AssociateSeqOptions) fileChooserAssSeqPanel
+ .getCmb_assSeq().getSelectedItem()).getSequence();
+ if (userSelectedSeq != null)
+ {
+ selectedSequence = userSelectedSeq;
+ }
+ PDBEntry fileEntry = new AssociatePdbFileWithSeq()
+ .associatePdbWithSeq(selectedPdbFileName,
+ DataSourceType.FILE, selectedSequence, true,
+ Desktop.instance);
+
+ sViewer = launchStructureViewer(
+ ssm, new PDBEntry[]
+ { fileEntry }, ap,
+ new SequenceI[]
+ { selectedSequence });
+ }
+ SwingUtilities.invokeLater(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ closeAction(preferredHeight);
+ mainFrame.dispose();
+ }
+ });
+ }
+ };
+ Thread runner = new Thread(viewStruc);
+ runner.start();
+ if (waitUntilFinished)
+ {
+ while (sViewer == null ? runner.isAlive()
+ : (sViewer.sview == null ? true
+ : !sViewer.sview.hasMapping()))
+ {
+ try
+ {
+ Thread.sleep(300);
+ } catch (InterruptedException ie)
+ {
+
+ }
+ }
+ }
+ }
+
+ private PDBEntry getFindEntry(String id, Vector<PDBEntry> pdbEntries)
+ {
+ Objects.requireNonNull(id);
+ Objects.requireNonNull(pdbEntries);
+ PDBEntry foundEntry = null;
+ for (PDBEntry entry : pdbEntries)
+ {
+ if (entry.getId().equalsIgnoreCase(id))
+ {
+ return entry;
+ }
+ }
+ return foundEntry;
+ }
+
+ /**
+ * @param ssm
+ * @return targetted structure view (new or existing) configured according to
+ * superpose checkbox
+ */
+ public StructureViewer getTargetedStructureViewer(
+ StructureSelectionManager ssm)
+ {
+ Object _sv = targetView.getSelectedItem();
+ StructureViewer sv;
+ if (_sv == null)
+ {
+ sv = new StructureViewer(ssm);
+ } else {
+ sv = (StructureViewer) _sv;
+ }
+ sv.setSuperpose(chk_superpose.isSelected());
+ return sv;
+ }
+ private StructureViewer launchStructureViewer(
+ StructureSelectionManager ssm,
+ final PDBEntry[] pdbEntriesToView,
+ final AlignmentPanel alignPanel, SequenceI[] sequences)
+ {
+ long progressId = sequences.hashCode();
+ setProgressBar(MessageManager
+ .getString("status.launching_3d_structure_viewer"), progressId);
+ final StructureViewer sViewer = getTargetedStructureViewer(ssm);
+ sViewer.setSuperpose(chk_superpose.isSelected());
+
+ setProgressBar(null, progressId);
+ if (SiftsSettings.isMapWithSifts())
+ {
+ List<SequenceI> seqsWithoutSourceDBRef = new ArrayList<>();
+ int p = 0;
+ // TODO: skip PDBEntry:Sequence pairs where PDBEntry doesn't look like a
+ // real PDB ID. For moment, we can also safely do this if there is already
+ // a known mapping between the PDBEntry and the sequence.
+ for (SequenceI seq : sequences)
+ {
+ PDBEntry pdbe = pdbEntriesToView[p++];
+ if (pdbe != null && pdbe.getFile() != null)
+ {
+ StructureMapping[] smm = ssm.getMapping(pdbe.getFile());
+ if (smm != null && smm.length > 0)
+ {
+ for (StructureMapping sm : smm)
+ {
+ if (sm.getSequence() == seq)
+ {
+ continue;
+ }
+ }
+ }
+ }
+ if (seq.getPrimaryDBRefs().size() == 0)
+ {
+ seqsWithoutSourceDBRef.add(seq);
+ continue;
+ }
+ }
+ if (!seqsWithoutSourceDBRef.isEmpty())
+ {
+ int y = seqsWithoutSourceDBRef.size();
+ setProgressBar(MessageManager.formatMessage(
+ "status.fetching_dbrefs_for_sequences_without_valid_refs",
+ y), progressId);
+ SequenceI[] seqWithoutSrcDBRef = new SequenceI[y];
+ int x = 0;
+ for (SequenceI fSeq : seqsWithoutSourceDBRef)
+ {
+ seqWithoutSrcDBRef[x++] = fSeq;
+ }
+
+ DBRefFetcher dbRefFetcher = new DBRefFetcher(seqWithoutSrcDBRef);
+ dbRefFetcher.fetchDBRefs(true);
+
+ setProgressBar("Fetch complete.", progressId); // todo i18n
+ }
+ }
+ if (pdbEntriesToView.length > 1)
+ {
+ setProgressBar(MessageManager.getString(
+ "status.fetching_3d_structures_for_selected_entries"),
+ progressId);
+ sViewer.viewStructures(pdbEntriesToView, sequences, alignPanel);
+ }
+ else
+ {
+ setProgressBar(MessageManager.formatMessage(
+ "status.fetching_3d_structures_for",
+ pdbEntriesToView[0].getId()),progressId);
+ sViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
+ }
+ setProgressBar(null, progressId);
+ // remember the last viewer we used...
+ lastTargetedView = sViewer;
+ return sViewer;
+ }
+
+ /**
+ * Populates the combo-box used in associating manually fetched structures to
+ * a unique sequence when more than one sequence selection is made.
+ */
+ @Override
+ public void populateCmbAssociateSeqOptions(
+ JComboBox<AssociateSeqOptions> cmb_assSeq,
+ JLabel lbl_associateSeq)