11import requests
22
3+ ENCODE_HEADERS = {'accept' : 'application/json' }
4+ ENCODE_BASE_URL = 'https://www.encodeproject.org/'
5+ GDC_BASE_URL = 'https://api.gdc.cancer.gov/'
6+
7+
8+ # ['experiments', 'biosample']
9+ def encode_api (cls , endpoint = 'experiments' , id = None , limit = None , format = 'json' , frame = 'object' ):
10+ api_url = ENCODE_BASE_URL + endpoint + '/' + (id if id else '@@listing' ) + '?' + '&' .join (
11+ (['limit=' + limit ] if limit else []) + (['format=' + format ] if format else [])
12+ + (['frame=' + frame ] if frame else []))
13+ print (api_url )
14+ response = requests .get (api_url , headers = ENCODE_HEADERS )
15+ if response .status_code == 200 :
16+ results = response .json ()
17+ if results ['notification' ] == 'Success' :
18+ graph = results ['@graph' ]
19+ return graph
20+ else :
21+ print ('No result found' )
22+
323
424# ['projects', 'cases', 'files', 'annotations'], starting_point='0', size='25'
525def gdc_api (cls , object_type = 'projects' , starting_point = None , size = None ):
6- api_url = cls . GDC_BASE_URL + object_type + '/' + '?' + \
26+ api_url = GDC_BASE_URL + object_type + '/' + '?' + \
727 '&' .join (
828 (['from=' + starting_point ] if starting_point else [])
929 + (['size=' + size ] if size else [])
@@ -24,19 +44,3 @@ def gdc_api(cls, object_type='projects', starting_point=None, size=None):
2444
2545 hits = (results ['data' ]['hits' ])
2646 return hits
27-
28-
29- # ['experiments', 'biosample']
30- def encode_api (cls , endpoint = 'experiments' , id = None , limit = None , format = 'json' , frame = 'object' ):
31- api_url = cls .ENCODE_BASE_URL + endpoint + '/' + (id if id else '@@listing' ) + '?' + '&' .join (
32- (['limit=' + limit ] if limit else []) + (['format=' + format ] if format else [])
33- + (['frame=' + frame ] if frame else []))
34- print (api_url )
35- response = requests .get (api_url , headers = cls .HEADERS )
36- if response .status_code == 200 :
37- results = response .json ()
38- if results ['notification' ] == 'Success' :
39- graph = results ['@graph' ]
40- return graph
41- else :
42- print ('No result found' )
0 commit comments