Skip to content

Commit

Permalink
feat: add notebook for submitting civic assertions via prod api
Browse files Browse the repository at this point in the history
  • Loading branch information
korikuzma committed May 28, 2024
1 parent d785946 commit 344b50d
Show file tree
Hide file tree
Showing 2 changed files with 138 additions and 0 deletions.
122 changes: 122 additions & 0 deletions analysis/civic/prod_submission.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"import json\n",
"import os\n",
"import sys\n",
"from pathlib import Path\n",
"\n",
"module_path = os.path.abspath(os.path.join(\"../\"))\n",
"if module_path not in sys.path:\n",
" sys.path.append(module_path)\n",
"from utils import dry_run_test_api, submit # noqa: E402"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"with Path(\"assertion_onco.json\").open() as f:\n",
" onco_sub = json.load(f)\n",
"\n",
"assert dry_run_test_api(onco_sub).status_code == 204"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"with Path(\"batch_assertions_clinical_impact.json\").open() as f:\n",
" clin_impact_sub = None\n",
" _data = json.load(f)\n",
" _subs = _data[\"clinicalImpactSubmission\"]\n",
"\n",
" for _sub in _subs:\n",
" if _sub[\"localKey\"] == \"civic.AID:7\":\n",
" clin_impact_sub = {\"clinicalImpactSubmission\": [_sub]}\n",
" break\n",
"\n",
"assert dry_run_test_api(clin_impact_sub).status_code == 204"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"201"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"onco_sub_resp = submit(onco_sub)\n",
"onco_sub_resp.status_code"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"201"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"clin_impact_sub_resp = submit(clin_impact_sub)\n",
"clin_impact_sub_resp.status_code"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
16 changes: 16 additions & 0 deletions analysis/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,26 @@

load_dotenv()

CLINVAR_API = "https://submit.ncbi.nlm.nih.gov/api/v1/submissions/"
TEST_URL = "https://submit.ncbi.nlm.nih.gov/apitest/v1/submissions"
HEADERS = {"Content-type": "application/json", "SP-API-KEY": environ["CLINVAR_API_KEY"]}


def submit(submission: list[dict]) -> requests.Response:
"""Create submission via ClinVar Submission API
:param submission: ClinVar submission
:return: Response from ClinVar Submission API
"""
payload = {
"actions": [
{"type": "AddData", "targetDb": "clinvar", "data": {"content": submission}}
]
}

return requests.post(CLINVAR_API, headers=HEADERS, json=payload, timeout=5)


def dry_run_test_api(submission: list[dict]) -> requests.Response:
"""Perform a dry run using ClinVar Submission Test API
Expand Down

0 comments on commit 344b50d

Please sign in to comment.