* @param id
* DOCUMENT ME!
*/
- public void setPDBId(Vector ids);
+ public void setPDBId(Vector<PDBEntry> ids);
/**
- * DOCUMENT ME!
+ * Returns a list
*
* @return DOCUMENT ME!
*/
- public Vector getPDBId();
+ public Vector<PDBEntry> getPDBId();
/**
* add entry to the vector of PDBIds, if it isn't in the list already
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 java.util.Vector;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
+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);
+ " Found (" + totalTime + ")");
}
+ public void loadLocalCachedPDBEntries()
+ {
+ DefaultTableModel tableModel = new DefaultTableModel();
+ tableModel.addColumn("Sequence");
+ tableModel.addColumn("PDB Id");
+ 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[] pdbEntryRowData = new String[]
+ { seq.getDisplayId(false), pdbEntry.getId(), pdbEntry.getType(),
+ pdbEntry.getFile() };
+ tableModel.addRow(pdbEntryRowData);
+ cachedEntryMap.put(seq.getDisplayId(false) + pdbEntry.getId(),
+ pdbEntry);
+ }
+ }
+ }
+ tbl_local_pdb.setModel(tableModel);
+ }
+
/**
* Update the DBRef entry for a given sequence with values retrieved from
* PDBResponseSummary
* the sequences to build a query for
* @return the built query string
*/
- @SuppressWarnings("unchecked")
+
public static String buildQuery(SequenceI seq)
{
String query = seq.getName();
if (seq.getPDBId() != null)
{
- for (PDBEntry entry : (Vector<PDBEntry>) seq.getPDBId())
+ for (PDBEntry entry : seq.getPDBId())
{
queryBuilder.append("text:").append(entry.getId()).append(" OR ");
}
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)
{
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();
pdbEntry.setType("PDB");
pdbEntriesToView[count++] = pdbEntry;
}
- new StructureViewer(ap.getStructureSelectionManager())
- .viewStructures(ap, pdbEntriesToView,
- ap.av.collateForPDB(pdbEntriesToView));
+
+ 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)
+ {
+ 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)
{
- selectedSequence = ((AssociateSeqOptions) idInputAssSeqPanel
+ SequenceI userSelectedSeq = ((AssociateSeqOptions) idInputAssSeqPanel
.getCmb_assSeq().getSelectedItem()).getSequence();
+ if (userSelectedSeq != null)
+ {
+ selectedSequence = userSelectedSeq;
+ }
PDBEntry pdbEntry = new PDBEntry();
pdbEntry.setId(txt_search.getText());
pdbEntry.setType("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 = ((AssociateSeqOptions) fileChooserAssSeqPanel
+ SequenceI userSelectedSeq = ((AssociateSeqOptions) fileChooserAssSeqPanel
.getCmb_assSeq().getSelectedItem()).getSequence();
- new AssociatePdbFileWithSeq().associatePdbWithSeq(
+ if (userSelectedSeq != null)
+ {
+ selectedSequence = userSelectedSeq;
+ }
+ 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.
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
import javax.swing.ImageIcon;
import javax.swing.JButton;
private JPanel pnl_actions = new JPanel();
- private JPanel pnl_filter = new JPanel();
+ private JPanel pnl_main = new JPanel();
private JPanel pnl_idInput = new JPanel(new FlowLayout());
private JPanel pnl_fileChooserBL = new JPanel(new BorderLayout());
+ private JPanel pnl_locPDB = new JPanel(new BorderLayout());
+
protected JPanel pnl_switchableViews = new JPanel(new CardLayout());
protected CardLayout layout_switchableViews = (CardLayout) (pnl_switchableViews
protected static final String VIEWS_ENTER_ID = "VIEWS_ENTER_ID";
+ protected static final String VIEWS_LOCAL_PDB = "VIEWS_LOCAL_PDB";
+
protected JTable tbl_summary = new JTable();
protected JScrollPane scrl_foundStructures = new JScrollPane(
tbl_summary);
- private JTabbedPane tabbedPane = new JTabbedPane();
+ protected JTable tbl_local_pdb = new JTable();
+
+ protected JScrollPane scrl_localPDB = new JScrollPane(tbl_local_pdb);
+
+ private JTabbedPane pnl_filter = new JTabbedPane();
private PDBDocFieldPreferences pdbDocFieldPrefs = new PDBDocFieldPreferences(
PreferenceSource.STRUCTURE_CHOOSER);
private void jbInit() throws Exception
{
tbl_summary.setAutoCreateRowSorter(true);
+ tbl_local_pdb.setAutoCreateRowSorter(true);
+ tbl_local_pdb.addMouseListener(new MouseAdapter()
+ {
+ public void mouseClicked(MouseEvent e)
+ {
+ updateCurrentView();
+ }
+ });
+
btn_view.setFont(new java.awt.Font("Verdana", 0, 12));
btn_view.setText(MessageManager.getString("action.view"));
btn_view.addActionListener(new java.awt.event.ActionListener()
scrl_foundStructures
.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+ scrl_localPDB.setPreferredSize(new Dimension(500, 300));
+ scrl_localPDB
+ .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
+
cmb_filterOption.setFont(new java.awt.Font("Verdana", 0, 12));
chk_invertFilter.setFont(new java.awt.Font("Verdana", 0, 12));
chk_rememberSettings.setFont(new java.awt.Font("Verdana", 0, 12));
pnl_actions.add(btn_cancel);
// pnl_filter.add(lbl_result);
- pnl_filter.add(cmb_filterOption);
- pnl_filter.add(lbl_loading);
- pnl_filter.add(chk_invertFilter);
+ pnl_main.add(cmb_filterOption);
+ pnl_main.add(lbl_loading);
+ pnl_main.add(chk_invertFilter);
lbl_loading.setVisible(false);
- pnl_idInput.add(txt_search);
- pnl_idInput.add(lbl_pdbManualFetchStatus);
pnl_fileChooser.add(btn_pdbFromFile);
pnl_fileChooser.add(lbl_fromFileStatus);
-
pnl_fileChooserBL.add(fileChooserAssSeqPanel, BorderLayout.NORTH);
pnl_fileChooserBL.add(pnl_fileChooser, BorderLayout.CENTER);
+ pnl_idInput.add(txt_search);
+ pnl_idInput.add(lbl_pdbManualFetchStatus);
pnl_idInputBL.add(idInputAssSeqPanel, BorderLayout.NORTH);
pnl_idInputBL.add(pnl_idInput, BorderLayout.CENTER);
}
}
};
- tabbedPane.addChangeListener(changeListener);
- tabbedPane.setPreferredSize(new Dimension(500, 300));
- tabbedPane.add(foundStructureSummary, scrl_foundStructures);
- tabbedPane.add(
+ pnl_filter.addChangeListener(changeListener);
+ pnl_filter.setPreferredSize(new Dimension(500, 300));
+ pnl_filter.add(foundStructureSummary, scrl_foundStructures);
+ pnl_filter.add(
MessageManager.getString("label.configure_displayed_columns"),
pdbDocFieldPrefs);
+ pnl_locPDB.add(scrl_localPDB);
pnl_switchableViews.add(pnl_fileChooserBL, VIEWS_FROM_FILE);
pnl_switchableViews.add(pnl_idInputBL, VIEWS_ENTER_ID);
- pnl_switchableViews.add(tabbedPane, VIEWS_FILTER);
+ pnl_switchableViews.add(pnl_filter, VIEWS_FILTER);
+ pnl_switchableViews.add(pnl_locPDB, VIEWS_LOCAL_PDB);
this.setLayout(mainLayout);
- this.add(pnl_filter, java.awt.BorderLayout.NORTH);
+ this.add(pnl_main, java.awt.BorderLayout.NORTH);
this.add(pnl_switchableViews, java.awt.BorderLayout.CENTER);
this.add(pnl_actions, java.awt.BorderLayout.SOUTH);
import java.util.Collection;
import java.util.HashMap;
-import java.util.HashSet;
+import java.util.LinkedHashSet;
import javax.swing.JScrollPane;
import javax.swing.JTable;
private HashMap<String, PDBDocField> map = new HashMap<String, PDBDocField>();
- private static Collection<PDBDocField> searchSummaryFields = new HashSet<PDBDocField>();
+ private static Collection<PDBDocField> searchSummaryFields = new LinkedHashSet<PDBDocField>();
- private static Collection<PDBDocField> structureSummaryFields = new HashSet<PDBDocField>();
+ private static Collection<PDBDocField> structureSummaryFields = new LinkedHashSet<PDBDocField>();
public enum PreferenceSource
{
{
// Note that the data/cell address is constant,
// no matter where the cell appears onscreen.
- return col == 1 || col == 2;
+ // !isPDBID(row, col) ensures the PDB_Id cell is never editable as it
+ // serves as a unique id for each row.
+ return (col == 1 || col == 2) && !isPDBID(row, col);
}
+ /**
+ * Determines whether the data in a given cell is a PDB ID.
+ *
+ * @param row
+ * @param col
+ * @return
+ */
+
+ public boolean isPDBID(int row, int col)
+ {
+ boolean matched = false;
+ String name = getValueAt(row, 0).toString();
+ PDBDocField pdbField = map.get(name);
+ if (pdbField == PDBDocField.PDB_ID)
+ {
+ matched = true;
+ }
+ return matched;
+ }
+
/*
* Don't need to implement this method unless your table's data can change.
*/
*/
public class PDBRestClient
{
- private static String PDB_SEARCH_ENDPOINT = "http://wwwdev.ebi.ac.uk/pdbe/search/pdb/select?";
+ private static String PDB_SEARCH_ENDPOINT = "http://www.ebi.ac.uk/pdbe/search/pdb/select?";
private static int DEFAULT_RESPONSE_SIZE = 200;
*/
public static String parseJsonExceptionString(String jsonErrorResponse)
{
- String errorMessage = "RunTime error";
+ StringBuilder errorMessage = new StringBuilder(
+ "\n============= PDB Rest Client RunTime error =============\n");
+
try
{
JSONParser jsonParser = new JSONParser();
JSONObject jsonObj = (JSONObject) jsonParser.parse(jsonErrorResponse);
JSONObject errorResponse = (JSONObject) jsonObj.get("error");
- errorMessage = errorResponse.get("msg").toString();
JSONObject responseHeader = (JSONObject) jsonObj
.get("responseHeader");
- errorMessage += responseHeader.get("params").toString();
+ JSONObject paramsObj = (JSONObject) responseHeader.get("params");
+ String status = responseHeader.get("status").toString();
+ String message = errorResponse.get("msg").toString();
+ String query = paramsObj.get("q").toString();
+ String fl = paramsObj.get("fl").toString();
+
+ errorMessage.append("Status: ").append(status).append("\n");
+ errorMessage.append("Message: ").append(message).append("\n");
+ errorMessage.append("query: ").append(query).append("\n");
+ errorMessage.append("fl: ").append(fl).append("\n");
+
} catch (ParseException e)
{
e.printStackTrace();
}
- return errorMessage;
+ return errorMessage.toString();
}
/**
import jalview.datamodel.Sequence;
import java.io.IOException;
+import java.util.Iterator;
+import org.json.simple.JSONArray;
+import org.json.simple.JSONObject;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
+import org.junit.Assert;
import org.junit.Test;
import com.json.JSONException;
Alignment al = new Alignment(seqs);
try
{
- String generatedJson = bioJsHtmlOuput
+
+ JSONParser jsonParser = new JSONParser();
+ String actualJsonString = bioJsHtmlOuput
.getJalviewAlignmentAsJsonString(al);
- org.junit.Assert
- .assertEquals(
- generatedJson.toLowerCase(),
- "{\"globalColorScheme\":\"zappo\",\"seqs\":[{\"id\":\"1\",\"start\":1,\"name\":\"name/1-26\",\"features\":[],\"seq\":\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\",\"end\":26}]}"
- .toLowerCase());
- System.out.println("Output : " + generatedJson);
+
+ JSONObject actualJsonObj = (JSONObject) jsonParser.parse(actualJsonString);
+
+ // System.out.println("Output : " + actualJsonString);
+ Assert.assertTrue(actualJsonObj.get("globalColorScheme") != null);
+ Assert.assertTrue((actualJsonObj.get("globalColorScheme").toString()).equals("zappo"));
+
+ Assert.assertTrue(actualJsonObj.get("webStartUrl") != null);
+ Assert.assertTrue((actualJsonObj.get("webStartUrl").toString())
+ .equals("http://www.jalview.org/services/launchApp"));
+
+ JSONArray actualSeqJsonObj = (JSONArray) actualJsonObj.get("seqs");
+ Assert.assertTrue(actualSeqJsonObj != null);
+ Assert.assertTrue(actualSeqJsonObj.size() == 1);
+
+ @SuppressWarnings("unchecked")
+ Iterator<JSONObject> jsonIter = actualSeqJsonObj.iterator();
+ JSONObject jsonSeq = jsonIter.next();
+ Assert.assertTrue(jsonSeq != null);
+
+ Assert.assertTrue("'name' cannot be null!",
+ jsonSeq.get("name") != null);
+ Assert.assertTrue("Expected name mismatched!",
+ (jsonSeq.get("name").toString())
+ .equals("name/1-26"));
+
+ Assert.assertTrue("'seq' cannot be null!", jsonSeq.get("seq") != null);
+ Assert.assertTrue("Expected sequence mismatched!", (jsonSeq
+ .get("seq").toString())
+ .equals("ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
+
+ Assert.assertTrue("'id' cannot be null!", jsonSeq.get("id") != null);
+ Assert.assertTrue("Expected id mismatched!",
+ (jsonSeq.get("id").toString()).equals("1"));
+
+ Assert.assertTrue("'start' cannot be null!",
+ jsonSeq.get("start") != null);
+ Assert.assertTrue("Expected start mismatched!",
+ (jsonSeq.get("start").toString()).equals("1"));
+
+ Assert.assertTrue("'end' cannot be null!", jsonSeq.get("end") != null);
+ Assert.assertTrue("Expected end mismatched!",
+ (jsonSeq.get("end").toString()).equals("26"));
+
+ Assert.assertTrue("'features' cannot be null!",
+ jsonSeq.get("features") != null);
+ Assert.assertTrue("Expected features mismatched!",
+ jsonSeq.get("features").toString().equals("[]"));
+
} catch (IOException e)
{
e.printStackTrace();
} catch (JSONException e)
{
e.printStackTrace();
+ } catch (ParseException e)
+ {
+ e.printStackTrace();
}
}
-
+
}
wantedFields.add(PDBDocField.GENUS);
wantedFields.add(PDBDocField.GENE_NAME);
wantedFields.add(PDBDocField.TITLE);
- assertEquals("molecule_type,pdb_id,genus,gene_name,title",
- PDBRestClient
- .getPDBDocFieldsAsCommaDelimitedString(wantedFields));
+
+ String expectedResult = "molecule_type,pdb_id,genus,gene_name,title";
+ String actualResult = PDBRestClient
+ .getPDBDocFieldsAsCommaDelimitedString(wantedFields);
+
+ assertEquals("", expectedResult, actualResult);
}
@Test
String parsedErrorResponse = PDBRestClient
.parseJsonExceptionString(jsonErrorResponse);
- String expectedErrorMsg = "org.apache.solr.search.SyntaxError: Cannot parse 'text:abc OR text:go:abc AND molecule_sequence:['' TO *]': Encountered \" \":\" \": \"\" at line 1, column 19.{\"q\":\"text:abc OR text:go:abc AND molecule_sequence:['' TO *]\",\"fl\":\"pdb_id\",\"sort\":\"\",\"rows\":\"100\",\"wt\":\"json\"}";
+ System.out.println(parsedErrorResponse);
+
+ String expectedErrorMsg = "\n============= PDB Rest Client RunTime error =============\n"
+ + "Status: 400\n"
+ + "Message: org.apache.solr.search.SyntaxError: Cannot parse 'text:abc OR text:go:abc AND molecule_sequence:['' TO *]': Encountered \" \":\" \": \"\" at line 1, column 19.\n"
+ + "query: text:abc OR text:go:abc AND molecule_sequence:['' TO *]\n"
+ + "fl: pdb_id\n";
assertEquals(expectedErrorMsg, parsedErrorResponse);
}