-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
77 additions
and
25 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import json | ||
import urllib.request | ||
import urllib.parse | ||
|
||
|
||
def get_cpic_data(endpoint, params): | ||
base_url = 'https://api.cpicpgx.org/v1/' | ||
url = base_url + endpoint + '?' + urllib.parse.urlencode(params) | ||
with urllib.request.urlopen(url) as response: | ||
return json.loads(response.read()) | ||
|
||
def get_phenotype_map(): | ||
# Would get gene but list of activity scores is not complete | ||
lookup_data = get_cpic_data('recommendation', params={ | ||
'select': 'lookupkey,phenotypes', | ||
}) | ||
phenotype_map = {} | ||
for result in lookup_data: | ||
for gene in result['lookupkey']: | ||
gene_result = result['lookupkey'][gene] | ||
phenotype = result['phenotypes'][gene] \ | ||
if gene in result['phenotypes'] \ | ||
else gene_result | ||
if not gene in phenotype_map: | ||
phenotype_map[gene] = {} | ||
if not gene_result in phenotype_map[gene]: | ||
phenotype_map[gene][gene_result] = phenotype | ||
return phenotype_map | ||
|
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