Skip to content

Commit

Permalink
Merge branch 'main' into update_fastapi
Browse files Browse the repository at this point in the history
  • Loading branch information
northwestwitch authored Mar 14, 2024
2 parents fce9e05 + 06ddc8c commit 9ea3907
Show file tree
Hide file tree
Showing 7 changed files with 1,008 additions and 883 deletions.
212 changes: 168 additions & 44 deletions poetry.lock

Large diffs are not rendered by default.

37 changes: 23 additions & 14 deletions preClinVar/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import uvicorn
from fastapi import FastAPI, File, Form, Request, UploadFile
from fastapi.responses import JSONResponse

from preClinVar.__version__ import VERSION
from preClinVar.build import build_header, build_submission
from preClinVar.constants import DRY_RUN_SUBMISSION_URL, VALIDATE_SUBMISSION_URL
Expand Down Expand Up @@ -43,7 +44,13 @@ async def validate(api_key: str = Form(), json_file: UploadFile = File(...)):

# And use it in POST request to API
data = {
"actions": [{"type": "AddData", "targetDb": "clinvar", "data": {"content": submission_obj}}]
"actions": [
{
"type": "AddData",
"targetDb": "clinvar",
"data": {"content": submission_obj},
}
]
}
resp = requests.post(VALIDATE_SUBMISSION_URL, data=json.dumps(data), headers=header)
return JSONResponse(
Expand All @@ -63,7 +70,13 @@ async def dry_run(api_key: str = Form(), json_file: UploadFile = File(...)):

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

Expand All @@ -83,11 +96,6 @@ async def dry_run(api_key: str = Form(), json_file: UploadFile = File(...)):
async def tsv_2_json(
request: Request,
files: List[UploadFile] = File(...),
submissionName: Union[str, None] = None,
releaseStatus: Union[str, None] = None,
assertionCriteriaDB: Union[str, None] = None,
assertionCriteriaID: Union[str, None] = None,
assembly: Union[str, None] = None,
):
"""Create a json submission object using 2 TSV files (Variant.tsv and CaseData.tsv).
Validate the submission objects agains the official schema:
Expand Down Expand Up @@ -140,11 +148,6 @@ async def tsv_2_json(
async def csv_2_json(
request: Request,
files: List[UploadFile] = File(...),
submissionName: Union[str, None] = None,
releaseStatus: Union[str, None] = None,
assertionCriteriaDB: Union[str, None] = None,
assertionCriteriaID: Union[str, None] = None,
assembly: Union[str, None] = None,
):
"""Create a json submission object using 2 CSV files (Variant.csv and CaseData.csv).
Validate the submission objects agains the official schema:
Expand Down Expand Up @@ -178,8 +181,14 @@ async def csv_2_json(
)

# Convert lines extracted from csv files to a submission object (a dictionary)
submission_dict = file_fields_to_submission(variants_lines, casedata_lines)
build_submission(submission_dict, request)
try:
submission_dict = file_fields_to_submission(variants_lines, casedata_lines)
build_submission(submission_dict, request)
except Exception as ex:
return JSONResponse(
status_code=400,
content={"message": str(ex)},
)

# Validate submission object using official schema
valid_results = validate_submission(submission_dict)
Expand Down
Loading

0 comments on commit 9ea3907

Please sign in to comment.