From 932e8e05e697e1b581c47414cf25b99dce70eeb6 Mon Sep 17 00:00:00 2001 From: "spaceBearAmadeus (Alex)" Date: Fri, 16 Aug 2024 00:28:12 -0400 Subject: [PATCH] updates for fix of simularium --- compose_api/main.py | 58 +++++++++---------- compose_api/spec/openapi_3_1_0_generated.yaml | 40 +++---------- 2 files changed, 37 insertions(+), 61 deletions(-) diff --git a/compose_api/main.py b/compose_api/main.py index 1ff8a6901..648931f76 100644 --- a/compose_api/main.py +++ b/compose_api/main.py @@ -417,7 +417,7 @@ async def fetch_results(job_id: str): @app.post( "/generate-simularium-file", - response_model=PendingSimulariumJob, + # response_model=PendingSimulariumJob, operation_id='generate-simularium-file', tags=["Files"], summary='Generate a simularium file with a compatible simulation results file from either Smoldyn, SpringSaLaD, or ReaDDy.') @@ -425,35 +425,33 @@ async def generate_simularium_file( uploaded_file: UploadFile = File(..., description="A file containing results that can be parse by Simularium (spatial)."), box_size: float = Query(..., description="Size of the simulation box as a floating point number."), filename: str = Query(default=None, description="Name desired for the simularium file. NOTE: pass only the file name without an extension."), -) -> PendingSimulariumJob: - try: - job_id = "files-generate-simularium-file" + str(uuid.uuid4()) - _time = db_connector.timestamp() - upload_prefix = f"uploads/{job_id}/" - bucket_prefix = f"gs://{BUCKET_NAME}/" + upload_prefix - uploaded_file_location = await write_uploaded_file(job_id=job_id, uploaded_file=uploaded_file, bucket_name=BUCKET_NAME, extension='.txt') - - # new simularium job in db - if filename is None: - filename = 'simulation' - - new_job_submission = await db_connector.insert_job_async( - collection_name=DatabaseCollections.PENDING_JOBS.value, - status=JobStatus.PENDING.value, - job_id=job_id, - timestamp=_time, - path=uploaded_file_location, - filename=filename, - box_size=box_size, - ) - - gen_id = new_job_submission.get('_id') - if gen_id is not None: - new_job_submission.pop('_id') - - return PendingSimulariumJob(**new_job_submission) - except Exception as e: - raise HTTPException(status_code=404, detail=f"A simularium file cannot be parsed from your input. Please check your input file and refer to the simulariumio documentation for more details.") +): + job_id = "files-generate-simularium-file" + str(uuid.uuid4()) + _time = db_connector.timestamp() + upload_prefix = f"uploads/{job_id}/" + bucket_prefix = f"gs://{BUCKET_NAME}/" + upload_prefix + uploaded_file_location = await write_uploaded_file(job_id=job_id, uploaded_file=uploaded_file, bucket_name=BUCKET_NAME, extension='.txt') + + # new simularium job in db + if filename is None: + filename = 'simulation' + + new_job_submission = await db_connector.insert_job_async( + collection_name=DatabaseCollections.PENDING_JOBS.value, + status=JobStatus.PENDING.value, + job_id=job_id, + timestamp=_time, + path=uploaded_file_location, + filename=filename, + box_size=box_size, + ) + gen_id = new_job_submission.get('_id') + if gen_id is not None: + new_job_submission.pop('_id') + + return new_job_submission + # except Exception as e: + # raise HTTPException(status_code=404, detail=f"A simularium file cannot be parsed from your input. Please check your input file and refer to the simulariumio documentation for more details.") @app.post( diff --git a/compose_api/spec/openapi_3_1_0_generated.yaml b/compose_api/spec/openapi_3_1_0_generated.yaml index 7939e5f50..7530ec7f8 100644 --- a/compose_api/spec/openapi_3_1_0_generated.yaml +++ b/compose_api/spec/openapi_3_1_0_generated.yaml @@ -392,6 +392,14 @@ paths: from either Smoldyn, SpringSaLaD, or ReaDDy. operationId: generate-simularium-file parameters: + - name: box_size + in: query + required: true + schema: + type: number + description: Size of the simulation box as a floating point number. + title: Box Size + description: Size of the simulation box as a floating point number. - name: filename in: query required: false @@ -413,8 +421,7 @@ paths: description: Successful Response content: application/json: - schema: - $ref: '#/components/schemas/PendingSimulariumJob' + schema: {} '422': description: Validation Error content: @@ -803,35 +810,6 @@ components: - steps - simulators title: PendingSbmlVerificationJob - PendingSimulariumJob: - properties: - job_id: - type: string - title: Job Id - status: - type: string - title: Status - default: PENDING - timestamp: - type: string - title: Timestamp - comparison_id: - type: string - title: Comparison Id - input_file: - type: string - title: Input File - filename: - type: string - title: Filename - type: object - required: - - job_id - - timestamp - - comparison_id - - input_file - - filename - title: PendingSimulariumJob Simulator: properties: name: