mechanochat.tools.contact_lr_communication#
- mechanochat.tools.contact_lr_communication(df_ligrec: DataFrame, sem: SEM2 | SEM3 | None = None, adata: AnnData | None = None, contact_key: str | None = 'contacts', lr_delimiter: str = '-', heteromeric_delimiter: str = '_', prefix: str = 'contact')[source]#
Contact-based ligand-receptor communication inference.
For every pair of contacting cells, the signal of a ligand-receptor pair is the product of the ligand expression in the sender and the receptor expression in the receiver, evaluated only on the cell-cell contact graph.
- Parameters:
df_ligrec (
pandas.DataFrame) – Dataframe of ligand-receptor pairs. Required columns: Ligand, Receptor, Pathway.sem (
SEM2,SEM3, optional) –SEM object providing .contact_matrix (cell-cell contact matrix) and .adata.
If sem.contact_matrix has not been computed, call sem.compute_contact().
If None, the contact matrix is read from adata.obsp[contact_key].
If both sem.adata and adata are provided, adata parameter takes precedence.
adata (
AnnData, optional) –AnnData object that the results are written into if sem is not provided
If sem is None, the contact matrix is read from adata.obsp[contact_key].
contact_key (
str, default'contacts') – Key of the contact matrix in adata.obsp, used only when sem is None.lr_delimiter (
str, default'-') – Delimiter used to construct ligand-receptor pair names in output.heteromeric_delimiter (
str, default'_') –Delimiter used to separate subunits in heteromeric complexes within df_ligrec.
For example, if a receptor complex is ‘TGFBR1_TGFBR2’, this parameter should be ‘_’.
prefix (
str, default'contact') – Prefix of the keys written to .obsp.
- Returns:
Sets the following fields in adata–.obsp[‘<prefix>_<ligand>-<receptor>’] : (nc, nc) csr_matrix of cell-cell communication mediated by <ligand>-<receptor>
.obsp[‘<prefix>_<pathway>’] : sum over the LR pairs of one pathway
.obsp[‘<prefix>_total’] : sum over all pathways
.obsm[‘sender_<prefix>_signal’] : (nc, n_signal) DataFrame of row sums, columns prefixed ‘s-’
.obsm[‘receiver_<prefix>_signal’] : (nc, n_signal) DataFrame of column sums, columns prefixed ‘r-’
.uns[‘<prefix>_signal_info’] : dict with keys ‘signal’, ‘pathway’, ‘total’, ‘db’
Notes
Orientation:
s[i, j]is the signal from senderito receiverj(row = sender, column = receiver).