From 7c183ce05c0858209ebe7c30e799907f4b5bd24c Mon Sep 17 00:00:00 2001 From: Chiara Rasi Date: Wed, 13 Nov 2024 14:19:43 +0100 Subject: [PATCH 1/5] Work in progress --- preClinVar/main.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/preClinVar/main.py b/preClinVar/main.py index 326bf3b..8b6b76a 100644 --- a/preClinVar/main.py +++ b/preClinVar/main.py @@ -233,3 +233,30 @@ async def status(api_key: str = Form(), submission_id: str = Form()) -> JSONResp status_code=actions_resp.status_code, content=actions_resp.json(), ) + +@app.post("/delete") +async def delete(api_key: str = Form(), clinvar_accession: str = Form(), reason: str = Form()) -> JSONResponse: + """Delete ONE ClinVar submission.""" + + # Create a submission header + header = build_header(api_key) + + # And use it in POST request to API + data = { + "clinvarDeletion": { + "accessionSet": [ + { + "accession": clinvar_accession, + "reason": reason + } + ] + } + } + resp = requests.post(SUBMISSION_URL, data=json.dumps(data), headers=header) + return JSONResponse( + status_code=resp.status_code, + content=resp.json(), + ) + + + From 9d99f37ce55225fe923fc54cef0fd4e354bca57b Mon Sep 17 00:00:00 2001 From: Chiara Rasi Date: Fri, 15 Nov 2024 13:09:34 +0100 Subject: [PATCH 2/5] Endpoint to remove one submission --- CHANGELOG.md | 2 ++ .../demo/delete_submission_example.json | 9 ++++++ preClinVar/main.py | 29 ++++++++++++------- 3 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 preClinVar/demo/delete_submission_example.json diff --git a/CHANGELOG.md b/CHANGELOG.md index d77e43f..22ef0a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## [unreleased] +### Added +- Delete submission endpoint, with json example (under demo files) ### Changed - Updated API submission schema to the latest available on `ncbi/clinvar` GitHub pages - Modified the json submission example to use one from the ClinVar GitHib repo (`sample_clinical_significance_hgvs_submission.json`) diff --git a/preClinVar/demo/delete_submission_example.json b/preClinVar/demo/delete_submission_example.json new file mode 100644 index 0000000..11839c8 --- /dev/null +++ b/preClinVar/demo/delete_submission_example.json @@ -0,0 +1,9 @@ +{ + "clinvarDeletion": { + "accessionSet": [ + { + "accession": "SCV005395965" + } + ] + } +} \ No newline at end of file diff --git a/preClinVar/main.py b/preClinVar/main.py index 8b6b76a..683aead 100644 --- a/preClinVar/main.py +++ b/preClinVar/main.py @@ -235,28 +235,35 @@ async def status(api_key: str = Form(), submission_id: str = Form()) -> JSONResp ) @app.post("/delete") -async def delete(api_key: str = Form(), clinvar_accession: str = Form(), reason: str = Form()) -> JSONResponse: - """Delete ONE ClinVar submission.""" - +async def dry_run(api_key: str = Form(), json_file: UploadFile = File(...)): + """A proxy to the dry run submission ClinVar API endpoint""" # Create a submission header header = build_header(api_key) + # Get json file content as dict: + delete_obj = json.load(json_file.file) + # And use it in POST request to API data = { - "clinvarDeletion": { - "accessionSet": [ - { - "accession": clinvar_accession, - "reason": reason - } + "actions": [ + { + "type": "AddData", + "targetDb": "clinvar", + "data": {"content": delete_obj}, + } ] - } } resp = requests.post(SUBMISSION_URL, data=json.dumps(data), headers=header) + + # A successful response will be an empty response with code 204 (A dry-run submission was successful and no submission was created) + if resp.status_code == 204: + return JSONResponse( + status_code=200, + content={"message": "success"}, + ) return JSONResponse( status_code=resp.status_code, content=resp.json(), ) - From 4710fbdd268bd2833224330fc89e816fe983c238 Mon Sep 17 00:00:00 2001 From: Chiara Rasi Date: Fri, 15 Nov 2024 13:25:46 +0100 Subject: [PATCH 3/5] Create a submission deletion endpoint --- preClinVar/main.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/preClinVar/main.py b/preClinVar/main.py index 683aead..092088f 100644 --- a/preClinVar/main.py +++ b/preClinVar/main.py @@ -10,7 +10,11 @@ from preClinVar.__version__ import VERSION from preClinVar.build import build_header, build_submission -from preClinVar.constants import DRY_RUN_SUBMISSION_URL, SUBMISSION_URL, VALIDATE_SUBMISSION_URL +from preClinVar.constants import ( + DRY_RUN_SUBMISSION_URL, + SUBMISSION_URL, + VALIDATE_SUBMISSION_URL, +) from preClinVar.file_parser import csv_lines, file_fields_to_submission, tsv_lines from preClinVar.validate import validate_submission @@ -34,7 +38,9 @@ async def root(): @app.post("/apitest-status") -async def apitest_status(api_key: str = Form(), submission_id: str = Form()) -> JSONResponse: +async def apitest_status( + api_key: str = Form(), submission_id: str = Form() +) -> JSONResponse: """Returns the status (validation) of a test submission to the apitest endpoint.""" # Create a submission header @@ -156,7 +162,9 @@ async def tsv_2_json( ) return JSONResponse( status_code=400, - content={"message": f"Created json file contains validation errors: {valid_results[1]}"}, + content={ + "message": f"Created json file contains validation errors: {valid_results[1]}" + }, ) @@ -215,7 +223,9 @@ async def csv_2_json( ) return JSONResponse( status_code=400, - content={"message": f"Created json file contains validation errors: {valid_results[1]}"}, + content={ + "message": f"Created json file contains validation errors: {valid_results[1]}" + }, ) @@ -234,16 +244,18 @@ async def status(api_key: str = Form(), submission_id: str = Form()) -> JSONResp content=actions_resp.json(), ) + @app.post("/delete") -async def dry_run(api_key: str = Form(), json_file: UploadFile = File(...)): +async def dry_run(api_key: str = Form(), clinvar_accession: str = Form()): """A proxy to the dry run submission ClinVar API endpoint""" # Create a submission header header = build_header(api_key) - # Get json file content as dict: - delete_obj = json.load(json_file.file) + # Create a submission deletion object + delete_obj = { + "clinvarDeletion": {"accessionSet": [{"accession": clinvar_accession}]} + } - # And use it in POST request to API data = { "actions": [ { @@ -253,6 +265,7 @@ async def dry_run(api_key: str = Form(), json_file: UploadFile = File(...)): } ] } + # And send a POST request to the API resp = requests.post(SUBMISSION_URL, data=json.dumps(data), headers=header) # A successful response will be an empty response with code 204 (A dry-run submission was successful and no submission was created) @@ -265,5 +278,3 @@ async def dry_run(api_key: str = Form(), json_file: UploadFile = File(...)): status_code=resp.status_code, content=resp.json(), ) - - From 8713e5a033c51f5afec7ac6b6db2ce160552e27a Mon Sep 17 00:00:00 2001 From: Chiara Rasi Date: Fri, 15 Nov 2024 13:36:23 +0100 Subject: [PATCH 4/5] Reformat with line length 100 --- preClinVar/main.py | 22 ++++------------------ 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/preClinVar/main.py b/preClinVar/main.py index 092088f..905c2ed 100644 --- a/preClinVar/main.py +++ b/preClinVar/main.py @@ -38,9 +38,7 @@ async def root(): @app.post("/apitest-status") -async def apitest_status( - api_key: str = Form(), submission_id: str = Form() -) -> JSONResponse: +async def apitest_status(api_key: str = Form(), submission_id: str = Form()) -> JSONResponse: """Returns the status (validation) of a test submission to the apitest endpoint.""" # Create a submission header @@ -162,9 +160,7 @@ async def tsv_2_json( ) return JSONResponse( status_code=400, - content={ - "message": f"Created json file contains validation errors: {valid_results[1]}" - }, + content={"message": f"Created json file contains validation errors: {valid_results[1]}"}, ) @@ -223,9 +219,7 @@ async def csv_2_json( ) return JSONResponse( status_code=400, - content={ - "message": f"Created json file contains validation errors: {valid_results[1]}" - }, + content={"message": f"Created json file contains validation errors: {valid_results[1]}"}, ) @@ -252,9 +246,7 @@ async def dry_run(api_key: str = Form(), clinvar_accession: str = Form()): header = build_header(api_key) # Create a submission deletion object - delete_obj = { - "clinvarDeletion": {"accessionSet": [{"accession": clinvar_accession}]} - } + delete_obj = {"clinvarDeletion": {"accessionSet": [{"accession": clinvar_accession}]}} data = { "actions": [ @@ -268,12 +260,6 @@ async def dry_run(api_key: str = Form(), clinvar_accession: str = Form()): # And send a POST request to the API resp = requests.post(SUBMISSION_URL, data=json.dumps(data), headers=header) - # A successful response will be an empty response with code 204 (A dry-run submission was successful and no submission was created) - if resp.status_code == 204: - return JSONResponse( - status_code=200, - content={"message": "success"}, - ) return JSONResponse( status_code=resp.status_code, content=resp.json(), From 17202f0bb588e9f3410c4f03ba1edf5cf7c52b1e Mon Sep 17 00:00:00 2001 From: Chiara Rasi Date: Fri, 15 Nov 2024 13:42:44 +0100 Subject: [PATCH 5/5] rename function --- preClinVar/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preClinVar/main.py b/preClinVar/main.py index 905c2ed..e49c6b7 100644 --- a/preClinVar/main.py +++ b/preClinVar/main.py @@ -240,7 +240,7 @@ async def status(api_key: str = Form(), submission_id: str = Form()) -> JSONResp @app.post("/delete") -async def dry_run(api_key: str = Form(), clinvar_accession: str = Form()): +async def delete(api_key: str = Form(), clinvar_accession: str = Form()): """A proxy to the dry run submission ClinVar API endpoint""" # Create a submission header header = build_header(api_key)