Why Model Contamination as a Mixture?
A cell barcode can contain transcripts from the cell itself and ambient RNA captured during droplet formation. The same gene count may therefore reflect endogenous expression, contamination, or both. DecontX addresses this ambiguity by modeling each cell’s observed expression as a mixture of an endogenous component and a contaminating component, using information about the cell’s cluster to help distinguish them.
The cluster information matters because cells in the same cluster tend to have more similar endogenous expression profiles than cells in different clusters. A gene that is common in other clusters but unusual in a cell’s own cluster may be more consistent with contamination than with that cell’s endogenous expression. This is evidence, not proof: real biological variation, imperfect clustering, and shared expression can all blur the distinction.
The Cluster-Informed Mixture Model
Let \(x_{ig}\) be the observed count for gene \(g\) in cell \(i\), and let \(N_i=\sum_g x_{ig}\) be the total count for that cell. A useful expression of the mixture model is
Here, \(\boldsymbol{p}_i\) is the cell’s endogenous gene-probability profile and \(\boldsymbol{q}_i\) is its contaminating profile. Each profile has nonnegative entries that sum to one across genes. Thus, the probability of observing a count from gene \(g\) is \((1-\theta_i)p_{ig}+\theta_i q_{ig}\). The mixture fraction \(\theta_i\) is between zero and one.
In DecontX, the profiles are not simply known in advance. The method estimates them using the observed counts and cluster assignments. Cluster membership informs the expected endogenous profile: expression patterns shared within a cluster support the endogenous component. Expression from cells outside the assigned cluster informs the contaminating component. Hierarchical modeling allows cell profiles to vary while borrowing information across cells, rather than treating every cell’s proportions as completely unrelated.
This is a count-composition model: conditional on a cell’s total \(N_i\), the gene counts are modeled jointly as multinomial. The basic formulation assumes that the cluster labels are informative about endogenous similarity, that the contaminating profile can be distinguished sufficiently from the endogenous profile, and that the fitted profiles provide a reasonable description of the observed counts. It does not establish that every transcript assigned to the contaminating component came from a particular physical source.
How the Mixture Separates the Components
The separation can be understood using the probability that an observed count of a particular gene came from the contaminating component. If the profiles and \(\theta_i\) were known, that conditional probability for gene \(g\) would be
This follows from Bayes’ rule: the numerator is the probability contribution from contamination, and the denominator is the total probability of observing that gene under either component. It explains why a gene’s contamination attribution depends not only on the cell-level fraction but also on how common the gene is in each profile.
DecontX estimates the mixture parameters through a Bayesian procedure, using cluster-informed structure and prior regularization. The displayed conditional probability is a concise way to understand the fitted model; it is not a claim that each molecule’s true origin is observed. In practice, the model expresses uncertainty by estimating component contributions from the count patterns across cells.
Worked Example: Estimating a Mixture Fraction From Two Genes
Suppose a hypothetical cell belongs to a cluster whose endogenous profile assigns probabilities \(0.80\) and \(0.20\) to genes A and B. Suppose the contaminating profile assigns probabilities \(0.10\) and \(0.90\). The observed proportions are \(0.66\) for A and \(0.34\) for B. For this simplified calculation, treat both profiles as known and suppose the two-gene proportions are exact.
For gene A, the mixture equation is \(0.66=(1-\theta_i)(0.80)+\theta_i(0.10)\). Rearranging gives \(0.66=0.80-0.70\theta_i\), so \(\theta_i=(0.80-0.66)/0.70=0.20\).
The gene B equation agrees: \(0.34=(1-0.20)(0.20)+(0.20)(0.90)=0.16+0.18=0.34\). Under these simplified assumptions, 20% of the cell’s transcript-count composition is attributed to contamination. Real DecontX estimation must also infer profiles from data and account for uncertainty; this arithmetic illustrates the mixture, not the full fitting procedure.
Interpreting Cell- and Gene-Level Outputs
The cell-level contamination fraction \(\theta_i\) is a summary for one cell. For example, \(\theta_i=0.12\) indicates that the fitted model attributes 12% of that cell’s observed transcript-count composition to contamination. It does not mean that 12% of the genes are contaminated, nor does it say that every gene in the cell has the same contamination fraction.
Gene-level contributions vary because \(p_{ig}\) and \(q_{ig}\) differ across genes. A gene abundant in the contaminating profile can have a substantial contaminating contribution even when the overall \(\theta_i\) is modest. Conversely, a gene strongly characteristic of the cell’s endogenous profile can have little estimated contamination. Gene-level quantities should therefore be interpreted in relation to both the cell-level mixture fraction and the two fitted profiles.
A corrected count matrix is another common output. Its entries represent the counts retained or estimated for the endogenous component under the model; they are not new measurements of the molecules’ true origins. Exact output details and whether gene-by-cell contamination contributions are directly returned can depend on the software interface and version. If only a cell-level fraction and corrected matrix are provided, do not describe a separate gene-level contamination matrix as though it were necessarily a default output.
Worked Example: Reading a Cell-Level Estimate
Consider a hypothetical cell with \(N_i=1{,}000\) observed counts and an estimated contamination fraction \(\theta_i=0.12\). The fitted model’s expected total contribution from contamination is \(1{,}000(0.12)=120\) counts, while the expected endogenous contribution is \(1{,}000(1-0.12)=880\) counts.
These are model-based expected contributions, not a statement that exactly 120 identifiable molecules were observed to come from ambient RNA. If the output reports a corrected matrix, its total for this cell may be close to the estimated endogenous contribution, subject to the method’s estimation and output conventions. The cell-level estimate alone does not reveal how the 120 expected contaminating counts are distributed across genes.
Worked Example: Why a Gene’s Contribution Depends on Both Profiles
Suppose a hypothetical cell has \(N_i=1{,}000\), \(\theta_i=0.10\), and for gene C the fitted profiles give \(p_{iC}=0.05\) and \(q_{iC}=0.40\). The mixture probability for gene C is \((1-0.10)(0.05)+(0.10)(0.40)=0.045+0.040=0.085\). The model therefore predicts 85 counts for this gene on average, of which 40 are attributable to the contaminating component: \(1{,}000(0.10)(0.40)=40\).
Among the expected 85 counts, the contaminating share is \(40/85\approx0.471\), or about 47.1%. This exceeds the cell-level contamination fraction of 10% because gene C is much more prevalent in the contaminating profile than in the endogenous profile. The calculation illustrates the interpretation of a gene-level contribution; it does not imply that the observed 85 counts can be individually labeled by their true source.
Assumptions, Diagnostics, and Failure Modes
The most important practical assumption is that the clusters provide useful information about endogenous expression. If distinct cell types are incorrectly merged, their genuine marker expression can appear foreign to the pooled cluster profile. If one cell type is split across clusters, its endogenous expression may be treated as atypical relative to the assigned cluster. Either error can distort the estimated contaminating component.
The mixture also becomes difficult to identify when the endogenous and contaminating profiles are too similar. If \(p_{ig}=q_{ig}\) for every gene, then the mixture probability is the same for every value of \(\theta_i\), so the data cannot distinguish the components. More generally, if the profiles overlap substantially, different combinations of profiles and mixture fractions may explain the counts similarly well.
Useful checks include examining whether estimated contamination fractions are extreme or unexpectedly similar across cells, comparing them across clusters, and inspecting whether genes driving high contamination estimates have plausible contaminating-profile patterns. Also check whether results change substantially under reasonable alternative cluster assignments. These checks do not prove the model correct, but sharp sensitivity to clustering or implausible gene patterns are warnings that the decomposition may be unreliable.
A common mistake is to interpret \(\theta_i=0.12\) as meaning that every gene in the cell is 12% contaminated. The correction is that \(\theta_i\) is a cell-level mixture fraction; the contaminating share for a particular gene depends on that gene’s probability in both profiles. Another mistake is to treat corrected counts as direct observations of uncontaminated molecules. They are model-based estimates, and uncertainty in the profiles and cluster assignments remains relevant.
How DecontX Differs From Ambient-Profile-Based Correction
The earlier material on SoupX Ambient RNA Correction considers an approach that estimates an ambient profile and uses it to assess contamination. DecontX instead emphasizes a cluster-informed mixture model: endogenous expression is supported by the cell’s cluster, while expression patterns in other clusters help inform the contaminating component. Both approaches estimate contamination rather than directly observing molecule origins, and both can be affected by uncertain profiles and biological expression shared across cell types.
The choice between approaches depends on the available information and the structure of the data. An explicit ambient profile can be useful when it is well estimated, while cluster-informed modeling can be useful when cell groups provide a meaningful contrast. Neither approach removes the need to check assumptions, and their estimates need not agree because they use different information and modeling choices.
Check Your Understanding
Answer each question, then compare your reasoning with the solutions.
- A cell has \(N_i=800\) observed counts and \(\theta_i=0.05\). What total contaminating contribution does the fitted model imply on average, and what does this number not establish?
- For one gene, let \(p_{ig}=0.10\), \(q_{ig}=0.30\), and \(\theta_i=0.20\). Calculate the mixture probability for that gene.
- Why can incorrect cluster assignments distort the estimated contamination fraction?
- If the endogenous and contaminating profiles are identical across all genes, can the data identify \(\theta_i\)? Explain.
- Does a cell-level contamination fraction of 10% mean that every gene in the cell is 10% contaminated? Explain.
Solutions. (1) The expected contaminating contribution is \(800(0.05)=40\) counts. This is a model-based expectation, not evidence that 40 individually identified molecules came from ambient RNA. (2) The mixture probability is \((1-0.20)(0.10)+(0.20)(0.30)=0.08+0.06=0.14\). (3) Clusters inform the endogenous profile; incorrect groupings can make genuine endogenous expression look atypical or contaminate the reference profile, changing the decomposition. (4) No. If the profiles are identical, the mixture is unchanged for every \(\theta_i\), so the components are not distinguishable from the observed composition. (5) No. The cell-level fraction summarizes the whole cell; a gene’s contaminating share depends on its probability in both the endogenous and contaminating profiles.