<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/Plugin.jar"/>
+ <classpathentry kind="lib" path="lib/jersey-client-1.19.jar"/>
+ <classpathentry kind="lib" path="lib/jersey-core-1.19.jar"/>
+ <classpathentry kind="lib" path="lib/jersey-json-1.19.jar"/>
+ <classpathentry kind="lib" path="lib/jsr311-api-1.1.1.jar"/>
<classpathentry kind="output" path="classes"/>
</classpath>
label.display_name = Display Label
label.description = Description
label.include_description= Include Description
+action.back = Back
--- /dev/null
+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<PDBSummaryListModel>());
+ 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();
+ }
+
+}
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;
private static Thread initingThread = null;
+ int x = 0;
/**
* Blocking method that initialises and returns the shared instance of the
* SequenceFetcher client
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("");
}
+ 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;
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)
{
--- /dev/null
+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<PDBSearchOptionListModel> searchFeild = new JComboBox<PDBSearchOptionListModel>();
+
+ protected JButton ok = new JButton();
+
+ protected JButton back = new JButton();
+
+ protected JButton cancel = new JButton();
+
+ protected JTextField search = new JTextField(20);
+
+ protected JList<PDBSummaryListModel> jListSearchResult = new JList<PDBSummaryListModel>();
+
+ 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();
+
+}
--- /dev/null
+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<PDBSummaryListModel> 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<PDBSummaryListModel>();
+ JSONArray docs = (JSONArray) pdbResponse.get("docs");
+ for (Iterator<JSONObject> 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;
+ }
+
+}
--- /dev/null
+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<PDBSearchOptionListModel> searchOptions = new ArrayList<PDBSearchOptionListModel>();
+ 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());
+ }
+
+}
--- /dev/null
+package jalview.ws.uimodel;
+
+import javax.swing.DefaultListModel;
+
+public class PDBSearchResultPojo
+{
+ private int itemFound;
+
+ private String responseTime;
+
+ private DefaultListModel<PDBSummaryListModel> 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<PDBSummaryListModel> getSearchSummary()
+ {
+ return searchSummary;
+ }
+
+ public void setSearchSummary(
+ DefaultListModel<PDBSummaryListModel> searchSummary)
+ {
+ this.searchSummary = searchSummary;
+ }
+}
--- /dev/null
+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("<img src=\""
+ + getClass().getResource("/images/protein.png").toString()
+ + "\">");
+ }
+ if (moleculeType.equalsIgnoreCase("dna"))
+ {
+ summary.append("<img src=\""
+ + getClass().getResource("/images/dna.png").toString()
+ + "\">");
+ }
+ if (moleculeType.equalsIgnoreCase("rna"))
+ {
+ summary.append("<img src=\""
+ + getClass().getResource("/images/dna.png").toString()
+ + "\">");
+ }
+ if (moleculeType.equalsIgnoreCase("sugar"))
+ {
+ summary.append("<img src=\""
+ + getClass().getResource("/images/sugar.png").toString()
+ + "\">");
+ }
+ }
+ 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><div style=\"width:" + width
+ + "; word-wrap: break-word; border-bottom-style: dotted;\"> ");
+ html.append(summary);
+ html.append("</div></html>");
+ return html.toString();
+ }
+
+}