Read mixed marker signals
A capture spot can contain transcripts from several cells. Two marker genes can therefore appear together even when the corresponding signals usually occur in different cell populations. Joint detection in a spot does not prove joint expression within one cell, and a marker’s normalized count is not a cell fraction. This example has one section from one mouse, so marker-positive spots remain observations within that donor.
The fixed panel provides descriptive biological context.
Tasic et al. distinguish
glutamatergic and GABAergic cortical neurons with Slc17a7 and Gad1, and
identify Gad2 as another inhibitory neuronal marker.
Zhang et al. describe
astrocyte markers Gfap and Aqp4 and myelinating oligodendrocyte markers
that include Mbp and Plp.
Butovsky et al.
identify a microglial expression signature that includes P2ry12.
Marker expression can vary with anatomy and state.
Those studies motivate interpretation; their reference cells do not enter this
example or provide labels for its spots.
| Gene group | Descriptive context | Limit |
|---|---|---|
Slc17a7 |
The gene supports a glutamatergic neuronal signal. | A positive spot can include other cells. |
Gad1, Gad2 |
The genes support a GABA synthesis signal. | Their abundance does not count inhibitory neurons. |
Mbp, Plp1 |
The genes support a myelin-associated signal. | Captured RNA and cell numbers have different denominators. |
Gfap, Aqp4 |
The genes provide astroglial context. | State and anatomical variation can alter expression. |
P2ry12 |
The gene provides microglial context. | One gene does not establish a complete cell identity. |
Inspect joint detection and relative expression
Section titled “Inspect joint detection and relative expression”Both examples retain all valid tissue spots and use the same normalized expression as the earlier lessons. Joint detection means that both original counts exceed zero. The scatterplots show expression values, while the printed counts report spots with both signals, not cells with both markers.
source("/shared/spatial_utils.R")data <- ReadSection()panel <- PanelIndices(data$features)raw <- t(as.matrix(data$counts[panel, ]))relative <- t(as.matrix(NormalizeCounts(data$counts)[panel, ]))colnames(raw) <- data$features$symbol[panel]colnames(relative) <- colnames(raw)joint_myelin <- sum(raw[, "Mbp"] > 0 & raw[, "Plp1"] > 0)joint_neuronal <- sum(raw[, "Slc17a7"] > 0 & raw[, "Gad1"] > 0)dir.create("outputs", showWarnings = FALSE)write.table(data.frame(barcode = data$barcodes, relative), "outputs/markers_r.tsv", sep = "\t", quote = FALSE, row.names = FALSE)write.table(data.frame(barcode = data$barcodes, raw), "outputs/marker_counts_r.tsv", sep = "\t", quote = FALSE, row.names = FALSE)png("outputs/markers_r.png", width = 1400, height = 1200, res = 145)par(mfrow = c(2, 2), mar = c(4, 4, 3, 1))DrawSpatial(data, relative[, "Mbp"], "Mbp relative expression")DrawSpatial(data, relative[, "Gad1"], "Gad1 relative expression")plot(relative[, "Mbp"], relative[, "Plp1"], pch = 16, cex = 0.4, col = "#16808060", xlab = "Mbp log1p counts per 10,000", ylab = "Plp1 log1p counts per 10,000", main = "Two myelin-associated genes")plot(relative[, "Slc17a7"], relative[, "Gad1"], pch = 16, cex = 0.4, col = "#8159a360", xlab = "Slc17a7 log1p counts per 10,000", ylab = "Gad1 log1p counts per 10,000", main = "Mixed neuronal signals")invisible(dev.off())WriteMetrics(list(spots = nrow(relative), joint_mbp_plp1 = joint_myelin, joint_slc17a7_gad1 = joint_neuronal, marker_sum = sum(relative)))cat(sprintf("Mbp and Plp1 are both detected in %d spots.\n", joint_myelin))cat(sprintf("Slc17a7 and Gad1 are both detected in %d spots.\n", joint_neuronal))cat("These values count spots, not cells or cell fractions.\n")Mbp and Plp1 are both detected in 2623 spots.Slc17a7 and Gad1 are both detected in 2286 spots.These values count spots, not cells or cell fractions.
Each scatterplot point is one capture spot. Both axes contain log1p counts
per 10,000 UMIs, and every valid tissue spot remains visible.
import sys
import matplotlib.pyplot as pltimport numpy as npimport pandas as pd
sys.path.insert(0, "/shared")import spatial_utils as spatial
data = spatial.read_section()panel = spatial.panel_indices(data["features"])symbols = data["features"].iloc[panel]["symbol"].tolist()raw = data["counts"][panel].T.toarray()relative = spatial.normalize_counts(data["counts"])[panel].T.toarray()raw_table = pd.DataFrame(raw, index=data["barcodes"], columns=symbols)table = pd.DataFrame(relative, index=data["barcodes"], columns=symbols)raw_table.index.name = "barcode"table.index.name = "barcode"reference = pd.read_csv("outputs/markers_r.tsv", sep="\t", index_col=0)expected_counts = pd.read_csv("outputs/marker_counts_r.tsv", sep="\t", index_col=0)assert table.index.tolist() == reference.index.tolist()np.testing.assert_array_equal(raw_table, expected_counts[symbols])np.testing.assert_allclose(table, reference[symbols], atol=1e-6, rtol=0)joint_myelin = int(((raw_table["Mbp"] > 0) & (raw_table["Plp1"] > 0)).sum())joint_neuronal = int(((raw_table["Slc17a7"] > 0) & (raw_table["Gad1"] > 0)).sum())table.to_csv("outputs/markers_python.tsv", sep="\t")raw_table.to_csv("outputs/marker_counts_python.tsv", sep="\t")fig, axes = plt.subplots(2, 2, figsize=(12, 10))spatial.draw_spatial(axes[0, 0], data, table["Mbp"], "Mbp relative expression")spatial.draw_spatial(axes[0, 1], data, table["Gad1"], "Gad1 relative expression")axes[1, 0].scatter(table["Mbp"], table["Plp1"], s=4, alpha=0.4, color="#168080")axes[1, 0].set(xlabel="Mbp log1p counts per 10,000", ylabel="Plp1 log1p counts per 10,000", title="Two myelin-associated genes")axes[1, 1].scatter(table["Slc17a7"], table["Gad1"], s=4, alpha=0.4, color="#8159a3")axes[1, 1].set(xlabel="Slc17a7 log1p counts per 10,000", ylabel="Gad1 log1p counts per 10,000", title="Mixed neuronal signals")fig.tight_layout()fig.savefig("outputs/markers_python.png", dpi=150, bbox_inches="tight")plt.close(fig)spatial.write_metrics(dict(spots=len(table), joint_mbp_plp1=joint_myelin, joint_slc17a7_gad1=joint_neuronal, marker_sum=float(relative.sum())))print(f"Mbp and Plp1 are both detected in {joint_myelin} spots.")print(f"Slc17a7 and Gad1 are both detected in {joint_neuronal} spots.")print("These values count spots, not cells or cell fractions.")Mbp and Plp1 are both detected in 2623 spots.Slc17a7 and Gad1 are both detected in 2286 spots.These values count spots, not cells or cell fractions.
The examples compare all original marker counts exactly and every normalized
marker value within 1e-6. That agreement validates the calculation, not a
cell type assignment.
The tissue images come from 10x Genomics under CC BY 4.0. These figures add expression overlays. No cell segmentation, reference transfer, or deconvolution model enters the result.
What a composition estimate would require
Section titled “What a composition estimate would require”A reference-based estimate needs an audited single-cell reference with suitable species, tissue, states, and cell type coverage. Its donor design, gene identifiers, and assay differences affect whether the model can separate the proposed populations. Missing reference populations can force their signal into the populations that remain.
A model also needs an explicit output definition and independent validation. Some methods estimate relative contributions to RNA rather than cell numbers. The present section has no validated reference or ground truth for either quantity, so it stops at descriptive marker expression. The interpretation lesson connects that limit to the experimental unit.
Further reading
Section titled “Further reading”Tasic and colleagues describe the neuronal populations used to interpret the glutamatergic and GABAergic markers. Zhang and colleagues describe purified brain cell populations and their glial marker expression. Compare those reference-cell contexts with the mixed captured pools in this lesson before assigning a cell identity to a spot.