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 petab.Problem.__str__ #178

Merged
merged 2 commits into from
Sep 6, 2022
Merged
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
25 changes: 25 additions & 0 deletions petab/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,31 @@ def __setattr__(self, name, value):
else:
super().__setattr__(name, value)

def __str__(self):
model = f"with model ({self.model})" if self.model else "without model"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Model has no __str__, what gets printed here?

Copy link
Member Author

@dweindl dweindl Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently the not so informative default __repr__. The plan would be to add something more meaningful there as well.

conditions = f"{self.condition_df.shape[0]} conditions" \
if self.condition_df is not None else "without conditions table"

observables = f"{self.observable_df.shape[0]} observables" \
if self.observable_df is not None else "without observables table"

measurements = f"{self.measurement_df.shape[0]} measurements" \
if self.measurement_df is not None \
else "without measurements table"

if self.parameter_df is not None:
num_estimated_parameters = sum(self.parameter_df[ESTIMATE] == 1) \
if ESTIMATE in self.parameter_df \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ESTIMATE is a required column

Copy link
Member Author

@dweindl dweindl Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. Not sure how much we want to assume/require correctness here. Should it just fail if this is missing? Should we validate in __str__?
Might be more convenient to allow for some slack, if this is used during assembling a Problem. Similar to libsbml where one is allowed to create invalid models.

else self.parameter_df.shape[0]
parameters = f"{num_estimated_parameters} estimated parameters"
else:
parameters = "without parameter_df table"

return (
f"PEtab Problem {model}, {conditions}, {observables}, "
f"{measurements}, {parameters}"
)

@staticmethod
def from_files(
sbml_file: Union[str, Path] = None,
Expand Down