Skip to content

Commit

Permalink
Ensure upload directories exist for sequencing results
Browse files Browse the repository at this point in the history
  • Loading branch information
alubbock committed Oct 4, 2023
1 parent ef73fec commit d29075f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 27 deletions.
26 changes: 22 additions & 4 deletions backend/antigenapi/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import collections.abc
import io
import os
import urllib.error
import urllib.parse
Expand Down Expand Up @@ -597,22 +598,38 @@ def upload_sequencing_run_results(self, request, pk, submission_idx):
# TODO: Validate submission_idx

# Run bioinformatics using .zip file
print("Extracting zip file...")
# print("Extracting zip file...")
seq_data = load_sequences(results_file.temporary_file_path())

# Convert to FASTA in-memory (vquest api handles chunking to
# max 50 seqs per file)
fasta_file = as_fasta_files(seq_data, max_file_size=None)[0]

# Submit to vquest
print("Running vquest...")
# print("Running vquest...")
vquest_results = run_vquest(fasta_file)

parameters_file_data = vquest_results["Parameters.txt"]
vquest_airr_data = vquest_results["vquest_airr.tsv"]

base_filename = f"SequencingResults_{pk}_{submission_idx}"

# Make sure directory exists
base_dirs = set(
[
os.path.join(
settings.MEDIA_ROOT,
SequencingRunResults.parameters_file.field.upload_to,
),
os.path.join(
settings.MEDIA_ROOT, SequencingRunResults.airr_file.field.upload_to
),
]
)

for base_dir in base_dirs:
os.makedirs(base_dir, exist_ok=True)

# Create SequencingRunResults object
with open(
os.path.join(
Expand Down Expand Up @@ -655,7 +672,7 @@ def upload_sequencing_run_results(self, request, pk, submission_idx):
name="Get sequencing results.",
url_path="results",
)
def upload_sequencing_run_results(self, request, pk):
def get_sequencing_run_results(self, request, pk):
"""Get sequencing results."""
IMPORTANT_COLUMNS = (
"sequence_id",
Expand All @@ -673,7 +690,8 @@ def upload_sequencing_run_results(self, request, pk):
sequencing_run_id=int(pk)
).order_by("seq")

import io
if not results:
return JsonResponse({"records": []})

csvs = []
for r in results:
Expand Down
43 changes: 20 additions & 23 deletions frontend/src/crudtemplates/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ export const uploadSequencingResults = (event, props) => {
).then((res) => {
props.setLoading(false);
res.json().then((json) => {
console.log(json);
props.setRecord(json);
});
});
Expand Down Expand Up @@ -208,28 +207,26 @@ export const displayFieldSingle = (field, record, context, props) => {
</button>
</a>,
);
if (record.sequencingrunresults_set.find((x) => x.seq === p)) {
// Sequencing results found
} else {
// Sequencing results not uploaded yet
retVal.push(
<label
key={"resultsFileUpload" + p}
type="button"
className="w-full cursor-pointer sm:w-auto mb-2 mt-2 sm:mb-0 relative inline-flex items-center justify-center rounded-md border border-transparent bg-teal-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-teal-700 focus:outline-none focus:ring-2 focus:ring-teal-500 focus:ring-offset-2"
>
<input
type="file"
data-residx={p}
data-seqidx={record.id}
onChange={(event) => uploadSequencingResults(event, props)}
className="hidden"
name={"resultsFile" + p}
/>
Upload sequencing results file
</label>,
);
}
retVal.push(
<label
key={"resultsFileUpload" + p}
type="button"
className="w-full cursor-pointer sm:w-auto mb-2 mt-2 sm:mb-0 relative inline-flex items-center justify-center rounded-md border border-transparent bg-teal-600 px-4 py-2 text-sm font-medium text-white shadow-sm hover:bg-teal-700 focus:outline-none focus:ring-2 focus:ring-teal-500 focus:ring-offset-2"
>
<input
type="file"
data-residx={p}
data-seqidx={record.id}
onChange={(event) => uploadSequencingResults(event, props)}
className="hidden"
name={"resultsFile" + p}
/>
{(record.sequencingrunresults_set.find((x) => x.seq === p) &&
"Replace") ||
"Upload"}{" "}
sequencing results file
</label>,
);
}
return retVal;
} else if (field.type === "platethreshold" && record[field.field]) {
Expand Down

0 comments on commit d29075f

Please sign in to comment.