From Per-Cell Counts to a Matrix
After reads or molecules have been assigned to genes and associated with cells, the results can be arranged as a rectangular table. This arrangement is more than a display choice: the row and column labels specify which gene and which cell each count describes. A matrix also makes it possible to summarize counts across genes or cells without losing the identity of an individual entry.
The convention used here is genes in rows and cells in columns. Each entry is the count for one particular gene in one particular cell. Keep that orientation fixed when reading, creating, or passing a matrix to an analysis.
The order of the rows and columns must be known and applied consistently. If the first row is gene A and the first column is cell 1, then the upper-left entry refers to gene A in cell 1. The number alone is not enough to identify the observation: its row and column labels are part of its meaning.
How the Entries Are Formed
Conceptually, begin with records that connect a cell, a gene, and a countable feature. Depending on the assay, a countable feature can be an assigned read or a molecule identified after UMI deduplication. For each cell–gene pair, count the features assigned to that pair and put the result in the corresponding matrix entry. The earlier material on aligning reads and assigning them to genes and on UMI deduplication establishes how those assignments and molecule counts are obtained; the matrix collects the resulting counts.
A precise way to describe this aggregation is to index the countable features by \(i\). Let \(c(i)\) be the cell assigned to feature \(i\), and \(g(i)\) its assigned gene. For a gene \(g\) and cell \(c\), the entry is the number of features assigned to both:
Here, \(\mathbf{1}\{\cdot\}\) equals 1 when the condition inside the braces is true and 0 otherwise. In a UMI-based matrix, the indexed features are the countable molecule records after the applicable deduplication step. In a non-UMI matrix that counts reads, they are the reads assigned to a cell and gene. A feature that is not assigned to a matrix gene–cell pair does not contribute to that entry. This definition describes the aggregation; it does not settle how a particular assay handles ambiguous assignments or other special cases.
A zero is an entry too. It means that the chosen counting procedure assigned no countable features to that gene in that cell. It does not mean that the gene is absent from the organism, that the cell contains no molecules of the gene under every possible measurement, or that the measurement is error-free.
Worked Example: Placing Counts in the Correct Cells
Suppose a hypothetical assay produces molecule counts for three genes, \(G_1,G_2,G_3\), in two cells, \(A,B\). The counted molecules assigned to \(A\) are 4 for \(G_1\), 0 for \(G_2\), and 2 for \(G_3\). The counts assigned to \(B\) are 1, 3, and 0, respectively. Write the gene-by-cell matrix and check its totals.
The genes are the rows, in the order \(G_1,G_2,G_3\), and the cells are the columns, in the order \(A,B\). Therefore:
The column total for cell \(A\) is \(4+0+2=6\) molecules, and the column total for cell \(B\) is \(1+3+0=4\) molecules. The row totals are \(4+1=5\) molecules for \(G_1\), \(0+3=3\) for \(G_2\), and \(2+0=2\) for \(G_3\). Both ways of summing give the same grand total: \(6+4=5+3+2=10\) molecules. The zero at \(G_2,A\) records no counted molecules for that pair; it is not a missing matrix entry.
Keeping Count Units and Orientation Straight
The matrix layout does not determine what one unit of count means. The counting procedure does. In a UMI-based assay, an entry may count deduplicated molecule records; in a non-UMI plate-based assay, an entry may count reads assigned to that gene in that cell. These are both integer-valued counts, but they are not automatically interchangeable measurements of the same quantity. When writing or interpreting a matrix, state which counting unit it contains rather than calling every entry a molecule or every entry a read.
Similarly, a cell-by-gene table can contain the same numerical information as a gene-by-cell matrix if it is simply the transpose: rows and columns have been exchanged. But it does not follow the orientation defined here. Confusing the two can lead to describing a gene total as a cell total, or vice versa. Labels and dimensions should be checked before interpreting a row or column.
| Representation | What one record or entry describes | Useful distinction |
|---|---|---|
| Gene-by-cell matrix | One gene–cell pair and its count | Genes are rows; cells are columns. |
| Cell-by-gene table | One cell–gene pair and its count | Contains the same values only if the orientation is transposed consistently. |
| Assignment-record list | An individual read or countable molecule with its assignment | Records are aggregated by gene–cell pair to form matrix entries. |
Worked Example: Aggregating UMI-Based Records
Consider a hypothetical UMI-based assay with genes \(G_1,G_2\) and cells \(A,B\). After gene assignment, the records for cell \(A\) are: \(G_1\) with UMI \(u_1\) on two reads, \(G_1\) with UMI \(u_2\) on one read, and \(G_2\) with UMI \(u_3\) on one read. For cell \(B\), the records are \(G_1\) with UMI \(u_4\) on one read and no assigned \(G_2\) molecule. Suppose the stated counting rule counts each distinct deduplicated UMI as one molecule for its gene and cell. Construct the matrix.
For \(G_1\) in \(A\), \(u_1\) and \(u_2\) are two distinct counted molecules. The two reads carrying \(u_1\) do not make two UMI-defined molecules under the stated rule. Thus \(x_{G_1,A}=2\). For \(G_2\) in \(A\), \(u_3\) gives \(x_{G_2,A}=1\). In cell \(B\), \(u_4\) gives \(x_{G_1,B}=1\), and the absence of an assigned \(G_2\) molecule gives \(x_{G_2,B}=0\).
The column totals are \(2+1=3\) molecules for \(A\) and \(1+0=1\) molecule for \(B\); the row totals are \(2+1=3\) for \(G_1\) and \(1+0=1\) for \(G_2\). The grand total is \(3+1=4\) molecules, matching the four distinct UMI-defined molecule records in the description.
Basic Checks and a Short Justification
For a small matrix, row totals, column totals, and the grand total provide simple checks on placement and arithmetic. Define the total for gene \(g\) as the sum over cells in its row, and the total for cell \(c\) as the sum over genes in its column:
The grand total can also be obtained by adding the cell totals or by adding the gene totals:
To justify this identity, substitute the definition of each cell total into the first sum. This gives \(\sum_{c\in C}\sum_{g\in G}x_{gc}\). Since there are finitely many matrix entries, addition can be reordered, giving \(\sum_{g\in G}\sum_{c\in C}x_{gc}\), which is the sum of the row totals. Both calculations add every entry exactly once. The check can reveal an arithmetic or transcription error, but agreement alone does not prove that every count was assigned to the correct gene and cell.
Worked Example: Checking a Non-UMI Read-Count Matrix
A hypothetical non-UMI assay uses assigned reads as its count unit. Suppose the counts are \(G_1: (5,2,0)\) and \(G_2: (1,4,3)\) across cells \(A,B,C\), in that order. Construct the matrix and verify its totals in reads.
The cell totals are \(K_A=5+1=6\), \(K_B=2+4=6\), and \(K_C=0+3=3\) reads. Their sum is \(6+6+3=15\) reads. The gene totals are \(R_{G_1}=5+2+0=7\) and \(R_{G_2}=1+4+3=8\) reads; their sum is \(7+8=15\) reads. The totals agree. In this example the entries count assigned reads, not deduplicated molecules, so the unit in the interpretation is reads.
Assumptions, Failure Modes, and Limits
The matrix definition assumes that the row and column lists identify the intended genes and cells, that the selected counting procedure has been applied consistently, and that each counted feature contributes to the appropriate gene–cell pair under that procedure. For the simple aggregation formula, each feature contributes once to one matrix entry. If an analysis uses a special assignment rule that permits a feature to contribute differently, that rule must be specified rather than assumed.
A few practical checks help catch mistakes while constructing a matrix:
- Check the orientation. Confirm that rows are genes and columns are cells before interpreting totals or entries.
- Check the labels and order. Confirm that each count is paired with the intended gene and cell, and that the displayed order matches the labels.
- Check the count unit. Confirm whether values count reads, deduplicated molecules, or another explicitly defined feature.
- Check arithmetic totals. For a hand-constructed example, calculate row totals, column totals, and the grand total independently where feasible.
- Distinguish zero from unavailable information. A zero means no count under the chosen procedure; it is different from a value that was not recorded.
These checks have limits. Correct dimensions and matching totals cannot establish that gene assignment was biologically appropriate, that cell labels were correctly identified upstream, or that the assay captured every molecule. A matrix records results of a defined counting process; it does not by itself explain why counts differ between cells. It is also not a normalized expression measure: the entries described here are raw feature counts.
A common mistake is to say, “The first row is cell A because its total is 6.” That reasoning reverses the stated layout. In the first worked example, cell A is a column, and its total is the sum down that column; the first row is gene \(G_1\). Another mistake is to interpret a zero as proof that the gene is not expressed in that cell. The correction is to interpret it narrowly: no feature was counted for that gene–cell pair under the chosen assignment and counting procedure.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions.
- A matrix has four genes and seven cells. Under the convention in this tutorial, how many rows and columns does it have, and what does entry \(x_{3,5}\) describe?
- For one gene in one cell, three reads carry the same deduplicated UMI. Under a rule that counts each distinct UMI once, how many molecules do these reads contribute to that matrix entry?
- A gene has counts 2 and 0 across cells A and B. What does the zero mean, and what does it not establish?
- For a matrix with entries \(1,2\) in its first row and \(3,4\) in its second row, calculate the row totals, column totals, and grand total.
- Why is a non-UMI read-count entry not automatically a UMI molecule count, even though both are represented by integers?
Solutions. (1) It has four rows and seven columns; \(x_{3,5}\) is the count for the third listed gene in the fifth listed cell. (2) It contributes one molecule under that rule, not three. (3) The procedure counted no features for that gene–cell pair; this does not prove the gene is absent or that no molecules exist. (4) Row totals are \(1+2=3\) and \(3+4=7\); column totals are \(1+3=4\) and \(2+4=6\); the grand total is \(3+7=10\), also \(4+6=10\). (5) The entries use different counting units: one counts assigned reads, while the other counts deduplicated UMI-defined molecules. Integer format does not make those units equivalent.