Skip to content

Commit

Permalink
Doc: Clean up visualization examples
Browse files Browse the repository at this point in the history
* Don't use deprecated `Problem.from_files`
* Simplify by not loading all files separately
* Fix grammar / typos
* Add replicate plot example
  • Loading branch information
dweindl committed Dec 15, 2023
1 parent 91ba4dc commit 096f0bc
Show file tree
Hide file tree
Showing 3 changed files with 146 additions and 153 deletions.
159 changes: 92 additions & 67 deletions doc/example/example_visualization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
},
"outputs": [],
"source": [
"from petab.visualize import plot_with_vis_spec, plot_without_vis_spec"
"from petab.visualize import plot_problem, plot_without_vis_spec\n",
"from petab import Problem\n",
"from pathlib import Path\n",
"import petab"
]
},
{
Expand All @@ -38,12 +41,8 @@
},
"outputs": [],
"source": [
"folder = \"example_Isensee/\"\n",
"\n",
"data_file_path = folder + \"Isensee_measurementData.tsv\"\n",
"condition_file_path = folder + \"Isensee_experimentalCondition.tsv\"\n",
"visualization_file_path = folder + \"Isensee_visualizationSpecification.tsv\"\n",
"simulation_file_path = folder + \"Isensee_simulationData.tsv\""
"example_dir = Path(\"example_Isensee\")\n",
"petab_problem = Problem.from_yaml(example_dir / \"Isensee.yaml\")"
]
},
{
Expand All @@ -52,12 +51,7 @@
"metadata": {},
"outputs": [],
"source": [
"ax = plot_with_vis_spec(\n",
" visualization_file_path,\n",
" condition_file_path,\n",
" data_file_path,\n",
" simulation_file_path,\n",
")"
"plot_problem(petab_problem);"
]
},
{
Expand All @@ -73,9 +67,9 @@
"metadata": {},
"outputs": [],
"source": [
"ax_without_sim = plot_with_vis_spec(\n",
" visualization_file_path, condition_file_path, data_file_path\n",
")"
"plot_problem(\n",
" petab_problem, simulations_df=example_dir / \"Isensee_simulationData.tsv\"\n",
");"
]
},
{
Expand All @@ -91,49 +85,76 @@
"metadata": {},
"outputs": [],
"source": [
"ax = plot_with_vis_spec(\n",
" visualization_file_path,\n",
" condition_file_path,\n",
" simulations_df=simulation_file_path,\n",
")"
"petab_problem_with_measurements = Problem.from_yaml(\n",
" example_dir / \"Isensee.yaml\"\n",
")\n",
"petab_problem_with_measurements.measurement_df = None\n",
"plot_problem(\n",
" petab_problem_with_measurements,\n",
" simulations_df=example_dir / \"Isensee_simulationData.tsv\",\n",
");"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"If the measurement file contains replicates, the replicates can also be visualized individually:"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"petab_problem = Problem.from_yaml(example_dir / \"Isensee.yaml\")\n",
"petab_problem.visualization_df = petab.get_visualization_df(\n",
" example_dir / \"Isensee_visualizationSpecification_replicates.tsv\"\n",
")\n",
"plot_problem(\n",
" petab_problem, simulations_df=example_dir / \"Isensee_simulationData.tsv\"\n",
");"
],
"metadata": {
"collapsed": false
}
},
{
"cell_type": "markdown",
"source": [
"If both measurements and simulated data are available, they can be visualized using scatter plot:"
]
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"visualization_file_scatterplots = (\n",
" folder + \"Isensee_visualizationSpecification_scatterplot.tsv\"\n",
"petab_problem_scatterplot = Problem.from_yaml(example_dir / \"Isensee.yaml\")\n",
"petab_problem_scatterplot.visualization_df = petab.get_visualization_df(\n",
" example_dir / \"Isensee_visualizationSpecification_scatterplot.tsv\"\n",
")\n",
"ax = plot_with_vis_spec(\n",
" visualization_file_scatterplots,\n",
" condition_file_path,\n",
" data_file_path,\n",
" simulation_file_path,\n",
")"
]
"plot_problem(\n",
" petab_problem_scatterplot,\n",
" simulations_df=example_dir / \"Isensee_simulationData.tsv\",\n",
");"
],
"metadata": {}
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also call the plotting routine without the visualization specification file, but by passing a list of lists as `dataset_id_list`. Each sublist corresponds to a plot, and contains the datasetIds which should be plotted.\n",
"In this simply structured plotting routine, the independent variable will always be time."
]
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"datasets = [\n",
Expand All @@ -147,21 +168,26 @@
" \"JI09_160201_Drg453-452_CycNuc__Sp8_Br_cAMPS_AM\",\n",
" ],\n",
"]\n",
"ax_without_sim = plot_without_vis_spec(\n",
" condition_file_path, datasets, \"dataset\", data_file_path\n",
")"
]
"petab_problem = Problem.from_yaml(example_dir / \"Isensee.yaml\")\n",
"plot_without_vis_spec(\n",
" petab_problem.condition_df,\n",
" measurements_df=petab_problem.measurement_df,\n",
" grouping_list=datasets,\n",
" group_by=\"dataset\",\n",
");"
],
"metadata": {}
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let's look more closely at the plotting routines, if no visualization specification file is provided. If such a file is missing, PEtab needs to know how to group the data points. For this, three options can be used:\n",
"Let's look more closely at the plotting routines if no visualization specification file is provided. If such a file is missing, PEtab needs to know how to group the data points. For this, three options can be used:\n",
" * dataset_id_list\n",
" * sim_cond_id_lis\n",
" * observable_id_list\n",
"\n",
"Each of them is a list of lists. Again, each sublist is a plot and its content are either simulation condition IDs or observable IDs or the dataset IDs.\n",
"Each of them is a list of lists. Again, each sublist is a plot, and its content are either simulation condition IDs or observable IDs or the dataset IDs.\n",
"\n",
"We want to illustrate this functionality by using a simpler example, a model published in 2010 by Fujita et al."
]
Expand All @@ -172,9 +198,8 @@
"metadata": {},
"outputs": [],
"source": [
"data_file_Fujita = \"example_Fujita/Fujita_measurementData.tsv\"\n",
"condition_file_Fujita = \"example_Fujita/Fujita_experimentalCondition.tsv\"\n",
"\n",
"example_dir_fujita = Path(\"example_Fujita\")\n",
"petab_problem_fujita = Problem.from_yaml(example_dir_fujita / \"Fujita.yaml\")\n",
"# Plot 4 axes objects, plotting\n",
"# - in the first window all observables of the simulation condition 'model1_data1'\n",
"# - in the second window all observables of the simulation conditions 'model1_data2', 'model1_data3'\n",
Expand All @@ -188,13 +213,13 @@
" [\"model1_data6\"],\n",
"]\n",
"\n",
"ax = plot_without_vis_spec(\n",
" condition_file_Fujita,\n",
"plot_without_vis_spec(\n",
" petab_problem_fujita.condition_df,\n",
" sim_cond_id_list,\n",
" \"simulation\",\n",
" data_file_Fujita,\n",
" petab_problem_fujita.measurement_df,\n",
" plotted_noise=\"provided\",\n",
")"
");"
]
},
{
Expand All @@ -204,20 +229,20 @@
"outputs": [],
"source": [
"# Plot 3 axes objects, plotting\n",
"# - in the first window the observable 'pS6_tot' for all simulation conditions\n",
"# - in the second window the observable 'pEGFR_tot' for all simulation conditions\n",
"# - in the third window the observable 'pAkt_tot' for all simulation conditions\n",
"# - in the first window, the observable 'pS6_tot' for all simulation conditions\n",
"# - in the second window, the observable 'pEGFR_tot' for all simulation conditions\n",
"# - in the third window, the observable 'pAkt_tot' for all simulation conditions\n",
"\n",
"observable_id_list = [[\"pS6_tot\"], [\"pEGFR_tot\"], [\"pAkt_tot\"]]\n",
"\n",
"\n",
"ax = plot_without_vis_spec(\n",
" condition_file_Fujita,\n",
"plot_without_vis_spec(\n",
" petab_problem_fujita.condition_df,\n",
" observable_id_list,\n",
" \"observable\",\n",
" data_file_Fujita,\n",
" petab_problem_fujita.measurement_df,\n",
" plotted_noise=\"provided\",\n",
")"
");"
]
},
{
Expand All @@ -235,13 +260,13 @@
"observable_id_list = [[\"pS6_tot\"], [\"pEGFR_tot\"]]\n",
"\n",
"\n",
"ax = plot_without_vis_spec(\n",
" condition_file_Fujita,\n",
"plot_without_vis_spec(\n",
" petab_problem_fujita.condition_df,\n",
" observable_id_list,\n",
" \"observable\",\n",
" data_file_Fujita,\n",
" petab_problem_fujita.measurement_df,\n",
" plotted_noise=\"provided\",\n",
")"
");"
]
},
{
Expand All @@ -257,7 +282,7 @@
"metadata": {},
"outputs": [],
"source": [
"simu_file_Fujita = \"example_Fujita/Fujita_simulatedData.tsv\"\n",
"simu_file_Fujita = example_dir_fujita / \"Fujita_simulatedData.tsv\"\n",
"\n",
"sim_cond_id_list = [\n",
" [\"model1_data1\"],\n",
Expand All @@ -266,13 +291,13 @@
" [\"model1_data6\"],\n",
"]\n",
"\n",
"ax = plot_without_vis_spec(\n",
" condition_file_Fujita,\n",
"plot_without_vis_spec(\n",
" petab_problem_fujita.condition_df,\n",
" sim_cond_id_list,\n",
" \"simulation\",\n",
" simulations_df=simu_file_Fujita,\n",
" plotted_noise=\"provided\",\n",
")"
");"
]
},
{
Expand All @@ -283,13 +308,13 @@
"source": [
"observable_id_list = [[\"pS6_tot\"], [\"pEGFR_tot\"], [\"pAkt_tot\"]]\n",
"\n",
"ax = plot_without_vis_spec(\n",
" condition_file_Fujita,\n",
"plot_without_vis_spec(\n",
" petab_problem_fujita.condition_df,\n",
" observable_id_list,\n",
" \"observable\",\n",
" simulations_df=simu_file_Fujita,\n",
" plotted_noise=\"provided\",\n",
")"
");"
]
}
],
Expand Down
Loading

0 comments on commit 096f0bc

Please sign in to comment.