Tutorials › Statistical Methods for Single-Cell RNA Sequencing › Handling Cell Types Across Samples

Differential Expression With Pseudobulk and Mixed Models · Tutorial 477 of 700

Handling Cell Types Across Samples

Learn when a sample contributes a pseudobulk row for a cell type, why an absent group is not a zero-count observation, and how this distinction affects comparisons across samples.

Advanced 9 min read

What You'll Learn

  • Define sample–cell-type groups and the conditions for creating a pseudobulk row.
  • Aggregate raw counts for each observed group while retaining genuine zero counts for individual genes.
  • Explain why an unobserved cell type cannot be represented by a zero vector.
  • Track which samples contribute to a cell-type-specific dataset and recognize incomplete sample coverage.
  • Diagnose labeling, capture, and library-total problems without confusing them with biological absence.
  • Compare omission of absent groups with analyses of cell-type presence or abundance.

Why Sample Coverage Matters

A cell-type-specific pseudobulk dataset has one row for each sample in which the cell type is observed. That sounds straightforward until a sample contains no cells assigned to the cell type. The sample still exists, but there are no cells from which to aggregate a pseudobulk expression profile. Treating that situation as an ordinary zero-count observation changes the meaning of the data.

The key distinction is between no observed cells in a sample–cell-type group and observed cells whose counts for a particular gene are zero. The first is an absent group; the second is a valid gene-level count within an observed group. Correctly recording that difference preserves what the experiment actually measured and makes sample coverage transparent.

Definition: Let \(s\) index samples, \(k\) index cell types, \(g\) index genes, and \(i\) index cells. Let \(C_{sk}\) be the set of cells from sample \(s\) assigned to cell type \(k\), and let \(Y_{ig}\) be the raw count for gene \(g\) in cell \(i\). The cell-type-specific pseudobulk count is $$ P_{skg}=\sum_{i\in C_{sk}}Y_{ig}. $$ A pseudobulk row for sample \(s\) and cell type \(k\) is observed only when \(C_{sk}\) contains at least one cell. If the set is empty, that sample–cell-type group is absent; it is not a measured expression profile.

This definition assumes that each cell has a reliable sample identifier and a cell-type assignment, that the count matrix uses a consistent gene-feature definition, and that the counts being summed are appropriate raw counts. Misassigned barcodes, inconsistent cell-type labels, or mixing samples before aggregation can create false absences or false presences. The earlier material on Aggregating Counts by Donor and Cell Type establishes the aggregation step; here the focus is which sample–cell-type groups actually produce rows.

Build Rows From Observed Groups

A practical construction starts by listing the samples and cell types, counting the assigned cells in every sample–cell-type combination, and aggregating counts only for combinations with at least one cell. The result is naturally an unbalanced set of rows: some samples may contribute to a cell type while others do not. Keep the sample identifier, cell-type label, number of contributing cells, and gene counts together so that the observed coverage can be audited.

1
Define the sample and cell-type labels.
Use identifiers that refer to the biological sample being analyzed and a consistent cell-type annotation scheme.
2
Count cells in each group.
For every sample–cell-type combination, calculate \(n_{sk}=|C_{sk}|\). This count records whether the group is observed.
3
Aggregate observed groups.
When \(n_{sk}>0\), sum each gene’s raw counts over the cells in \(C_{sk}\) and create one pseudobulk row.
4
Record absent groups as absent.
When \(n_{sk}=0\), create no expression row for that group. Preserve the coverage information separately rather than inserting a row of zeros.

Worked Example: Aggregating an Observed Cell Type

Suppose three hypothetical samples are being summarized for two genes, A and B. Sample 1 has three cells assigned to T cells, with counts (A, B) of (3, 1), (0, 2), and (2, 0). Sample 2 has two T cells with counts (1, 0) and (0, 4). Sample 3 has no cells assigned to T cells.

For Sample 1, the T-cell pseudobulk counts are the gene-wise sums: $$ P_{1,\mathrm{T},A}=3+0+2=5,\qquad P_{1,\mathrm{T},B}=1+2+0=3. $$ The row for Sample 1 is therefore (A, B) = (5, 3), based on three observed T cells.

For Sample 2: $$ P_{2,\mathrm{T},A}=1+0=1,\qquad P_{2,\mathrm{T},B}=0+4=4. $$ Its row is (1, 4), based on two observed T cells. Sample 3 contributes no T-cell row because its T-cell set is empty. The resulting T-cell pseudobulk dataset has two observed rows, not three rows with a third row (0, 0).

The zero count for gene A in one Sample 1 cell is included in the sum and does not remove the cell or the pseudobulk row. A gene count of zero is meaningful here because cells were observed and their counts were measured.

Why an Empty Group Is Not a Zero-Count Profile

For an observed group, a zero for gene \(g\) means that the measured cells in that group contributed no recorded counts for that gene. It is possible for other genes in the same row to have positive counts. By contrast, an absent group has no cells and therefore no gene measurements to aggregate. It provides no pseudobulk profile for that sample and cell type.

There is a mathematical subtlety: a sum over an empty set is conventionally defined as zero. That convention does not turn an empty group into an observed pseudobulk sample. The zero is an algebraic value, not an expression measurement with a biological sample behind it. In particular, an all-zero row would imply observed counts for a group where there were no cells. It could also be mistaken for a very low-expression observation rather than a lack of observations.

The distinction can be stated in terms of what was measured. If cells were present, the data include their gene counts, even when those counts are zero. If no cells were present, the data include no cell-level counts for that sample–cell-type group. The absence may reflect biological absence, incomplete cell capture, annotation decisions, or other sampling processes; the count table alone does not settle which explanation applies.

Worked Example: A Zero for One Gene in an Observed Group

In a hypothetical sample, four cells are assigned to a cell type. Their counts for genes X and Y are (0, 3), (0, 1), (0, 0), and (0, 2). The sample has an observed cell-type group because four cells were assigned to it.

The aggregate for gene X is \(0+0+0+0=0\), and the aggregate for gene Y is \(3+1+0+2=6\). Thus the valid pseudobulk row for these two genes is (0, 6). It records zero counts for X among four observed cells, alongside six counts for Y.

If the sample instead had no cells assigned to this cell type, there would be no observed values to sum for either gene and no row to create. Reporting (0, 0) in that case would falsely suggest that an observed group had zero counts for both genes. The arithmetic looks similar, but the data provenance and interpretation are different.

Comparisons When Coverage Is Incomplete

A cell-type-specific analysis uses only samples with an observed pseudobulk row for that cell type. Therefore, two cell types can have different sets of contributing samples, and a given cell type can have fewer observed samples than the full experiment. Report that coverage explicitly. A statement such as “there were 12 samples in the study” does not imply that there are 12 pseudobulk observations for every cell type.

This changes the scope of a comparison. An expression comparison for a cell type is based on samples in which that cell type was observed, not automatically on every sample originally enrolled. If cell-type observation is related to condition, donor characteristics, or technical quality, the observed samples may differ systematically from the intended target group. Missing cell-type observations therefore require interpretation, not just a software workaround. The earlier material on Missing Donors and Incomplete Cell Sampling provides relevant context for distinguishing incomplete observation from a simple reduction in sample count.

Worked Example: Tracking Incomplete Coverage Across Conditions

Consider four hypothetical donors, each intended to contribute a control and a treated sample. For a particular cell type, the observed-group pattern is:

DonorControl groupTreated group
1Observed, 6 cellsAbsent, 0 cells
2Observed, 5 cellsObserved, 4 cells
3Observed, 7 cellsObserved, 3 cells
4Absent, 0 cellsObserved, 5 cells

There are six observed pseudobulk rows: three control rows (Donors 1, 2, and 3) and three treated rows (Donors 2, 3, and 4). Only Donors 2 and 3 have an observed row in both conditions. Donor 1’s absent treated group and Donor 4’s absent control group are not zero-count expression observations.

If the scientific comparison requires a within-donor contrast, the directly observed paired information comes from two donors, not four. This observation does not by itself determine the appropriate model or establish why the other groups are absent; it identifies the data available for that cell type. Reporting four complete pairs, or filling the absent groups with zeros to create them, would misrepresent the observed data.

Diagnostics, Alternatives, and Limits

Before using a cell-type-specific pseudobulk dataset, inspect coverage by sample and cell type. Check whether absent groups cluster in one condition, donor, batch, or processing run. Compare cell counts across observed groups, confirm that sample identifiers map to the intended experimental units, and inspect whether unexpected absences result from annotation or filtering rules. These checks identify patterns requiring investigation; they cannot prove that a cell type is truly absent from the underlying tissue.

An observed group with a zero total across the entire feature set is different from an absent group, but it is usually a data-quality warning. If cells were assigned yet every recorded gene count sums to zero, verify the count matrix, feature selection, and aggregation pipeline before treating the row as usable. A zero total is not evidence that an unobserved group has been measured. Likewise, a very small number of cells is still an observed group, but the resulting aggregate may be less stable and should be disclosed.

The main alternatives answer different questions:

  • Omit absent expression rows and analyze observed groups. This preserves the distinction between measured expression and no observed cells, but conclusions apply to the samples contributing observations and may be affected by nonrandom absence.
  • Analyze cell-type presence or abundance separately. This addresses whether, or how often, the cell type is observed or represented. It does not substitute for a cell-type-specific expression profile when no cells are present.
  • Use a cell-level approach designed for the data structure. This may retain cell-level information, but it still cannot create expression measurements for cells that were not observed. Its assumptions and inferential target must be made explicit.

No single representation resolves informative absence. If the probability of observing a cell type differs across conditions, an expression comparison among observed groups may not describe the same population of samples as the planned study. Separate information about sampling, cell-type composition, and the intended expression estimand is needed to judge the consequences.

Common Mistakes

  • Adding a zero vector for a missing cell type. This treats “no cells to measure” as “measured cells had zero counts.” Create no pseudobulk row for an absent group.
  • Dropping a gene’s zero count as if its group were absent. If cells were observed, retain the row even when a particular gene’s aggregate is zero.
  • Assuming all study samples contribute to every cell type. Count observed groups separately for each cell type and report the resulting coverage.
  • Calling an unobserved cell type biologically absent without qualification. Lack of assigned cells can also reflect capture, annotation, or data-processing limits.
  • Confusing expression with cell abundance. Pseudobulk gene counts summarize counts from observed cells; whether the cell type was observed or how many cells were captured is a separate feature of the data.
Key takeaway: A pseudobulk row requires at least one observed cell in that sample–cell-type group. Keep zero counts for genes within observed rows, but represent groups with no observed cells as absent—not as all-zero expression profiles.

Check Your Understanding

Answer each question, then compare your reasoning with the solutions.

  1. A sample has three cells assigned to a cell type, and the counts for gene Z are 0, 0, and 0. Is the sample–cell-type group observed? What is its aggregate count for Z?
  2. A sample has no cells assigned to a cell type. Should its pseudobulk row contain zero for every gene? Explain.
  3. Across five samples, a cell type is observed in four. How many pseudobulk rows should be present for this cell type, assuming one row per observed sample?
  4. In a paired study, one donor has an observed control group but no observed treated group for a cell type. Can that donor supply an observed within-donor expression pair for that cell type?

Solutions. (1) Yes. Three cells are observed, so the group has a row; the aggregate for Z is \(0+0+0=0\). (2) No. With no assigned cells, no expression profile was measured and no row should be created. (3) Four rows, one for each sample in which the cell type is observed. (4) No. The donor has only one observed group for that cell type, so there is no observed pair; inserting an all-zero treated row would invent an observation.

Clinical Biostats