Skip to content

Commit fadde0e

Browse files
Fixed bugs and added features to analyzePerturbations; began perturbation_analysis.ipynb
1 parent 9143ce7 commit fadde0e

2 files changed

Lines changed: 137 additions & 4 deletions

File tree

notebooks/perturbation_analysis.ipynb

Lines changed: 124 additions & 0 deletions
Large diffs are not rendered by default.

src/system_discovery.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,8 @@ def analyzePerturbations(
417417
figsize: tuple[float, float] | None = None,
418418
poly_degree: int = 1,
419419
frac_scatter_skip: float = 0.2,
420+
plot_species_names: list[str] | None = None,
421+
subtitle: str = "Perturbation Analysis",
420422
is_plot: bool = True,
421423
) -> pd.DataFrame:
422424
"""Fit on training_df; evaluate timecourse accuracy on perturbed timecourses.
@@ -454,6 +456,8 @@ def analyzePerturbations(
454456
Scatter-plot density: num_skip = max(1, int(n_points * frac_scatter_skip)).
455457
is_plot : bool
456458
Show a trajectory comparison figure when True.
459+
plot_species_names : list[str] | None
460+
List of species to plot. If None, all species are plotted.
457461
458462
Returns
459463
-------
@@ -475,6 +479,8 @@ def analyzePerturbations(
475479
num_point = len(training_df)
476480

477481
disc = cls(training_df, threshold=threshold, poly_degree=poly_degree)
482+
if plot_species_names is None:
483+
plot_species_names = disc.species_names
478484
disc.fit()
479485

480486
plot_records: list[
@@ -521,16 +527,19 @@ def analyzePerturbations(
521527
model_accuracy_df = pd.DataFrame(records)
522528
# Construct plots
523529
if is_plot and plot_records:
524-
n = len(disc.species_names)
530+
n = len(plot_species_names)
525531
ncols = min(n, 3)
526532
nrows = (n + ncols - 1) // ncols
527533
if figsize is None:
528534
figsize = (5 * ncols, 3.5 * nrows)
529535
fig, axes = plt.subplots(nrows, ncols, figsize=figsize, squeeze=False)
530-
fig.suptitle("Perturbation Analysis", fontsize=14, fontweight="bold")
536+
fig.suptitle(subtitle, fontsize=14, fontweight="bold")
531537
num_skip = max(1, int(num_point * frac_scatter_skip))
532-
for sp_idx, sp_name in enumerate(disc.species_names):
533-
ax_row, ax_col = divmod(sp_idx, ncols)
538+
for pos_idx, sp_name in enumerate(plot_species_names):
539+
sp_idx = disc.species_names.index(sp_name)
540+
if not sp_name in plot_species_names:
541+
continue
542+
ax_row, ax_col = divmod(pos_idx, ncols)
534543
ax = axes[ax_row][ax_col]
535544
sp_col = disc.species_cols[sp_idx]
536545
for p_idx, (p, test_df, pred_df, accuracy_ser) in enumerate(plot_records):

0 commit comments

Comments
 (0)