Prerequisities:
Wrapper functions for the Open PHACTS API
In [3]:
import json
import urllib2
from IPython import display
from pprint import pprint
app_id = "0e939a76"
app_key = "1004d9ef5f4ee1ab0bbfc02b623cb955"
def getOPSUrlForString(qStr):
results = json.load(urllib2.urlopen("https://beta.openphacts.org/search/freetext?app_id=" + app_id + "&app_key=" + app_key + "&q="+ qStr + "&_format=json"))
res = results['result']['primaryTopic']['result'][0]['_about']
return res
def getCompoundInformation(uri):
results = json.load(urllib2.urlopen("https://beta.openphacts.org/compound?app_id=" + app_id + "&app_key=" + app_key + "&uri="+ uri + "&_format=json"))
res = results['result']['primaryTopic']
return res
def getCompoundImage(compoundInfo):
for em in compoundInfo['exactMatch']:
if type(em) == dict:
if em['inDataset'] == "http://www.chemspider.com":
csid = em['_about'].lstrip("http://rdf.chemspider.com/")
return display.Image(url='http://www.chemspider.com/ImagesHandler.ashx?id='+csid)
Example Usage: Getting a picture of Sorafenib
In [4]:
uri = getOPSUrlForString('sorafenib')
res = getCompoundInformation(uri)
getCompoundImage(res)
Example Usage: Just output the json we get back from getCompoundInformation()
In [8]:
res
Out[8]: