> For the complete documentation index, see [llms.txt](https://docs.owkin.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.owkin.com/explore-and-analyse-data/data-analysis/single-cell-spatial/single-cell-spatial-expression-by-group.md).

# Single-cell / Spatial expression by group

Summarize mean gene or feature expression and the fraction of expressing cells or spots by group, and compare sample-level expressing fractions across groups.

Summarize mean gene or feature expression and the fraction of expressing cells or spots by group, and compare sample-level expressing fractions across groups.

## Per-group expression dotplot

### Description

#### Analysis summary

Summarises sparse expression per feature per group: the share of observations expressing the feature, and the mean expression among them — the canonical marker-expression view of single-cell or spatial data.

#### Computation

Observations are aggregated per (primary group, secondary group) combination — typically gene × cell type — into the fraction of observations whose presence signal is above zero (expressed) and the mean of the expression quantity over those expressing observations, along with the observation counts backing them. The same table doubles as the descriptive stats. Pairwise statistical comparisons of the expression value across the primary groups (within each secondary-group stratum when present) are computed automatically and returned with the results. Gene signatures collapse their member genes into per-observation averages before aggregation.

#### When to use

Use to compare the prevalence and mean level of one or many markers across cell types, conditions or spot groups on single-cell or spatial data. For overlap between exactly two features, use coexpression\_analysis instead; for the distribution of expressed fractions across patients, use this analysis's per-sample mode.

#### Caveats

The expressed fraction is over all observations of the group; the mean expression is over the expressing observations only — a group can show a high mean with a low expressed fraction. Groups with very few observations give unstable estimates.

### Example questions

<details>

<summary><code>example questions</code></summary>

* Single-cell gene expression across multiple genes and groups
* Single-cell gene expression across gene signatures and cell types
* Single-cell gene expression across groups and cell types
* Spatial transcriptomics gene expression across multiple genes and groups
* Spatial transcriptomics single-gene expression across groups and tumor regions

</details>

### Input columns

<details>

<summary><code>input columns</code></summary>

| column          | type        | required | description                                                                                                          |
| --------------- | ----------- | -------- | -------------------------------------------------------------------------------------------------------------------- |
| index           | any         | required | Observation identifier (e.g. cell\_id). Documents the unit of observation; not used in aggregation.                  |
| value\_sparsity | numeric     | required | Threshold column — value\_sparsity > 0 means the feature is expressed/present (e.g. count\_raw).                     |
| value           | numeric     | required | Quantity to average (e.g. count\_lognorm).                                                                           |
| x\_group        | categorical | required | Primary grouping variable (e.g. gene\_name for a gene × cell type view; clinical\_var for a clinical-variable view). |
| y\_group        | categorical | optional | Secondary grouping variable (e.g. cell\_type).                                                                       |
| patient\_id     | categorical | required | Patient identifier required for population summary statistics.                                                       |

</details>

### Visualizations

* `dotplot` How to read: One dot per (feature, group) pair: the dot's colour encodes the mean expression (colour bar) and its area the share of expressing observations (size legend, in %). Scanning a row compares features across one group's cell types; scanning a column compares cell types for one gene. Big pale dots mean 'expressed in many cells but weakly'; small bright ones the reverse. The accompanying statistical table reports the pairwise expression comparisons between groups.

### Example analysis 1

#### Name — Single Cell Expression of ERBB2, TP53 and ROR1 in Immune Cells (MOSAIC Bladder, Age > 40)

#### Analysis parameters

<details>

<summary><code>analysis_name, analysis_params, viz_params</code></summary>

```json
{
  "analysis_name": "sparse_aggregation_analysis",
  "analysis_params": {},
  "viz_params": {
    "value_sparsity_label": "Percent Expressing",
    "x_group_label": "Gene",
    "y_group_label": "Cell Type (Mid Level)",
    "value_label": "Mean Expression (log-norm)",
    "plot_name": "dotplot",
    "title": "Single Cell Expression of ERBB2, TP53 and ROR1 in Immune Cells (MOSAIC Bladder, Age > 40)"
  }
}
```

</details>

#### Visualization — `dotplot`

![Single Cell Expression of ERBB2, TP53 and ROR1 in Immune Cells (MOSAIC Bladder, Age > 40)](https://1034377358-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTmCjUj6W0sltjW7q2vBp%2Fuploads%2Fgit-blob-8b5a3152466dbd54b5b717db4752f3a1090fc1e3%2Fsparse_aggregation_analysis__per_group__dotplot.png?alt=media)

#### Output table

<details>

<summary><code>descriptive_stats</code> (first 10 of 21 rows)</summary>

| x\_group | y\_group    | percentage\_expressed | mean\_value | n    | n\_zeros | n\_non\_zeros |
| -------- | ----------- | --------------------- | ----------- | ---- | -------- | ------------- |
| ERBB2    | Plasma      | 0.03281               | 0.1695      | 3962 | 3832     | 130           |
| ERBB2    | DC          | 0.04876               | 0.2925      | 1251 | 1190     | 61            |
| ROR1     | Granulocyte | 0.00463               | 0.03206     | 432  | 430      | 2             |
| ROR1     | B\_cell     | 0.01003               | 0.06818     | 1596 | 1580     | 16            |
| ERBB2    | Granulocyte | 0.06019               | 0.4099      | 432  | 406      | 26            |
| ERBB2    | MoMac       | 0.02933               | 0.1755      | 8150 | 7911     | 239           |
| TP53     | Plasma      | 0.05628               | 0.3045      | 3962 | 3739     | 223           |
| ROR1     | Plasma      | 0.005048              | 0.02755     | 3962 | 3942     | 20            |
| ROR1     | T\_NK       | 0.002843              | 0.0188      | 8091 | 8068     | 23            |
| TP53     | B\_cell     | 0.1065                | 0.7293      | 1596 | 1426     | 170           |

</details>

<details>

<summary><code>statistical_tests</code> (first 10 of 63 rows)</summary>

| Test used for pairwise comparison | Group | Contrast          | Statistic  | Mean Difference | Higher Group | P-value   | Adjusted P-value | Significance level | comparison\_a | comparison\_b |
| --------------------------------- | ----- | ----------------- | ---------- | --------------- | ------------ | --------- | ---------------- | ------------------ | ------------- | ------------- |
| wilcoxon                          | TP53  | (DC, Plasma)      | 2718000.0  | 0.6217          | DC           | 1.562e-28 | 9.844e-27        | ★★★★               | DC            | Plasma        |
| wilcoxon                          | ROR1  | (DC, T NK)        | 5172000.0  | 0.1298          | DC           | 1.908e-21 | 6.011e-20        | ★★★★               | DC            | T\_NK         |
| wilcoxon                          | TP53  | (DC, T NK)        | 5433000.0  | 0.4437          | DC           | 9.564e-19 | 2.009e-17        | ★★★★               | DC            | T\_NK         |
| wilcoxon                          | TP53  | (DC, MoMac)       | 5431000.0  | 0.4124          | DC           | 1.66e-13  | 2.615e-12        | ★★★★               | DC            | MoMac         |
| wilcoxon                          | TP53  | (DC, Mast)        | 483200.0   | 0.6681          | DC           | 2.541e-13 | 3.202e-12        | ★★★★               | DC            | Mast          |
| wilcoxon                          | TP53  | (B cell, Plasma)  | 3334000.0  | 0.4249          | B cell       | 6.906e-13 | 7.251e-12        | ★★★★               | B\_cell       | Plasma        |
| wilcoxon                          | ROR1  | (DC, MoMac)       | 5195000.0  | 0.1146          | DC           | 2.825e-12 | 2.542e-11        | ★★★★               | DC            | MoMac         |
| wilcoxon                          | ROR1  | (DC, Plasma)      | 2527000.0  | 0.1211          | DC           | 5.837e-10 | 4.201e-09        | ★★★★               | DC            | Plasma        |
| wilcoxon                          | TP53  | (DC, Granulocyte) | 300600.0   | 0.6993          | DC           | 6.002e-10 | 4.201e-09        | ★★★★               | DC            | Granulocyte   |
| wilcoxon                          | TP53  | (MoMac, Plasma)   | 16630000.0 | 0.2093          | MoMac        | 3.438e-09 | 2.166e-08        | ★★★★               | MoMac         | Plasma        |

</details>

## Per-sample expressed fractions (violin)

### Description

#### Analysis summary

Computes the share of observations expressing a feature within each sample, then compares how those per-sample fractions vary across groups — preserving the sample-to-sample spread instead of collapsing it.

#### Computation

For each (sample, primary group, secondary group) combination, the fraction of observations whose presence signal is above zero is computed, alongside the mean expression among the expressing observations of that sample. The distribution of these per-sample fractions is then compared across the primary groups. Group-level descriptive stats summarise both dimensions (mean, standard deviation, median, maximum of the per-sample fractions and of the mean expressions). Pairwise statistical comparisons of the per-sample fractions across the secondary groups (within each primary-group stratum when present) are computed automatically and returned with the results. Requires a sample identifier column.

#### When to use

Use to compare the prevalence of a marker between cohorts while keeping the patient-to-patient variability visible. When the group-level summary without the per-sample spread is enough — e.g. the canonical marker view — use this analysis's per-group mode instead.

#### Caveats

Samples with very few observations give noisy per-sample fractions, which dominate the distribution's tails.

### Example questions

<details>

<summary><code>example questions</code></summary>

* Per-sample fraction of single cells expressing a gene by group

</details>

### Input columns

<details>

<summary><code>input columns</code></summary>

| column          | type        | required | description                                                                                                                        |
| --------------- | ----------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------- |
| index           | any         | required | Observation identifier (e.g. cell\_id). Documents the unit of observation; not used in aggregation.                                |
| value\_sparsity | numeric     | required | Threshold column — value\_sparsity > 0 means the feature is expressed/present (e.g. count\_raw).                                   |
| x\_group        | categorical | required | Primary grouping variable (e.g. gene\_name for a gene × cell type view; clinical\_var for a clinical-variable view).               |
| y\_group        | categorical | optional | Secondary grouping variable (e.g. cell\_type).                                                                                     |
| sample\_id      | any         | required | Sample identifier — cells are aggregated per sample to compute the per-sample expressed fraction. Required in the per-sample mode. |
| patient\_id     | categorical | required | Patient identifier required for population summary statistics.                                                                     |

</details>

### Visualizations

* `violin` How to read: Each violin is one primary group: its width shows where that group's per-sample expressed fractions concentrate, the embedded box marks the median and the middle half, and the dots are the individual samples. The y-axis is the expressed fraction, in percent. When the data is stratified by a secondary group, a dropdown (or side-by-side violins, engine permitting) switches between the strata; dots are coloured by the sample's mean expression. The accompanying statistical table reports the pairwise fraction comparisons between groups.

### Example analysis 1

#### Name — CD8A Fraction Expressing per Sample by Lymphocyte Density in Tumor (MOSAIC Bladder)

#### Analysis parameters

<details>

<summary><code>analysis_name, analysis_params, viz_params</code></summary>

```json
{
  "analysis_name": "sparse_aggregation_analysis",
  "analysis_params": {
    "aggregation_type": "per_sample"
  },
  "viz_params": {
    "plot_name": "violin",
    "title": "CD8A Fraction Expressing per Sample by Lymphocyte Density in Tumor (MOSAIC Bladder)",
    "value_sparsity_label": "Percent Cell Expressing",
    "x_group_label": "Lymphocyte Density in Tumor",
    "y_group_label": "Cell Type (Level 2)",
    "value_label": "Mean Expression<br>(log2(CPM+1))"
  }
}
```

</details>

#### Visualization — `violin`

![CD8A Fraction Expressing per Sample by Lymphocyte Density in Tumor (MOSAIC Bladder)](https://1034377358-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTmCjUj6W0sltjW7q2vBp%2Fuploads%2Fgit-blob-c26b33940155d3c9c9f13d99603c9fa930889ea8%2Fsparse_aggregation_analysis__per_sample__violin.png?alt=media)

#### Output table

<details>

<summary><code>descriptive_stats</code> (first 10 of 39 rows)</summary>

| x\_group | y\_group          | mean\_percentage\_expressed | std\_percentage\_expressed | p50\_percentage\_expressed | max\_percentage\_expressed | mean\_value | std\_value | min\_value | p25\_value | p50\_value | p75\_value | max\_value |
| -------- | ----------------- | --------------------------- | -------------------------- | -------------------------- | -------------------------- | ----------- | ---------- | ---------- | ---------- | ---------- | ---------- | ---------- |
| High     | B\_cell           | 2.554                       | 1.427                      | 2.505                      | 4.0                        | 6.721       | 0.2401     | 6.478      | 6.498      | 6.723      | 6.872      | 7.036      |
| High     | DC                | 2.318                       | 1.789                      | 2.469                      | 4.762                      | 5.819       | 0.6574     | 4.841      | 6.028      | 6.188      | 6.188      | 6.219      |
| High     | Endothelial       | 0.9737                      | 0.7809                     | 0.6135                     | 2.299                      | 6.239       | 0.4824     | 5.439      | 6.261      | 6.372      | 6.38       | 6.742      |
| High     | Epithelial\_other | 0.7539                      | 0.6537                     | 1.099                      | 1.163                      | 5.173       | 1.053      | 4.428      | 4.428      | 5.917      | 5.917      | 5.917      |
| High     | Fibroblast        | 0.7661                      | 0.6183                     | 0.8397                     | 1.688                      | 5.372       | 0.4714     | 4.978      | 5.053      | 5.054      | 5.879      | 5.895      |
| High     | Granulocyte       | 0.7143                      | 1.597                      | 0.0                        | 3.571                      | 7.18        |            | 7.18       | 7.18       | 7.18       | 7.18       | 7.18       |
| High     | Malignant         | 1.649                       | 2.023                      | 0.916                      | 5.239                      | 5.195       | 0.139      | 5.053      | 5.081      | 5.161      | 5.316      | 5.363      |
| High     | Mast              | 2.272                       | 3.173                      | 1.538                      | 7.692                      | 6.885       | 0.1905     | 6.665      | 6.98       | 6.98       | 7.009      | 7.009      |
| High     | MoMac             | 0.9108                      | 0.7592                     | 0.6859                     | 2.085                      | 6.005       | 0.6001     | 5.06       | 5.994      | 6.079      | 6.172      | 6.722      |
| High     | Muscle            | 0.757                       | 0.4238                     | 0.5155                     | 1.316                      | 5.822       | 0.8491     | 4.593      | 5.329      | 6.129      | 6.402      | 6.659      |

</details>

<details>

<summary><code>statistical_tests</code> (first 10 of 39 rows)</summary>

| Test used for pairwise comparison | Group      | Contrast       | Statistic | Mean Difference | Higher Group | P-value  | Adjusted P-value | Significance level | comparison\_a | comparison\_b |
| --------------------------------- | ---------- | -------------- | --------- | --------------- | ------------ | -------- | ---------------- | ------------------ | ------------- | ------------- |
| wilcoxon                          | B cell     | (High, Low)    | 25.0      | 2.554           | High         | 0.007495 | 0.2923           |                    | High          | Low           |
| wilcoxon                          | Muscle     | (High, Low)    | 24.0      | 0.4837          | High         | 0.01587  | 0.3095           |                    | High          | Low           |
| wilcoxon                          | Malignant  | (High, Low)    | 22.0      | 1.295           | High         | 0.05556  | 0.468            |                    | High          | Low           |
| wilcoxon                          | Muscle     | (High, Medium) | 22.0      | 0.4938          | High         | 0.05933  | 0.468            |                    | High          | Medium        |
| wilcoxon                          | B cell     | (High, Medium) | 18.0      | 2.014           | High         | 0.06169  | 0.468            |                    | High          | Medium        |
| wilcoxon                          | Mast       | (High, Low)    | 20.0      | 2.272           | High         | 0.07201  | 0.468            |                    | High          | Low           |
| wilcoxon                          | Mast       | (High, Medium) | 16.0      | 2.272           | High         | 0.1094   | 0.5346           |                    | High          | Medium        |
| wilcoxon                          | Plasma     | (High, Medium) | 20.0      | 1.134           | High         | 0.1388   | 0.5346           |                    | High          | Medium        |
| wilcoxon                          | Fibroblast | (High, Medium) | 20.0      | 0.4961          | High         | 0.1425   | 0.5346           |                    | High          | Medium        |
| wilcoxon                          | Malignant  | (High, Medium) | 20.0      | 1.253           | High         | 0.1508   | 0.5346           |                    | High          | Medium        |

</details>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.owkin.com/explore-and-analyse-data/data-analysis/single-cell-spatial/single-cell-spatial-expression-by-group.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
