Skip to content

Commit 9c1d057

Browse files
Examples (#218)
* Added immediate possibility to load problem completely * replaced with proper example needed for tutorial. * Updated files * removed unneccesary comments
1 parent 210d5fd commit 9c1d057

File tree

19 files changed

+172
-7
lines changed

19 files changed

+172
-7
lines changed

MANIFEST.in

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
include example/*.csv
2-
include example/*.tsv
3-
include example/*.xml
1+
include example/*/*.csv
2+
include example/*/*.tsv
3+
include example/*/*.xml
4+
include example/*/*.yaml
5+
include example/*/*.yml
46
exclude .git_archival.txt
57
exclude .gitattributes

example/data_matrix.csv

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
time obs_A obs_B
2+
0 10.1 0.1
3+
2 8.0 2.1
4+
4 6.8 3.4
5+
6 5.6 4.6
6+
8 4.4 5.4
7+
10 3.8 6.4
8+
12 3.1 7.2
9+
15 2.3 7.9
10+
18 1.6 8.2
11+
20 1.3 8.5

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ include-package-data = true
5656

5757
[tool.setuptools.package-data]
5858
"petab_gui.assets" = ["PEtab.png"]
59+
"petab_gui.example" = ["*/*.yaml", "*/*.yml", "*/*.tsv", "*/*.csv", "*/*.xml", "*/*.sbml"]
5960

6061
[tool.setuptools_scm]
6162

src/petab_gui/controllers/mother_controller.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,23 @@ def setup_actions(self):
308308
actions["add"].triggered.connect(
309309
partial(self.open_file, mode="append")
310310
)
311+
# Load Examples
312+
actions["load_example_boehm"] = QAction(
313+
qta.icon("mdi6.book-open-page-variant"),
314+
"Load Example: Boehm",
315+
self.view,
316+
)
317+
actions["load_example_boehm"].triggered.connect(
318+
partial(self.load_example, "Boehm")
319+
)
320+
actions["load_example_simple"] = QAction(
321+
qta.icon("mdi6.book-open-page-variant"),
322+
"Load Example: Simple Conversion",
323+
self.view,
324+
)
325+
actions["load_example_simple"].triggered.connect(
326+
partial(self.load_example, "Simple_Conversion")
327+
)
311328
# Save
312329
actions["save"] = QAction(
313330
qta.icon("mdi6.content-save-all"), "&Save As...", self.view
@@ -1085,6 +1102,64 @@ def new_file(self):
10851102
self.view.plot_dock.plot_it()
10861103
self.unsaved_changes_change(False)
10871104

1105+
def load_example(self, example_name):
1106+
"""Load an internal example PEtab problem.
1107+
1108+
Parameters
1109+
----------
1110+
example_name : str
1111+
Name of the example subdirectory (e.g., "Boehm", "Simple_Conversion").
1112+
1113+
Finds and loads the example dataset from the package directory.
1114+
No internet connection required - the example is bundled with the package.
1115+
"""
1116+
try:
1117+
# Use importlib.resources to access packaged example files
1118+
from importlib.resources import as_file, files
1119+
1120+
example_files = files("petab_gui.example")
1121+
1122+
# Check if the example package exists
1123+
if not example_files.is_dir():
1124+
error_msg = (
1125+
"Could not find the example dataset. "
1126+
"The example folder may not be properly installed."
1127+
)
1128+
self.logger.log_message(error_msg, color="red")
1129+
QMessageBox.warning(self.view, "Example Not Found", error_msg)
1130+
return
1131+
1132+
# Get the problem.yaml file path for the specified example
1133+
yaml_file = example_files.joinpath(example_name, "problem.yaml")
1134+
1135+
with as_file(yaml_file) as yaml_path:
1136+
if not yaml_path.exists():
1137+
error_msg = f"Example '{example_name}' not found or problem.yaml file is missing."
1138+
self.logger.log_message(error_msg, color="red")
1139+
QMessageBox.warning(
1140+
self.view, "Example Invalid", error_msg
1141+
)
1142+
return
1143+
1144+
# Load the example
1145+
self.logger.log_message(
1146+
f"Loading '{example_name}' example dataset...",
1147+
color="blue",
1148+
)
1149+
self.open_yaml_and_load_files(str(yaml_path))
1150+
1151+
except ModuleNotFoundError as e:
1152+
error_msg = (
1153+
"Example dataset not found. It may not be installed properly. "
1154+
f"Error: {str(e)}"
1155+
)
1156+
self.logger.log_message(error_msg, color="red")
1157+
QMessageBox.warning(self.view, "Example Not Found", error_msg)
1158+
except Exception as e:
1159+
error_msg = f"Failed to load example: {str(e)}"
1160+
self.logger.log_message(error_msg, color="red")
1161+
QMessageBox.critical(self.view, "Error Loading Example", error_msg)
1162+
10881163
def check_model(self):
10891164
"""Check the consistency of the model. And log the results."""
10901165
capture_handler = CaptureLogHandler()

0 commit comments

Comments
 (0)