Skip to content

Commit

Permalink
Fix SBML Rule handling logic (#120)
Browse files Browse the repository at this point in the history
Rules other than assignment rules were ignored so far
  • Loading branch information
dweindl committed Apr 4, 2022
1 parent e912ff7 commit 93d8551
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 3 additions & 1 deletion petab/parameter_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,13 @@ def _apply_condition_parameters(par_mapping: ParMappingDict,
if overridee_id == CONDITION_NAME:
continue

# Species and compartments are handled elsewhere
# Species, compartments, and rule targets are handled elsewhere
if sbml_model.getSpecies(overridee_id) is not None:
continue
if sbml_model.getCompartment(overridee_id) is not None:
continue
if sbml_model.getRuleByVariable(overridee_id) is not None:
continue

par_mapping[overridee_id] = core.to_float_if_float(
condition_df.loc[condition_id, overridee_id])
Expand Down
13 changes: 6 additions & 7 deletions petab/sbml.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,24 +399,23 @@ def get_sigmas(sbml_model: libsbml.Model, remove: bool = False) -> dict:

def get_model_parameters(sbml_model: libsbml.Model, with_values=False
) -> Union[List[str], Dict[str, float]]:
"""Return SBML model parameters which are not AssignmentRule
targets for observables or sigmas
"""Return SBML model parameters which are not Rule targets
Arguments:
sbml_model: SBML model
with_values:
If False, returns list of SBML model parameter IDs which
are not AssignmentRule targets for observables or sigmas. If True,
returns a dictionary with those parameter IDs as keys and parameter
values from the SBML model as values.
are not Rule targets. If True, returns a dictionary with those
parameter IDs as keys and parameter values from the SBML model as
values.
"""
if not with_values:
return [p.getId() for p in sbml_model.getListOfParameters()
if sbml_model.getAssignmentRuleByVariable(p.getId()) is None]
if sbml_model.getRuleByVariable(p.getId()) is None]

return {p.getId(): p.getValue()
for p in sbml_model.getListOfParameters()
if sbml_model.getAssignmentRuleByVariable(p.getId()) is None}
if sbml_model.getRuleByVariable(p.getId()) is None}


def write_sbml(
Expand Down

0 comments on commit 93d8551

Please sign in to comment.