-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbioport-batch-cui.py
More file actions
47 lines (40 loc) · 1.19 KB
/
Copy pathbioport-batch-cui.py
File metadata and controls
47 lines (40 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import requests
import json
import argparse
import csv
# this program reads in a simple list of CUIs then looks them up in BioPortal
term = ""
termCache = []
colhdr = ['code', 'name']
url = "http://data.bioontology.org/search"
querystring = {"q":term}
headers = {
'authorization': "apikey token=75479e12-0267-4718-a7d7-2e5aed3b3ca4",
'cache-control': "no-cache",
'postman-token': "e9e97c86-ecba-cca7-4213-3933e49f3e09"
}
print('Searching...')
reader = open("conceptlist.csv", "r")
cnt = 0
for term in reader:
querystring = {"q":term}
response = requests.request("GET", url, headers=headers, params=querystring) # search bioportal
j = json.loads(response.text)
try:
col = j["collection"]
if col:
name = col[0]["prefLabel"]
if not name:
name = "[Unable to determine]"
d = {'code': col[0]["cui"][0], 'name':name}
#print(d)
termCache.append(d)
except:
continue
print('building out csv...')
with open("conceptlist-bioportal.csv", "w") as out:
writer = csv.DictWriter(out, fieldnames=colhdr, dialect='excel', lineterminator='\n')
writer.writeheader()
for data in termCache:
writer.writerow(data)
#print(response.text)