Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix requests in proxy endpoints and parsing of observedIn #17

Merged
merged 1 commit into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
- Tests and coverage GitHub workflow
- Updated submission schema in resources following new release of schema by ClinVar (draft-07)
- Proxy endpoint to interrogate the submission dry run endpoint of ClinVar API
- Proxy endpoint to interrogate the submission validate endpoint of ClinVar API
1 change: 0 additions & 1 deletion preClinVar/constants.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
DRY_RUN_SUBMISSION_URL = "https://submit.ncbi.nlm.nih.gov/api/v1/submissions/?dry-run=true"

VALIDATE_SUBMISSION_URL = "https://submit.ncbi.nlm.nih.gov/apitest/v1/submissions"
28 changes: 28 additions & 0 deletions preClinVar/demo/submission.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
},
"localID": "1d9ce6ebf2f82d913cfbe20c5085947b",
"localKey": "1d9ce6ebf2f82d913cfbe20c5085947b",
"observedIn": [
{
"affectedStatus": "yes",
"alleleOrigin": "germline",
"collectionMethod": "clinical testing"
}
],
"recordStatus": "novel",
"releaseStatus": "public",
"variantSet": {
Expand Down Expand Up @@ -61,6 +68,13 @@
},
"localID": "69b138a4c5caf211d796a59a7b46e40d",
"localKey": "69b138a4c5caf211d796a59a7b46e40d",
"observedIn": [
{
"affectedStatus": "yes",
"alleleOrigin": "germline",
"collectionMethod": "clinical testing"
}
],
"recordStatus": "novel",
"releaseStatus": "public",
"variantSet": {
Expand Down Expand Up @@ -99,6 +113,13 @@
},
"localID": "e1bdbf66cd8df98d0d6874a9c4a0d7bc",
"localKey": "e1bdbf66cd8df98d0d6874a9c4a0d7bc",
"observedIn": [
{
"affectedStatus": "yes",
"alleleOrigin": "germline",
"collectionMethod": "clinical testing"
}
],
"recordStatus": "novel",
"releaseStatus": "public",
"variantSet": {
Expand Down Expand Up @@ -137,6 +158,13 @@
},
"localID": "ace28c419a620040c49be5ec9cb7ba37",
"localKey": "ace28c419a620040c49be5ec9cb7ba37",
"observedIn": [
{
"affectedStatus": "yes",
"alleleOrigin": "germline",
"collectionMethod": "clinical testing"
}
],
"recordStatus": "novel",
"releaseStatus": "public",
"variantSet": {
Expand Down
28 changes: 25 additions & 3 deletions preClinVar/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from fastapi import FastAPI, File, Query, UploadFile
from fastapi.responses import JSONResponse
from preClinVar.build import build_header
from preClinVar.constants import DRY_RUN_SUBMISSION_URL
from preClinVar.constants import DRY_RUN_SUBMISSION_URL, VALIDATE_SUBMISSION_URL
from preClinVar.parse import csv_fields_to_submission, csv_lines
from preClinVar.validate import validate_submission
from pydantic import BaseModel, Field
Expand All @@ -31,19 +31,41 @@ async def root():
return {"message": "preClinVar is up and running!"}


@app.post("/validate")
async def validate(
api_key: str = Query(max_length=64, min_length=64), json_file: UploadFile = File(...)
):
"""A proxy to the validate submission ClinVar API endpoint"""
# Create a submission header
header = build_header(api_key)

# Get json file content as dict:
submission_obj = json.load(json_file.file)

# And use it in POST request to API
data = {
"actions": [{"type": "AddData", "targetDb": "clinvar", "data": {"content": submission_obj}}]
}
resp = requests.post(VALIDATE_SUBMISSION_URL, data=json.dumps(data), headers=header)
return resp.json()


@app.post("/dry-run")
async def dry_run(
api_key: str = Query(max_length=64, min_length=64), json_file: UploadFile = File(...)
):
"""Dry-run a ClinVar submission by sending a test to the ClinVar API"""
"""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:
submission_obj = json.load(json_file.file)

# And use it in POST request to API
resp = requests.post(DRY_RUN_SUBMISSION_URL, json=submission_obj, headers=header)
data = {
"actions": [{"type": "AddData", "targetDb": "clinvar", "data": {"content": submission_obj}}]
}
resp = requests.post(DRY_RUN_SUBMISSION_URL, data=json.dumps(data), headers=header)
return resp.json()


Expand Down
2 changes: 2 additions & 0 deletions preClinVar/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def set_item_observed_in(item, casedata_dict):
if casedata_dict.get("Clinical features"):
obs_in["clinicalFeatures"] = casedata_dict.get("Clinical features").split(";")

item["observedIn"] = [obs_in]

# NOT parsing the following key/values for now:
# clinicalFeaturesComment
# numberOfIndividuals
Expand Down
11 changes: 11 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,14 @@ def test_dry_run_wrong_api_key():
response = client.post(url, files=json_file)
assert response.status_code == 200
assert response.json()["message"] == "No valid API key provided"


def test_validate_wrong_api_key():
"""Test endpoint that sends a request to the ClinVar dry run API endpoint"""
json_file = {"json_file": open(subm_json_path, "rb")}

url = "?api_key=".join(["/validate", DEMO_API_KEY])

response = client.post(url, files=json_file)
assert response.status_code == 200
assert response.json()["message"] == "No valid API key provided"