Querying with the Web Service
InterMine includes a RESTful web service InterMine that allows you to run queries programatically via HTTP.
There is full documentation for the web service available here: WebService
Template web service
You can fetch results for any public template query via the web service just by using the template name and setting some parameters.
Look at the Chromosome --> All genes template in the FlyMine preview. Clicking on the 'web service URL' link at the bottom gives:
http://preview.flymine.org/preview/service/template/results?name=Chromosome_Gene&constraint1=Gene.chromosome.primaryIdentifier&op1=eq&value1=2L&constraint2=Gene.organism.name&op2=eq&value2=Drosophila+melanogaster&size=10&format=tab
- You can run this from the command line simply with wget, the following produces a file called results:
wget -O results 'http://preview.flymine.org/preview/service/template/results?name=Chromosome_Gene&constraint1=Gene.chromosome.primaryIdentifier&op1=eq&value1=2L&constraint2=Gene.organism.name&op2=eq&value2=Drosophila+melanogaster&size=10&format=tab'
- try editing the constraint values to fetch genes for chromosome '4'
- change the number of results to fetch with the size paramenter
- try other values for format: csv and xml
Note that on the template query form there is also a link to generate HTML that will embed results in another HTML page.
Choose another public template from the FlyMine preview and:
- find the URL to execute the template
- try 'See results in the example page' to see how this could be embedded in another web page
- try out the REST web service from the command line as above, try editing some of the parameters
XML query service
You can also run any query as XML from the web service, this lets you run any query you create not just template queries. You can export an XML representation of a query from the webapp: on the QueryBuilder page there are links in the 'Actions' section below the 'Show Results' button.
- navigate to the template 'Chromosome --> All genes'
- click 'Edit query' to get to the QueryBuilder
- click the 'XML' link at the bottom of the page to see an XML representation of this query
- Note that there is an 'Import query from XML' link on the front page and QueryBuilder tab so you can send this XML to somebody else and they can import the query.
- go back and click the 'Get the url' link. This gives a URL that will run this query and fetch the the first ten results.
- try this from the command line with wget -O results with the URL in quotes:
wget -O results 'paste url here'
- try changing:
- the number of rows with the size parameter
- the output format to XML
- add &tcount=yes to the URL to fetch the count of rows
Java and Perl client APIs
We've seen how any query can be run by accessing corresponding URLs. We also provide both Java and Perl client APIs to make it easier to build and run REST queries. Internally these client APIs simply generate the URLs to execute, but they provide a simple method to build new queries in your programs.
Continue this tutorial with either the Java or Perl web service client:
