async def upload_reads_to_cache(request): name = request.match_info["name"] sample_id = request.match_info["sample_id"] key = request.match_info["key"] if name not in ["reads_1.fq.gz", "reads_2.fq.gz"]: return not_found() if sample_id != TEST_SAMPLE_ID or key != TEST_CACHE["key"]: return not_found() document = await read_file_from_request(request, name, "fastq") return json_response(document, status=201)
async def create_mock_cache(request): sample_id = request.match_info["sample_id"] if sample_id != TEST_SAMPLE_ID: return not_found() _json = await request.json() key = _json["key"] if key == TEST_CACHE["key"]: return json_response(TEST_CACHE, status=201) else: return not_found()
async def get_sample(request): sample_id = request.match_info["sample_id"] if sample_id != TEST_SAMPLE_ID: return not_found() return json_response(TEST_SAMPLE, status=200)
async def get_cache(request): sample_id = request.match_info["sample_id"] key = request.match_info["key"] if sample_id != TEST_SAMPLE_ID or key != TEST_CACHE["key"]: return not_found() return json_response(TEST_CACHE)
async def download_reads_file(request): sample_id = request.match_info["sample_id"] filename = request.match_info["filename"] if sample_id != TEST_SAMPLE_ID or filename not in ("reads_1.fq.gz", "reads_2.fq.gz"): return not_found() file_name = "paired_small_1.fq.gz" if filename == "reads_1.fq.gz" else "paired_small_2.fq.gz" return FileResponse(ANALYSIS_TEST_FILES_DIR / file_name)
async def delete_cache(request): sample_id = request.match_info["sample_id"] key = request.match_info["key"] if sample_id != TEST_SAMPLE_ID or key != TEST_CACHE["key"]: return not_found() if TEST_CACHE["ready"] is True: return json_response({"message": "Cache is finalized."}, status=409) return Response(status=204)
async def upload_read_files(request): sample_id = request.match_info["sample_id"] if sample_id != TEST_SAMPLE_ID: return not_found() name = request.query.get("name") type = request.query.get("type") file = await read_file_from_request(request, name, type) return json_response(file, status=201)
async def finalize(request): sample_id = request.match_info["sample_id"] if sample_id != TEST_SAMPLE_ID: return not_found() response_json = await request.json() TEST_SAMPLE["quality"] = response_json["quality"] TEST_SAMPLE["ready"] = True return json_response(TEST_SAMPLE)
async def upload_artifact_to_cache(request): sample_id = request.match_info["sample_id"] key = request.match_info["key"] type = request.query.get("type") name = request.query.get("name") if sample_id != TEST_SAMPLE_ID or key != TEST_CACHE["key"]: return not_found() document = await read_file_from_request(request, name, type) return json_response(document, status=201)
async def delete(request): sample_id = request.match_info["sample_id"] if sample_id != TEST_SAMPLE_ID: return not_found() if "ready" in TEST_SAMPLE and TEST_SAMPLE["ready"] is True: return json_response( {"message": "Already Finalized"}, status=400, ) return Response(status=204)
async def download_artifact(request): sample_id = request.match_info["sample_id"] filename = request.match_info["filename"] if sample_id != TEST_SAMPLE_ID: return not_found() tempdir = Path(tempfile.mkdtemp()) file = tempdir / filename file.touch() return FileResponse(file)
async def finalize_cache(request): sample_id = request.match_info["sample_id"] key = request.match_info["key"] if sample_id != TEST_SAMPLE_ID or key != TEST_CACHE["key"]: return not_found() _json = await request.json() quality = _json["quality"] TEST_CACHE["quality"] = quality TEST_CACHE["ready"] = True return json_response(TEST_CACHE)