Skip to content

Commit

Permalink
updates for fix of simularium
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPatrie committed Aug 16, 2024
1 parent 614bc16 commit 932e8e0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 61 deletions.
58 changes: 28 additions & 30 deletions compose_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,43 +417,41 @@ 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.')
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(
Expand Down
40 changes: 9 additions & 31 deletions compose_api/spec/openapi_3_1_0_generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -413,8 +421,7 @@ paths:
description: Successful Response
content:
application/json:
schema:
$ref: '#/components/schemas/PendingSimulariumJob'
schema: {}
'422':
description: Validation Error
content:
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 932e8e0

Please sign in to comment.