Plotting & reduction#
Heatmaps, top-H-bond bar plot, aggregated heatmap, and bond statistics bar plots.
- phenoms.plotting.plot_heatmap(pivot_table, file_name, save_path=None, figsize=(12, 8))[source]#
H-bond occupation over time (bond labels vs frames). Optionally save to file.
- phenoms.plotting.plot_heatmap_with_legend(pivot_table, title, save_path=None, figsize=(12, 8))[source]#
Same as plot_heatmap but with a legend for Absent (0) / Present (1).
- phenoms.plotting.plot_top_hbonds(all_pivot_tables, threshold, sub_frames=None, save_path=None)[source]#
Bar chart of top H-bonds by average lifetime (presence fraction > threshold).
- phenoms.plotting.plot_bond_lifetimes_with_error_bars(mean_lifetimes, std_lifetimes, title='Average Lifetime of Hydrogen Bonds with Standard Deviation (Threshold = 50%)', save_path=None)[source]#
Bar plot of mean bond lifetimes with std error bars across replicates.
- phenoms.plotting.plot_break_frequencies_with_error_bars(mean_break_frequencies, std_break_frequencies, title='Frequency of Breaks of Hydrogen Bonds with Standard Deviation', save_path=None)[source]#
Bar plot of mean break frequency with std error bars across replicates.
- phenoms.plotting.plot_aggregated_heatmap(all_pivot_tables, save_path=None, figsize=(12, 8), region_str='Entire protein')[source]#
Average presence of each bond across replicates (one row heatmap).
- phenoms.plotting.suggest_difference_threshold_autocorr(comparison_df, y_column='Difference_clipped', kappa=1.96)[source]#
Estimate an absolute-difference threshold from sequence structure (lag-1 autocorrelation).
Treats the per-residue difference series (in table order) as roughly AR(1); the innovation standard deviation scales local noise. Returns
clip(kappa * sigma_innovation, 0.05, 0.35).Use with
plot_difference(..., diff_threshold_mode="autocorr")or call directly.
- phenoms.plotting.plot_difference(comparison_df, x_column='Residue Number', y_column='Difference_clipped', title='Change in Protection (Set B − Set A)', diff_threshold=0.2, diff_threshold_mode='manual', impute_small_differences=True, show_labels=True, interpolate=True, interpolation_points=900, autocorr_kappa=1.96, save_path=None, figsize=(12, 8), return_meta=False)[source]#
Line plot of per-donor difference vs residue.
By default
y_column="Difference_clipped"(values in [-1, 1]); usey_column="Difference"for raw donor deltas.- Parameters:
diff_threshold (float or None) – Used when
diff_threshold_mode="manual": residues withabs(y)above this get text labels. When imputing, plotted y is set to 0 whereabs(y)< threshold. Default is0.2(20% delta).diff_threshold_mode (str) –
"manual"— usediff_threshold."autocorr"— threshold fromsuggest_difference_threshold_autocorr()(diff_thresholdignored except if autocorr fails).impute_small_differences (bool) – If True (default), plot values with
abs(y)below the effective threshold as 0 (smoothed / noise-suppressed line). If False, plot raw differences; labels still use the effective threshold when set.show_labels (bool) – If True (default), add red residue-number text for residues with
abs(difference)>= effective threshold.interpolate (bool) – If True, draw a dashed smoothed line (visual only) using interpolation. This does not change the underlying data or thresholding.
interpolation_points (int) – Number of x points to draw the interpolated line.
autocorr_kappa (float) – Passed to autocorr threshold only.
return_meta (bool) – If True, return dict with
effective_threshold,diff_threshold_mode,impute_small_differences.
PCA, t-SNE, Isomap on aggregated replicate H-bond data.
Use with one simulation set (replicates as points, colored by replicate or custom labels) or two sets (ComparisonSet: two groups).
- phenoms.dimensionality_reduction.aggregate_replicate_data(pivot_tables_list)[source]#
One row per replicate: mean occupancy per bond across frames. Shape (n_replicates, n_bonds). Fill missing bonds with 0.
- phenoms.dimensionality_reduction.run_pca(aggregated_data, n_components=2)[source]#
Standardize and run PCA. Returns (scores, explained_variance_ratio).
- phenoms.dimensionality_reduction.run_tsne(aggregated_data, perplexity=2, random_state=42)[source]#
Standardize and run t-SNE. Returns 2D scores.
- phenoms.dimensionality_reduction.run_isomap(aggregated_data, n_neighbors=5, n_components=2)[source]#
Standardize and run Isomap. Returns 2D scores.
- phenoms.dimensionality_reduction.plot_manifold(scores, group_labels, replicate_labels=None, title='PCA', palette=None, ax=None)[source]#
Scatter plot of 2D manifold (PCA/t-SNE/Isomap) with points colored by group.
- Parameters:
scores (np.ndarray) – (n_replicates, 2).
group_labels (list or array) – One label per replicate (e.g. True/False for ligand, or “no_lig”/”lig”).
replicate_labels (list or None) – Optional text label per point.
title (str)
palette (dict or None) – Mapping group_label -> color.
ax (matplotlib axes or None)
- phenoms.dimensionality_reduction.run_manifold_suite(pivot_tables, group_labels, perplexity=2, n_neighbors=5, random_state=42, plot=True)[source]#
Run PCA, t-SNE, and Isomap on the same aggregated matrix (glassfrog-style workflow).
- Parameters:
pivot_tables (list of pd.DataFrame) – Bond × frame pivots (one per replicate).
group_labels (list) – One label per replicate (e.g. replicate name, or True/False for two conditions).
perplexity – Passed to t-SNE / Isomap.
n_neighbors – Passed to t-SNE / Isomap.
random_state – Passed to t-SNE / Isomap.
plot (bool) – If True, show three scatter plots (PCA, t-SNE, Isomap).
- Returns:
dict with keys ‘pca’ (scores, var_ratio), ‘tsne’ (scores), ‘isomap’ (scores),
and ‘aggregated_data’ (np.ndarray).
Pivot tables, bond label sorting, and bond statistics (lifetime, break frequency).
- phenoms.analysis.extract_residue_numbers(bond_label)[source]#
Parse ‘Residue1 – Residue2’ into (res1, res2) as integers.
- phenoms.analysis.create_pivot_table(hbonds_df, bond_labels_sorted)[source]#
Pivot table: rows = bond labels (consistent order), columns = frames, values = count (0/1+).
- phenoms.analysis.calculate_bond_statistics(hbonds_pivot, threshold)[source]#
For bonds with mean occupancy > threshold, compute average lifetime and break frequency.
- Parameters:
hbonds_pivot (pd.DataFrame) – Rows = bond labels, columns = frames, values = 0/1 (or counts).
threshold (float) – Keep only bonds with mean(row) > threshold.
- Returns:
average_bond_lifetimes (pd.Series)
break_frequencies (pd.Series)