Skip to content

Commit

Permalink
Sbml model enhancements (#333)
Browse files Browse the repository at this point in the history
* - allow to initialize from sbml str

* - disambiguate between warning and errors
  • Loading branch information
fbergmann authored Dec 5, 2024
1 parent 9a4efb4 commit d3e4006
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
16 changes: 16 additions & 0 deletions petab/v1/models/sbml_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ def from_file(filepath_or_buffer, model_id: str = None):
model_id=model_id,
)

@staticmethod
def from_string(sbml_string, model_id: str = None):
sbml_reader, sbml_document, sbml_model = load_sbml_from_string(
sbml_string
)

if not model_id:
model_id = sbml_model.getIdAttribute()

return SbmlModel(
sbml_model=sbml_model,
sbml_reader=sbml_reader,
sbml_document=sbml_document,
model_id=model_id,
)

@property
def model_id(self):
return self._model_id
Expand Down
16 changes: 11 additions & 5 deletions petab/v1/sbml.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,18 @@ def is_sbml_consistent(
libsbml.LIBSBML_CAT_UNITS_CONSISTENCY, False
)

has_problems = sbml_document.checkConsistency()
if has_problems:
has_issues = sbml_document.checkConsistency()

# we only have an issue with errors or fatals
has_problems = sbml_document.getNumErrors(
libsbml.LIBSBML_SEV_ERROR
) + sbml_document.getNumErrors(libsbml.LIBSBML_SEV_FATAL)
if has_issues:
log_sbml_errors(sbml_document)
logger.warning(
"WARNING: Generated invalid SBML model. Check messages above."
)
if has_problems:
logger.warning(
"WARNING: Generated invalid SBML model. Check messages above."
)

return not has_problems

Expand Down

0 comments on commit d3e4006

Please sign in to comment.