Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add candidate schema for version 2 #142

Merged
merged 4 commits into from
Jul 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Store PEtab extension config in petab.Problem
  • Loading branch information
dweindl committed Jun 24, 2022
commit fe9d5cd7da3c583be618f7458cbea0f3189d77fa
2 changes: 2 additions & 0 deletions petab/C.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@
OBSERVABLE_FILES = 'observable_files'
#:
VISUALIZATION_FILES = 'visualization_files'
#:
EXTENSIONS = 'extensions'


# MORE
Expand Down
7 changes: 7 additions & 0 deletions petab/lint.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,13 @@ def lint_problem(problem: 'petab.Problem') -> bool:
# pylint: disable=too-many-statements
errors_occurred = False

if problem.extensions_config:
logger.warning(
"Validation of PEtab extensions is not yet implemented, "
"but the given problem uses the following extensions: "
f"{'', ''.join(problem.extensions_config.keys())}"
)

# Run checks on individual files
if problem.model is not None:
logger.info("Checking model...")
Expand Down
67 changes: 41 additions & 26 deletions petab/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,22 @@ class Problem:
sbml_reader: Stored to keep object alive (deprecated).
sbml_document: Stored to keep object alive (deprecated).
sbml_model: PEtab SBML model (deprecated)
extensions_config: Information on the extensions used
"""

def __init__(self,
sbml_model: libsbml.Model = None,
sbml_reader: libsbml.SBMLReader = None,
sbml_document: libsbml.SBMLDocument = None,
model: Model = None,
condition_df: pd.DataFrame = None,
measurement_df: pd.DataFrame = None,
parameter_df: pd.DataFrame = None,
visualization_df: pd.DataFrame = None,
observable_df: pd.DataFrame = None):

def __init__(
self,
sbml_model: libsbml.Model = None,
sbml_reader: libsbml.SBMLReader = None,
sbml_document: libsbml.SBMLDocument = None,
model: Model = None,
condition_df: pd.DataFrame = None,
measurement_df: pd.DataFrame = None,
parameter_df: pd.DataFrame = None,
visualization_df: pd.DataFrame = None,
observable_df: pd.DataFrame = None,
extensions_config: Dict = None,
):
self.condition_df: Optional[pd.DataFrame] = condition_df
self.measurement_df: Optional[pd.DataFrame] = measurement_df
self.parameter_df: Optional[pd.DataFrame] = parameter_df
Expand All @@ -80,6 +83,8 @@ def __init__(self,
sbml_document=sbml_document)

self.model: Optional[Model] = model
self.extensions_config = extensions_config or {}


def __getattr__(self, name):
# For backward-compatibility, allow access to SBML model related
Expand Down Expand Up @@ -113,6 +118,7 @@ def from_files(
Iterable[Union[str, Path]]] = None,
observable_files: Union[str, Path,
Iterable[Union[str, Path]]] = None,
extensions_config: Dict = None,
) -> 'Problem':
"""
Factory method to load model and tables from files.
Expand All @@ -124,6 +130,7 @@ def from_files(
parameter_file: PEtab parameter table
visualization_files: PEtab visualization tables
observable_files: PEtab observables tables
extensions_config: Information on the extensions used
"""
warn("petab.Problem.from_files is deprecated and will be removed in a "
"future version. Use `petab.Problem.from_yaml instead.",
Expand Down Expand Up @@ -154,12 +161,16 @@ def from_files(
observable_files, observables.get_observable_df) \
if observable_files else None

return Problem(model=model,
condition_df=condition_df,
measurement_df=measurement_df,
parameter_df=parameter_df,
observable_df=observable_df,
visualization_df=visualization_df)
return Problem(
model=model,
condition_df=condition_df,
measurement_df=measurement_df,
parameter_df=parameter_df,
observable_df=observable_df,
visualization_df=visualization_df,
extensions_config=extensions_config,
)


@staticmethod
def from_yaml(yaml_config: Union[Dict, Path, str]) -> 'Problem':
Expand Down Expand Up @@ -258,12 +269,15 @@ def from_yaml(yaml_config: Union[Dict, Path, str]) -> 'Problem':
observable_files, observables.get_observable_df) \
if observable_files else None

return Problem(condition_df=condition_df,
measurement_df=measurement_df,
parameter_df=parameter_df,
observable_df=observable_df,
model=model,
visualization_df=visualization_df)
return Problem(
condition_df=condition_df,
measurement_df=measurement_df,
parameter_df=parameter_df,
observable_df=observable_df,
model=model,
visualization_df=visualization_df,
extensions_config=yaml_config.get(EXTENSIONS, {})
)

@staticmethod
def from_combine(filename: Union[Path, str]) -> 'Problem':
Expand All @@ -281,10 +295,11 @@ def from_combine(filename: Union[Path, str]) -> 'Problem':
# other SWIG interfaces
try:
import libcombine
except ImportError:
except ImportError as e:
raise ImportError(
"To use PEtab's COMBINE functionality, libcombine "
"(python-libcombine) must be installed.")
"To use PEtab's COMBINE functionality, libcombine "
"(python-libcombine) must be installed.") from e


archive = libcombine.CombineArchive()
if archive.initializeFromArchive(str(filename)) is None:
Expand Down