From: tcofoegbu Date: Tue, 21 Apr 2015 16:26:17 +0000 (+0100) Subject: Resolved diffs from 2.8.3 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=466c5639624028f92e214121672dc409ad10514b;p=jalview.git Resolved diffs from 2.8.3 --- diff --git a/src/jalview/datamodel/SequenceI.java b/src/jalview/datamodel/SequenceI.java index a9a7589..04f3588 100755 --- a/src/jalview/datamodel/SequenceI.java +++ b/src/jalview/datamodel/SequenceI.java @@ -265,14 +265,14 @@ public interface SequenceI * @param id * DOCUMENT ME! */ - public void setPDBId(Vector ids); + public void setPDBId(Vector ids); /** - * DOCUMENT ME! + * Returns a list * * @return DOCUMENT ME! */ - public Vector getPDBId(); + public Vector getPDBId(); /** * add entry to the vector of PDBIds, if it isn't in the list already diff --git a/src/jalview/gui/StructureChooser.java b/src/jalview/gui/StructureChooser.java index 3a54cc1..5c86ce2 100644 --- a/src/jalview/gui/StructureChooser.java +++ b/src/jalview/gui/StructureChooser.java @@ -27,6 +27,7 @@ import jalview.datamodel.PDBEntry; 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; @@ -38,13 +39,15 @@ import java.awt.event.ItemEvent; 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 @@ -73,6 +76,8 @@ public class StructureChooser extends GStructureChooser private boolean isValidPBDEntry; + private static Hashtable cachedEntryMap; + public StructureChooser(SequenceI[] selectedSeqs, SequenceI selectedSeq, AlignmentPanel ap) { @@ -96,6 +101,7 @@ public class StructureChooser extends GStructureChooser long startTime = System.currentTimeMillis(); String msg = MessageManager.getString("status.fetching_db_refs"); updateProgressIndicator(msg, startTime); + loadLocalCachedPDBEntries(); fetchStructuresMetaData(); populateFilterComboBox(); updateProgressIndicator(null, startTime); @@ -168,6 +174,33 @@ public class StructureChooser extends GStructureChooser + " 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(); + 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 @@ -196,7 +229,7 @@ public class StructureChooser extends GStructureChooser * the sequences to build a query for * @return the built query string */ - @SuppressWarnings("unchecked") + public static String buildQuery(SequenceI seq) { String query = seq.getName(); @@ -205,7 +238,7 @@ public class StructureChooser extends GStructureChooser if (seq.getPDBId() != null) { - for (PDBEntry entry : (Vector) seq.getPDBId()) + for (PDBEntry entry : seq.getPDBId()) { queryBuilder.append("text:").append(entry.getId()).append(" OR "); } @@ -353,6 +386,8 @@ public class StructureChooser extends GStructureChooser VIEWS_ENTER_ID)); cmb_filterOption.addItem(new FilterOption("From File", "-", VIEWS_FROM_FILE)); + cmb_filterOption.addItem(new FilterOption("Cached PDB Entries", "-", + VIEWS_LOCAL_PDB)); } /** @@ -373,7 +408,8 @@ public class StructureChooser extends GStructureChooser chk_invertFilter.setVisible(true); filterResultSet(selectedFilterOpt.getValue()); } - else + else if (selectedFilterOpt.getView() == VIEWS_ENTER_ID + || selectedFilterOpt.getView() == VIEWS_FROM_FILE) { idInputAssSeqPanel.loadCmbAssSeq(); fileChooserAssSeqPanel.loadCmbAssSeq(); @@ -398,6 +434,13 @@ public class StructureChooser extends GStructureChooser 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(); @@ -513,35 +556,78 @@ public class StructureChooser extends GStructureChooser 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. diff --git a/src/jalview/jbgui/GStructureChooser.java b/src/jalview/jbgui/GStructureChooser.java index b79a7f7..fc035b6 100644 --- a/src/jalview/jbgui/GStructureChooser.java +++ b/src/jalview/jbgui/GStructureChooser.java @@ -34,6 +34,8 @@ import java.awt.FlowLayout; 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; @@ -83,7 +85,7 @@ public abstract class GStructureChooser extends JPanel implements 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()); @@ -93,6 +95,8 @@ public abstract class GStructureChooser extends JPanel implements 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 @@ -132,12 +136,18 @@ public abstract class GStructureChooser extends JPanel implements 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); @@ -164,6 +174,15 @@ public abstract class GStructureChooser extends JPanel implements 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() @@ -198,6 +217,10 @@ public abstract class GStructureChooser extends JPanel implements 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)); @@ -236,20 +259,19 @@ public abstract class GStructureChooser extends JPanel implements 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); @@ -270,20 +292,22 @@ public abstract class GStructureChooser extends JPanel implements } } }; - 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); diff --git a/src/jalview/jbgui/PDBDocFieldPreferences.java b/src/jalview/jbgui/PDBDocFieldPreferences.java index 2021d0b..96e27e6 100644 --- a/src/jalview/jbgui/PDBDocFieldPreferences.java +++ b/src/jalview/jbgui/PDBDocFieldPreferences.java @@ -4,7 +4,7 @@ import jalview.ws.dbsources.PDBRestClient.PDBDocField; import java.util.Collection; import java.util.HashMap; -import java.util.HashSet; +import java.util.LinkedHashSet; import javax.swing.JScrollPane; import javax.swing.JTable; @@ -20,9 +20,9 @@ public class PDBDocFieldPreferences extends JScrollPane private HashMap map = new HashMap(); - private static Collection searchSummaryFields = new HashSet(); + private static Collection searchSummaryFields = new LinkedHashSet(); - private static Collection structureSummaryFields = new HashSet(); + private static Collection structureSummaryFields = new LinkedHashSet(); public enum PreferenceSource { @@ -171,10 +171,32 @@ public class PDBDocFieldPreferences extends JScrollPane { // 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. */ diff --git a/src/jalview/ws/dbsources/PDBRestClient.java b/src/jalview/ws/dbsources/PDBRestClient.java index 1ab6125..c5642a9 100644 --- a/src/jalview/ws/dbsources/PDBRestClient.java +++ b/src/jalview/ws/dbsources/PDBRestClient.java @@ -31,7 +31,7 @@ import com.sun.jersey.api.json.JSONConfiguration; */ 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; @@ -107,22 +107,33 @@ public class PDBRestClient */ 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(); } /** diff --git a/test/jalview/io/BioJsHTMLOutputTest.java b/test/jalview/io/BioJsHTMLOutputTest.java index 4b817ab..514cce0 100644 --- a/test/jalview/io/BioJsHTMLOutputTest.java +++ b/test/jalview/io/BioJsHTMLOutputTest.java @@ -4,7 +4,13 @@ import jalview.datamodel.Alignment; 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; @@ -30,21 +36,69 @@ public class BioJsHTMLOutputTest 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 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(); } } - + } diff --git a/test/jalview/ws/dbsources/PDBRestClientTest.java b/test/jalview/ws/dbsources/PDBRestClientTest.java index ba07562..d86edd2 100644 --- a/test/jalview/ws/dbsources/PDBRestClientTest.java +++ b/test/jalview/ws/dbsources/PDBRestClientTest.java @@ -61,9 +61,12 @@ public class PDBRestClientTest 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 @@ -94,7 +97,13 @@ public class PDBRestClientTest 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); }