From: Charles Ofoegbu Date: Thu, 26 Feb 2015 18:20:38 +0000 (+0000) Subject: JAL-1667 PDBe Search Interface implementation X-Git-Tag: Jalview_2_9~71^2~13 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=e4da162f3c4eb461c40f7b97794cd77d3b1e2407;p=jalview.git JAL-1667 PDBe Search Interface implementation --- diff --git a/.classpath b/.classpath index c110217..832b6d6 100644 --- a/.classpath +++ b/.classpath @@ -56,5 +56,9 @@ + + + + diff --git a/lib/jersey-client-1.19.jar b/lib/jersey-client-1.19.jar new file mode 100644 index 0000000..c9e0f56 Binary files /dev/null and b/lib/jersey-client-1.19.jar differ diff --git a/lib/jersey-core-1.19.jar b/lib/jersey-core-1.19.jar new file mode 100644 index 0000000..92feb63 Binary files /dev/null and b/lib/jersey-core-1.19.jar differ diff --git a/lib/jersey-json-1.19.jar b/lib/jersey-json-1.19.jar new file mode 100644 index 0000000..b609411 Binary files /dev/null and b/lib/jersey-json-1.19.jar differ diff --git a/lib/jsr311-api-1.1.1.jar b/lib/jsr311-api-1.1.1.jar new file mode 100644 index 0000000..ec8bc81 Binary files /dev/null and b/lib/jsr311-api-1.1.1.jar differ diff --git a/resources/images/dna.png b/resources/images/dna.png new file mode 100644 index 0000000..f9854fe Binary files /dev/null and b/resources/images/dna.png differ diff --git a/resources/images/protein.png b/resources/images/protein.png new file mode 100644 index 0000000..3789793 Binary files /dev/null and b/resources/images/protein.png differ diff --git a/resources/images/sugar.png b/resources/images/sugar.png new file mode 100644 index 0000000..5d62ce5 Binary files /dev/null and b/resources/images/sugar.png differ diff --git a/resources/lang/Messages.properties b/resources/lang/Messages.properties index 7f62deb..7c2a41a 100644 --- a/resources/lang/Messages.properties +++ b/resources/lang/Messages.properties @@ -1192,3 +1192,4 @@ label.search_filter = Search Filter label.display_name = Display Label label.description = Description label.include_description= Include Description +action.back = Back diff --git a/src/jalview/gui/EBIFetchPanel.java b/src/jalview/gui/EBIFetchPanel.java new file mode 100644 index 0000000..8c2ef29 --- /dev/null +++ b/src/jalview/gui/EBIFetchPanel.java @@ -0,0 +1,69 @@ +package jalview.gui; + +import jalview.jbgui.GEBIFetchPanel; +import jalview.ws.dbsources.PDBRestClient; +import jalview.ws.uimodel.PDBSearchOptionListModel; +import jalview.ws.uimodel.PDBSearchResultPojo; +import jalview.ws.uimodel.PDBSummaryListModel; + +import javax.swing.DefaultListModel; +import javax.swing.SwingUtilities; + +@SuppressWarnings("serial") +public class EBIFetchPanel extends GEBIFetchPanel +{ + public static void main(String[] args) + { + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + new EBIFetchPanel(); + } + }); + } + + @Override + public void searchStringAction() + { + + jListSearchResult.setModel(new DefaultListModel()); + mainFrame.setTitle("PDB Sequence Fetcher"); + if (search.getText().trim().length() > 0) + { + long startTime = System.currentTimeMillis(); + + PDBSearchResultPojo resultList = new PDBRestClient().searchResult( + ((PDBSearchOptionListModel) searchFeild.getSelectedItem()).getCode(), + search.getText()); + if (resultList.getSearchSummary() != null) + { + jListSearchResult.setModel(resultList.getSearchSummary()); + } + long endTime = System.currentTimeMillis(); + mainFrame.setTitle("PDB Sequence Fetcher - " + + resultList.getItemFound() + " results (" + + (endTime - startTime) + " milli secs)"); + } + + } + + @Override + public void okActionPerformed() + { + System.out.println("ok! pressed!"); + } + + @Override + public void backActionPerformed() + { + System.out.println("back! pressed!"); + } + + @Override + public void cancelActionPerformed() + { + mainFrame.dispose(); + } + +} diff --git a/src/jalview/gui/SequenceFetcher.java b/src/jalview/gui/SequenceFetcher.java index 2928102..fb94c05 100755 --- a/src/jalview/gui/SequenceFetcher.java +++ b/src/jalview/gui/SequenceFetcher.java @@ -59,7 +59,42 @@ import com.stevesoft.pat.Regex; public class SequenceFetcher extends JPanel implements Runnable { - // ASequenceFetcher sfetch; + JLabel dbeg = new JLabel(); + + JDatabaseTree database; + + JButton databaseButt; + + JLabel jLabel1 = new JLabel(); + + JCheckBox replacePunctuation = new JCheckBox(); + + JButton ok = new JButton(); + + JButton clear = new JButton(); + + JButton example = new JButton(); + + JButton close = new JButton(); + + JPanel jPanel1 = new JPanel(); + + JTextArea textArea = new JTextArea(); + + JScrollPane jScrollPane1 = new JScrollPane(); + + JPanel jPanel2 = new JPanel(); + + JPanel jPanel3 = new JPanel(); + + JPanel jPanel4 = new JPanel(); + + BorderLayout borderLayout1 = new BorderLayout(); + + BorderLayout borderLayout2 = new BorderLayout(); + + BorderLayout borderLayout3 = new BorderLayout(); + JInternalFrame frame; IProgressIndicator guiWindow; @@ -80,6 +115,7 @@ public class SequenceFetcher extends JPanel implements Runnable private static Thread initingThread = null; + int x = 0; /** * Blocking method that initialises and returns the shared instance of the * SequenceFetcher client @@ -318,37 +354,22 @@ public class SequenceFetcher extends JPanel implements Runnable databaseButt.setFont(JvSwingUtils.getLabelFont()); database.addActionListener(new ActionListener() { - @Override public void actionPerformed(ActionEvent e) { - try - { - databaseButt.setText(database.getSelectedItem() - + (database.getSelectedSources().size() > 1 ? " (and " - + database.getSelectedSources().size() - + " others)" : "")); - String eq = database.getExampleQueries(); - dbeg.setText(MessageManager.formatMessage( - "label.example_query_param", new String[] - { eq })); - boolean enablePunct = !(eq != null && eq.indexOf(",") > -1); - for (DbSourceProxy dbs : database.getSelectedSources()) - { - if (dbs instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource) - { - enablePunct = false; - break; - } - } - replacePunctuation.setEnabled(enablePunct); + x++; + String currentSelection = database.getSelectedItem(); - } catch (Exception ex) + if (!currentSelection.equalsIgnoreCase("pdb")) + { + otherSourceAction(); + } + if (currentSelection.equalsIgnoreCase("pdb") && ((x % 2) == 0)) { - dbeg.setText(""); - replacePunctuation.setEnabled(true); + frame.dispose(); + new EBIFetchPanel(); } - jPanel2.repaint(); + } }); dbeg.setText(""); @@ -367,6 +388,41 @@ public class SequenceFetcher extends JPanel implements Runnable } + private void hideX() + { + this.setVisible(false); + } + private void otherSourceAction() + { + try + { + databaseButt.setText(database.getSelectedItem() + + (database.getSelectedSources().size() > 1 ? " (and " + + database.getSelectedSources().size() + " others)" + : "")); + String eq = database.getExampleQueries(); + dbeg.setText(MessageManager.formatMessage( + "label.example_query_param", new String[] + { eq })); + boolean enablePunct = !(eq != null && eq.indexOf(",") > -1); + for (DbSourceProxy dbs : database.getSelectedSources()) + { + if (dbs instanceof jalview.ws.dbsources.das.datamodel.DasSequenceSource) + { + enablePunct = false; + break; + } + } + replacePunctuation.setEnabled(enablePunct); + + } catch (Exception ex) + { + dbeg.setText(""); + replacePunctuation.setEnabled(true); + } + jPanel2.repaint(); + } + protected void example_actionPerformed() { DbSourceProxy db = null; @@ -385,41 +441,7 @@ public class SequenceFetcher extends JPanel implements Runnable jPanel3.repaint(); } - JLabel dbeg = new JLabel(); - - JDatabaseTree database; - - JButton databaseButt; - - JLabel jLabel1 = new JLabel(); - - JCheckBox replacePunctuation = new JCheckBox(); - - JButton ok = new JButton(); - - JButton clear = new JButton(); - - JButton example = new JButton(); - - JButton close = new JButton(); - - JPanel jPanel1 = new JPanel(); - - JTextArea textArea = new JTextArea(); - - JScrollPane jScrollPane1 = new JScrollPane(); - - JPanel jPanel2 = new JPanel(); - - JPanel jPanel3 = new JPanel(); - - JPanel jPanel4 = new JPanel(); - - BorderLayout borderLayout1 = new BorderLayout(); - BorderLayout borderLayout2 = new BorderLayout(); - - BorderLayout borderLayout3 = new BorderLayout(); public void close_actionPerformed(ActionEvent e) { diff --git a/src/jalview/jbgui/GEBIFetchPanel.java b/src/jalview/jbgui/GEBIFetchPanel.java new file mode 100644 index 0000000..74091af --- /dev/null +++ b/src/jalview/jbgui/GEBIFetchPanel.java @@ -0,0 +1,167 @@ +package jalview.jbgui; + +import jalview.gui.Desktop; +import jalview.util.MessageManager; +import jalview.ws.uimodel.PDBSearchOptionListModel; +import jalview.ws.uimodel.PDBSummaryListModel; + +import java.awt.BorderLayout; +import java.awt.Dimension; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JFrame; +import javax.swing.JInternalFrame; +import javax.swing.JList; +import javax.swing.JPanel; +import javax.swing.JScrollPane; +import javax.swing.JTextField; +import javax.swing.ListSelectionModel; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; + +@SuppressWarnings("serial") +public abstract class GEBIFetchPanel extends JPanel +{ + protected String frameTitle = "PDB Sequence Fetcher"; + + protected JInternalFrame mainFrame = new JInternalFrame(frameTitle); + + protected JComboBox searchFeild = new JComboBox(); + + protected JButton ok = new JButton(); + + protected JButton back = new JButton(); + + protected JButton cancel = new JButton(); + + protected JTextField search = new JTextField(20); + + protected JList jListSearchResult = new JList(); + + protected JScrollPane searchResultScroller = new JScrollPane( + jListSearchResult); + + private JPanel actionPanel = new JPanel(); + + private JPanel resultPanel = new JPanel(); + + private JPanel inputPanel = new JPanel(); + + private BorderLayout mainLayout = new BorderLayout(); + + + public GEBIFetchPanel() + { + try + { + jbInit(); + mainFrame.invalidate(); + mainFrame.pack(); + } catch (Exception e) + { + e.printStackTrace(); + } + } + + private void jbInit() throws Exception + { + back.setFont(new java.awt.Font("Verdana", 0, 12)); + back.setText(MessageManager.getString("action.back")); + back.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + backActionPerformed(); + } + }); + ok.setFont(new java.awt.Font("Verdana", 0, 12)); + ok.setText(MessageManager.getString("action.ok")); + ok.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + okActionPerformed(); + } + }); + cancel.setFont(new java.awt.Font("Verdana", 0, 12)); + cancel.setText(MessageManager.getString("action.cancel")); + cancel.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + cancelActionPerformed(); + } + }); + actionPanel.add(back); + actionPanel.add(ok); + actionPanel.add(cancel); + + jListSearchResult + .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); + jListSearchResult.setLayoutOrientation(JList.VERTICAL); + jListSearchResult.setVisibleRowCount(-1); + searchResultScroller.setPreferredSize(new Dimension(500, 300)); + searchResultScroller + .setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); + resultPanel.add(searchResultScroller); + + searchFeild.setFont(new java.awt.Font("Verdana", 0, 12)); + searchFeild.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + searchStringAction(); + } + }); + + PDBSearchOptionListModel.populateCombo(searchFeild); + + search.setFont(new java.awt.Font("Verdana", 0, 12)); + search.getDocument().addDocumentListener(new DocumentListener() + { + @Override + public void insertUpdate(DocumentEvent e) + { + searchStringAction(); + } + + @Override + public void removeUpdate(DocumentEvent e) + { + searchStringAction(); + } + + @Override + public void changedUpdate(DocumentEvent e) + { + searchStringAction(); + } + }); + + inputPanel.add(searchFeild); + inputPanel.add(search); + + + this.setLayout(mainLayout); + this.add(inputPanel, java.awt.BorderLayout.NORTH); + this.add(resultPanel, java.awt.BorderLayout.CENTER); + this.add(actionPanel, java.awt.BorderLayout.SOUTH); + mainFrame.setVisible(true); + mainFrame.setContentPane(this); + mainFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + Desktop.addInternalFrame(mainFrame, frameTitle, 800, 400); + } + + public abstract void searchStringAction(); + + public abstract void okActionPerformed(); + + public abstract void backActionPerformed(); + + public abstract void cancelActionPerformed(); + +} diff --git a/src/jalview/ws/dbsources/PDBRestClient.java b/src/jalview/ws/dbsources/PDBRestClient.java new file mode 100644 index 0000000..c26c88f --- /dev/null +++ b/src/jalview/ws/dbsources/PDBRestClient.java @@ -0,0 +1,97 @@ +package jalview.ws.dbsources; + +import jalview.ws.uimodel.PDBSearchResultPojo; +import jalview.ws.uimodel.PDBSummaryListModel; + +import java.util.Iterator; + +import javax.swing.DefaultListModel; +import javax.ws.rs.core.MediaType; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import com.sun.jersey.api.client.Client; +import com.sun.jersey.api.client.ClientResponse; +import com.sun.jersey.api.client.WebResource; +import com.sun.jersey.api.client.config.ClientConfig; +import com.sun.jersey.api.client.config.DefaultClientConfig; +import com.sun.jersey.api.json.JSONConfiguration; + +public class PDBRestClient +{ + private String pdbSearchEndpoint = "http://wwwdev.ebi.ac.uk/pdbe/search/pdb/select?"; + + + public static void main(String[] args) + { + new PDBRestClient().searchResult("pfam_name", "Lipoc*"); + } + + private String executeRestSearch(String qParam, + String searchTerm) + { + ClientConfig clientConfig = new DefaultClientConfig(); + clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, + Boolean.TRUE); + Client client = Client.create(clientConfig); + WebResource webResource = client.resource(pdbSearchEndpoint) + .queryParam("wt", "json") + .queryParam("q", qParam + ":" + searchTerm); + ClientResponse clientResponse = webResource.accept( + MediaType.APPLICATION_JSON).get(ClientResponse.class); + + String responseString = clientResponse.getEntity(String.class); + if (clientResponse.getStatus() != 200) + { + throw new RuntimeException("Failed : HTTP error code : " + + clientResponse.getStatus()); + } + return responseString; + } + + public PDBSearchResultPojo searchResult(String qParam, + String searchTerm) + { + String jsonResponseString = executeRestSearch(qParam, searchTerm); + PDBSearchResultPojo searchResult = new PDBSearchResultPojo(); + DefaultListModel result = null; + try + { + JSONParser jsonParser = new JSONParser(); + JSONObject jsonObj = (JSONObject) jsonParser + .parse(jsonResponseString); + + JSONObject pdbResponse = (JSONObject) jsonObj.get("response"); + String queryTime = ((JSONObject) jsonObj.get("responseHeader")).get( + "QTime").toString(); + int numFound = Integer + .valueOf(pdbResponse.get("numFound").toString()); + if (numFound > 0) + { + result = new DefaultListModel(); + JSONArray docs = (JSONArray) pdbResponse.get("docs"); + for (Iterator docIter = docs.iterator(); docIter + .hasNext();) + { + JSONObject doc = docIter.next(); + if (doc.get("molecule_sequence") != null) + { + result.addElement(new PDBSummaryListModel(doc)); + } + } + searchResult.setItemFound(numFound); + searchResult.setResponseTime(queryTime); + searchResult.setSearchSummary(result); + } + } catch (ParseException e) + { + e.printStackTrace(); + } + + return searchResult; + } + +} diff --git a/src/jalview/ws/uimodel/PDBSearchOptionListModel.java b/src/jalview/ws/uimodel/PDBSearchOptionListModel.java new file mode 100644 index 0000000..093f038 --- /dev/null +++ b/src/jalview/ws/uimodel/PDBSearchOptionListModel.java @@ -0,0 +1,133 @@ +package jalview.ws.uimodel; + +import java.util.ArrayList; +import java.util.List; + +import javax.swing.DefaultListModel; +import javax.swing.JComboBox; + +@SuppressWarnings( +{ "unchecked", "serial", "rawtypes" }) +public class PDBSearchOptionListModel extends DefaultListModel implements Comparable +{ + private String name; + + private String code; + + private boolean showInSummary; + + private boolean searchFilter; + + private FieldType type; + + public enum FieldType + { + INT, STRING, BOOLEAN; + }; + + public PDBSearchOptionListModel(String name, String code, FieldType type) + { + this.name = name; + this.code = code; + this.type = type; + } + + public String getName() + { + return name; + } + + public void setName(String name) + { + this.name = name; + } + + public String getCode() + { + return code; + } + + public void setCode(String code) + { + this.code = code; + } + + public boolean isShowInSummary() + { + return showInSummary; + } + + public void setShowInSummary(boolean showInSummary) + { + this.showInSummary = showInSummary; + } + + public boolean isSearchFilter() + { + return searchFilter; + } + + public void setSearchFilter(boolean searchFilter) + { + this.searchFilter = searchFilter; + } + + public FieldType getFieldType() + { + return type; + } + + public void setFieldType(FieldType type) + { + this.type = type; + } + + public String toString() + { + return name; + } + + public PDBSearchOptionListModel() + { + + } + + public static void populateCombo(JComboBox searchItems) + { + List searchOptions = new ArrayList(); + searchOptions.add(new PDBSearchOptionListModel("PDB ID", "pdb_id", + PDBSearchOptionListModel.FieldType.STRING)); + searchOptions.add(new PDBSearchOptionListModel("PFAM Name", "pfam_name", + PDBSearchOptionListModel.FieldType.STRING)); + searchOptions.add(new PDBSearchOptionListModel("ALL", "text", + PDBSearchOptionListModel.FieldType.STRING)); + searchOptions.add(new PDBSearchOptionListModel("Molecule Type", "molecule_type", + PDBSearchOptionListModel.FieldType.STRING)); + searchOptions.add(new PDBSearchOptionListModel("Title", "title", + PDBSearchOptionListModel.FieldType.STRING)); + searchOptions.add(new PDBSearchOptionListModel("Molecule Name", "molecule_name", + PDBSearchOptionListModel.FieldType.STRING)); + searchOptions.add(new PDBSearchOptionListModel("Tax ID", "tax_id", + PDBSearchOptionListModel.FieldType.STRING)); + searchOptions.add(new PDBSearchOptionListModel("UniProt Accession", + "uniprot_accession", PDBSearchOptionListModel.FieldType.STRING)); + searchOptions.add(new PDBSearchOptionListModel("Gene Name", "gene_name", + PDBSearchOptionListModel.FieldType.STRING)); + searchOptions.add(new PDBSearchOptionListModel("Genus", "genus", + PDBSearchOptionListModel.FieldType.STRING)); + + java.util.Collections.sort(searchOptions); + + for (PDBSearchOptionListModel pdbSO : searchOptions) + { + searchItems.addItem(pdbSO); + } + } + + @Override + public int compareTo(Object o) + { + return this.name.compareTo(((PDBSearchOptionListModel) o).getName()); + } + +} diff --git a/src/jalview/ws/uimodel/PDBSearchResultPojo.java b/src/jalview/ws/uimodel/PDBSearchResultPojo.java new file mode 100644 index 0000000..aef7820 --- /dev/null +++ b/src/jalview/ws/uimodel/PDBSearchResultPojo.java @@ -0,0 +1,43 @@ +package jalview.ws.uimodel; + +import javax.swing.DefaultListModel; + +public class PDBSearchResultPojo +{ + private int itemFound; + + private String responseTime; + + private DefaultListModel searchSummary; + + public int getItemFound() + { + return itemFound; + } + + public void setItemFound(int itemFound) + { + this.itemFound = itemFound; + } + + public String getResponseTime() + { + return responseTime; + } + + public void setResponseTime(String responseTime) + { + this.responseTime = responseTime; + } + + public DefaultListModel getSearchSummary() + { + return searchSummary; + } + + public void setSearchSummary( + DefaultListModel searchSummary) + { + this.searchSummary = searchSummary; + } +} diff --git a/src/jalview/ws/uimodel/PDBSummaryListModel.java b/src/jalview/ws/uimodel/PDBSummaryListModel.java new file mode 100644 index 0000000..ef93aed --- /dev/null +++ b/src/jalview/ws/uimodel/PDBSummaryListModel.java @@ -0,0 +1,108 @@ +package jalview.ws.uimodel; + +import javax.swing.DefaultListModel; + +import org.json.simple.JSONObject; + + +@SuppressWarnings( +{ "serial", "rawtypes" }) +public class PDBSummaryListModel extends DefaultListModel +{ + private String pdbId; + + private String summary; + + private int width = 480; + + public PDBSummaryListModel(String pdbId, String summary) + { + this.pdbId = pdbId; + this.summary = summary; + } + + public PDBSummaryListModel(JSONObject doc) + { + StringBuilder summary = new StringBuilder(); + if (doc.get("molecule_type") != null) + { + String moleculeType = doc.get("molecule_type").toString(); + if (moleculeType.equalsIgnoreCase("protein")) + { + summary.append(""); + } + if (moleculeType.equalsIgnoreCase("dna")) + { + summary.append(""); + } + if (moleculeType.equalsIgnoreCase("rna")) + { + summary.append(""); + } + if (moleculeType.equalsIgnoreCase("sugar")) + { + summary.append(""); + } + } + this.pdbId = doc.get("pdb_id").toString(); + summary.append("PDB ID: ").append(pdbId); + + + if (doc.get("molecule_name") != null) + { + summary.append(" | Molecule Name: ").append(doc.get("molecule_name")); + } + if (doc.get("gene_name") != null) + { + summary.append(" | Gene Name: ").append(doc.get("gene_name")); + } + if (doc.get("genus") != null) + { + summary.append(" | Genus: ").append(doc.get("genus")); + } + if (doc.get("title") != null) + { + summary.append(" | Title: ").append(doc.get("title")); + } + this.summary = summary.toString(); + } + + public String getPdbId() + { + return pdbId; + } + + public void setPdbId(String pdbId) + { + this.pdbId = pdbId; + } + + public String getSummary() + { + return summary; + } + + public void setSummary(String summary) + { + this.summary = summary; + } + + public String toString() + { + StringBuilder html = new StringBuilder(); + html.append("
"); + html.append(summary); + html.append("
"); + return html.toString(); + } + +}