@@ -77,11 +77,9 @@ def query_oncokb_cnas_to_csv(cna_annotations: pd.DataFrame, i):
7777 Response: The HTTP response from the OncoKB API.
7878 """
7979
80- token = ONCOKB_TOKEN
81-
8280 api_url = "https://www.oncokb.org/api/v1/annotate/copyNumberAlterations"
8381 #request_url = api_url + 'copyNameAlterationType='+AlterationType[cna.CNstatus].value+'&hugoSymbol='+hugosymbol+'&tumorType='+tumorType
84- header = {'accept' :'application/json' , 'Content-Type' : 'application/json' , 'Authorization' :'Bearer ' + token }
82+ header = {'accept' :'application/json' , 'Content-Type' : 'application/json' , 'Authorization' :'Bearer ' + ONCOKB_TOKEN }
8583
8684 print ("Request OncoKB API " + api_url )
8785
@@ -111,21 +109,16 @@ def query_oncokb_cnas_to_csv(cna_annotations: pd.DataFrame, i):
111109 print ("Querying " + str (len (uniques ))+ " CNAs...." )
112110
113111 # Sending a POST request and getting back response as HTTPResponse object.
114- #response = urllib3.PoolManager().request("POST", api_url, body=data, headers={'accept':'application/json','Content-Type':'application/json','Authorization':'Bearer 16d3a20d-c93c-4b2d-84ad-b3657a367fdb'})
115- response = httpx .post (api_url , json = data , headers = {'Authorization' :'Bearer 16d3a20d-c93c-4b2d-84ad-b3657a367fdb' }, timeout = None )
116- #response = http.request("GET",request_url, headers=header)
117- #print(response.data)
118- #print(response.data.decode('utf-8'))
112+ #response = urllib3.PoolManager().request("POST", api_url, body=data, headers={'accept':'application/json','Content-Type':'application/json','Authorization':'Bearer '})
113+ response = httpx .post (api_url , json = data , headers = {'Authorization' :'Bearer {ONCOKB_TOKEN}' }, timeout = None )
114+
119115
120- #treatmentsdf = pd.DataFrame.from_dict({'alteration_type':[],'alteration':[],'approvedIndications':[],'description':[],'treatment':[],'level_of_evidence':[],'citations':[],'tumorType':[]})
121116 if (response .status_code == 200 ):
122117 treatments = []
123118 respjson = json .loads (response .text )
124119
125120 for rjson in respjson :
126121 hugosymbol = handle_string_field (rjson ["query" ]["hugoSymbol" ])
127- #idsplit = str(cryptocode.decrypt(rjson["query"]["id"], settings.CRYPTOCODE)).split(":")
128- #cna_id = idsplit[2]
129122 alteration = str .upper (handle_string_field (rjson ["query" ]["alteration" ]))
130123
131124 updatedf = cna_annotations .loc [(cna_annotations ['hugoSymbol' ]== hugosymbol ) & (cna_annotations ['alteration' ]== alteration )]
@@ -135,8 +128,6 @@ def query_oncokb_cnas_to_csv(cna_annotations: pd.DataFrame, i):
135128 cna_annotations .at [indxs ,'referenceGenome' ] = handle_string_field (rjson ["query" ]["referenceGenome" ])
136129 cna_annotations .at [indxs ,'tumorType' ] = handle_string_field (rjson ["query" ]["tumorType" ])
137130 cna_annotations .at [indxs ,'consequence' ] = handle_string_field (rjson ["query" ]["consequence" ])
138- #updatedf['proteinStart'] = handle_int_field(rjson["query"]["proteinStart"])
139- #updatedf['proteinEnd'] = handle_int_field(rjson["query"]["proteinEnd"])
140131 cna_annotations .at [indxs ,'oncogenic' ] = handle_string_field (rjson ["oncogenic" ])
141132 cna_annotations .at [indxs ,'mutationEffectDescription' ] = handle_string_field (rjson ["mutationEffect" ]["description" ])
142133 cna_annotations .at [indxs ,'gene_role' ] = handle_string_field (rjson ["mutationEffect" ]["knownEffect" ])
@@ -150,8 +141,6 @@ def query_oncokb_cnas_to_csv(cna_annotations: pd.DataFrame, i):
150141 cna_annotations .at [indxs ,'geneSummary' ] = handle_string_field (rjson ["geneSummary" ])
151142 cna_annotations .at [indxs ,'variantSummary' ] = handle_string_field (rjson ["variantSummary" ])
152143 cna_annotations .at [indxs ,'tumorTypeSummary' ] = handle_string_field (rjson ["tumorTypeSummary" ])
153- #cna_annotations.at[indxs,'treatments'] = handle_drugs_field(rjson["treatments"])
154-
155144 treatments .extend (handle_treatments_oncokb (rjson ["treatments" ], 'CNA' , hugosymbol + ':' + alteration ))
156145
157146 #print("Updated "+str(updatedf.count())+" CNAs")
@@ -177,8 +166,7 @@ def query_oncokb_somatic_mutations(snv_annotations: pd.DataFrame, i):
177166 None
178167 """
179168
180- token = ONCOKB_TOKEN
181- header = {"accept" :"application/json" , 'Content-Type' : 'application/json' , "Authorization" :'Bearer ' + token }
169+ header = {"accept" :"application/json" , 'Content-Type' : 'application/json' , "Authorization" :'Bearer ' + ONCOKB_TOKEN }
182170 request_url = "https://www.oncokb.org/api/v1/annotate/mutations/byGenomicChange"
183171 #request_url = "https://www.oncokb.org/api/v1/annotate/mutations/byHGVSg"
184172
@@ -197,14 +185,11 @@ def query_oncokb_somatic_mutations(snv_annotations: pd.DataFrame, i):
197185 for row in uniques
198186 ]
199187
200- #print(data)
201- # Sending a GET request and getting back response as HTTPResponse object.
202188 print ("Request OncoKB API " + request_url )
203189 print ("Querying " + str (len (uniques )) + " CNAs...." )
204190
205- #response = urllib3.PoolManager().request("POST", request_url, body=data, headers={'accept':'application/json','Content-Type':'application/json','Authorization':'Bearer 16d3a20d-c93c-4b2d-84ad-b3657a367fdb'})
206- response = httpx .post (request_url , json = data , headers = {'Authorization' :'Bearer 16d3a20d-c93c-4b2d-84ad-b3657a367fdb' }, timeout = None )
207- # response = http.request("GET",request_url, headers=header)
191+ #response = urllib3.PoolManager().request("POST", request_url, body=data, headers={'accept':'application/json','Content-Type':'application/json','Authorization':'Bearer'})
192+ response = httpx .post (request_url , json = data , headers = {'Authorization' :'Bearer {ONCOKB_TOKEN}' }, timeout = None )
208193 print (response .status_code )
209194
210195 #TODO: check why EGFR chr7,55181426,55181427,A,C is not found but is found from web api (and also from CGI)
@@ -213,8 +198,7 @@ def query_oncokb_somatic_mutations(snv_annotations: pd.DataFrame, i):
213198
214199 respjson = json .loads (response .text )
215200 for rjson in respjson :
216- #print(rjson)
217- #print("OBJ", rjson)
201+
218202 id = str (rjson ["query" ]["id" ])
219203 idsplit = id .split (":" )
220204 chromosome = str (idsplit [0 ])
@@ -228,7 +212,6 @@ def query_oncokb_somatic_mutations(snv_annotations: pd.DataFrame, i):
228212 snv_annotations .at [indxs , 'alteration' ] = alteration
229213 snv_annotations .at [indxs , 'referenceGenome' ] = handle_string_field (rjson ["query" ]["referenceGenome" ])
230214 snv_annotations .at [indxs ,'tumorType' ] = handle_string_field (rjson ["query" ]["tumorType" ])
231- #snv_annotations.at[indxs,'consequence'] = handle_string_field(rjson["query"]["consequence"])
232215 snv_annotations .at [indxs ,'consequence' ] = handle_string_field (rjson ["query" ]["consequence" ])
233216 snv_annotations .at [indxs ,'oncogenic' ] = handle_string_field (rjson ["oncogenic" ])
234217 snv_annotations .at [indxs ,'mutationEffectDescription' ] = handle_string_field (rjson ["mutationEffect" ]["description" ])
@@ -238,11 +221,9 @@ def query_oncokb_somatic_mutations(snv_annotations: pd.DataFrame, i):
238221 snv_annotations .at [indxs ,'geneSummary' ] = handle_string_field (rjson ["geneSummary" ])
239222 snv_annotations .at [indxs ,'variantSummary' ] = handle_string_field (rjson ["variantSummary" ])
240223 snv_annotations .at [indxs ,'tumorTypeSummary' ] = handle_string_field (rjson ["tumorTypeSummary" ])
241- #snv_annotations.at[indxs,'treatments'] = handle_drugs_field(rjson["treatments"])
242224 treatments .extend (handle_treatments_oncokb (rjson ["treatments" ], 'SNV' , alteration ))
243225
244226 print (snv_annotations )
245- #snv_annotations.drop(columns=snv_annotations.columns[0], axis=1, inplace=True)
246227 header = False if i > 1 else True
247228 snv_annotations .to_csv ("snv_annotated_oncokb.csv" , mode = "a" , header = header , index = False , sep = "\t " , columns = ['patient_id' , 'sample_id' , 'alteration' , 'hugoSymbol' , 'tumorType' , 'consequence' , 'oncogenic' , 'mutationEffectDescription' , 'gene_role' , 'citationPMids' , 'level_of_evidence' , 'geneSummary' , 'variantSummary' , 'tumorTypeSummary' ])
248229 trdf = pd .DataFrame (treatments )
0 commit comments