Counts and Locations Describe Different Features of a Spatial Assay
A spatial transcriptomics data set pairs molecular measurements with locations in a tissue. The measurements are usually organized as a matrix, while the locations are stored in one or more coordinate tables. Keeping these objects distinct matters: a gene-count matrix says what was measured at each spot; a coordinate system says where that spot is represented. Array geometry then determines which locations are immediate neighbors.
A spot is a capture location, not necessarily an individual cell. Its row of counts summarizes molecules assigned to that location under the assay’s capture and processing procedures. A row total, \(\sum_{g=1}^{G}Y_{ig}\), is the total count across the included genes for spot \(i\); it is not a direct measurement of the number of cells there.
The location of a spot can be represented in more than one coordinate system. Array coordinates identify a position in the assay’s grid, often with integer row and column indices. Image coordinates give the location in pixels in an image. Physical tissue coordinates represent distances in physical units, such as micrometers. An array coordinate such as \((2,3)\) is an index, not a distance of two or three micrometers.
Array Geometry Determines the Candidate Neighbors
For a regular array, spot centers lie on a lattice. A lattice is described by an origin and two basis vectors: integer steps in the two grid directions move between capture positions. The shape and spacing of those basis vectors determine the physical distances between positions. In practice, the assay layout or validated coordinate metadata should establish the geometry; it should not be inferred from a gene-expression pattern.
On a square array with equal spacing \(d\), the basis vectors are perpendicular and each has length \(d\). If two positions differ by \(m\) grid steps in one direction and \(n\) in the other, their squared distance is \(d^2(m^2+n^2)\). The nearest distinct grid positions differ by one step along exactly one axis. This gives four nearest neighbors, at distance \(d\). A diagonal position is at distance \(\sqrt{2}d\), so it is not one of these four nearest neighbors.
Some analyses instead use eight-neighbor adjacency on a square grid, including the four diagonal positions. That is a different convention, not a consequence of the word “neighbor” alone. Whether diagonals are included should be stated explicitly. For a regular hexagonal packing, each interior position has six nearest neighbors. One convenient coordinate system for this geometry uses two integer coordinates \((q,r)\) whose physical basis vectors have equal length \(d\) and meet at \(60^\circ\).
Here \((q,r)\) is the difference between two spots’ array coordinates. The cross-product term follows from the \(60^\circ\) angle between the basis vectors. The six offsets \((1,0)\), \((0,1)\), \((1,-1)\), and their negatives have squared distance \(d^2\). They are the nearest positions. For example, the offset \((1,1)\) has squared distance \(3d^2\), so it is farther away than those six.
Worked Example: Reading a Spot-Count Matrix
Suppose a hypothetical assay reports counts for three spots and three genes as follows. The array coordinates are shown separately so that the measurement and location information are not conflated.
| Spot | Gene A | Gene B | Gene C | Array coordinate |
|---|---|---|---|---|
| S1 | 12 | 4 | 0 | (0, 0) |
| S2 | 8 | 5 | 2 | (1, 0) |
| S3 | 3 | 0 | 7 | (0, 1) |
The count matrix, with rows ordered S1, S2, S3 and columns ordered Gene A, Gene B, Gene C, is
For S2, the row total is \(8+5+2=15\) counts across these three genes. The zero for Gene C at S1 means no count for that gene was recorded there under the stated processing rules; it does not mean that the location is absent. On a hexagonal array using the coordinate convention above, S2 differs from S1 by \((1,0)\), and S3 differs from S1 by \((0,1)\). Both are nearest positions to S1. The coordinate table identifies those relationships; the count values do not.
Coordinate Geometry and a Short Derivation
The nearest-neighbor rule can be justified directly from the lattice. For a square grid, a nonzero integer offset \((m,n)\) has squared distance \(d^2(m^2+n^2)\). The smallest possible value of \(m^2+n^2\) is 1, attained only by \((1,0)\), \((-1,0)\), \((0,1)\), and \((0,-1)\). If both coordinates are nonzero, the squared distance is at least \(2d^2\). Thus the four axis offsets, and not the diagonals, are the nearest positions under four-neighbor square adjacency.
For the hexagonal coordinate convention, the distance formula comes from adding the two basis-vector displacements. If the basis vectors \(a_1\) and \(a_2\) have length \(d\) and angle \(60^\circ\), the displacement is \(q a_1+r a_2\). Expanding its squared length gives
For a nonzero integer offset, the smallest value of \(q^2+r^2+qr\) is 1, reached at \((1,0)\), \((0,1)\), \((1,-1)\) and their negatives. These are therefore the six nearest offsets. This result relies on a regular hexagonal lattice with equal basis lengths and a \(60^\circ\) angle; it should not be applied blindly to irregular or differently encoded arrays.
Worked Example: Finding Neighbors on a Hexagonal Array
Consider a hypothetical hexagonal array with spacing \(d=100\) micrometers and spots at array coordinates A \((0,0)\), B \((1,0)\), C \((1,1)\), D \((2,0)\), and E \((0,1)\). Use the six nearest offsets derived above.
From A to B, the offset is \((1,0)\), so the squared distance is \(100^2(1+0+0)=10{,}000\) square micrometers and the distance is \(100\) micrometers. From A to E, the offset is \((0,1)\), giving the same distance. Both are nearest neighbors of A.
From A to C, the offset is \((1,1)\). Its squared distance is \(100^2(1+1+1)=30{,}000\) square micrometers, so its distance is \(\sqrt{30{,}000}\approx173.2\) micrometers. C is not a nearest neighbor of A. From A to D, the offset is \((2,0)\), giving distance \(200\) micrometers. D is also not a nearest neighbor of A. Thus, among the listed spots, A’s nearest neighbors are B and E. Other nearest positions may exist on the full array but are not included in this hypothetical list.
Units, Coordinate Transformations, and Checks
Image coordinates are often in pixels, while array coordinates are indices. If pixel positions are converted to physical positions by a calibrated scale, the units change accordingly. For example, a spacing of 80 pixels corresponds to 40 micrometers when the scale is 0.5 micrometers per pixel. A distance calculated in pixels cannot be compared directly with a threshold specified in micrometers.
Coordinate frames may also differ in origin or orientation. A translation changes the origin but preserves pairwise distances; a rotation or reflection preserves distances as well. Scaling changes distances. More generally, if physical coordinates are computed by \(z_i=A u_i+b\), where \(A\) is a calibration or transformation matrix and \(b\) is a translation, distances must be calculated after applying the relevant scale and orientation. If the image has unequal horizontal and vertical scales, treating both pixel axes as the same physical unit can distort which locations appear closest.
Worked Example: Converting Pixel Spacing to Micrometers
Suppose three hypothetical square-array spots have pixel coordinates P \((40,25)\), Q \((120,25)\), and R \((40,105)\). The image calibration is 0.5 micrometers per pixel in both axes. The physical coordinates are obtained by multiplying each pixel coordinate by 0.5: P is \((20,12.5)\), Q is \((60,12.5)\), and R is \((20,52.5)\), in micrometers.
The distance from P to Q is \(\sqrt{(60-20)^2+(12.5-12.5)^2}=40\) micrometers. The distance from P to R is \(\sqrt{(20-20)^2+(52.5-12.5)^2}=40\) micrometers. These are the two listed positions one grid step from P, so they are nearest neighbors under four-neighbor square adjacency. In pixel units, each distance is 80 pixels; the two values describe the same separation in different units.
Several checks help identify coordinate errors before interpreting spatial relationships:
- Confirm that spot identifiers match between the rows of \(Y\) and the coordinate records, and verify that each retained spot has one valid location.
- Check the documented array geometry and coordinate convention. In hexagonal systems, different software may encode the same layout with different row and column offsets.
- Inspect distances between adjacent positions. Regular interior spacings should be compatible with the stated geometry and calibration.
- Check axis orientation, image registration, and units. A flipped axis may preserve distances but misalign spots with tissue features; an incorrect scale changes distances.
- Distinguish an unobserved or filtered position from a measured position with zero counts. A missing position has no row in the retained matrix, whereas a measured zero is an observed count value.
Choosing and Interpreting a Neighbor Convention
For a regular square array, four-neighbor adjacency is a natural rule when only edge-sharing grid positions are intended; eight-neighbor adjacency also includes diagonals. For a regular hexagonal array, the six closest lattice positions are the natural nearest-neighbor set. These rules differ because the layouts differ, not because one universal neighbor rule applies to all spatial data.
A distance threshold is another possible convention: declare two spots neighbors when their physical separation is below a chosen cutoff. This can be useful when positions are irregular, but the cutoff must be stated in meaningful units and justified for the assay layout. It may yield different numbers of neighbors for different spots. A fixed number of nearest positions is a further alternative, but it can link spots across unusually large gaps at tissue boundaries. These are ways of defining proximity; none should be silently substituted for the array’s documented geometry.
The rules above identify geometric neighbors, not statistical dependence. A later analysis may use a set of neighboring locations to define a spatial structure, but the neighbor convention is an input that can affect that analysis. It should therefore be recorded along with the coordinate frame, units, and array geometry.
The main limitation is that a regular-lattice rule describes the intended capture layout, while the observed tissue may cover only part of that layout or may be distorted in an image. Missing spots do not create new lattice positions, and a chosen proximity rule does not repair registration or calibration errors. Confirming the physical alignment and reporting the rule are essential when spatial comparisons depend on location.
Check Your Understanding
Answer each question, then compare with the solutions.
- In a spot-count matrix, what does \(Y_{ig}\) represent, and what do its row and column indices identify?
- On a square lattice with equal spacing \(d\), what is the distance from a spot to a diagonal position one step away along each axis? Is it a four-neighbor position?
- On a hexagonal lattice, determine whether offset \((1,-1)\) is a nearest position and calculate its distance in terms of \(d\).
- A pair of spots is 120 pixels apart, and the calibration is 0.25 micrometers per pixel. What is their physical separation?
- Why is a spot with zero counts different from a capture position absent from the retained matrix?
Solutions. (1) \(Y_{ig}\) is the observed count for gene \(g\) at spot \(i\); rows identify spots and columns identify genes. (2) The squared distance is \(d^2(1^2+1^2)=2d^2\), so the distance is \(\sqrt{2}d\); it is diagonal and not among the four nearest positions. (3) The squared distance is \(d^2(1+1-1)=d^2\), so its distance is \(d\); it is one of the six nearest offsets. (4) \(120\) pixels \(\times 0.25\) micrometers per pixel \(=30\) micrometers. (5) A zero is an observed count value for a represented spot, whereas an absent position has no retained spot row and therefore no observed entry for that location.