grassp.tl.mgsa_to_cluster_distribution#
- mgsa_to_cluster_distribution(posterior, map_matrix=None, use_map=True, unknown_label='unknown', inactivity='product', drop_empty=True)[source]#
Convert a per-cluster MGSA posterior matrix into a soft-label distribution.
MGSA returns per-set marginal activity probabilities
q_t(each in[0, 1]; several compartments can be active simultaneously), whereas the soft-label seed used bysoft_cluster_annotation()is a per-cluster distribution over compartments (plus an explicitunknownclass) that sums to 1.The recommended mode (
use_map=True) uses the MAP active set as a filter and the marginals as weights: only compartments in the MAP (the single best joint configuration) receive mass, weighted by their marginals. This is important because a completely redundant subset term (e.g.Nucleolusinside an activeNucleus) has a marginal equal to the prior activation ratep— it is never in the MAP, so the filter removes that≈presidual that would otherwise inflate the distribution. Withuse_map=Falseall marginals are used (the residuals leak in).After (optional) MAP masking,
Q[c, t] ∝ q_tand the leftover mass goes tounknownvia the probability that no (admissible) compartment is active:inactivity="product"(default):unknown ∝ ∏_t (1 - q_t)(over the admissible sets; an independence approximation of “no set active”).inactivity="complement":unknown ∝ 1 - max_t q_t.
everything renormalized so each cluster row sums to 1. A confidently single-compartment cluster becomes peaked, a genuine multi-compartment MAP is split by its marginals (equal marginals -> uniform), and a cluster with an empty MAP / nothing active puts its mass on
unknown.- Parameters:
- posterior
DataFrame (cluster x compartment) matrix of MGSA marginal activity probabilities, as produced by
calculate_mgsa()(data.uns[..._posterior]).- map_matrix
DataFrame|None(default:None) (cluster x compartment) 0/1 indicator of the MAP active set per cluster (
data.uns[..._map]). Required whenuse_map=True.- use_map
bool(default:True) If
True(default) mask the marginals to the MAP active set before building the distribution, removing redundant-subset≈presiduals.- unknown_label
str|None(default:'unknown') Name of the background/unknown class, or
Noneto omit it.- inactivity
Literal['product','complement'] (default:'product') How to compute the unknown/inactivity mass (see above).
- drop_empty
bool(default:True) Drop compartments that never carry mass, tightening the vocabulary.
- posterior
- Return type:
- Returns:
- Qpandas.DataFrame
Row-stochastic (cluster x category) matrix,
unknownlast if present.- categorieslist of str
Column order, suitable as
seed_categoriesforcompetitive_propagation().