Last active
August 29, 2015 13:57
-
-
Save lindenb/9408883 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.PHONY:all | |
PROXY1= ## -httpproxy:host:port | |
PROXY2= ## -Dhttp.proxyHost=host -Dhttp.proxyPort=port | |
all: Test.class | |
java ${PROXY2} -cp tmp:. Test | |
Test.class : Test.java tmp/uk/ac/ebi/webservices/whatizit/ws/ObjectFactory.java tmp/gov/nih/nlm/ncbi/eutils/entrez/eutils/esearch/ObjectFactory.java | |
javac -sourcepath tmp:. $< | |
tmp/uk/ac/ebi/webservices/whatizit/ws/ObjectFactory.java: | |
mkdir -p tmp | |
wsimport -d tmp -keep ${PROXY1} "http://www.ebi.ac.uk/webservices/whatizit/ws?wsdl" | |
tmp/gov/nih/nlm/ncbi/eutils/entrez/eutils/esearch/ObjectFactory.java: | |
mkdir -p tmp | |
curl -o tmp/esearch.xsd "https://raw.github.com/lindenb/xsd-sandbox/master/schemas/bio/ncbi/esearch.xsd" | |
xjc -d tmp -p gov.nih.nlm.ncbi.eutils.entrez.eutils.esearch tmp/esearch.xsd | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.InputStream; | |
import java.net.URL; | |
import java.net.URLEncoder; | |
import java.util.HashSet; | |
import java.util.Set; | |
import java.util.logging.Logger; | |
import javax.xml.parsers.DocumentBuilder; | |
import javax.xml.parsers.DocumentBuilderFactory; | |
import javax.xml.transform.stream.StreamSource; | |
import javax.xml.xpath.XPath; | |
import javax.xml.xpath.XPathConstants; | |
import javax.xml.xpath.XPathExpression; | |
import javax.xml.xpath.XPathFactory; | |
import org.w3c.dom.Document; | |
import org.w3c.dom.Node; | |
/* generated with wsimport */ | |
import uk.ac.ebi.webservices.whatizit.ws.*; | |
import gov.nih.nlm.ncbi.eutils.entrez.eutils.esearch.*; | |
public class Test | |
{ | |
private static Logger LOG=Logger.getLogger("testwhatizit"); | |
private gov.nih.nlm.ncbi.eutils.entrez.eutils.esearch.ObjectFactory _foo_javac=null; | |
public void run(String[] args) throws Exception | |
{ | |
final String errorPrefix="################################################################## "; | |
XPath xpath=XPathFactory.newInstance().newXPath(); | |
XPathExpression abstractExpr=xpath.compile( | |
"/PubmedArticleSet/PubmedArticle/MedlineCitation/Article/Abstract" | |
); | |
Whatizit_Service service=new Whatizit_Service(); | |
LOG.info("getting pipelines"); | |
Whatizit whatizit=service.getPipeline(); | |
LOG.info("getting enabled pipelines"); | |
Set<String> pipelines=new HashSet<String>(); | |
for(SelectItem status:whatizit.getPipelinesStatus()) | |
{ | |
if(status.isDisabled()) continue; | |
System.out.println("adding pipeline "+status.getLabel()+" "+status.getDescription()); | |
pipelines.add(status.getLabel()); | |
} | |
DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance(); | |
factory.setCoalescing(true); | |
factory.setExpandEntityReferences(true); | |
factory.setValidating(false); | |
factory.setIgnoringComments(true); | |
DocumentBuilder builder=factory.newDocumentBuilder(); | |
String terms="Exome[title]"; | |
LOG.info("searching pubmed for "+terms); | |
String uri="http://eutils.ncbi.nlm.nih.gov/entrez/eutils/esearch.fcgi?db=pubmed&term="+ | |
URLEncoder.encode(terms,"UTF-8") | |
; | |
javax.xml.bind.JAXBContext jaxbCtxt=javax.xml.bind.JAXBContext.newInstance(ESearchResult.class); | |
javax.xml.bind.Unmarshaller unmarshaller=jaxbCtxt.createUnmarshaller(); | |
InputStream in=new URL(uri).openStream(); | |
ESearchResult eSearchResult=unmarshaller.unmarshal(new StreamSource(in),ESearchResult.class).getValue(); | |
in.close(); | |
IdList idList=eSearchResult.getIdList(); | |
if(idList==null) return ; | |
for(Integer pmid:idList.getId()) | |
{ | |
LOG.info("PMID is:"+pmid); | |
Document dom=builder.parse("http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?db=pubmed&retmode=xml&id="+pmid); | |
Node abstractNode=(Node)abstractExpr.evaluate(dom, XPathConstants.NODE); | |
if(abstractNode==null) continue; | |
String content=abstractNode.getTextContent(); | |
if(content==null || content.trim().isEmpty()) continue; | |
LOG.info("content is "+content); | |
for(String pipeline:pipelines) | |
{ | |
try | |
{ | |
LOG.info("contact MID "+pmid+" vs pipeline:"+pipeline); | |
String result = whatizit.contact(pipeline, content, false); | |
System.out.println("contact output is :"+result); | |
} | |
catch(Exception err) | |
{ | |
err.printStackTrace(); | |
LOG.severe(errorPrefix+err.getMessage()+" content:"+content); | |
} | |
try | |
{ | |
LOG.info("queryPmid : PMID "+pmid+" vs pipeline:"+pipeline); | |
String xml = whatizit.queryPmid(pipeline, ""+pmid); | |
System.err.println(pipeline+":\n"+xml); | |
} | |
catch(Exception err) | |
{ | |
err.printStackTrace(); | |
LOG.severe(errorPrefix+pipeline+":"+err.getMessage()+" content:"+content); | |
} | |
try | |
{ | |
LOG.info("invoking whatizit.search with pipeline:"+pipeline); | |
Search search=new Search(); | |
search.setPipelineName(pipeline); | |
search.setQuery(content); | |
search.setLimit(10); | |
SearchResponse src=whatizit.search(search); | |
System.out.println("SearchResponse:"+src); | |
} | |
catch(Exception err) | |
{ | |
err.printStackTrace(); | |
LOG.severe(errorPrefix+pipeline+":"+err.getMessage()+" content:"+content); | |
} | |
} | |
} | |
} | |
public static void main(String[] args) throws Exception | |
{ | |
new Test().run(args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment