smftools.plotting.autocorrelation_plotting

smftools.plotting.autocorrelation_plotting#

Functions

plot_rolling_grid(rolling_dict, out_dir, site)

Plot rolling metrics in a grid, creating a separate paginated page-set for each metric.

plot_rolling_metrics(df[, out_png, title, ...])

Plot NRL and SNR vs window center from the dataframe returned by rolling_autocorr_metrics.

plot_spatial_autocorr_grid(adata, out_dir[, ...])

Plot a grid of mean spatial autocorrelations per sample × (site_type × reference).

smftools.plotting.autocorrelation_plotting.plot_spatial_autocorr_grid(adata, out_dir, site_types=('GpC', 'CpG', 'any_C'), sample_col='Sample', reference_col='Reference_strand', window=25, rows_per_fig=6, dpi=160, filename_prefix='autocorr_grid', include_combined_column=True, references=None, annotate_periodicity=True, counts_key_suffix='_counts', normalization_method='pearson', plot_min_count=10)#

Plot a grid of mean spatial autocorrelations per sample × (site_type × reference). Expects preprocessing to have created:

  • adata.obsm[f"{site}_spatial_autocorr"] -> (n_molecules, n_lags) float32

  • adata.obsm[f"{site}_spatial_autocorr_counts"] -> (n_molecules, n_lags) int32 (optional)

  • adata.uns[f"{site}_spatial_autocorr_lags"] -> 1D lags array

  • adata.uns[f"{site}_spatial_periodicity_metrics_by_group"] -> dict keyed by (sample, ref)

If per-group metrics are missing and analyze_autocorr_matrix is importable, the function will fall back to running the analyzer for that group (slow) and cache the result into adata.uns.

smftools.plotting.autocorrelation_plotting.plot_rolling_metrics(df, out_png=None, title=None, figsize=(10, 3.5), dpi=160, show=False)#

Plot NRL and SNR vs window center from the dataframe returned by rolling_autocorr_metrics. If out_png is None, returns the matplotlib Figure object; otherwise saves PNG and returns path.

smftools.plotting.autocorrelation_plotting.plot_rolling_grid(rolling_dict, out_dir, site, metrics=('nrl_bp', 'snr', 'xi'), sample_order=None, reference_order=None, rows_per_page=6, cols_per_page=None, dpi=160, figsize_per_panel=(3.5, 2.2), per_metric_ylim=None, filename_prefix='rolling_grid', metric_display_names=None)#

Plot rolling metrics in a grid, creating a separate paginated page-set for each metric.

Parameters#

rolling_dictdict

mapping (sample, ref) -> DataFrame (must contain 'center' and metric columns). Keys may use None for combined/"all" reference.

out_dirstr

Directory to write output figures into.

sitestr

Site type label, used in output filenames/titles.

metricssequence[str]

list of metric column names to plot. One page-set per metric will be written.

sample_order, reference_orderlist or None

optional lists for ordering (values as in keys).

rows_per_pageint

number of sample rows per page.

cols_per_pageint | None

number of columns per page (defaults to number of unique refs).

figsize_per_paneltuple

(w,h) for each subplot panel.

per_metric_ylimdict or None

optional mapping metric -> (ymin,ymax) to force consistent y-limits for that metric. If absent, y-limits are autoscaled per page.

filename_prefixstr

Prefix for output figure filenames.

metric_display_namesdict or None

optional mapping metric -> friendly label for y-axis/title.

Returns#

pages_by_metric : dict mapping metric -> [out_png_paths]