/*
-
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
package jalview.gui;
+import jalview.bin.Jalview;
import jalview.datamodel.DBRefEntry;
+import jalview.datamodel.DBRefSource;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SequenceI;
import jalview.jbgui.GStructureChooser;
import jalview.util.MessageManager;
import jalview.ws.dbsources.PDBRestClient;
import jalview.ws.dbsources.PDBRestClient.PDBDocField;
+import jalview.ws.sifts.SiftsSettings;
import jalview.ws.uimodel.PDBRestRequest;
import jalview.ws.uimodel.PDBRestResponse;
import jalview.ws.uimodel.PDBRestResponse.PDBResponseSummary;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.List;
+import java.util.Objects;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
*
*/
@SuppressWarnings("serial")
-public class StructureChooser extends GStructureChooser
+public class StructureChooser extends GStructureChooser implements
+ IProgressIndicator
{
private boolean structuresDiscovered = false;
private boolean isValidPBDEntry;
-
public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq,
AlignmentPanel ap)
{
*/
public void init()
{
+ if (!Jalview.isHeadlessMode())
+ {
+ progressBar = new ProgressBar(this.statusPanel, this.statusBar);
+ }
+
Thread discoverPDBStructuresThread = new Thread(new Runnable()
{
@Override
PDBRestRequest pdbRequest = new PDBRestRequest();
pdbRequest.setAllowEmptySeq(false);
pdbRequest.setResponseSize(500);
- pdbRequest.setFieldToSearchBy("(text:");
+ pdbRequest.setFieldToSearchBy("(");
pdbRequest.setWantedFields(wantedFields);
pdbRequest.setSearchTerm(buildQuery(seq) + ")");
pdbRequest.setAssociatedSequence(seq);
discoveredStructuresSet));
structuresDiscovered = true;
noOfStructuresFound = discoveredStructuresSet.size();
- mainFrame.setTitle("Structure Chooser - " + noOfStructuresFound
- + " Found (" + totalTime + ")");
+ mainFrame.setTitle(MessageManager.formatMessage(
+ "label.structure_chooser_no_of_structures",
+ noOfStructuresFound, totalTime));
}
else
{
- mainFrame.setTitle("Structure Chooser - Manual association");
+ mainFrame.setTitle(MessageManager
+ .getString("label.structure_chooser_manual_association"));
if (errors.size() > 0)
{
StringBuilder errorMsg = new StringBuilder();
errorMsg.append(error).append("\n");
}
JOptionPane.showMessageDialog(this, errorMsg.toString(),
- "PDB Web-service Error", JOptionPane.ERROR_MESSAGE);
+ MessageManager.getString("label.pdb_web-service_error"),
+ JOptionPane.ERROR_MESSAGE);
}
}
}
if (seq.getDatasetSequence() != null
&& seq.getDatasetSequence().getAllPDBEntries() != null)
{
- for (PDBEntry pdbEntry : seq.getDatasetSequence().getAllPDBEntries())
+ for (PDBEntry pdbEntry : seq.getDatasetSequence()
+ .getAllPDBEntries())
{
if (pdbEntry.getFile() != null)
{
tbl_local_pdb.setModel(tableModelx);
}
-
/**
* Builds a query string for a given sequences using its DBRef entries
*
public static String buildQuery(SequenceI seq)
{
+ boolean isPDBRefsFound = false;
+ boolean isUniProtRefsFound = false;
+ StringBuilder queryBuilder = new StringBuilder();
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.getAllPDBEntries() != null)
{
{
if (isValidSeqName(entry.getId()))
{
- seqRefs.add(entry.getId());
+ queryBuilder.append(PDBRestClient.PDBDocField.PDB_ID.getCode())
+ .append(":")
+.append(entry.getId().toLowerCase())
+ .append(" OR ");
+ isPDBRefsFound = true;
+ // seqRefs.add(entry.getId());
}
}
}
- if (seq.getDBRef() != null && seq.getDBRef().length != 0)
+ if (seq.getDBRefs() != null && seq.getDBRefs().length != 0)
{
- int count = 0;
- for (DBRefEntry dbRef : seq.getDBRef())
+ for (DBRefEntry dbRef : seq.getDBRefs())
{
if (isValidSeqName(getDBRefId(dbRef)))
{
- seqRefs.add(getDBRefId(dbRef));
+ if (dbRef.getSource().equalsIgnoreCase(DBRefSource.UNIPROT))
+ {
+ queryBuilder
+ .append(PDBRestClient.PDBDocField.UNIPROT_ACCESSION
+ .getCode()).append(":")
+ .append(getDBRefId(dbRef))
+ .append(" OR ");
+ queryBuilder
+ .append(PDBRestClient.PDBDocField.UNIPROT_ID.getCode())
+ .append(":")
+ .append(getDBRefId(dbRef)).append(" OR ");
+ isUniProtRefsFound = true;
+ }
+ else if (dbRef.getSource().equalsIgnoreCase(DBRefSource.PDB))
+ {
+
+ queryBuilder.append(PDBRestClient.PDBDocField.PDB_ID.getCode())
+ .append(":").append(getDBRefId(dbRef).toLowerCase())
+ .append(" OR ");
+ isPDBRefsFound = true;
+ }
+ else
+ {
+ seqRefs.add(getDBRefId(dbRef));
+ }
}
- ++count;
- if (count > 10)
+ }
+ }
+
+ if (!isPDBRefsFound && !isUniProtRefsFound)
+ {
+ String seqName = seq.getName();
+ seqName = sanitizeSeqName(seqName);
+ String[] names = seqName.toLowerCase().split("\\|");
+ for (String name : names)
+ {
+ // System.out.println("Found name : " + name);
+ name.trim();
+ if (isValidSeqName(name))
{
- break;
+ seqRefs.add(name);
}
}
+
+ for (String seqRef : seqRefs)
+ {
+ queryBuilder.append("text:").append(seqRef).append(" OR ");
+ }
}
- StringBuilder queryBuilder = new StringBuilder();
- for (String seqRef : seqRefs)
+ int endIndex = queryBuilder.lastIndexOf(" OR ");
+ if (queryBuilder.toString().length() < 6)
{
- queryBuilder.append("text:").append(seqRef).append(" OR ");
+ return null;
}
- int endIndex = queryBuilder.lastIndexOf(" OR ");
- String query = queryBuilder.toString().substring(5, endIndex);
+ String query = queryBuilder.toString().substring(0, endIndex);
return query;
}
/**
+ * Remove the following special characters from input string +, -, &, |, !, (,
+ * ), {, }, [, ], ^, ", ~, *, ?, :, \
+ *
+ * @param seqName
+ * @return
+ */
+ private static String sanitizeSeqName(String seqName)
+ {
+ Objects.requireNonNull(seqName);
+ return seqName.replaceAll("\\[\\d*\\]", "")
+ .replaceAll("[^\\dA-Za-z ]", "").replaceAll("\\s+", "+");
+ }
+
+
+ /**
* Ensures sequence ref names are not less than 3 characters and does not
* contain a database name
*
.getStructureSummaryFields();
Collection<PDBResponseSummary> filteredResponse = new HashSet<PDBResponseSummary>();
HashSet<String> errors = new HashSet<String>();
+ // try
+ // {
+ // PDBDocField fiterField = PDBRestClient
+ // .getPDBDocFieldByCode(fieldToFilterBy);
+ // if (!wantedFields.contains(fiterField))
+ // {
+ // wantedFields.add(fiterField);
+ // }
+ // } catch (Exception e)
+ // {
+ // e.printStackTrace();
+ // }
+
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);
+ if (fieldToFilterBy.equalsIgnoreCase("uniprot_coverage"))
+ {
+ System.out.println(">>>>>> Filtering with uniprot coverate");
+ pdbRequest.setAllowEmptySeq(false);
+ pdbRequest.setResponseSize(1);
+ pdbRequest.setFieldToSearchBy("(");
+ pdbRequest.setSearchTerm(buildQuery(seq) + ")");
+ pdbRequest.setWantedFields(wantedFields);
+ pdbRequest.setAssociatedSequence(seq);
+ pdbRequest.setFacet(true);
+ pdbRequest.setFacetPivot(fieldToFilterBy + ",entry_entity");
+ pdbRequest.setFacetPivotMinCount(1);
+ }
+ else
+ {
+ pdbRequest.setAllowEmptySeq(false);
+ pdbRequest.setResponseSize(1);
+ pdbRequest.setFieldToSearchBy("(");
+ pdbRequest.setFieldToSortBy(fieldToFilterBy,
+ !chk_invertFilter.isSelected());
+ pdbRequest.setSearchTerm(buildQuery(seq) + ")");
+ pdbRequest.setWantedFields(wantedFields);
+ pdbRequest.setAssociatedSequence(seq);
+ }
pdbRestCleint = new PDBRestClient();
PDBRestResponse resultList;
try
// Update table selection model here
tbl_summary.addRowSelectionInterval(0, filterResponseCount - 1);
-
- mainFrame.setTitle("Structure Chooser - Filter time ("
- + totalTime + ")");
+ mainFrame.setTitle(MessageManager.formatMessage(
+ "label.structure_chooser_filter_time", totalTime));
}
else
{
- mainFrame.setTitle("Structure Chooser - Filter time ("
- + totalTime + ")");
+ mainFrame.setTitle(MessageManager.formatMessage(
+ "label.structure_chooser_filter_time", totalTime));
if (errors.size() > 0)
{
StringBuilder errorMsg = new StringBuilder();
{
errorMsg.append(error).append("\n");
}
- JOptionPane.showMessageDialog(null, errorMsg.toString(),
- "PDB Web-service Error", JOptionPane.ERROR_MESSAGE);
+ JOptionPane.showMessageDialog(
+ null,
+ errorMsg.toString(),
+ MessageManager.getString("label.pdb_web-service_error"),
+ JOptionPane.ERROR_MESSAGE);
}
}
/**
* Handles action event for btn_pdbFromFile
*/
+ @Override
public void pdbFromFile_actionPerformed()
{
jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
chooser.setFileView(new jalview.io.JalviewFileView());
chooser.setDialogTitle(MessageManager.formatMessage(
- "label.select_pdb_file_for", new String[]
- { selectedSequence.getDisplayId(false) }));
+ "label.select_pdb_file_for",
+ selectedSequence.getDisplayId(false)));
chooser.setToolTipText(MessageManager.formatMessage(
- "label.load_pdb_file_associate_with_sequence", new String[]
- { selectedSequence.getDisplayId(false) }));
+ "label.load_pdb_file_associate_with_sequence",
+ selectedSequence.getDisplayId(false)));
int value = chooser.showOpenDialog(null);
if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
* Populates the filter combo-box options dynamically depending on discovered
* structures
*/
+ @Override
protected void populateFilterComboBox()
{
if (isStructuresDiscovered())
{
cmb_filterOption.addItem(new FilterOption("Best Quality",
PDBDocField.OVERALL_QUALITY.getCode(), VIEWS_FILTER));
- cmb_filterOption.addItem(new FilterOption("Best UniProt Coverage",
+ cmb_filterOption.addItem(new FilterOption("Most UniProt Coverage",
PDBDocField.UNIPROT_COVERAGE.getCode(), VIEWS_FILTER));
- cmb_filterOption.addItem(new FilterOption("Highest Resolution",
+ cmb_filterOption.addItem(new FilterOption("Best Resolution",
PDBDocField.RESOLUTION.getCode(), VIEWS_FILTER));
- cmb_filterOption.addItem(new FilterOption("Highest Protein Chain",
+ cmb_filterOption.addItem(new FilterOption("Most Protein Chain",
PDBDocField.PROTEIN_CHAIN_COUNT.getCode(), VIEWS_FILTER));
- cmb_filterOption.addItem(new FilterOption("Highest Bound Molecules",
+ cmb_filterOption.addItem(new FilterOption("Most Bound Molecules",
PDBDocField.BOUND_MOLECULE_COUNT.getCode(), VIEWS_FILTER));
- cmb_filterOption.addItem(new FilterOption("Highest Polymer Residues",
+ cmb_filterOption.addItem(new FilterOption("Most Polymer Residues",
PDBDocField.POLYMER_RESIDUE_COUNT.getCode(), VIEWS_FILTER));
}
cmb_filterOption.addItem(new FilterOption("Enter PDB Id", "-",
/**
* Updates the displayed view based on the selected filter option
*/
+ @Override
protected void updateCurrentView()
{
FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID
|| selectedFilterOpt.getView() == VIEWS_FROM_FILE)
{
- mainFrame.setTitle(filterTitle);
+ mainFrame.setTitle(MessageManager
+ .getString("label.structure_chooser_manual_association"));
idInputAssSeqPanel.loadCmbAssSeq();
fileChooserAssSeqPanel.loadCmbAssSeq();
}
* Validates user selection and activates the view button if all parameters
* are correct
*/
+ @Override
public void validateSelections()
{
FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
lbl_pdbManualFetchStatus.setToolTipText("");
if (txt_search.getText().length() > 0)
{
- lbl_pdbManualFetchStatus.setToolTipText(JvSwingUtils.wrapTooltip(
- true, "No PDB entry found for \'" + txt_search.getText()
- + "\'"));
+ lbl_pdbManualFetchStatus
+ .setToolTipText(JvSwingUtils.wrapTooltip(true, MessageManager
+ .formatMessage("info.no_pdb_entry_found_for",
+ txt_search.getText())));
}
if (errorWarning.length() > 0)
@Override
public void ok_ActionPerformed()
{
+ final long progressSessionId = System.currentTimeMillis();
+ final StructureSelectionManager ssm = ap.getStructureSelectionManager();
+ ssm.setProgressIndicator(this);
+ ssm.setProgressSessionId(progressSessionId);
+ new Thread(new Runnable()
+ {
+ @Override
+ public void run()
+ {
FilterOption selectedFilterOpt = ((FilterOption) cmb_filterOption
.getSelectedItem());
String currentView = selectedFilterOpt.getView();
}
SequenceI[] selectedSeqs = selectedSeqsToView
.toArray(new SequenceI[selectedSeqsToView.size()]);
- launchStructureViewer(ap.getStructureSelectionManager(),
- pdbEntriesToView, ap, selectedSeqs);
+ launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
}
else if (currentView == VIEWS_LOCAL_PDB)
{
}
SequenceI[] selectedSeqs = selectedSeqsToView
.toArray(new SequenceI[selectedSeqsToView.size()]);
- launchStructureViewer(ap.getStructureSelectionManager(),
- pdbEntriesToView, ap, selectedSeqs);
+ launchStructureViewer(ssm, pdbEntriesToView, ap, selectedSeqs);
}
else if (currentView == VIEWS_ENTER_ID)
{
selectedSequence.getDatasetSequence().addPDBId(pdbEntry);
}
- PDBEntry[] pdbEntriesToView = new PDBEntry[]
- { pdbEntry };
- launchStructureViewer(ap.getStructureSelectionManager(),
- pdbEntriesToView, ap, new SequenceI[]
- { selectedSequence });
+ PDBEntry[] pdbEntriesToView = new PDBEntry[] { pdbEntry };
+ launchStructureViewer(ssm, pdbEntriesToView, ap,
+ new SequenceI[] { selectedSequence });
}
else if (currentView == VIEWS_FROM_FILE)
{
jalview.io.AppletFormatAdapter.FILE,
selectedSequence, true, Desktop.instance);
- launchStructureViewer(ap.getStructureSelectionManager(),
- new PDBEntry[]
- { fileEntry }, ap, new SequenceI[]
- { selectedSequence });
+ launchStructureViewer(ssm, new PDBEntry[] { fileEntry }, ap,
+ new SequenceI[] { selectedSequence });
}
mainFrame.dispose();
+ }
+ }).start();
}
- private void launchStructureViewer(final StructureSelectionManager ssm,
+ private void launchStructureViewer(StructureSelectionManager ssm,
final PDBEntry[] pdbEntriesToView,
- final AlignmentPanel alignPanel, final SequenceI[] sequences)
+ final AlignmentPanel alignPanel, SequenceI[] sequences)
{
+ ssm.setProgressBar("Launching PDB structure viewer..");
final StructureViewer sViewer = new StructureViewer(ssm);
- new Thread(new Runnable()
+
+ if (SiftsSettings.isMapWithSifts())
{
- public void run()
+ for (SequenceI seq : sequences)
{
+ if (seq.getSourceDBRef() == null)
+ {
+ ssm.setProgressBar(null);
+ ssm.setProgressBar("Fetching Database refs..");
+ new jalview.ws.DBRefFetcher(sequences, null, null, null, false)
+ .fetchDBRefs(true);
+ break;
+ }
+ }
+ }
if (pdbEntriesToView.length > 1)
{
ArrayList<SequenceI[]> seqsMap = new ArrayList<SequenceI[]>();
for (SequenceI seq : sequences)
{
- seqsMap.add(new SequenceI[]
- { seq });
+ seqsMap.add(new SequenceI[] { seq });
}
SequenceI[][] collatedSeqs = seqsMap.toArray(new SequenceI[0][0]);
+ ssm.setProgressBar(null);
+ ssm.setProgressBar("Fetching PDB Structures for selected entries..");
sViewer.viewStructures(pdbEntriesToView, collatedSeqs, alignPanel);
}
else
{
+ ssm.setProgressBar(null);
+ ssm.setProgressBar("Fetching PDB Structure for "
+ + pdbEntriesToView[0].getId());
sViewer.viewStructures(pdbEntriesToView[0], sequences, alignPanel);
}
- }
- }).start();
}
/**
* 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)
{
@Override
protected void txt_search_ActionPerformed()
{
- errorWarning.setLength(0);
- isValidPBDEntry = false;
- if (txt_search.getText().length() > 0)
+ new Thread()
{
- List<PDBDocField> wantedFields = new ArrayList<PDBDocField>();
- wantedFields.add(PDBDocField.PDB_ID);
- PDBRestRequest pdbRequest = new PDBRestRequest();
- pdbRequest.setAllowEmptySeq(false);
- pdbRequest.setResponseSize(1);
- pdbRequest.setFieldToSearchBy("(pdb_id:");
- pdbRequest.setWantedFields(wantedFields);
- pdbRequest.setSearchTerm(txt_search.getText() + ")");
- pdbRequest.setAssociatedSequence(selectedSequence);
- pdbRestCleint = new PDBRestClient();
- PDBRestResponse resultList;
- try
- {
- resultList = pdbRestCleint.executeRequest(pdbRequest);
- } catch (Exception e)
- {
- errorWarning.append(e.getMessage());
- return;
- } finally
+ @Override
+ public void run()
{
+ errorWarning.setLength(0);
+ isValidPBDEntry = false;
+ if (txt_search.getText().length() > 0)
+ {
+ List<PDBDocField> wantedFields = new ArrayList<PDBDocField>();
+ wantedFields.add(PDBDocField.PDB_ID);
+ PDBRestRequest pdbRequest = new PDBRestRequest();
+ pdbRequest.setAllowEmptySeq(false);
+ pdbRequest.setResponseSize(1);
+ pdbRequest.setFieldToSearchBy("(pdb_id:");
+ pdbRequest.setWantedFields(wantedFields);
+ pdbRequest
+ .setSearchTerm(txt_search.getText().toLowerCase() + ")");
+ pdbRequest.setAssociatedSequence(selectedSequence);
+ pdbRestCleint = new PDBRestClient();
+ PDBRestResponse resultList;
+ try
+ {
+ resultList = pdbRestCleint.executeRequest(pdbRequest);
+ } catch (Exception e)
+ {
+ errorWarning.append(e.getMessage());
+ return;
+ } finally
+ {
+ validateSelections();
+ }
+ if (resultList.getSearchSummary() != null
+ && resultList.getSearchSummary().size() > 0)
+ {
+ isValidPBDEntry = true;
+ }
+ }
validateSelections();
}
- if (resultList.getSearchSummary() != null
- && resultList.getSearchSummary().size() > 0)
- {
- isValidPBDEntry = true;
- }
- }
- validateSelections();
+ }.start();
}
@Override
public class PDBEntryTableModel extends AbstractTableModel
{
- String[] columns =
- { "Ref Sequence", "PDB Id", "Chain", "Type", "File" };
+ String[] columns = { "Ref Sequence", "PDB Id", "Chain", "Type", "File" };
private List<CachedPDB> pdbEntries;
}
}
+
+ private IProgressIndicator progressBar;
+
+ @Override
+ public void setProgressBar(String message, long id)
+ {
+ progressBar.setProgressBar(message, id);
+ }
+
+ @Override
+ public void registerHandler(long id, IProgressIndicatorHandler handler)
+ {
+ progressBar.registerHandler(id, handler);
+ }
+
+ @Override
+ public boolean operationInProgress()
+ {
+ return progressBar.operationInProgress();
+ }
}