The user wants a walkthrough of quality control (QC) for spatial transcriptomics data.
Specifically, the request mentions three key areas:
- Registration: Aligning the tissue image to the spatial coordinates.
- Deconvolution: Estimating cell type proportions from spot data (usually relevant for Visium/slide-seq).
- Confounders: Technical and biological factors that affect the data.
I need to structure the response logically, moving through the standard pipeline of spatial transcriptomics analysis, focusing on the QC aspects of each requested section.
1. Introduction:
- Briefly define Spatial Transcriptomics (ST) and why QC is crucial (it bridges histology and genomics).
- Mention the most common platforms (10x Visium is the standard mental model here, but I should keep it general enough).
2. Registration (Image Alignment):
- What is it? Aligning the H&E (histology) image to the spatial coordinates of the gene expression matrix.
- QC checks:
- Landmark alignment: Do the tissue boundaries match?
- Scale/Rotation: Is the image warped?
- Spot under-tissue: Are the spots actually covering the tissue, or are some on the background?
- Tissue segmentation: If using the image for segmentation (cellpose, etc.), how accurate is the mask?
3. Deconvolution (Cell Type Resolution):
- Context: Most spots (Visium) contain multiple cells (1-10+). Deconvolution tries to estimate the proportion of cell types per spot.
- QC checks:
- Reference quality: The scRNA-seq reference must match the tissue.
- Correlation with Histology: Does the predicted cell type match what the pathologist sees? (e.g., don't predict neurons in a blank stroma region).
- Proportion Sum: Do proportions sum to 1? Are there "unknown" or "junk" fractions?
- Metrics: RMSE or correlation metrics if using synthetic mixtures.
4. Confounders (Technical/Biological Noise):
- What are they? Factors that drive variation that isn't biological reality.
- Types:
- Tissue thickness/Density: Thicker areas yield more RNA but might be artifactually dense.
- Mitochondrial content: High % Mito usually means dying cells or bad capture (edge effect).
- Number of Genes/UMIs: Library size normalization is needed.
- Batch Effects: Different slides, sequencing runs.
- Spatial Autocorrelation: Is a gene variable because it's biological or just because adjacent spots are similar (Moran's I)?
5. General Standard QC (The Basics):
- Need to briefly touch on standard RNA-seq QC (Total counts, Genes per spot, % Mitochondrial) before getting too deep into the spatial specific stuff.
6. Structure of the response:
- Use clear headings.
- Use bullet points for readability.
- Provide "Red Flags" or "Actionable Steps" to make it practical.
Drafting the Content - Section by Section:
- Registration: Focus on the
tissue_lowres_image vs tissue_hires_image and the scalefactors json file. Mention manual inspection.
- Deconvolution: Mention tools like Cell2location, RCTD, SPOTlight. The key QC here is cross-validation with the image.
- Confounders: Focus on the "Tissue Density" problem. H&E staining intensity often correlates with RNA capture. This is a specific spatial confounder. Also, edge effects (tissue tearing).
Refining the Content:
- Registration: Make sure to distinguish between "rigid" (rotation/translation) and "non-rigid" (warping) registration if applicable, though standard Visium is usually rigid.
- Deconvolution: Emphasize that this is an estimation. The QC is validating that estimation.
- Confounders: Mention "spatial variability" vs "technical variability".
Self-Correction during drafting:
- Initial thought: Maybe detail the code (Scanpy/Squidpy).
- Correction: The prompt asks to "Walk me through," implying concepts and logic rather than specific code syntax. I will describe what to check and why, rather than just pasting Python code, but I will mention the libraries (Scanpy, Seurat, Squidpy) as context.
Final Polish:
- Ensure the tone is professional and educational.
- Add a concluding summary about the iterative nature of this process.
(Self-Correction regarding "Registration"): In some contexts (Xenium/Merfish), registration is automatically handled by the instrument. In Visium, it's manual/semi-automated. I should clarify that registration QC is mostly about ensuring the fiducial markers align and the spots fall on the tissue.
(Self-Correction regarding "Deconvolution"): Is the user asking about image deconvolution (microscopy) or transcriptomic deconvolution (cell type mixing)?
Context clue: "Spatial transcriptomics QC". It is almost certainly transcriptomic deconvolution (unmixing cell types). However, image deconvolution (removing blur) is a microscopy step. I will focus on transcriptomic deconvolution but briefly nod to image processing if relevant (though usually less critical for standard QC discussions compared to cell typing). I will stick to cell-type deconvolution as it's the major analysis hurdle.
Let's build the response.
- Overview: Image + Gene Matrix alignment.
- Registration: Scale factors, Fiducials, Tissue boundary check.
- General RNA QC: N genes, N counts, %Mito (spatially aware).
- Deconvolution: Reference selection, Consistency with histology, Residuals.
- Confounders: Tissue morphology (thickness), Ripley's K / Moran's I, Batch effects.
Let's write it out.
Spatial transcriptomics (ST) combines histological imaging with gene expression data. Because it generates two distinct data types (images and RNA counts) that must be integrated, Quality Control (QC) is more complex than in standard single-cell RNA-seq.
Here is a walkthrough of the three critical stages you requested: Registration, Deconvolution, and Confounders.
1. Registration (Image Alignment)
Registration is the process of aligning the stained tissue image (H&E or IF) to the spatial coordinate system used to capture the RNA. If this is off, your gene expression maps will not match the tissue architecture.
A. The Fiducial Alignment
Most platforms (like 10x Visium) use a "fiducial frame"—a patterned border around the capture area.
- The Check: You must verify that the software has correctly identified the fiducial markers.
- QC Metric: Residual error (measured in pixels). If the software reports a high alignment error, the downstream spot placement will be skewed.
- Manual Override: Automated alignment often fails on tissues with unusual morphology or if the image contrast is poor. Visual inspection is required to ensure the fiducial grid lines up perfectly with the frame.
B. Tissue Boundary Detection
The system defines which spots (or pixels) contain tissue and which are blank background.
- The Check: Overlay the "tissue mask" onto the H&E image.
- Common Failure: The thresholding algorithm might miss faint tissue (e.g., adipose or loose connective tissue) or falsely include background debris.
- Action: Manually adjust the intensity threshold or use a machine-learning segmentation tool (like ilastik or CellPose) to refine the mask.
C. Scale Factors
- The Check: Ensure the conversion factor (microns to pixels) is correct.
- Why it matters: If the scale factor is wrong, your "50µm spot" might actually be covering 100µm of tissue, leading to mixed signals from distinct structures.
2. Deconvolution (Cell Type Resolution)
In spot-based ST (like Visium), a single spot (55µm) may contain 1 to 30 cells. Deconvolution uses reference data (scRNA-seq) to estimate the proportion of cell types within each spot.
A. Reference Quality Control
The output is only as good as the reference input.
- QC Check: Perform cross-validation. If you train the deconvolution model on 80% of the scRNA-seq data and test it on the remaining 20%, can it accurately predict the cell types?
- Warning: Using a reference from a different tissue state (e.g., fetal vs. adult) or species will result in "hallucinated" cell types.
B. Biological Plausibility (The "Sanity Check")
Since there is no ground truth for spatial mixtures, you rely on biological priors.
- The Check: Compare the deconvoluted map against the H&E image.
- Example: Does your "B-cell" map perfectly overlay a germinal center? Does your "Adipocyte" prediction land on the empty white blobs in the image?
- Red Flag: If a cell type is predicted to be ubiquitous across the entire tissue (including necrotic regions or artifacts), the deconvolution has likely failed or the reference signature is too generic.
C. Statistical Confidence
- Metrics: Use tools like Cell2location or RCTD which provide confidence intervals or "q-value" matrices.
- Action: Filter out spots where the confidence intervals are massive (e.g., the model predicts "5 to 500 T-cells").
3. Confounders (Technical & Biological Noise)
Once you have a count matrix, you must filter noise. In ST, confounders are unique because they are often spatially structured.
A. The "Tissue Edge" Effect
- The Issue: Spots at the periphery of the tissue often contain less RNA because they partially cover empty space, yet they might show high counts due to light scattering or background noise.
- QC Metric: Plot
nGenes or nCounts against the distance from the tissue centroid. Look for sharp drops at the edges.
- Action: Filter spots with low
nGenes specifically at the edges, or use normalization methods that account for library size differences.
B. Mitochondrial Content (Cell Viability)
- The Issue: High mitochondrial RNA percentage usually indicates dying or stressed cells.
- The Spatial Nuance: In ST, "dying" might be biological (e.g., a necrotic tumor core).
- Action: Don't just blindly filter out high-Mito spots. Check the H&E image. If the high-Mito spot corresponds to a necrotic region on the slide, it is biological signal, not technical noise. If it looks like healthy tissue, it is noise.
C. Background and "Bleed-through"
- The Issue: Free-floating RNA (ambient RNA) can diffuse from one spot to another.
- QC Metric: Look for the expression of highly abundant genes (like Malat1 or ribosomal genes) in spots that are outside the tissue mask (background spots).
- Action: Use algorithms like SoupX or DecontX to estimate the ambient RNA profile from the background spots and subtract it from the tissue spots.
D. Histological Artifacts
- The Issue: Tears, folds, or debris on the slide.
- QC Action: These spots usually have bizarre gene count profiles (very low counts or weird gene ratios).
- Manual Curation: You often have to manually draw polygons around tissue rips in the visualization software to exclude those spots from the analysis.
Summary Checklist
- Registration: Is the H&E image perfectly overlaid on the spots? Are fiducials straight?
- Counts: Are spots with low UMI/Genes filtered? Is Mito% correlated with necrosis?
- Deconvolution: Do the predicted cell types match the visible histology?
- Confounders: Have you accounted for edge effects and ambient RNA?