The section, the array, and the files
The example follows one anterior sagittal brain section from one mouse. Its capture array contains positions both under and outside tissue, while the filtered expression matrix contains only the provider’s tissue spots. Those two matrices describe different observation sets from the same experiment.
The 10x Genomics dataset
provides the counts, coordinates, images, and archived reports under
CC BY 4.0. Space Ranger 1.1.0
produced the archived outputs with the mm10-2020-A reference. This section
starts with those outputs and calculates new downstream results. It does not
rerun read alignment or validate the provider’s tissue classification.
Preserve the source identity
Section titled “Preserve the source identity”| Input | Role |
|---|---|
| Filtered HDF5 matrix | The matrix contains the provider-selected tissue spots. |
| Unfiltered HDF5 matrix | The matrix contains every supplied array barcode. |
| Spatial archive | The archive links barcodes to positions, images, and scale factors. |
| Metrics CSV | The table contains archived Space Ranger metrics. |
| Web report | The report records the archived primary analysis. |
The unfiltered matrix is a count output. It is not a collection of raw sequencing reads. The local SHA-256 values identify the exact downloaded bytes; they are not independent checksums supplied by 10x Genomics.
The private companion repository
contains the source manifest, preparation scripts, and locked spatial:0.1.0
image. Its runners mount the public input fixture at /fixtures and shared
format readers at /shared. Access to that repository requires permission.
The public dataset remains available directly from 10x Genomics.
Reconcile the matrices and the mask
Section titled “Reconcile the matrices and the mask”Both examples check every selected column against its unfiltered source.
The R example uses the same HDF5 reader through reticulate, then performs
matrix comparisons in R. Later R calculations also run in R; the shared reader
only handles the file format. Run each language’s blocks in order.
source("/shared/spatial_utils.R")provenance <- fromJSON("/fixtures/provenance.json")for (index in seq_len(nrow(provenance$files))) { record <- provenance$files[index, ] path <- file.path("/fixtures/source", record$filename) stopifnot(file.info(path)$size == record$bytes) stopifnot(digest::digest(file = path, algo = "sha256") == record$sha256)}data <- ReadCounts()unfiltered <- ReadCounts("raw")positions <- ReadPositions()stopifnot(identical(data$features$feature_id, unfiltered$features$feature_id))stopifnot(identical(data$features$symbol, unfiltered$features$symbol))stopifnot(setequal(unfiltered$barcodes, positions$barcode))tissue <- positions$barcode[positions$in_tissue == 1]stopifnot(setequal(data$barcodes, tissue))index <- match(data$barcodes, unfiltered$barcodes)stopifnot(Matrix::nnzero(data$counts - unfiltered$counts[, index]) == 0)dir.create("outputs", showWarnings = FALSE)png("outputs/array_r.png", width = 1000, height = 760, res = 130)plot(positions$array_col, -positions$array_row, pch = 16, cex = 0.45, col = ifelse(positions$in_tissue == 1, "#168080", "#c9cdd2"), asp = sqrt(3), xlab = "Array column", ylab = "Negative array row", main = "One section on the complete capture array")legend("bottomleft", c("Under tissue", "Outside tissue"), col = c("#168080", "#c9cdd2"), pch = 16, bty = "n")invisible(dev.off())metrics <- list(features = nrow(data$counts), spots = ncol(data$counts), array_spots = nrow(positions), umi = sum(data$counts), raw_umi = sum(unfiltered$counts), donors = 1, sections = 1)WriteMetrics(metrics)cat(sprintf("The matrix contains %d genes and %d tissue spots.\n", metrics$features, metrics$spots))cat(sprintf("The array contains %d positions from one section.\n", metrics$array_spots))cat(sprintf("All filtered columns match their unfiltered source.\n"))The matrix contains 32285 genes and 2695 tissue spots.The array contains 4992 positions from one section.All filtered columns match their unfiltered source.
The colors distinguish the archived tissue mask from positions outside tissue. The array contains one section from one donor.
import sysfrom pathlib import Path
import matplotlib.pyplot as pltimport numpy as npimport pandas as pd
sys.path.insert(0, "/shared")import spatial_utils as spatialfrom spatial_io import read_counts
provenance = spatial.verify_sources()data = read_counts()unfiltered = read_counts("raw")positions = pd.read_csv( "/fixtures/spatial/tissue_positions_list.csv", header=None, names=spatial.FIELDS,)assert data["features"].equals(unfiltered["features"])assert set(unfiltered["barcodes"]) == set(positions["barcode"])tissue = positions.loc[positions["in_tissue"].eq(1), "barcode"]assert set(data["barcodes"]) == set(tissue)index = pd.Index(unfiltered["barcodes"]).get_indexer(data["barcodes"])assert (data["counts"] != unfiltered["counts"][:, index]).nnz == 0Path("outputs").mkdir(exist_ok=True)fig, ax = plt.subplots(figsize=(8, 6))for state, label, color in [(0, "Outside tissue", "#c9cdd2"), (1, "Under tissue", "#168080")]: selected = positions.loc[positions["in_tissue"].eq(state)] ax.scatter(selected["array_col"], -selected["array_row"], s=7, color=color, label=label)ax.set(aspect=np.sqrt(3), xlabel="Array column", ylabel="Negative array row", title="One section on the complete capture array")ax.legend(loc="lower left")fig.savefig("outputs/array_python.png", dpi=160, bbox_inches="tight")plt.close(fig)metrics = dict(features=data["counts"].shape[0], spots=len(tissue), array_spots=len(positions), umi=int(data["counts"].sum()), raw_umi=int(unfiltered["counts"].sum()), donors=1, sections=1)spatial.write_metrics(metrics)print(f"The matrix contains {metrics['features']} genes and " f"{metrics['spots']} tissue spots.")print(f"The array contains {len(positions)} positions from one section.")print("All filtered columns match their unfiltered source.")The matrix contains 32285 genes and 2695 tissue spots.The array contains 4992 positions from one section.All filtered columns match their unfiltered source.
The Python figure uses the same complete barcode set and archived tissue mask. Colors do not represent independent samples.
The equality check establishes that the filtered file selects columns without changing their stored counts. It cannot establish whether the tissue mask is biologically correct. The coordinate lesson puts those positions over the supplied image so that the geometry can be read.
Further reading
Section titled “Further reading”The 10x Genomics specimen record identifies the section, software version, and downloadable archive. Use it to establish which specimen the file checks describe.
The Space Ranger spatial output specification defines tissue-position fields and image scale factors. Its version notes explain the headerless position file in this older archive.