How to use the Open PHACTS API
Ian Dunlop
Ian.dunlop@manchester.ac.uk
Go to https://dev.openphacts.org
Sign up, sign in or use the app ID/app Keys available from:
http://goo.gl/z3rWwZ
Use the API from the documentation
View results in a browser
Write some code
What shall we do?
Anatomy of an API 1
Required elements with a single
value
Optional elements with a
single value
Optional elements with a single
value or array
Anatomy of an API 2
URI identifying the item you are
interested in
Application ID created
at
https://dev.openphacts.
org
Application Key for the
application ID created at
https://dev.openphacts.org
Compound Info
https://beta.openphacts.org/1.3/compound?uri=+http%3A%2F%2Fwww
.conceptwiki.org%2Fconcept%2F38932552-111f-4a4e-a46a-
4ed1d7bdf9d5&app_id=a921aad5&app_key=1be1aa775de4126dab09
d54ef95e5832&_format=json
http://goo.gl/cjLiIZ
Compound Pharmacology
Count
https://beta.openphacts.org/1.3/compound/pharmacology/count?uri=htt
p%3A%2F%2Fwww.conceptwiki.org%2Fconcept%2F38932552-111f-
4a4e-a46a-
4ed1d7bdf9d5&app_id=a921aad5&app_key=1be1aa775de4126dab09
d54ef95e5832&_format=json
http://goo.gl/DNG4uA
Compound Pharmacology
List (page 1, 10 results)
https://beta.openphacts.org/1.3/compound/pharmacology/pages?uri=htt
p%3A%2F%2Fwww.conceptwiki.org%2Fconcept%2F38932552-111f-
4a4e-a46a-
4ed1d7bdf9d5&app_id=a921aad5&app_key=1be1aa775de4126dab09
d54ef95e5832&_format=json
http://goo.gl/nw4YFQ
Compound Pharmacology Filters
How many results are there with an IC50 less than or equal to
1500nM?
Compound Pharmacology Filters
Answer: 146
https://beta.openphacts.org/1.3/compound/pharmacology/count?uri=http%3A%
2F%2Fwww.conceptwiki.org%2Fconcept%2F38932552-111f-4a4e-a46a-
4ed1d7bdf9d5&app_id=a921aad5&app_key=1be1aa775de4126dab09d54ef95
e5832&activity_type=IC50&max-
activity_value=1500&activity_unit=nanomolar&_format=json
activity_type=IC50
max-activity_value=1500
activity_unit=nanomolar
http://goo.gl/BbHmKN
First 30 results?
First 30 results?
https://beta.openphacts.org/1.3/compound/pharmacology/pages?uri=http%3A%
2F%2Fwww.conceptwiki.org%2Fconcept%2F38932552-111f-4a4e-a46a-
4ed1d7bdf9d5&app_id=a921aad5&app_key=1be1aa775de4126dab09d54ef95
e5832&activity_type=IC50&max-
activity_value=1500&activity_unit=nanomolar&_page=1&_pageSize=30&_form
at=json
activity_type=IC50
max-activity_value=1500
activity_unit=nanomolar
_page=1
_pageSize=30
http://goo.gl/LQmDLz
Write some code
Open up zip (available from http://goo.gl/NaN5BJ)
Start with an empty HTML page
– Open compound.html in your browser (file:///….)
Not much to see here
– Loads OPS.js and jQuery
Write some code
Open the HTML in your favourite text editor
Add some magic (http://goo.gl/JvE4mt) inside the JavaScript code block
appID = "a921aad5";
appKey = "1be1aa775de4126dab09d54ef95e5832";
var searcher = new
Openphacts.CompoundSearch("https://beta.openphacts.org/1.3",
appID, appKey);
var callback = function(success, status, response) {
var compoundResult =
searcher.parseCompoundResponse(response);
$("#compound-info").append("I am " + compoundResult.prefLabel
+ " with molecular weight " + compoundResult.fullMWT);
};
searcher.fetchCompound('http://www.conceptwiki.org/concept/389325
52-111f-4a4e-a46a-4ed1d7bdf9d5', null, callback);
Refresh your browser
Open PHACTS widgets
Collaboration with Biojs
http://openphacts.github.io/ops-html-widgets/
https://github.com/biojs/biojs
Useful links
https://dev.openphacts.org/docs/1.3
https://explorer.openphacts.org
http://jupiter.cs.man.ac.uk
https://github.com/openphacts/ops.js
https://github.com/biojs/biojs
http://goo.gl/JvE4mt (OPS.js code example)

How to use the Open PHACTS API

Editor's Notes

  • #3 The app id and key is used to measure number of uses of the API, not who is using it. The actual API calls used are wiped from the logs.
  • #4 All the API calls are documented at https://dev.openphacts.org/1.3/docs and can be run from within that page
  • #5 Response format is described in RDF triple format. Green means that the element will be present in the response and will have a single value. Yellow means that the element may or may not be in the response and will have a single value Orange means that the element may or may not be in the response and can have a single value or multiple values wrapped inside an array (ie list) Purple means that the element will be present in the response and can have a single value or multiple values wrapped inside an array (ie list)
  • #6 Most API calls follow the same format of https://beta.openphacts.org/API_VERSION/API_CALL?uri=URI&app_id=YOUR_APP_ID&app_key=YOUR_APP_KEY&_format=CHOSEN_FORMAT _callback parameter is for JSONP _metadata parameter adds additional info to the response eg formats returns the mime types available Click the ‘Send Request’ button to see the call executed inside the page which returns a response along with the actual API call sent in CURL format
  • #7 Each version of the API has a number and starting with 1.3 the URL contains the API verison number ie https://beta.openphacts.org/1.3 followed by the path to the call itself eg /compound. Each call must contain a valid app_id and app_key parameter created at dev.openpahcts.org.
  • #10 Various filters and extra parameters can be added to the API calls.
  • #13 The default page is 1 and page size is 20 but you can change these to suit your applications. Set the _pageSize parameter to ‘all’ to retrieve all the results in one API call.
  • #14 Template has a JavaScript code block that is called when the page loads. Loads the OPS.js library which can be used to call the Open PHACTS API and flatten the results. This library is used by the Open PHACTS Explorer ‘2’.
  • #16 There are currently 2 Open PHACTS widgets in the Biojs codebase. Compound Info and Target Info. They will eventually end up on http://www.ebi.ac.uk/Tools/biojs/registry/ They allow the addition of Open PHACTS UI components on any web page with minimal coding, only a couple of lines of JavaScript.
  • #17 Note: the explorer 2 demo on jupiter.cs.man.ac.uk is liable to change or move at any time. It will be hosted under an openphacts IP address in the near future.