Hacking PubChem in Java: Learning to Speak PUG
Submit complex queries to the Power User Gateway using Java.
how ?
- creating a request
- receiving an PCT-Waiting_reqid
- check the
responseDocumentfor the requiered downloadURL refresh()the request until the response contains a downloadURLstore(URL, File)the result in a local file.
Code
The simple way to use the this class:int[] pctIDs = new int[]{1,2,3,4}; PowerUserGatewayRequest request = new PowerUserGatewayRequest(pctIDs);
request.submitInitalRequest();
while(!request.getStatus().isFinished()){
System.out.println("waiting for " + request.getRequestID()); request.refresh();
}
// download it to your directoryPowerUserGatewayRequest.store(request.getResponseURL(), targetFile);
Update: Java 1.4 & Java5
added support for java 1.4 and java 5:xpath(String, Document) method is now redirecting to xpathJDK1_4(String, Document) or xpathJDK5(String, Document).Seperation was needed to support java5 without additional libraries.
In case you are running it on java1.4 you need to import
org.apache.xpath.XPathAPI and modify the mehtod xpath(String, Document): public static Node xpath(String pathString, final Document doc) throws Exception {
depending on your JDK use one of the methods.
//Node node = xpathJDK1_4(pathString, doc);
Node node = xpathJDK5(pathString, doc);
return node;
}
- See Also:
- http://pubchem.ncbi.nlm.nih.gov/
- http://depth-first.com/articles/2007/06/04/hacking-pubchem-power-user-gateway
- http://depth-first.com/articles/2007/06/11/hacking-pubchem-learning-to-speak-pug
- Author:
- Martin Scholz
- @version
- $Revision: 1.18 $
This work is licensed under a Creative Commons Attribution 3.0 United States License.
Created by
zwluxx
Last modified 2007-08-02 02:47 PM
Last modified 2007-08-02 02:47 PM