Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading