Skip to content

DIALOGUE

DIALOGUE: multicellular programmes, genes that are cell type specific but whose activity covaries across the samples the cell types share.

One function does the work. dialogue takes an experiment, the obs columns that hold the cell types and the samples, and a per-cell-type feature frame, and returns a DialogueResult. Read it with get_results (the programme table) or straight off its fields: signatures for the permissive and strict gene lists, scores for the per-cell programme scores, refit_fidelity for how well each cell type's score survived the final refit. Programmes are 0-based: mcp_00 is programme 0.

What lands where. Nothing is written to the experiment. The result is returned, and the run reads the normalised layer of the kept cells only. SingleCells, SingleCellsSubset and MetaCells are all accepted; for meta cells the ids are meta_cell_id and you build them within samples, or a meta cell has no well-defined sample.

Features are yours to make. Per cell type, a frame of cell_id plus at least two numeric columns, rows matched to cells by id. Compute them within the cell type (subset, find_hvg, calculate_pca): slicing a global PCA hands every cell type the same axis. Genes for the signatures default to the HVGs, so run bv.pp.find_hvg first or pass gene_ids.

sim = bv.io.generate_dialogue_test_data()
sc = bv.io.load_csr("dialogue_demo", sim.counts.scipy_csr(), sim.obs, sim.var)
bv.pp.find_hvg(sc, hvg_no=200)

res = bv.dialogue.dialogue(
    sc,
    "cell_grp",
    "sample_id",
    sim.features,
    pmd_params=bv.params.DialoguePmdParams(k=2, n_permutations=100),
)
bv.dialogue.get_results(res)
res.signatures.filter(res.signatures["list"] == "strict")

Gotchas. The design decides whether it runs at all: at least two cell types and five samples present in every one of them, with enough cells per sample per cell type to clear abn_c. It errors below that. k is the number of programmes you ask for, with no sweep to pick it, and n_permutations sets the floor of the empirical p-value. Without quality_col the cell quality covariate is the z-scored log library size, which needs lib_size in obs.

References: Jerby-Arnon & Regev, Nat. Biotechnol., 2022.

Worked through in Multicellular programmes with DIALOGUE.

Running DIALOGUE

DIALOGUE: multicellular programmes, genes that are cell type specific but whose activity covaries across the samples the cell types share.

One function does the work. dialogue takes an experiment, the obs columns that hold the cell types and the samples, and a per-cell-type feature frame, and returns a DialogueResult. Read it with get_results (the programme table) or straight off its fields: signatures for the permissive and strict gene lists, scores for the per-cell programme scores, refit_fidelity for how well each cell type's score survived the final refit. Programmes are 0-based: mcp_00 is programme 0.

What lands where. Nothing is written to the experiment. The result is returned, and the run reads the normalised layer of the kept cells only. SingleCells, SingleCellsSubset and MetaCells are all accepted; for meta cells the ids are meta_cell_id and you build them within samples, or a meta cell has no well-defined sample.

Features are yours to make. Per cell type, a frame of cell_id plus at least two numeric columns, rows matched to cells by id. Compute them within the cell type (subset, find_hvg, calculate_pca): slicing a global PCA hands every cell type the same axis. Genes for the signatures default to the HVGs, so run bv.pp.find_hvg first or pass gene_ids.

sim = bv.io.generate_dialogue_test_data()
sc = bv.io.load_csr("dialogue_demo", sim.counts.scipy_csr(), sim.obs, sim.var)
bv.pp.find_hvg(sc, hvg_no=200)

res = bv.dialogue.dialogue(
    sc,
    "cell_grp",
    "sample_id",
    sim.features,
    pmd_params=bv.params.DialoguePmdParams(k=2, n_permutations=100),
)
bv.dialogue.get_results(res)
res.signatures.filter(res.signatures["list"] == "strict")

Gotchas. The design decides whether it runs at all: at least two cell types and five samples present in every one of them, with enough cells per sample per cell type to clear abn_c. It errors below that. k is the number of programmes you ask for, with no sweep to pick it, and n_permutations sets the floor of the empirical p-value. Without quality_col the cell quality covariate is the z-scored log library size, which needs lib_size in obs.

References: Jerby-Arnon & Regev, Nat. Biotechnol., 2022.

dialogue

dialogue(
    sc: ScOrMc,
    cell_type_col: str,
    sample_col: str,
    features: Mapping[str, DataFrame],
    *,
    quality_col: str | None = None,
    gene_ids: Sequence[str] | None = None,
    pmd_params: DialoguePmdParams | None = None,
    hlm_params: DialogueHlmParams | None = None,
    refine_params: DialogueRefineParams | None = None,
    verbose: Verbose = True,
) -> DialogueResult

Multicellular programmes.

Three stages. Each cell type's features are collapsed to one row per sample and put through a sparse multi-CCA, giving every programme a weight vector per cell type plus a provisional gene signature. For every ordered pair of cell types and every candidate gene, a mixed model asks whether a cell's programme score tracks the partner cell type's expression of that gene in the same sample. The partners are then meta-analysed and the scores refit onto the surviving genes by non-negative least squares. Reads the normalised counts only.

The method needs at least two cell types, five samples present in every one of them, and enough cells per sample per cell type to clear abn_c. For meta cells, build them within samples, or the sample of a meta cell is not well-defined.

Parameters:

Name Type Description Default
sc ScOrMc

The kept cells of the experiment, a subset, or meta cells.

required
cell_type_col str

obs column with the cell type labels.

required
sample_col str

obs column with the sample labels; the random intercept of stage two is over these.

required
features Mapping[str, DataFrame]

Per analysed cell type (the keys, in order) a frame of cell_id (meta_cell_id for meta cells) plus at least two numeric feature columns covering that cell type's cells.

required
quality_col str | None

obs column with the cell quality covariate. None uses the z-scored log1p library size (lib_size in obs; the summed raw counts for meta cells).

None
gene_ids Sequence[str] | None

Genes to build the signatures from. None uses the HVGs.

None
pmd_params DialoguePmdParams | None

Stage one parameters. None uses the defaults.

None
hlm_params DialogueHlmParams | None

Stage two parameters. None uses the defaults.

None
refine_params DialogueRefineParams | None

Stage three parameters. None uses the defaults.

None
verbose Verbose

0 (False) silent, 1 (True) progress, 2 extra detail where the method has it.

True

Returns:

Type Description
DialogueResult

The DialogueResult.

Raises:

Type Description
ValueError

On a design DIALOGUE cannot run on, malformed features, or no genes.

Examples:

>>> res = bv.dialogue.dialogue(
...     sc,
...     "cell_grp",
...     "sample_id",
...     features,
...     pmd_params=bv.params.DialoguePmdParams(k=2, n_permutations=100),
... )
>>> res = bv.dialogue.dialogue(
...     sc, "cell_grp", "sample_id", features, quality_col="cell_quality"
... )
References

Jerby-Arnon & Regev, Nat. Biotechnol., 2022.

Reading the result

DIALOGUE: multicellular programmes, genes that are cell type specific but whose activity covaries across the samples the cell types share.

One function does the work. dialogue takes an experiment, the obs columns that hold the cell types and the samples, and a per-cell-type feature frame, and returns a DialogueResult. Read it with get_results (the programme table) or straight off its fields: signatures for the permissive and strict gene lists, scores for the per-cell programme scores, refit_fidelity for how well each cell type's score survived the final refit. Programmes are 0-based: mcp_00 is programme 0.

What lands where. Nothing is written to the experiment. The result is returned, and the run reads the normalised layer of the kept cells only. SingleCells, SingleCellsSubset and MetaCells are all accepted; for meta cells the ids are meta_cell_id and you build them within samples, or a meta cell has no well-defined sample.

Features are yours to make. Per cell type, a frame of cell_id plus at least two numeric columns, rows matched to cells by id. Compute them within the cell type (subset, find_hvg, calculate_pca): slicing a global PCA hands every cell type the same axis. Genes for the signatures default to the HVGs, so run bv.pp.find_hvg first or pass gene_ids.

sim = bv.io.generate_dialogue_test_data()
sc = bv.io.load_csr("dialogue_demo", sim.counts.scipy_csr(), sim.obs, sim.var)
bv.pp.find_hvg(sc, hvg_no=200)

res = bv.dialogue.dialogue(
    sc,
    "cell_grp",
    "sample_id",
    sim.features,
    pmd_params=bv.params.DialoguePmdParams(k=2, n_permutations=100),
)
bv.dialogue.get_results(res)
res.signatures.filter(res.signatures["list"] == "strict")

Gotchas. The design decides whether it runs at all: at least two cell types and five samples present in every one of them, with enough cells per sample per cell type to clear abn_c. It errors below that. k is the number of programmes you ask for, with no sweep to pick it, and n_permutations sets the floor of the empirical p-value. Without quality_col the cell quality covariate is the z-scored log library size, which needs lib_size in obs.

References: Jerby-Arnon & Regev, Nat. Biotechnol., 2022.

DialogueResult dataclass

DialogueResult(
    programmes: DataFrame,
    mcp_cell_types: tuple[tuple[str, ...], ...],
    scores: dict[str, DataFrame],
    cca_scores: dict[str, DataFrame],
    refit_fidelity: DataFrame,
    ws: dict[str, DataFrame],
    kept_features: dict[str, tuple[str, ...]],
    verdicts: DataFrame,
    signatures: DataFrame,
    shared_samples: tuple[str, ...],
    cell_types: tuple[str, ...],
    source_class: str,
    params: dict[str, object],
)

A DIALOGUE run.

Attributes:

Name Type Description
programmes DataFrame

One row per programme and cell type pair: programme, cell_type_a, cell_type_b, the empirical emp_p and the canonical correlation pair_cor.

mcp_cell_types tuple[tuple[str, ...], ...]

Per programme the cell types it spans.

scores dict[str, DataFrame]

Per cell type the final programme scores, cell_id plus mcp_00, ...

cca_scores dict[str, DataFrame]

The same for stage one's canonical scores.

refit_fidelity DataFrame

cell_type plus one column per programme: the correlation between the two. Low means the gene-level refit drifted from the programme the decomposition found.

ws dict[str, DataFrame]

Per cell type the sparse canonical weights, feature plus one column per programme.

kept_features dict[str, tuple[str, ...]]

Per cell type the feature columns that survived the ANOVA filter.

verdicts DataFrame

What the meta-analysis concluded per gene.

signatures DataFrame

The permissive and strict gene lists: cell_type, programme, gene_id, direction, list.

shared_samples tuple[str, ...]

Samples present in every cell type.

cell_types tuple[str, ...]

The analysed cell types, in order.

source_class str

The class it ran on.

params dict[str, object]

The parameters of the run.

get_results

get_results(x: DialogueResult) -> DataFrame

The programme table.

Parameters:

Name Type Description Default
x DialogueResult

The DIALOGUE result.

required

get_params

get_params(x: DialogueResult) -> dict[str, object]

The parameters of the run.

Parameters:

Name Type Description Default
x DialogueResult

The DIALOGUE result.

required