Skip to content

Commit d3e4006

Browse files
authored
Sbml model enhancements (#333)
* - allow to initialize from sbml str * - disambiguate between warning and errors
1 parent 9a4efb4 commit d3e4006

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

petab/v1/models/sbml_model.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,22 @@ def from_file(filepath_or_buffer, model_id: str = None):
8181
model_id=model_id,
8282
)
8383

84+
@staticmethod
85+
def from_string(sbml_string, model_id: str = None):
86+
sbml_reader, sbml_document, sbml_model = load_sbml_from_string(
87+
sbml_string
88+
)
89+
90+
if not model_id:
91+
model_id = sbml_model.getIdAttribute()
92+
93+
return SbmlModel(
94+
sbml_model=sbml_model,
95+
sbml_reader=sbml_reader,
96+
sbml_document=sbml_document,
97+
model_id=model_id,
98+
)
99+
84100
@property
85101
def model_id(self):
86102
return self._model_id

petab/v1/sbml.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,18 @@ def is_sbml_consistent(
4343
libsbml.LIBSBML_CAT_UNITS_CONSISTENCY, False
4444
)
4545

46-
has_problems = sbml_document.checkConsistency()
47-
if has_problems:
46+
has_issues = sbml_document.checkConsistency()
47+
48+
# we only have an issue with errors or fatals
49+
has_problems = sbml_document.getNumErrors(
50+
libsbml.LIBSBML_SEV_ERROR
51+
) + sbml_document.getNumErrors(libsbml.LIBSBML_SEV_FATAL)
52+
if has_issues:
4853
log_sbml_errors(sbml_document)
49-
logger.warning(
50-
"WARNING: Generated invalid SBML model. Check messages above."
51-
)
54+
if has_problems:
55+
logger.warning(
56+
"WARNING: Generated invalid SBML model. Check messages above."
57+
)
5258

5359
return not has_problems
5460

0 commit comments

Comments
 (0)