> 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/expression-molecular-profiles/differential-expression-deseq2.md).

# Differential expression (DESeq2)

Identify differentially expressed genes between two groups using DESeq2, from bulk RNA-seq counts or single-cell counts aggregated into patient-level pseudobulk samples.

Identify differentially expressed genes between two groups using DESeq2, from bulk RNA-seq counts or single-cell counts aggregated into patient-level pseudobulk samples.

## Bulk RNA-seq DEA via DESeq2

### Description

#### Analysis summary

Performs differential gene expression analysis between two biological or clinical cohorts in bulk RNA-seq, estimating effect sizes (log2 fold change) and statistical significance controlled for false discovery rate.

#### Computation

Raw read counts are modeled per gene with a negative binomial GLM (DESeq2): size factors normalize for sequencing depth, and gene-wise dispersions are shrunk toward a consensus trend line so that low-count genes do not generate false positives. The two groups are compared with a Wald test, and p-values are corrected for multiple testing with the Benjamini-Hochberg procedure (FDR); covariates (e.g. batch, age, sex) can be incorporated into the design formula to control confounding. Output per gene: base mean expression, log2 fold change (positive = enriched in the primary group), standard error, Wald statistic, raw and adjusted p-values (q-values), and a categorical directional label.

#### When to use

Use for bulk RNA-seq experiments with raw integer read counts comparing exactly two conditions. For single-cell RNA-seq use the mode pseudobulk of this analysis and aggregate counts per sample/donor first (pseudobulk mode of this analysis) before running this model.For continuous or pre-normalized intensities (e.g. proteomics log2 abundances), use ttest\_dea instead.

#### Caveats

Requires un-normalized, raw integer counts: TPM/FPKM, library-normalized or log-transformed values violate the negative binomial assumptions. The full, minimally pre-filtered transcriptome must be provided, since DESeq2 relies on the global distribution of genes to compute size factors and the mean-dispersion trend. Supports two-group pairwise contrasts only. Small sample sizes (n < 3 per group) severely limit statistical power and inflate false negative rates.

### Example questions

<details>

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

* What genes are differentially expressed between Female and Male bladder cancer patients?
* Which genes are upregulated in treatment responders vs non-responders?
* Find the top 20 differentially expressed genes adjusted for age and gender.

</details>

### Input columns

<details>

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

| column          | type        | required | description                                                                                                                                                       |
| --------------- | ----------- | -------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| index           | any         | required | Bulk RNA-seq sample identifier — maps to bk\_sample\_id. One row per (sample, gene) in the long-form input. SQL alias: bm.bk\_sample\_id AS index.                |
| count\_raw      | numeric     | required | Raw integer counts required by DESeq2. Must NOT be TPM or normalised counts. SQL alias: bc.count\_raw (no alias needed, column name matches canonical name). Do … |
| gene\_name      | categorical | required | Gene name — the feature axis of the volcano plot. SQL alias: bc.gene\_name (no alias needed, column name matches canonical name). Do NOT filter to a gene subset… |
| contrast\_group | categorical | required | Contrast variable — the clinical/metadata variable that defines exactly two groups to compare. SQL alias: c.gender AS contrast\_group (or any binary clinical va… |
| patient\_id     | any         | required | Patient identifier — used to count unique patients in stats output.                                                                                               |

</details>

### Visualizations

* `volcano` How to read: Each dot is one gene. Its horizontal position is the log2 fold change — right of centre means higher in the first arm of the contrast, left means higher in the second; its vertical position is the significance of the difference as -log10 adjusted p-value, so higher is more significant. Dotted lines mark the significance cut-offs on both axes. Red dots are genes significantly higher in the first arm, blue dots significantly higher in the second, and grey dots are not significant. The most significant genes are labelled (plus any explicitly highlighted genes), and hovering a dot shows its fold change, base mean, raw p-value and adjusted p-value.

### Example analysis 1

#### Name — DEA: Gender Contrast (TCGA Bladder Cancer)

#### Analysis parameters

<details>

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

```json
{
  "analysis_name": "bulk_dea",
  "analysis_params": {
    "padj_threshold": 0.05,
    "lfc_threshold": 1.0,
    "top_n_labels": 20
  },
  "viz_params": {
    "plot_name": "volcano",
    "title": "DEA: Gender Contrast (TCGA Bladder Cancer)",
    "contrast_label": "Gender (Female vs Male)"
  }
}
```

</details>

#### Visualization — `volcano`

![DEA: Gender Contrast (TCGA Bladder Cancer)](https://1034377358-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTmCjUj6W0sltjW7q2vBp%2Fuploads%2Fgit-blob-552ec518440338a2c0884b4fadb5850c3d607232%2Fbulk_dea__bulk_dea__volcano.png?alt=media)

#### Output table

<details>

<summary><code>descriptive_stats</code> (2 rows)</summary>

| type       | group  | n\_samples | n\_patients |
| ---------- | ------ | ---------- | ----------- |
| per\_group | female | 118        | 107         |
| per\_group | male   | 315        | 301         |

</details>

<details>

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

| type         | total\_genes | significant | higher\_in\_female | higher\_in\_male | padj\_threshold | lfc\_threshold | group\_1 | group\_2 | groups\_all         | covariates | lfc\_shrinkage | gene\_name | log2FoldChange | padj       | baseMean | significance |
| ------------ | ------------ | ----------- | ------------------ | ---------------- | --------------- | -------------- | -------- | -------- | ------------------- | ---------- | -------------- | ---------- | -------------- | ---------- | -------- | ------------ |
| dea\_summary | 17283        | 344         | 136                | 208              | 0.05            | 1.0            | female   | male     | \['female', 'male'] |            | none           |            |                |            |          |              |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                | EIF1AY     | -10.16         | 0.0        | 688.4    | Up in male   |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                | ZFY        | -8.347         | 0.0        | 386.0    | Up in male   |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                | DDX3Y      | -7.714         | 1.816e-256 | 1841.0   | Up in male   |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                | KDM5D      | -7.665         | 3.579e-247 | 1417.0   | Up in male   |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                | USP9Y      | -7.762         | 3.528e-239 | 686.0    | Up in male   |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                | NLGN4Y     | -6.25          | 6.045e-239 | 347.3    | Up in male   |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                | RPS4Y1     | -7.645         | 3.351e-235 | 6611.0   | Up in male   |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                | UTY        | -7.77          | 2.673e-234 | 516.9    | Up in male   |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                | TMSB4Y     | -9.237         | 9.706e-170 | 126.3    | Up in male   |

</details>

## scRNAseq Pseudobulk DEA via DESeq2

### Description

#### Analysis summary

One analysis mode with three variants that identify genes expressed at different levels in single-cell RNA-seq, by summing each patient's cells into pseudo-bulk samples so that cells from one patient are not treated as independent replicates. The variants compare two patient groups across all cell types (bulk-like), two patient groups within one chosen cell type, or one cell type against the rest within the same patients.

#### Computation

All three variants share one computation: raw counts are summed per patient and per arm into pseudo-bulk samples, and DESeq2 runs on them as in the bulk mode, with the patient as the replicate. They differ only in how the arms are formed — all cell types pooled per patient (variant 1), one cell type only (variant 2), or the cell type and the rest as arms with patient as a blocking covariate (variant 3). Log2 fold changes are shrunken (apeglm) in every variant; the unshrunken estimate is kept for reference, and shrinkage changes fold changes but not p-values or significance. The descriptive statistics report the cell-type composition of the pseudo-bulk samples and, in variant 3, which patients were dropped for lacking both arms; the summary always states which shrinkage was applied.

#### When to use

Variant 1 for a bulk-like whole-sample contrast between two groups (e.g. responders vs non-responders); variant 2 for a cell-type-intrinsic contrast within a chosen compartment (e.g. malignant cells only); variant 3 for cell-identity questions — which genes mark a cell type — within patients (e.g. malignant vs rest), optionally restricted to a patient subgroup. Use the bulk mode for bulk RNA-seq.

#### Caveats

Variant 1 confounds expression with composition: because all cell types are summed, a difference can reflect a shift in cell-type proportions rather than gene regulation, so it is bulk-like and the hardest to interpret biologically. Variant 2 removes that composition effect but needs enough cells of the chosen type per patient. Variant 3 is a within-patient design: patients lacking either arm are dropped, which can shrink the cohort substantially, and the result is not comparable to a between-patient contrast; its 'rest' arm pools all other cell types, so its composition varies by patient. Patients below the minimum-cell threshold are dropped in every variant, which can shift the cohort. Exactly two arms are supported, and no per-cell inference is possible.

### Example questions

<details>

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

* scRNAseq pseudobulk DEA between two clinical groups (all cell types aggregated per patient)
* scRNAseq pseudobulk DEA within a specific cell type between two clinical groups

</details>

### Input columns

<details>

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

| column          | type        | required | description                                                                                                                                                            |
| --------------- | ----------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| index           | any         | required | Bulk RNA-seq sample identifier — maps to bk\_sample\_id. One row per (sample, gene) in the long-form input. SQL alias: bm.bk\_sample\_id AS index.                     |
| count\_raw      | numeric     | required | Raw integer counts required by DESeq2. Must NOT be TPM or normalised counts. SQL alias: bc.count\_raw (no alias needed, column name matches canonical name). Do …      |
| gene\_name      | categorical | required | Gene name — the feature axis of the volcano plot. SQL alias: bc.gene\_name (no alias needed, column name matches canonical name). Do NOT filter to a gene subset…      |
| contrast\_group | categorical | required | Contrast variable — the clinical/metadata variable that defines exactly two groups to compare. SQL alias: c.gender AS contrast\_group (or any binary clinical va…      |
| patient\_id     | any         | required | Patient identifier — used to count unique patients in stats output.                                                                                                    |
| cell\_type      | categorical | required | Cell type label from the metadata table (e.g. cell\_type\_level\_2\_mid). One row per (patient × cell\_type × gene). When present, the analysis aggregates count\_raw… |
| n\_cells        | numeric     | required | Number of cells of the given cell\_type for this patient, derived from COUNT(\*) in the scRNAseq metadata table. Used to compute n\_cells\_in\_pseudobulk (total cel…  |

</details>

### Visualizations

* `volcano` How to read: Each dot is one gene. Its horizontal position is the log2 fold change — right of centre means higher in the first arm of the contrast, left means higher in the second; its vertical position is the significance of the difference as -log10 adjusted p-value, so higher is more significant. Dotted lines mark the significance cut-offs on both axes. Red dots are genes significantly higher in the first arm, blue dots significantly higher in the second, and grey dots are not significant. The most significant genes are labelled (plus any explicitly highlighted genes), and hovering a dot shows its fold change, base mean, raw p-value and adjusted p-value. The two arms are either two patient groups or a cell type and the rest, and the axis label notes that fold changes are apeglm-shrunken.

### Example analysis 1

#### Name — Pseudobulk DEA (NSCLC, 5 oldest M vs 5 oldest F): Gender

#### Analysis parameters

<details>

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

```json
{
  "analysis_name": "bulk_dea",
  "analysis_params": {
    "bulk_dea_mode": "pseudobulk",
    "padj_threshold": 0.05,
    "lfc_threshold": 1.0,
    "top_n_labels": 20
  },
  "viz_params": {
    "plot_name": "volcano",
    "title": "Pseudobulk DEA (NSCLC, 5 oldest M vs 5 oldest F): Gender",
    "contrast_label": "Gender (all cell types combined)"
  }
}
```

</details>

#### Visualization — `volcano`

![Pseudobulk DEA (NSCLC, 5 oldest M vs 5 oldest F): Gender](https://1034377358-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTmCjUj6W0sltjW7q2vBp%2Fuploads%2Fgit-blob-1d5bf3abdeab94f02a982b952dd10f7cf6a37679%2Fbulk_dea__pseudobulk_dea__volcano.png?alt=media)

#### Output table

<details>

<summary><code>descriptive_stats</code> (2 rows)</summary>

| type       | group  | n\_samples | n\_patients | cells\_per\_patient\_median | cells\_per\_patient\_iqr | malignant\_pct | fibroblast\_pct | momac\_pct | t\_nk\_pct | plasma\_pct | other\_pct |
| ---------- | ------ | ---------- | ----------- | --------------------------- | ------------------------ | -------------- | --------------- | ---------- | ---------- | ----------- | ---------- |
| per\_group | female | 5          | 5           | 4923.0                      | \[2783.0, 5613.0]        | 42.5           | 12.5            | 11.9       | 10.4       | 3.9         | 18.7       |
| per\_group | male   | 5          | 5           | 4761.0                      | \[3444.0, 5342.0]        | 25.0           | 13.6            | 13.8       | 13.2       | 11.3        | 23.1       |

</details>

<details>

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

| type         | total\_genes | significant | higher\_in\_female | higher\_in\_male | padj\_threshold | lfc\_threshold | group\_1 | group\_2 | groups\_all         | covariates | lfc\_shrinkage    | gene\_name | log2FoldChange | padj      | baseMean | significance | log2FoldChange\_unshrunken |
| ------------ | ------------ | ----------- | ------------------ | ---------------- | --------------- | -------------- | -------- | -------- | ------------------- | ---------- | ----------------- | ---------- | -------------- | --------- | -------- | ------------ | -------------------------- |
| dea\_summary | 15455        | 246         | 84                 | 162              | 0.05            | 1.0            | female   | male     | \['female', 'male'] |            | apeglm (PyDESeq2) |            |                |           |          |              |                            |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                   | KDM5D      | -15.37         | 7.643e-15 | 680.7    | Up in male   | -13.03                     |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                   | DDX3Y      | -15.12         | 1.119e-14 | 579.9    | Up in male   | -12.79                     |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                   | UTY        | -15.07         | 3.062e-14 | 562.4    | Up in male   | -12.75                     |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                   | SCNN1A     | 1.74           | 1.172e-12 | 2218.0   | Up in female | 1.794                      |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                   | USP9Y      | -13.38         | 5.029e-11 | 194.2    | Up in male   | -11.22                     |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                   | EIF1AY     | -13.31         | 4.562e-10 | 189.1    | Up in male   | -11.18                     |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                   | FGL1       | 4.095          | 3.995e-07 | 171.5    | Up in female | 4.318                      |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                   | ZFY        | -11.02         | 4.279e-06 | 46.47    | Up in male   | -9.161                     |
| gene         |              |             |                    |                  |                 |                |          |          |                     |            |                   | CD46       | 1.107          | 1.123e-05 | 3108.0   | Up in female | 1.175                      |

</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/expression-molecular-profiles/differential-expression-deseq2.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.
