Skip to content

Commit 2fc4ae8

Browse files
authored
Merge pull request #359 from CanDIG/daisieh/download
DIG-2008: drs analysis object has data download handover url
2 parents 2b4506f + c1f160e commit 2fc4ae8

File tree

3 files changed

+27
-18
lines changed

3 files changed

+27
-18
lines changed

htsget_server/database.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,14 @@ def get_drs_object(object_id, expand=False, tries=1):
411411
return None
412412

413413

414-
def list_drs_objects(program_id=None, sample_registration_id=None):
414+
def list_drs_objects(program_id=None, submitter_sample_id=None):
415415
with Session() as session:
416-
if program_id is None and sample_registration_id is None:
416+
if program_id is None and submitter_sample_id is None:
417417
result = session.query(DrsObject).all()
418-
elif sample_registration_id is None: # searching for program
418+
elif submitter_sample_id is None: # searching for program
419419
result = session.query(DrsObject).filter_by(program_id=program_id).all()
420420
else: # searching for experiments with sample registration IDs
421-
result = session.query(DrsObject).filter_by(name=sample_registration_id).all()
421+
result = session.query(DrsObject).filter_by(name=submitter_sample_id).all()
422422

423423
if result is not None:
424424
new_obj = json.loads(str(result))

htsget_server/drs_openapi.yaml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ components:
232232
type: string
233233
SampleRegistrationQuery:
234234
in: query
235-
name: sample_registration_id
236-
description: sample_registration_id from mohccn data model
235+
name: submitter_sample_id
236+
description: submitter_sample_id from mohccn data model
237237
schema:
238238
type: string
239239
ObjectId:
@@ -453,9 +453,7 @@ components:
453453
description: The descriptor for this analysis data entity
454454
name:
455455
type: string
456-
description: |-
457-
The filename for this entity, not including its file extensions.
458-
This string is made up of uppercase and lowercase letters, decimal digits, hypen, period, and underscore [A-Za-z0-9.-_]. See http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_282[portable filenames].
456+
description: same as the id
459457
contents:
460458
type: array
461459
description: The specific analysis contents objects that comprise this analysis DRS entity. Should contain a AnalysisDataContentsObject, an optional AnalysisIndexContentsObject, and ExperimentContentsObjects corresponding to the experiments analyzed in the analysis data object.
@@ -752,16 +750,18 @@ components:
752750
Until then, if implementors do choose such an algorithm (e.g. because it's implemented by their storage provider), they SHOULD use an existing
753751
standard `type` value such as `md5`, `etag`, `crc32c`, `trunc512`, or `sha1`.
754752
example: sha-256
755-
LocalFileAccessMethod:
753+
AccessUrlMethod:
756754
description: A full URL describing the file's location
757755
type: object
758756
required:
759757
- type
758+
- access_url
760759
properties:
761760
type:
762761
type: string
763762
enum:
764763
- file
764+
- download
765765
access_url:
766766
type: object
767767
required:
@@ -773,11 +773,12 @@ components:
773773
type: array
774774
items:
775775
type: string
776-
S3AccessMethod:
776+
AccessIdMethod:
777777
description: An access id and region that might be needed to specify to get a signed URL for obtaining bytes
778778
type: object
779779
required:
780780
- type
781+
- access_id
781782
properties:
782783
type:
783784
type: string
@@ -793,8 +794,8 @@ components:
793794
example: us-east-1
794795
AccessMethod:
795796
anyOf:
796-
- $ref: '#/components/schemas/LocalFileAccessMethod'
797-
- $ref: '#/components/schemas/S3AccessMethod'
797+
- $ref: '#/components/schemas/AccessUrlMethod'
798+
- $ref: '#/components/schemas/AccessIdMethod'
798799
AnalysisContentsObject:
799800
type: object
800801
required:

htsget_server/drs_operations.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ def get_object(object_id, expand=False):
5454
return {"message": f"Not authorized to access object {object_id}"}, auth_code
5555
if new_object is None:
5656
return {"message": "No matching object found"}, 404
57+
if "access_methods" in new_object:
58+
download_method = {
59+
"access_url": {
60+
"url": f"{HTSGET_URL}/ga4gh/drs/v1/objects/{object_id}/download"
61+
},
62+
"type": "download"
63+
}
64+
new_object["access_methods"].append(download_method)
5765
return new_object, 200
5866

5967

@@ -66,8 +74,8 @@ def get_object_for_drs_uri(drs_uri):
6674
return {"message": f"Couldn't resolve DRS server {drs_uri_parse.group(1)}"}, 401
6775

6876

69-
def list_objects(program_id=None, sample_registration_id=None):
70-
return database.list_drs_objects(program_id=program_id, sample_registration_id=sample_registration_id), 200
77+
def list_objects(program_id=None, submitter_sample_id=None):
78+
return database.list_drs_objects(program_id=program_id, submitter_sample_id=submitter_sample_id), 200
7179

7280

7381
@app.route('/ga4gh/drs/v1/objects/<object_id>/access_url/<path:access_id>')
@@ -95,10 +103,10 @@ def download_file(object_id, request=connexion.request):
95103
if drs_object["metadata"]["analysis_type"] == "reference_alignment":
96104
return {"message": f"Sorry, read files are not allowed to be downloaded"}, 403
97105
for method in drs_object["access_methods"]:
98-
if "access_url" in method:
106+
if "access_url" in method and method["type"] == "file":
99107
file_obj = _get_file_path(drs_object["id"])
100108
return send_file(file_obj["path"]), 200
101-
else:
109+
elif "access_id" in method:
102110
url, status_code = _get_access_url(method["access_id"])
103111
r = requests.get(url["url"], stream=True)
104112
return Response(r.iter_content(chunk_size=10*1024), content_type=r.headers['Content-Type'])
@@ -323,7 +331,7 @@ def _get_file_path(drs_file_obj_id):
323331
}
324332
result["size"] = url_obj["metadata"].size
325333
break
326-
else:
334+
elif method["type"] == "file":
327335
# the access_url has all the info we need
328336
url_pieces = urlparse(method["access_url"]["url"])
329337
if url_pieces.scheme == "file":

0 commit comments

Comments
 (0)