Created
March 8, 2021 15:37
-
-
Save caodac/59af7d452995e512c00e6520d0359aa9 to your computer and use it in GitHub Desktop.
page through the targets pharos graphql api
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, requests | |
QUERY = """{ | |
targets %s { | |
count | |
targets(top:%d, skip:%d) { | |
sym | |
name | |
tdl | |
novelty | |
description | |
expressionCounts { | |
name | |
value | |
} | |
} | |
} | |
}""" | |
if __name__ == "__main__": | |
top = 10 # number of rows per fetch | |
skip = 0 | |
total = 0 | |
filter = """(filter: { | |
facets: [ | |
{ facet: "tdl", values: ["Tclin", "Tchem"] } | |
] | |
order: "!tdl_info.JensenLab PubMed Score" | |
})""" | |
while True: | |
query = QUERY % (filter, top, skip) | |
#print ('>>> %s' % query) | |
res = requests.post('https://pharos-api.ncats.io/graphql', | |
json={'query': query}) | |
if 200 == res.status_code: | |
data = res.json() | |
# now do something with the data | |
print (json.dumps(data, indent=2)) | |
cnt = len(data['data']['targets']['targets']) | |
skip = skip + cnt | |
if cnt < top: | |
# we're done | |
break | |
else: | |
break | |
print ('%d target(s) fetched!' % skip) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment