class locat.locat_condensed.LOCAT(adata: AnnData, cell_embedding: ndarray, k: int, n_bootstrap_inits: int, show_progress=False, wgmm_dtype: str = 'same', knn=None, knn_k: int | None = None, knn_mode: str = 'binary')[source]#

Bases: object

The main LOCAT class

Attributes:
X
cell_dist
min_dist

Methods

background_n_components_init([...])

bic_score(gmm1, gene_prior)

calc_lratio(f1, ix, log_bkg_pdf, sample_size)

Per-cell LRT contribution on expressing cells:

estimate_null_parameters([fractions, n_reps])

Estimate LTST null mean/std as a function of expression fraction p using random pseudo-genes: - pick random expressing cells at frequency p - fit signal GMM with the same pipeline as real genes - compute LTST exactly as in gmm_scan_new

get_genes_indices(genes)

knn()

Return a KNN adjacency/connectivity matrix.

localization_pval_dep_scan(gmm1, gene_prior, *)

set_knn(knn)

Store a precomputed KNN graph.

auto_bkg_components

auto_n_components

background_pdf

fit_wgmm

get_gene_prior

gmm_local_pvalue

gmm_local_scan

gmm_loglikelihoodtest

gmm_scan_new

random_pdf

reg_covar

show_progress

signal_gmm

signal_pdf

property X[source]#
auto_bkg_components(n_points, weights_transform=None)[source]#
auto_n_components(coords, weights=None, indices=None, min_points_fraction=0.95)[source]#
background_n_components_init(weights_transform=None, min_points=10, n_reps=30)[source]#
background_pdf(n_comp=None, reps=10, total_counts_weight=True, weights_transform=None, force_refresh=False)[source]#
bic_score(gmm1, gene_prior)[source]#
static calc_lratio(f1, ix, log_bkg_pdf, sample_size, eps=1e-300)[source]#
Per-cell LRT contribution on expressing cells:

-2 * sum_{i in ix} ( log f0(i) - log f1(i) ) / sample_size

property cell_dist: ndarray[source]#
estimate_null_parameters(fractions=None, n_reps=50)[source]#

Estimate LTST null mean/std as a function of expression fraction p using random pseudo-genes:

  • pick random expressing cells at frequency p

  • fit signal GMM with the same pipeline as real genes

  • compute LTST exactly as in gmm_scan_new

fit_wgmm(n_comp, weights=None) WGMM[source]#
get_gene_prior(i_gene, weights_transform)[source]#
get_genes_indices(genes)[source]#
gmm_local_pvalue(genes=None, n_comp=None, weights_transform=None, alpha=0.05, n_inits=100, normalize_knn=True, eps=1e-12)[source]#
gmm_local_scan(genes=None, weights_transform=None, zscore_thresh=None, max_freq=0.5)[source]#
gmm_loglikelihoodtest(genes=None, weights_transform=None, max_freq=0.5)[source]#
gmm_scan_new(genes=None, weights_transform=None, zscore_thresh=None, max_freq=0.5, verbose=False, n_bootstrap_inits=None, rc_c_values=None, rc_min_p0_abs=0.1, rc_min_expected=30, rc_min_abs_deficit=0.02, rc_n_trials_cap=500, rc_soft_bound=1.0, rc_n_eff_scale=0.5, rc_p_floor=1e-12, rc_rho_bb=0.02, rc_weight_mode='amount', rc_eps_rel=0.01)[source]#
knn()[source]#

Return a KNN adjacency/connectivity matrix.

If a KNN was provided at init (or via set_knn), returns it. Otherwise computes one from the embedding.

localization_pval_dep_scan(gmm1, gene_prior, *, c_values=None, soft_bound=None, min_p0_abs=0.1, min_expected=30, min_abs_deficit=0.02, n_trials_cap=500, weight_mode='amount', p_floor=1e-12, n_eff_scale=1.0, rho_bb=0.2, eps_rel=0.01, debug=False, debug_store_masks=False, debug_max_cells=5000)[source]#
property min_dist: float[source]#
random_pdf(weights, n_comp=None, n_inits=300, buckets=None)[source]#
reg_covar(sample_size=None)[source]#
set_knn(knn)[source]#

Store a precomputed KNN graph.

Accepts:
  • scipy sparse (csr/csc/coo) adjacency or connectivities

  • dense numpy array adjacency/connectivities

Expected shape: (n_cells, n_cells)

show_progress(show_progress=True)[source]#
signal_gmm(weights, n_comp=None)[source]#
signal_pdf(weights, n_comp=None)[source]#
class locat.locat_condensed.LOCATNullDistribution(mean_func, std_func)[source]#

Bases: object

Attributes:
mean
std

Methods

from_estimates

to_zscore

classmethod from_estimates(p, means, stds)[source]#
mean = None[source]#
std = None[source]#
to_zscore(raw_score, p)[source]#
locat.locat_condensed.cauchy_combine(pvals, weights=None)[source]#

Robust p-value combiner for dependent tests (Cauchy combination). Liu & Xie (2020).

locat.locat_condensed.localization_pvalue_nn_func(x1, f1, f0, nn)[source]#

Sparse-safe rewrite of the original localization_pvalue_nn_func.

Preserves:
  • i1/obs1/obs2 definitions

  • n and o as neighborhood (weighted) counts / signed balance

  • f2 weighting for global mu_hat, p1, p0

  • effective_n, sd_hat

  • per-cell p via normal_sf(o[i], mu_hat, sd_hat[i])

Works for:
  • nn sparse CSR/CSC/COO

  • nn dense numpy array

locat.locat_condensed.ltst_score_func(f0, f1, p)[source]#
locat.locat_condensed.normal_sf(x, mu, sigma)[source]#

Normal survival function SF = 1 - CDF, numba-jitted.

locat.locat_condensed.sens_score_func(f0, f1, i)[source]#
locat.locat_condensed.smooth_qvals(x)[source]#
locat.locat_condensed.summarize_rc_debug(cs_res, top=8)[source]#

Convenience helper to inspect per-threshold diagnostics from localization_pval_dep_scan(…, debug=True).