Skip to content

Commit

Permalink
Fix issue with mangled IDs.
Browse files Browse the repository at this point in the history
MassPy seems to assume that metabolite IDs start with "M_" and that reaction IDs start with "R_"... but doesn't *require* them to.  But it'll strip those parts of the IDs if left unprompted.  But the wrapper was assuming that every ID originally had those characters, and was stripping them back off afterwards.  This change lets both be true.  (And adds a new omex test that doesn't have those characters in the IDs.)
  • Loading branch information
luciansmith committed Oct 29, 2024
1 parent f87287d commit d83be22
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 14 deletions.
35 changes: 21 additions & 14 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 @@ -352,11 +361,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(custom_parameters.keys())

msg = (
'The following targets are not supported:\n - {}'
Expand Down
Binary file not shown.
12 changes: 12 additions & 0 deletions tests/test_core_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,3 +645,15 @@ 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 = 'fixtures/Ciliberto-J-Cell-Biol-2003-morphogenesis-checkpoint-Fehlberg.omex'

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

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

0 comments on commit d83be22

Please sign in to comment.