Skip to content

Commit f4f7ff8

Browse files
committed
Update drs get_download_links_for_program_openapi.yaml
1 parent 6af84aa commit f4f7ff8

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

htsget_server/drs_openapi.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,23 @@ paths:
209209
application/json:
210210
schema:
211211
$ref: '#/components/schemas/ProgramIndexStatus'
212+
/programs/{program_id}/download:
213+
parameters:
214+
- $ref: "#/components/parameters/ProgramId"
215+
- $ref: '#/components/parameters/BearerAuth'
216+
- in: query
217+
name: sample_ids
218+
description: submitter sample ids
219+
schema:
220+
type: array
221+
items:
222+
type: string
223+
get:
224+
description: List download links for files associated with the program
225+
operationId: drs_operations.get_download_links_for_program
226+
responses:
227+
200:
228+
description: ok
212229
components:
213230
parameters:
214231
BearerAuth:

htsget_server/drs_operations.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,42 @@ def download_file(object_id, request=connexion.request):
118118
return Response(r.iter_content(chunk_size=10*1024), content_type=r.headers['Content-Type'])
119119

120120

121+
@app.route('/ga4gh/drs/v1/programs/<program_id>/download')
122+
def get_download_links_for_program(program_id):
123+
sample_ids = None
124+
if "sample_ids" in connexion.request.query_params:
125+
sample_ids = connexion.request.query_params["sample_ids"]
126+
drs_objects, status_code = list_objects(program_id=program_id)
127+
name_dict = {}
128+
for obj in drs_objects:
129+
name_dict[obj["name"]] = obj
130+
131+
# find the Experiments
132+
experiment_objects = []
133+
for obj in drs_objects:
134+
if obj["description"] in ["wgs", "wts"]:
135+
if sample_ids is None or obj["name"] in sample_ids:
136+
experiment_objects.append(obj)
137+
138+
# the contents will link to the related AnalysisDrsObjects
139+
analysis_objects = []
140+
for obj in experiment_objects:
141+
for contents_obj in obj["contents"]:
142+
analysis_objects.append(name_dict[contents_obj["name"]])
143+
144+
# the contents will contain analysis/index objects
145+
downloadable_objects = {}
146+
for obj in analysis_objects:
147+
if "contents" in obj:
148+
downloadable_objects[obj["name"]] = []
149+
for contents_obj in obj["contents"]:
150+
if contents_obj["id"] in ["analysis", "index"]:
151+
# /ga4gh/drs/v1/objects/<contents name>/download will download the file
152+
downloadable_objects[obj["name"]].append(f"{HTSGET_URL}/ga4gh/drs/v1/objects/{contents_obj["name"]}/download")
153+
154+
return downloadable_objects, 200
155+
156+
121157
async def post_object(tries=1):
122158
req = await connexion.request.json()
123159
program_id = req["program"]

0 commit comments

Comments
 (0)