Skip to content

Commit

Permalink
Merge pull request #6 from biosimulators/earlier-rr
Browse files Browse the repository at this point in the history
Use the latest possible roadrunner, and fix some bugs.
  • Loading branch information
luciansmith authored Oct 29, 2024
2 parents e17fbc7 + d5a8f94 commit ce6f19f
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 19 deletions.
2 changes: 1 addition & 1 deletion biosimulators_masspy/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.0'
__version__ = '0.1.1'
41 changes: 26 additions & 15 deletions biosimulators_masspy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,21 @@ def exec_sed_task(task, variables, preprocessed_task=None, log=None, config=None
else:
sbml_id = variable_target_sbml_id_map[variable.target]

if sbml_id.startswith('M_'):
if sbml_id[2:] in met_concs:
variable_results[variable.id] = met_concs[sbml_id[2:]][-(sim.number_of_points + 1):]
else:
variable_results[variable.id] = numpy.full((sim.number_of_points + 1,), met_ics[sbml_id[2:]])

else:
if sbml_id in met_concs:
variable_results[variable.id] = met_concs[sbml_id][-(sim.number_of_points + 1):]
elif sbml_id[2:] in met_concs:
variable_results[variable.id] = met_concs[sbml_id[2:]][-(sim.number_of_points + 1):]
elif sbml_id in met_ics:
variable_results[variable.id] = numpy.full((sim.number_of_points + 1,), met_ics[sbml_id])
elif sbml_id[2:] in met_ics:
variable_results[variable.id] = numpy.full((sim.number_of_points + 1,), met_ics[sbml_id[2:]])
elif sbml_id in rxn_fluxes:
variable_results[variable.id] = rxn_fluxes[sbml_id][-(sim.number_of_points + 1):]
elif sbml_id[2:] in rxn_fluxes:
variable_results[variable.id] = rxn_fluxes[sbml_id[2:]][-(sim.number_of_points + 1):]
else:
raise_errors_warnings(validation.validate_task(task),
error_summary='Unable to find variable `{}` in output.'.format(sbml_id))

# log action
if config.LOG:
Expand Down Expand Up @@ -272,8 +279,10 @@ def preprocess_sed_task(task, variables, config=None):
doc.setLevelAndVersion(3, 1)
sbml = libsbml.writeSBMLToString(doc)
mass_model = mass.io.sbml.read_sbml_model(sbml)
met_ids = ['M_' + mass_met.id for mass_met in mass_model.metabolites]
rxn_ids = ['R_' + mass_rxn.id for mass_rxn in mass_model.reactions]
met_ids = [mass_met.id for mass_met in mass_model.metabolites]
met_ids = met_ids + ['M_' + mass_met.id for mass_met in mass_model.metabolites]
rxn_ids = [mass_rxn.id for mass_rxn in mass_model.reactions]
rxn_ids = rxn_ids + ['R_' + mass_rxn.id for mass_rxn in mass_model.reactions]

# validate model changes
model_change_target_mass_map = {}
Expand Down Expand Up @@ -305,7 +314,11 @@ def preprocess_sed_task(task, variables, config=None):
invalid_changes = []
for target, sbml_id in model_change_target_sbml_id_map.items():
if sbml_id in met_ids:
model_change_target_mass_map[target] = (mass_model.metabolites[met_ids.index(sbml_id)], 'ic')
try:
model_change_target_mass_map[target] = (mass_model.metabolites[met_ids.index(sbml_id)], 'ic')
except IndexError:
# If the id has a "M_" in front of it:
model_change_target_mass_map[target] = (mass_model.metabolites[met_ids.index(sbml_id) - len(mass_model.metabolites)], 'ic')

elif sbml_id in sbml_id_mass_parameter_map:
model_change_target_mass_map[target] = sbml_id_mass_parameter_map[sbml_id]
Expand Down Expand Up @@ -352,11 +365,9 @@ def preprocess_sed_task(task, variables, config=None):
raise NotImplementedError(msg)

if invalid_targets:
valid_targets = []
for mass_met in mass_model.metabolites:
valid_targets.append("/sbml:sbml/sbml:model/sbml:listOfSpecies/sbml:species[@id='M_{}']".format(mass_met.id))
for mass_rxn in mass_model.reactions:
valid_targets.append("/sbml:sbml/sbml:model/sbml:listOfReactions/sbml:reaction[@id='R_{}']".format(mass_rxn.id))
valid_targets = met_ids
valid_targets += rxn_ids
valid_targets += list(mass_model.custom_parameters.keys())

msg = (
'The following targets are not supported:\n - {}'
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ python = "^3.9"
biosimulators_utils = {version = "^0.1.151", extras = ["logging", "sbml"]}
cobra = "<= 0.23.0"
kisao = "^2.34"
libroadrunner = "<= 2.2.0"
libroadrunner = "> 2.2.0"
lxml = "^4.5"
masspy = "^0.1.5"
numpy = "<= 1.22.0"
masspy = "^0.1.7"
numpy = "< 1.24.0"
docker = "^7.1.0"

[tool.poetry.group.dev.dependencies]
Expand Down
Binary file not shown.
13 changes: 13 additions & 0 deletions tests/test_core_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,3 +645,16 @@ def test_exec_sedml_docs_in_combine_archive_with_docker_image(self):
archive_filename, out_dir, docker_image, environment=env, pull_docker_image=False)

self._assert_combine_archive_outputs(doc, out_dir)

def test_exec_sedml_docs_in_combine_archive(self):
# with reports
archive_filename = 'Ciliberto-J-Cell-Biol-2003-morphogenesis-checkpoint-Fehlberg.omex'
archive_filename = os.path.join(os.path.dirname(__file__), 'fixtures', archive_filename)

dirname = os.path.join(self.dirname, 'reports')
_, log = core.exec_sedml_docs_in_combine_archive(str(archive_filename), dirname)
if log.exception:
raise log.exception

if __name__ == "__main__":
unittest.main()

0 comments on commit ce6f19f

Please sign in to comment.