|
1 | 1 | #!/usr/bin/python
|
2 | 2 |
|
3 | 3 | import sys
|
4 |
| -import getopt |
5 | 4 | import csv
|
6 |
| -import json |
7 |
| -import urllib |
| 5 | +import requests |
8 | 6 | import os.path
|
9 | 7 | import re
|
10 | 8 | import matplotlib
|
|
14 | 12 |
|
15 | 13 | csv.field_size_limit(sys.maxsize) # for reading large files
|
16 | 14 |
|
17 |
| -oncokbapiurl = "https://oncokb.org/api/v1" |
| 15 | +oncokbapiurl = "https://www.oncokb.org/api/v1" |
| 16 | +oncokbapibearertoken = "" |
18 | 17 |
|
19 | 18 | def setoncokbbaseurl(u):
|
20 | 19 | global oncokbapiurl
|
21 | 20 | oncokbapiurl = u.rstrip('/') + '/api/v1'
|
22 | 21 |
|
| 22 | +def setoncokbapitoken(t): |
| 23 | + global oncokbapibearertoken |
| 24 | + oncokbapibearertoken = t.strip() |
| 25 | + |
23 | 26 | cancerhotspotsbaseurl = "http://www.cancerhotspots.org"
|
24 | 27 | def setcancerhotspotsbaseurl(u):
|
25 | 28 | global cancerhotspotsbaseurl
|
@@ -109,17 +112,23 @@ def generateReadme(outfile):
|
109 | 112 | outf.close()
|
110 | 113 |
|
111 | 114 | def gethotspots(url, type):
|
112 |
| - hotspotsjson = json.load(urllib.urlopen(url)) |
113 | 115 | hotspots = {}
|
114 |
| - for hs in hotspotsjson: |
115 |
| - gene = hs['hugoSymbol'] |
116 |
| - start = hs['aminoAcidPosition']['start'] |
117 |
| - end = hs['aminoAcidPosition']['end'] |
118 |
| - if type is None or hs['type'] == type: |
119 |
| - if gene not in hotspots: |
120 |
| - hotspots[gene] = set() |
121 |
| - for i in range(start, end + 1): |
122 |
| - hotspots[gene].add(i) |
| 116 | + response = requests.get(url) |
| 117 | + if response.status_code == 200: |
| 118 | + hotspotsjson = response.json() |
| 119 | + |
| 120 | + for hs in hotspotsjson: |
| 121 | + gene = hs['hugoSymbol'] |
| 122 | + start = hs['aminoAcidPosition']['start'] |
| 123 | + end = hs['aminoAcidPosition']['end'] |
| 124 | + if type is None or hs['type'] == type: |
| 125 | + if gene not in hotspots: |
| 126 | + hotspots[gene] = set() |
| 127 | + for i in range(start, end + 1): |
| 128 | + hotspots[gene].add(i) |
| 129 | + else: |
| 130 | + print "error when processing %s" % url |
| 131 | + print "reason: %s" % response.reason |
123 | 132 | return hotspots
|
124 | 133 |
|
125 | 134 | missensesinglehotspots = None
|
@@ -920,40 +929,49 @@ def pulloncokb(key, url):
|
920 | 929 | oncokbdata['oncogenic'] = ""
|
921 | 930 |
|
922 | 931 | try:
|
923 |
| - evidences = json.load(urllib.urlopen(url)) |
924 |
| - # if not evidences['geneExist'] or (not evidences['variantExist'] and not evidences['alleleExist']): |
925 |
| - # return '' |
926 |
| - |
927 |
| - # mutation effect |
928 |
| - if (evidences['mutationEffect'] is not None): |
929 |
| - oncokbdata['mutation_effect'] = evidences['mutationEffect']['knownEffect'] |
930 |
| - oncokbdata['citations'] = appendoncokbcitations(oncokbdata['citations'], |
931 |
| - evidences['mutationEffect']['citations']['pmids'], |
932 |
| - evidences['mutationEffect']['citations']['abstracts']) |
933 |
| - |
934 |
| - # oncogenic |
935 |
| - oncokbdata['oncogenic'] = evidences['oncogenic'] |
936 |
| - |
937 |
| - # get treatment |
938 |
| - for treatment in evidences['treatments']: |
939 |
| - level = treatment['level'] |
940 |
| - |
941 |
| - if level not in levels: |
942 |
| - print level + " is ignored" |
943 |
| - # oncokbdata[level].append('') |
944 |
| - else: |
945 |
| - drugs = treatment['drugs'] |
946 |
| - |
947 |
| - oncokbdata['citations'] = appendoncokbcitations(oncokbdata['citations'], treatment['pmids'], |
948 |
| - treatment['abstracts']) |
949 |
| - |
950 |
| - if len(drugs) == 0: |
951 |
| - oncokbdata[level].append('[NOT SPECIFIED]') |
| 932 | + headers = { |
| 933 | + 'Content-Type': 'application/json', |
| 934 | + 'Authorization': 'Bearer %s' % oncokbapibearertoken |
| 935 | + } |
| 936 | + response = requests.get(url, headers=headers) |
| 937 | + if response.status_code == 200: |
| 938 | + evidences = response.json() |
| 939 | + # if not evidences['geneExist'] or (not evidences['variantExist'] and not evidences['alleleExist']): |
| 940 | + # return '' |
| 941 | + |
| 942 | + # mutation effect |
| 943 | + if (evidences['mutationEffect'] is not None): |
| 944 | + oncokbdata['mutation_effect'] = evidences['mutationEffect']['knownEffect'] |
| 945 | + oncokbdata['citations'] = appendoncokbcitations(oncokbdata['citations'], |
| 946 | + evidences['mutationEffect']['citations']['pmids'], |
| 947 | + evidences['mutationEffect']['citations']['abstracts']) |
| 948 | + |
| 949 | + # oncogenic |
| 950 | + oncokbdata['oncogenic'] = evidences['oncogenic'] |
| 951 | + |
| 952 | + # get treatment |
| 953 | + for treatment in evidences['treatments']: |
| 954 | + level = treatment['level'] |
| 955 | + |
| 956 | + if level not in levels: |
| 957 | + print level + " is ignored" |
| 958 | + # oncokbdata[level].append('') |
952 | 959 | else:
|
953 |
| - drugnames = [] |
954 |
| - for drug in drugs: |
955 |
| - drugnames.append(drug['drugName']) |
956 |
| - oncokbdata[level].append('+'.join(drugnames)) |
| 960 | + drugs = treatment['drugs'] |
| 961 | + |
| 962 | + oncokbdata['citations'] = appendoncokbcitations(oncokbdata['citations'], treatment['pmids'], |
| 963 | + treatment['abstracts']) |
| 964 | + |
| 965 | + if len(drugs) == 0: |
| 966 | + oncokbdata[level].append('[NOT SPECIFIED]') |
| 967 | + else: |
| 968 | + drugnames = [] |
| 969 | + for drug in drugs: |
| 970 | + drugnames.append(drug['drugName']) |
| 971 | + oncokbdata[level].append('+'.join(drugnames)) |
| 972 | + else: |
| 973 | + print "error when processing %s" % url |
| 974 | + print "reason: %s" % response.reason |
957 | 975 | except:
|
958 | 976 | print "error when processing " + url
|
959 | 977 | # sys.exit()
|
|
0 commit comments