import jalview.datamodel.SequenceI;
import jalview.jbgui.GStructureChooser;
import jalview.jbgui.PDBDocFieldPreferences;
+import jalview.structure.StructureSelectionManager;
import jalview.util.MessageManager;
import jalview.ws.dbsources.PDBRestClient;
import jalview.ws.dbsources.PDBRestClient.PDBDocField;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Hashtable;
import java.util.LinkedHashSet;
import java.util.List;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
+import javax.swing.JOptionPane;
+import javax.swing.table.DefaultTableModel;
+
/**
* Provides the behaviors for the Structure chooser Panel
private boolean isValidPBDEntry;
+ private static Hashtable<String, PDBEntry> cachedEntryMap;
+
public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
AlignmentPanel ap)
{
long startTime = System.currentTimeMillis();
String msg = MessageManager.getString("status.fetching_db_refs");
updateProgressIndicator(msg, startTime);
+ loadLocalCachedPDBEntries();
fetchStructuresMetaData();
populateFilterComboBox();
updateProgressIndicator(null, startTime);
.getStructureSummaryFields();
discoveredStructuresSet = new LinkedHashSet<PDBResponseSummary>();
+ HashSet<String> errors = new HashSet<String>();
for (SequenceI seq : selectedSequences)
{
PDBRestRequest pdbRequest = new PDBRestRequest();
pdbRequest.setSearchTerm(buildQuery(seq) + ")");
pdbRequest.setAssociatedSequence(seq.getName());
pdbRestCleint = new PDBRestClient();
- PDBRestResponse resultList = pdbRestCleint.executeRequest(pdbRequest);
+ PDBRestResponse resultList;
+ try
+ {
+ resultList = pdbRestCleint.executeRequest(pdbRequest);
+ } catch (Exception e)
+ {
+ errors.add(e.getMessage());
+ continue;
+ }
lastPdbRequest = pdbRequest;
if (resultList.getSearchSummary() != null
&& !resultList.getSearchSummary().isEmpty())
}
int noOfStructuresFound = 0;
+ String totalTime = (System.currentTimeMillis() - startTime)
+ + " milli secs";
if (discoveredStructuresSet != null
&& !discoveredStructuresSet.isEmpty())
{
discoveredStructuresSet));
structuresDiscovered = true;
noOfStructuresFound = discoveredStructuresSet.size();
+ mainFrame.setTitle("Structure Chooser - " + noOfStructuresFound
+ + " Found (" + totalTime + ")");
+ }
+ else
+ {
+ mainFrame
+.setTitle("Structure Chooser - Manual association");
+ if (errors.size() > 0)
+ {
+ StringBuilder errorMsg = new StringBuilder(
+ "Operation was unsucessful due to the following: \n");
+ for (String error : errors)
+ {
+ errorMsg.append(error).append("\n");
+ }
+ JOptionPane.showMessageDialog(this, errorMsg.toString(),
+ "PDB Web-service Error", JOptionPane.ERROR_MESSAGE);
+ }
}
- String totalTime = (System.currentTimeMillis() - startTime)
- + " milli secs";
- mainFrame.setTitle("Structure Chooser - " + noOfStructuresFound
- + " Found (" + totalTime + ")");
+ }
+
+ public void loadLocalCachedPDBEntries()
+ {
+ DefaultTableModel tableModel = new DefaultTableModel();
+ tableModel.addColumn("Sequence");
+ tableModel.addColumn("PDB Id");
+ tableModel.addColumn("Chain");
+ tableModel.addColumn("Type");
+ tableModel.addColumn("File");
+ cachedEntryMap = new Hashtable<String, PDBEntry>();
+ for (SequenceI seq : selectedSequences)
+ {
+ if (seq.getDatasetSequence() != null
+ && seq.getDatasetSequence().getPDBId() != null)
+ {
+ for (PDBEntry pdbEntry : seq.getDatasetSequence().getPDBId())
+ {
+ String chain = pdbEntry.getChainCode() == null ? "_" : pdbEntry
+ .getChainCode();
+ String[] pdbEntryRowData = new String[]
+ { seq.getDisplayId(false), pdbEntry.getId(),
+ chain,
+ pdbEntry.getType(),
+ pdbEntry.getFile() };
+ tableModel.addRow(pdbEntryRowData);
+ cachedEntryMap.put(seq.getDisplayId(false) + pdbEntry.getId(),
+ pdbEntry);
+ }
+ }
+ }
+ tbl_local_pdb.setModel(tableModel);
}
/**
{
PDBEntry newEntry = new PDBEntry();
newEntry.setId(response.getPdbId());
- newEntry.setType("PDB");
+ newEntry.setType(PDBEntry.Type.PDB);
seq.getDatasetSequence().addPDBId(newEntry);
}
}
* the sequences to build a query for
* @return the built query string
*/
- @SuppressWarnings("unchecked")
+
public static String buildQuery(SequenceI seq)
{
- String query = seq.getName();
- StringBuilder queryBuilder = new StringBuilder();
- int count = 0;
+ HashSet<String> seqRefs = new LinkedHashSet<String>();
+ String seqName = seq.getName();
+ String[] names = seqName.toLowerCase().split("\\|");
+ for (String name : names)
+ {
+ // System.out.println("Found name : " + name);
+ name.trim();
+ if (isValidSeqName(name))
+ {
+ seqRefs.add(name);
+ }
+ }
if (seq.getPDBId() != null)
{
for (PDBEntry entry : seq.getPDBId())
{
- queryBuilder.append("text:").append(entry.getId()).append(" OR ");
+ seqRefs.add(entry.getId());
}
}
if (seq.getDBRef() != null && seq.getDBRef().length != 0)
{
+ int count = 0;
for (DBRefEntry dbRef : seq.getDBRef())
{
- queryBuilder.append("text:")
- .append(dbRef.getAccessionId().replaceAll("GO:", ""))
- .append(" OR ");
+ seqRefs.add(getDBRefId(dbRef));
++count;
if (count > 10)
{
break;
}
}
- int endIndex = queryBuilder.lastIndexOf(" OR ");
- query = queryBuilder.toString().substring(5, endIndex);
}
+
+ StringBuilder queryBuilder = new StringBuilder();
+ for (String seqRef : seqRefs)
+ {
+ queryBuilder.append("text:").append(seqRef).append(" OR ");
+ }
+ int endIndex = queryBuilder.lastIndexOf(" OR ");
+ String query = queryBuilder.toString().substring(5, endIndex);
return query;
}
/**
+ * Ensures sequence ref names are not less than 3 characters and does not
+ * contain a database name
+ *
+ * @param seqName
+ * @return
+ */
+ public static boolean isValidSeqName(String seqName)
+ {
+ String ignoreList = "pdb,uniprot";
+ if (seqName.length() < 3)
+ {
+ return false;
+ }
+ for (String ignoredEntry : ignoreList.split(","))
+ {
+ if (seqName.equalsIgnoreCase(ignoredEntry))
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ public static String getDBRefId(DBRefEntry dbRef)
+ {
+ String ref = dbRef.getAccessionId().replaceAll("GO:", "");
+ return ref;
+ }
+
+ /**
* Filters a given list of discovered structures based on supplied argument
*
* @param fieldToFilterBy
public void run()
{
long startTime = System.currentTimeMillis();
- try
+ lbl_loading.setVisible(true);
+ Collection<PDBDocField> wantedFields = PDBDocFieldPreferences
+ .getStructureSummaryFields();
+ Collection<PDBResponseSummary> filteredResponse = new HashSet<PDBResponseSummary>();
+ HashSet<String> errors = new HashSet<String>();
+ for (SequenceI seq : selectedSequences)
{
- lbl_loading.setVisible(true);
-
- Collection<PDBDocField> wantedFields = PDBDocFieldPreferences
- .getStructureSummaryFields();
- Collection<PDBResponseSummary> filteredResponse = new HashSet<PDBResponseSummary>();
- for (SequenceI seq : selectedSequences)
+ PDBRestRequest pdbRequest = new PDBRestRequest();
+ pdbRequest.setAllowEmptySeq(false);
+ pdbRequest.setResponseSize(1);
+ pdbRequest.setFieldToSearchBy("(text:");
+ pdbRequest.setFieldToSortBy(fieldToFilterBy,
+ !chk_invertFilter.isSelected());
+ pdbRequest.setSearchTerm(buildQuery(seq) + ")");
+ pdbRequest.setWantedFields(wantedFields);
+ pdbRequest.setAssociatedSequence(seq.getName());
+ pdbRestCleint = new PDBRestClient();
+ PDBRestResponse resultList;
+ try
{
- PDBRestRequest pdbRequest = new PDBRestRequest();
- pdbRequest.setAllowEmptySeq(false);
- pdbRequest.setResponseSize(1);
- pdbRequest.setFieldToSearchBy("(text:");
- pdbRequest.setFieldToSortBy(fieldToFilterBy,
- !chk_invertFilter.isSelected());
- pdbRequest.setSearchTerm(buildQuery(seq) + ")");
- pdbRequest.setWantedFields(wantedFields);
- pdbRequest.setAssociatedSequence(seq.getName());
- pdbRestCleint = new PDBRestClient();
- PDBRestResponse resultList = pdbRestCleint
- .executeRequest(pdbRequest);
- lastPdbRequest = pdbRequest;
- if (resultList.getSearchSummary() != null
- && !resultList.getSearchSummary().isEmpty())
- {
- filteredResponse.addAll(resultList.getSearchSummary());
- }
+ resultList = pdbRestCleint.executeRequest(pdbRequest);
+ } catch (Exception e)
+ {
+ errors.add(e.getMessage());
+ continue;
}
-
- if (!filteredResponse.isEmpty())
+ lastPdbRequest = pdbRequest;
+ if (resultList.getSearchSummary() != null
+ && !resultList.getSearchSummary().isEmpty())
{
- final int filterResponseCount = filteredResponse.size();
- Collection<PDBResponseSummary> reorderedStructuresSet = new LinkedHashSet<PDBResponseSummary>();
- reorderedStructuresSet.addAll(filteredResponse);
- reorderedStructuresSet.addAll(discoveredStructuresSet);
- tbl_summary.setModel(PDBRestResponse.getTableModel(
- lastPdbRequest, reorderedStructuresSet));
+ filteredResponse.addAll(resultList.getSearchSummary());
+ }
+ }
- // Update table selection model here
- tbl_summary.addRowSelectionInterval(0, filterResponseCount - 1);
+ String totalTime = (System.currentTimeMillis() - startTime)
+ + " milli secs";
+ if (!filteredResponse.isEmpty())
+ {
+ final int filterResponseCount = filteredResponse.size();
+ Collection<PDBResponseSummary> reorderedStructuresSet = new LinkedHashSet<PDBResponseSummary>();
+ reorderedStructuresSet.addAll(filteredResponse);
+ reorderedStructuresSet.addAll(discoveredStructuresSet);
+ tbl_summary.setModel(PDBRestResponse.getTableModel(
+ lastPdbRequest, reorderedStructuresSet));
- }
+ // Update table selection model here
+ tbl_summary.addRowSelectionInterval(0, filterResponseCount - 1);
- lbl_loading.setVisible(false);
- String totalTime = (System.currentTimeMillis() - startTime)
- + " milli secs";
mainFrame.setTitle("Structure Chooser - Filter time ("
+ totalTime + ")");
-
- validateSelections();
- } catch (Exception e)
+ }
+ else
{
- e.printStackTrace();
+ mainFrame.setTitle("Structure Chooser - Filter time ("
+ + totalTime + ")");
+ if (errors.size() > 0)
+ {
+ StringBuilder errorMsg = new StringBuilder(
+ "Operation unsucessful due to the following: \n");
+ for (String error : errors)
+ {
+ errorMsg.append(error).append("\n");
+ }
+ JOptionPane.showMessageDialog(null, errorMsg.toString(),
+ "PDB Web-service Error", JOptionPane.ERROR_MESSAGE);
+ }
}
+
+ lbl_loading.setVisible(false);
+
+ validateSelections();
}
});
filterThread.start();
VIEWS_ENTER_ID));
cmb_filterOption.addItem(new FilterOption("From File", "-",
VIEWS_FROM_FILE));
+ cmb_filterOption.addItem(new FilterOption("Cached PDB Entries", "-",
+ VIEWS_LOCAL_PDB));
}
/**
chk_invertFilter.setVisible(true);
filterResultSet(selectedFilterOpt.getValue());
}
- else
+ else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
+ || selectedFilterOpt.getView() == VIEWS_FROM_FILE)
{
+ mainFrame.setTitle(filterTitle);
idInputAssSeqPanel.loadCmbAssSeq();
fileChooserAssSeqPanel.loadCmbAssSeq();
}
btn_view.setEnabled(true);
}
}
+ else if (currentView == VIEWS_LOCAL_PDB)
+ {
+ if (tbl_local_pdb.getSelectedRows().length > 0)
+ {
+ btn_view.setEnabled(true);
+ }
+ }
else if (currentView == VIEWS_ENTER_ID)
{
validateAssociationEnterPdb();
.toString();
PDBEntry pdbEntry = new PDBEntry();
pdbEntry.setId(pdbIdStr);
- pdbEntry.setType("PDB");
+ pdbEntry.setType(PDBEntry.Type.PDB);
pdbEntriesToView[count++] = pdbEntry;
}
- StructureViewer sViewer = new StructureViewer(
- ap.getStructureSelectionManager());
- if (pdbEntriesToView.length > 1)
- {
- sViewer.viewStructures(ap, pdbEntriesToView,
- ap.av.collateForPDB(pdbEntriesToView));
- }
- else
+ launchStructureViewer(ap.getStructureSelectionManager(),
+ pdbEntriesToView, ap, selectedSequences);
+ }
+ else if(currentView == VIEWS_LOCAL_PDB){
+ int[] selectedRows = tbl_local_pdb.getSelectedRows();
+ PDBEntry[] pdbEntriesToView = new PDBEntry[selectedRows.length];
+ int count = 0;
+ for (int row : selectedRows)
{
- sViewer.viewStructures(pdbEntriesToView[0], selectedSequences,
- null, ap);
+ String entryKey = tbl_local_pdb.getValueAt(row, 0).toString() + tbl_local_pdb.getValueAt(row, 1).toString();
+ pdbEntriesToView[count++] = cachedEntryMap.get(entryKey);
}
-
+ launchStructureViewer(ap.getStructureSelectionManager(),
+ pdbEntriesToView, ap, selectedSequences);
}
else if (currentView == VIEWS_ENTER_ID)
{
}
PDBEntry pdbEntry = new PDBEntry();
pdbEntry.setId(txt_search.getText());
- pdbEntry.setType("PDB");
+ pdbEntry.setType(PDBEntry.Type.PDB);
selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
PDBEntry[] pdbEntriesToView = new PDBEntry[]
{ pdbEntry };
- new StructureViewer(ap.getStructureSelectionManager())
- .viewStructures(ap, pdbEntriesToView,
- ap.av.collateForPDB(pdbEntriesToView));
+ launchStructureViewer(ap.getStructureSelectionManager(),
+ pdbEntriesToView, ap, new SequenceI[]
+ { selectedSequence });
}
else if (currentView == VIEWS_FROM_FILE)
{
{
selectedSequence = userSelectedSeq;
}
- System.out.println(">>>>>>>>>>>>> Selected file >>>>>>>>>>>>>>> "
- + selectedPdbFileName);
- new AssociatePdbFileWithSeq().associatePdbWithSeq(
+ PDBEntry fileEntry = new AssociatePdbFileWithSeq()
+ .associatePdbWithSeq(
selectedPdbFileName, jalview.io.AppletFormatAdapter.FILE,
selectedSequence, true, Desktop.instance);
+
+ launchStructureViewer(ap.getStructureSelectionManager(),
+ new PDBEntry[]
+ { fileEntry }, ap, new SequenceI[]
+ { selectedSequence });
}
mainFrame.dispose();
}
+ private void launchStructureViewer(StructureSelectionManager ssm,
+ PDBEntry[] pdbEntriesToView, AlignmentPanel alignPanel,
+ SequenceI[] selectedSequences)
+ {
+ StructureViewer sViewer = new StructureViewer(ssm);
+ if (pdbEntriesToView.length > 1)
+ {
+ sViewer.viewStructures(alignPanel, pdbEntriesToView,
+ alignPanel.av.collateForPDB(pdbEntriesToView));
+ }
+ else
+ {
+ sViewer.viewStructures(pdbEntriesToView[0], selectedSequences, null,
+ alignPanel);
+ }
+ }
+
/**
* Populates the combo-box used in associating manually fetched structures to
* a unique sequence when more than one sequence selection is made.
pdbRequest.setSearchTerm(txt_search.getText() + ")");
pdbRequest.setAssociatedSequence(selectedSequence.getName());
pdbRestCleint = new PDBRestClient();
- PDBRestResponse resultList = pdbRestCleint.executeRequest(pdbRequest);
+ PDBRestResponse resultList;
+ try
+ {
+ resultList = pdbRestCleint.executeRequest(pdbRequest);
+ } catch (Exception e)
+ {
+ JOptionPane.showMessageDialog(this, e.getMessage(),
+ "PDB Web-service Error", JOptionPane.ERROR_MESSAGE);
+ return;
+ } finally
+ {
+ System.out.println(">>>>> executing finally block");
+ validateSelections();
+ }
if (resultList.getSearchSummary() != null
&& resultList.getSearchSummary().size() > 0)
{