smftools.tools.position_stats#
Functions
|
Perform methylation vs. |
|
Compute per-(sample, ref) positionwise matrices for selected methods. |
|
Plot grids of matrices for each method with pagination and rotated sample-row labels. |
Fill NaNs with random values in-place. |
|
|
Context manager to patch joblib to update a tqdm progress bar. |
- smftools.tools.position_stats.random_fill_nans(X)#
Fill NaNs with random values in-place.
- Parameters:
X (
ndarray) -- Input array with NaNs.- Returns:
Array with NaNs replaced by random values.
- Return type:
- smftools.tools.position_stats.calculate_relative_risk_on_activity(adata, sites, alpha=0.05, groupby=None, index_col_suffix=None)#
Perform methylation vs. activity analysis within each group.
- Parameters:
adata (
AnnData) -- Annotated data matrix.sites (
Sequence[str]) -- Site keys (e.g.,["GpC_site", "CpG_site"]).alpha (
float(default:0.05)) -- FDR threshold for significance.groupby (
Union[str,Sequence[str],None] (default:None)) -- Obs column(s) to group by.index_col_suffix (
str|None(default:None)) -- If set, useadata.var[f"{ref}_{index_col_suffix}"]forGenomic_Positioninstead ofvar_names(e.g."reindexed"), so reindexing_offsets/reindexing_invert are reflected in the reported position.
- Returns:
Mapping of reference -> group label ->
(results_df, sig_df).- Return type:
- smftools.tools.position_stats.tqdm_joblib(tqdm_object)#
Context manager to patch joblib to update a tqdm progress bar.
- smftools.tools.position_stats.compute_positionwise_statistics(adata, layer, methods=('pearson',), sample_col='Barcode', ref_col='Reference_strand', site_types=None, encoding='signed', output_key='positionwise_result', min_count_for_pairwise=10, max_threads=None, reverse_indices_on_store=False, min_position_valid_fraction=None, index_col_suffix=None)#
Compute per-(sample, ref) positionwise matrices for selected methods.
- Parameters:
adata (
AnnData) -- AnnData object to analyze.layer (
str) -- Layer name to use for statistics.methods (
Sequence[str] (default:('pearson',))) -- Methods to compute (e.g.,"pearson").sample_col (
str(default:'Barcode')) -- Obs column containing sample identifiers.ref_col (
str(default:'Reference_strand')) -- Obs column containing reference identifiers.site_types (
Optional[Sequence[str]] (default:None)) -- Optional site types to subset positions.encoding (
str(default:'signed')) --"signed"or"binary"encoding.output_key (
str(default:'positionwise_result')) -- Key prefix for results stored inadata.uns.min_count_for_pairwise (
int(default:10)) -- Minimum counts for pairwise comparisons.max_threads (
Optional[int] (default:None)) -- Maximum number of threads.reverse_indices_on_store (
bool(default:False)) -- Whether to reverse indices on output storage.min_position_valid_fraction (
Optional[float] (default:None)) -- If set, exclude positions where the{ref}_valid_fractionvar column is below this threshold (same filtering as spatial clustermaps).index_col_suffix (
Optional[str] (default:None)) -- If set, useadata.var[f"{ref}_{index_col_suffix}"]for DataFrame labels instead ofvar_names(e.g."reindexed").
- Return type:
- smftools.tools.position_stats.plot_positionwise_matrices(adata, methods, cmaps=None, sample_col='Barcode', ref_col='Reference_strand', output_dir=None, vmin=None, vmax=None, figsize_per_cell=(3.5, 3.5), dpi=160, cbar_shrink=0.9, output_key='positionwise_result', show_colorbar=True, flip_display_axes=False, rows_per_page=6, sample_label_rotation=90.0, n_ticks=10, tick_fontsize=7, tick_rotation=90.0)#
Plot grids of matrices for each method with pagination and rotated sample-row labels.
- Parameters:
rows_per_page (-) -- how many sample rows per page/figure (pagination)
sample_label_rotation (-) -- rotation angle (deg) for the sample labels placed in the left margin.
- Returns:
dict mapping method -> list of saved filenames (empty list if figures were shown).