Skip to content

Commit e986983

Browse files
committed
Fixed ENCODE and GDC import functions
1 parent a24044d commit e986983

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

src/unifair/modules/fairtracks/functions.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,29 @@
11
import 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'
525
def 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

Comments
 (0)