Skip to content

Commit

Permalink
major refactor of library structure for unused content
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexPatrie committed May 1, 2024
1 parent 11259fb commit c8473f2
Show file tree
Hide file tree
Showing 37 changed files with 887 additions and 2,407 deletions.
8 changes: 4 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ WORKDIR /app

# copy and make dirs
COPY ./biosimulator_processes /app/biosimulator_processes
COPY notebooks /app/notebooks
COPY composer-notebooks /app/notebooks

# copy files
COPY ./pyproject.toml ./poetry.lock ./data ./scripts/trust-notebooks.sh /app/
Expand Down Expand Up @@ -51,10 +51,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
&& poetry config virtualenvs.in-project true \
&& poetry update \
&& poetry install \
&& chmod +x ./trust-notebooks.sh \
&& chmod +x ./trust-composer-notebooks.sh \
&& chmod +x /usr/local/bin/enter-lab.sh \
&& ./trust-notebooks.sh \
&& rm ./trust-notebooks.sh \
&& ./trust-composer-notebooks.sh \
&& rm ./trust-composer-notebooks.sh \
&& apt-get clean \
&& apt-get autoclean

Expand Down
3 changes: 3 additions & 0 deletions biosimulator_processes/data_model/compare_data_model.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from typing import *


__all__ = ['ComparisonDocument']


