-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbioport-term.py
More file actions
64 lines (51 loc) · 1.71 KB
/
Copy pathbioport-term.py
File metadata and controls
64 lines (51 loc) · 1.71 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import requests
import json
import argparse
term = ""
ontology = "SNOMEDCT"
BIOPORTAL_URL = 'http://data.bioontology.org/search'
BIOPORTAL_API_KEY = '75479e12-0267-4718-a7d7-2e5aed3b3ca4'
# see https://metamap.nlm.nih.gov/Docs/SemanticTypes_2018AB.txt
# T047|Disease or Syndrome, T191|Neoplastic Process
# T061|Therapeutic or Preventive Procedure
SEMANTIC_TYPES = 'T047, T191, T061'
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--term", help="Search term")
parser.add_argument("-o", "--onto", help="ontologies: SNOMEDCT NCIT")
args = parser.parse_args()
if args.term:
term =args.term
if args.onto:
ontology = args.onto
url = BIOPORTAL_URL
querystring = {"q":term, "semantic_types":SEMANTIC_TYPES,"ontologies": ontology} #SNOMEDCT NCIT ,"ontologies":"SNOMEDCT"
headers = {
'authorization': "apikey token=" + BIOPORTAL_API_KEY,
'cache-control': "no-cache",
'postman-token': "e9e97c86-ecba-cca7-4213-3933e49f3e09"
}
response = requests.request("GET", url, headers=headers, params=querystring)
j = json.loads(response.text)
#print (j)
collect = j["collection"]
i = 0
found = False
suggestedTerms = {}
while ((not found) and (i < len(collect))):
d = collect[i]
try:
for x in d['synonym']:
if (is_ascii(x)): # do this check because it contains weird char strings sometimes
suggestedTerms.update({x:x})
except Exception as e:
try:
pl = d['prefLabel']
suggestedTerms.update({pl: pl})
except Exception as e:
pass
i += 1
keylist = suggestedTerms.keys()
#print(keylist)
sorted_list = sorted(set(keylist))
for t in sorted_list:
print(t)