Skip to content

Commit

Permalink
updates
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPatrie committed May 21, 2024
1 parent 8eddf47 commit 02f04b6
Show file tree
Hide file tree
Showing 11 changed files with 345 additions and 907 deletions.
Binary file not shown.
4 changes: 2 additions & 2 deletions biosimulator_processes/processes/copasi_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CopasiProcess(SedProcess):
specification requires the presence of reactions which inherently define species types and optionally
addition parameters. See Basico for more details. There are two types of objects that are accepted
for this specification:
- A high-level api object from `biosimulator_processes.data_model`,
- A high-level server object from `biosimulator_processes.data_model`,
ie: `TimeCourseModel` or `SedModel`. (Recommended for first-time users). The parameters with
which these dataclasses are instantiated correspond to the `config_schema` for a given
process implementation. In the config schema, the outermost keys could be considered
Expand Down Expand Up @@ -271,7 +271,7 @@ class workingcopasiprocess(SedProcess):
specification requires the presence of reactions which inherently define species types and optionally
addition parameters. See Basico for more details. There are two types of objects that are accepted
for this specification:
- A high-level api object from `biosimulator_processes.data_model`,
- A high-level server object from `biosimulator_processes.data_model`,
ie: `TimeCourseModel` or `SedModel`. (Recommended for first-time users). The parameters with
which these dataclasses are instantiated correspond to the `config_schema` for a given
process implementation. In the config schema, the outermost keys could be considered
Expand Down
Empty file.
36 changes: 36 additions & 0 deletions biosimulator_processes/server/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import tempfile

from fastapi import FastAPI, UploadFile, File
from fastapi.middleware.cors import CORSMiddleware
import uvicorn

from biosimulator_processes.server.src.io import save_omex_archive


app = FastAPI(title='biosimulator-processes-server')


origins = [
"http://localhost:4200",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)


@app.post("/upload-omex")
async def upload_omex(file: UploadFile = File(...)):
contents = await file.read()

save_dir = tempfile.mkdtemp()
archive_response = save_omex_archive(contents, save_dir)
print(archive_response['archive'].contents)
return {"filename": archive_response['source']}


if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
69 changes: 69 additions & 0 deletions biosimulator_processes/server/spec/openapi_3_1_0_generated.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
openapi: 3.1.0
info:
title: biosimulator-processes-server
version: 0.1.0
paths:
/upload-omex:
post:
summary: Upload Omex
operationId: upload_omex_upload_omex_post
requestBody:
content:
multipart/form-data:
schema:
$ref: '#/components/schemas/Body_upload_omex_upload_omex_post'
required: true
responses:
'200':
description: Successful Response
content:
application/json:
schema: {}
'422':
description: Validation Error
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPValidationError'
components:
schemas:
Body_upload_omex_upload_omex_post:
properties:
file:
type: string
format: binary
title: File
type: object
required:
- file
title: Body_upload_omex_upload_omex_post
HTTPValidationError:
properties:
detail:
items:
$ref: '#/components/schemas/ValidationError'
type: array
title: Detail
type: object
title: HTTPValidationError
ValidationError:
properties:
loc:
items:
anyOf:
- type: string
- type: integer
type: array
title: Location
msg:
type: string
title: Message
type:
type: string
title: Error Type
type: object
required:
- loc
- msg
- type
title: ValidationError
Empty file.
16 changes: 16 additions & 0 deletions biosimulator_processes/server/src/io.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import tempfile

from biosimulators_utils.combine.io import CombineArchiveReader


def unpack_omex(archive_fp: str, save_dir: str):
return CombineArchiveReader().run(archive_fp, save_dir)


def save_omex_archive(contents: bytes, save_dir: str):
with tempfile.NamedTemporaryFile(delete=False, suffix='.omex') as temp_file:
temp_file.write(contents)
archive_path = temp_file.name

return {'source': archive_path, 'archive': unpack_omex(archive_path, save_dir), 'save_dir': save_dir}

36 changes: 36 additions & 0 deletions biosimulator_processes/server/src/openapi_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import json
import os

import yaml
from fastapi.openapi.utils import get_openapi

from biosimulator_processes.server.main import app


def main():
openapi_spec = get_openapi(
title=app.title,
version=app.version,
openapi_version=app.openapi_version,
description=app.description,
routes=app.routes,
)

# Convert the JSON OpenAPI spec to YAML
openapi_spec_yaml = yaml.dump(json.loads(json.dumps(openapi_spec)), sort_keys=False)

current_directory = os.path.dirname(os.path.realpath(__file__))

# Write the YAML OpenAPI spec to a file in subdirectory spec
openapi_version = app.openapi_version.replace('.', '_')
spec_fp = f"{current_directory}/../spec/openapi_{openapi_version}_generated.yaml"
if os.path.exists(spec_fp):
print('Spec exists, overwriting')
os.remove(spec_fp)

with open(spec_fp, "w") as f:
f.write(openapi_spec_yaml)


if __name__ == "__main__":
main()
4 changes: 2 additions & 2 deletions biosimulator_processes/services/rest_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ async def _search_source(cls, query: str) -> ProjectsQuery:
print(f'Failed to fetch OMEX archive:\n{e}')

@classmethod
async def _get_files(cls, run_id: str, project_name: str) -> ArchiveFiles:
def get_project_files(cls, run_id: str, project_name: str = None) -> ArchiveFiles:
get_files_url = f'https://api.biosimulations.dev/files/{run_id}'
# get_files_url = f'https://api.biosimulations.dev/results/{run_id}/download'
headers = {'accept': 'application/json'}
Expand All @@ -60,7 +60,7 @@ async def fetch_files(cls, query: str) -> ArchiveFiles:

selected_project_id = options_menu[user_selection]
simulation_run_id = archive_query.project_data[selected_project_id]['simulationRun']
simulation_run_files = await cls._get_files(simulation_run_id, selected_project_id)
simulation_run_files = cls.get_project_files(simulation_run_id, selected_project_id)
return simulation_run_files

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion biosimulator_processes/verify/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def verify_ode_process_outputs(process_name: str, target_report_fp: str, biomode
# TODO: make this more general
def verify_ode_process_output_names(process_name: str, source_report_fp: str, biomodel_id: str = None, sbml_model_file: str = None) -> OutputAspectVerification:
# Get the class from the module
# TODO: Automatically generate this from the biosimulations rest api
# TODO: Automatically generate this from the biosimulations rest server
process = create_ode_process_instance(process_name, biomodel_id, sbml_model_file)
process_keys = list(process.inputs()['floating_species_concentrations'].keys())

Expand Down
Loading

0 comments on commit 02f04b6

Please sign in to comment.