class ComparisonDocument:
"""To be called 'behind-the-scenes' by the Comparison REST API"""
def __init__(self,
Expand Down
9 changes: 6 additions & 3 deletions biosimulator_processes/data_model/sed_data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
from biosimulator_processes.data_model import _BaseClass


__all__ = ['SedDataModel']

@dataclass
class SimulationModelParameter(_BaseClass):
"""
Expand Down Expand Up @@ -135,7 +137,7 @@ class SedModel(_BaseClass):
model_source: Union[BiomodelID, ModelFilepath, str]
model_id: str = None
model_name: str = None
model_language: str = 'sbml'
model_language: str = Field(default='sbml')
model_changes: ModelChanges = None
model_units: ModelUnits = None

Expand Down Expand Up @@ -198,11 +200,11 @@ class TimeCourseModel(SedModel):
Attributes:
model_id: `str`
model_source: `Union[biosimulator_processes.data_model.ModelFilepath, biosimulator_processes.data_model.BiomodelId]`
model_language: `str`
model_language: `str` defaults to sbml
model_name: `str`
model_changes: `biosimulator_processes.data_model.TimeCourseModelChanges`
"""
model_language: str = None,
model_language: str = 'sbml',
model_changes: TimeCourseModelChanges = None,
model_units: ModelUnits = None

Expand Down Expand Up @@ -256,6 +258,7 @@ class TimeCourseProcess(_BaseClass):
"""Used as config for BioBuilder API"""
model: SedModel
method: str = 'lsoda'
model_language: str = 'sbml'


@dataclass
Expand Down
Binary file not shown.
Binary file not shown.
47 changes: 34 additions & 13 deletions biosimulator_processes/processes/copasi_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,15 @@ def __init__(self,
# Option C:
else:
if not self.model_changes:
raise AttributeError("You must pass a source of model changes specifying params, reactions, species or all three if starting from an empty model.")
raise AttributeError(
"""You must pass a source of model changes specifying params, reactions,
species or all three if starting from an empty model.""")
model_units = self.config['model'].get('model_units', {})
self.copasi_model_object = new_model(
name='CopasiProcess TimeCourseModel',
**model_units)

# handle context of species output
context_type = self.config['species_context']
self.species_context_key = f'floating_species_{context_type}'
self.use_counts = 'concentrations' in context_type
Expand Down Expand Up @@ -131,8 +134,8 @@ def __init__(self,
# Get the species (floating only) TODO: add boundary species
species_data = get_species(model=self.copasi_model_object)
self.floating_species_list = species_data.index.tolist()
self.floating_species_initial = species_data.concentration.tolist() \
if 'concentrations' in self.config['species_context'] else species_data.particle_number.tolist()
self.floating_species_initial = species_data.particle_number.tolist() \
if self.use_counts else species_data.concentration.tolist()

# ----GLOBAL PARAMS: set global parameter changes
global_parameter_changes = self.model_changes.get('global_parameter_changes', [])
Expand All @@ -154,9 +157,10 @@ def __init__(self,

# Get the list of parameters and their values (it is possible to run a model without any parameters)
model_parameters = get_parameters(model=self.copasi_model_object)

self.model_parameters_list = model_parameters.index.tolist() if isinstance(model_parameters, DataFrame) else []
self.model_parameters_values = model_parameters.initial_value.tolist() if isinstance(model_parameters, DataFrame) else []
self.model_parameters_list = model_parameters.index.tolist() \
if isinstance(model_parameters, DataFrame) else []
self.model_parameters_values = model_parameters.initial_value.tolist() \
if isinstance(model_parameters, DataFrame) else []

# Get a list of compartments
self.compartments_list = get_compartments(model=self.copasi_model_object).index.tolist()
Expand Down Expand Up @@ -236,14 +240,31 @@ def update(self, inputs, interval):

# extract end values of concentrations from the model and set them in results
results = {'time': interval}
measurement_type = 'particle_number' if self.use_counts else 'concentration'
results[self.species_context_key] = {
mol_id: float(get_species(
for mol_id in self.floating_species_list:
raw_mol_data = get_species(
name=mol_id,
exact=True,
model=self.copasi_model_object
)[measurement_type][0])
for mol_id in self.floating_species_list
}
model=self.copasi_model_object)

mol_data = raw_mol_data.particle_number[0] if self.use_counts else raw_mol_data.concentration[0]
results[self.species_context_key] = {
mol_id: float(mol_data)
}
"""if self.use_counts:
results[self.species_context_key] = {
mol_id: float(get_species(
name=mol_id,
exact=True,
model=self.copasi_model_object
).particle_number[0])
for mol_id in self.floating_species_list}
else:
results[self.species_context_key] = {
mol_id: float(get_species(
name=mol_id,
exact=True,
model=self.copasi_model_object
).concentration[0])
for mol_id in self.floating_species_list}"""

return results
2 changes: 1 addition & 1 deletion biosimulator_processes/steps/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def parse_composition_results(composition: Composite) -> Dict[float, Dict[str, U
float(n)
for n in range(int(composition.state['global_time']) + 1) # python ranges are not as they appear ;)
]
assert len(timescale) == len(result_vals) # internal check: is there a better way to perform the check?
assert len(timescale) == len(result_vals) # src check: is there a better way to perform the check?
return dict(zip(timescale, result_vals))


Expand Down
2 changes: 1 addition & 1 deletion biosimulator_processes/tests/test_copasi_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def test_process():

def test_process_from_document():
# read the document from local file:
five_process_fp = 'notebooks/out/five_process_composite.json'
five_process_fp = 'composer-notebooks/out/five_process_composite.json'
with open(five_process_fp, 'r') as fp:
instance = json.load(fp)

Expand Down
2 changes: 1 addition & 1 deletion biosimulator_processes/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def fix_execution_count(notebook_path):


def fix_notebooks_execution_count():
for root, _, files in os.walk('../notebooks'):
for root, _, files in os.walk('../composer-notebooks'):
for _file in files:
notebook_path = os.path.join(root, _file)
fix_execution_count(notebook_path)
Expand Down
2 changes: 1 addition & 1 deletion compare_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fastapi import FastAPI, HTTPException, Query, File, UploadFile
from fastapi.middleware.cors import CORSMiddleware
from compare_api.datamodel import SimulatorComparisonResult, CompositeRunError
from compare_api.internal.composite_doc import create_comparison_document, generate_workflow, run_workflow
from compare_api.src.composite_doc import create_comparison_document, generate_workflow, run_workflow

# logger for this module
logger = logging.getLogger(__name__)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file removed demos/__init__.py
Empty file.
Loading

0 comments on commit c8473f2

Please sign in to comment.