diff --git a/backend/antigenapi/views.py b/backend/antigenapi/views.py index 8b2f87b..91cb31d 100644 --- a/backend/antigenapi/views.py +++ b/backend/antigenapi/views.py @@ -596,10 +596,29 @@ def upload_sequencing_run_results(self, request, pk, submission_idx): raise ValidationError("file", "Results file should be a .zip file") # TODO: Validate submission_idx + try: + sr = SequencingRun.objects.get(pk=int(pk)) + except SequencingRun.DoesNotExist: + raise ValidationError( + f"Sequencing run {pk} does not exist " "to attach results" + ) + + wells = [w["location"] for w in sr.wells if w["plate"] == int(submission_idx)] + if not wells: + raise ValidationError( + f"Plate index {submission_idx} not found in " "sequencing run {pk}" + ) # Run bioinformatics using .zip file # print("Extracting zip file...") seq_data = load_sequences(results_file.temporary_file_path()) + if len(seq_data) != len(wells): + raise ValidationError( + { + "file": f"Upload contains data for {len(seq_data)} " + f"wells, expected {len(wells)}" + } + ) # Convert to FASTA in-memory (vquest api handles chunking to # max 50 seqs per file) diff --git a/frontend/src/crudtemplates/ViewObjectPage.js b/frontend/src/crudtemplates/ViewObjectPage.js index ae17a74..486edd2 100644 --- a/frontend/src/crudtemplates/ViewObjectPage.js +++ b/frontend/src/crudtemplates/ViewObjectPage.js @@ -147,6 +147,7 @@ const ViewObjectPage = (props) => { displayField(field, record, "ViewObjectPage", { setRecord: setRecord, setLoading: setLoading, + setError: props.onSetError, })} {loading && (
diff --git a/frontend/src/crudtemplates/utils.js b/frontend/src/crudtemplates/utils.js index 3cf2355..c5aca85 100644 --- a/frontend/src/crudtemplates/utils.js +++ b/frontend/src/crudtemplates/utils.js @@ -145,7 +145,17 @@ export const uploadSequencingResults = (event, props) => { ).then((res) => { props.setLoading(false); res.json().then((json) => { - props.setRecord(json); + if (res.status >= 200 && res.status < 300) { + props.setRecord(json); + } else { + if (typeof json === "string") { + props.setError(json); + } else if ("file" in json) { + props.setError("Problem with file: " + json["file"]); + } else { + props.setError("Error code " + res.status); + } + } }); }); };