Skip to content

Instantly share code, notes, and snippets.

@kantale
Created February 9, 2017 15:37
Show Gist options
  • Select an option

  • Save kantale/1477a3d9aef5895f164248d8d237e2fa to your computer and use it in GitHub Desktop.

Select an option

Save kantale/1477a3d9aef5895f164248d8d237e2fa to your computer and use it in GitHub Desktop.
import re
import sys
import json
import urllib
import requests
headers = {
"Host": "www.disease-ontology.org",
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:51.0) Gecko/20100101 Firefox/51.0",
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.5",
"Referer": "http://www.disease-ontology.org/",
"Connection": "keep-alive",
"Upgrade-Insecure-Requests": "1",
"Pragma": "no-cache",
"Cache-Control": "no-cache"
}
argument = "+".join(sys.argv[1].split())
url = "http://www.disease-ontology.org/search?q={}&adv_search=False&operator=AND&field-1=name&value-1=".format(argument)
r = requests.get(url, headers = headers)
text = r.text
#print text
s = re.search(r'<td class=\"tbl-doid\">([\w:]+)</td>', text)
g = s.group(1)
# DOID:0050741
#print g
url = "http://www.disease-ontology.org/query_tree?_dc=1486652979836&search=True&node={}".format(urllib.quote(g))
r2 = requests.get(url, headers = headers)
data = r2.json()
#print json.dumps(data, indent=4)
'''
[
{
"text": "disease",
"expanded": true,
"children": [
{
"text": "disease by infectious agent",
"leaf": false,
"id": "DOID:0050117"
},
{
"text": "disease of anatomical entity",
"leaf": false,
"id": "DOID:7"
},
{
"text": "disease of cellular proliferation",
"leaf": false,
"id": "DOID:14566"
},
{
"text": "disease of mental health",
"expanded": true,
"children": [
'''
for l1 in data:
for l2 in l1['children']:
if "children" in l2:
print l2["text"]
@kantale
Copy link
Copy Markdown
Author

kantale commented Feb 9, 2017

Usage:

$ python kleio.py "alcohol dependence"
disease of mental health

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment