Given a cell seg table and an image containing masks for two tissue classes, estimate the density of cells of each specified phenotype in bands from the boundary between the two tissue classes.
density_bands(cell_seg_path, phenotypes, positive, negative, width = 25, pixels_per_micron = getOption("phenoptr.pixels.per.micron"))
Path to a cell segmentation data file.
Optional named list of phenotypes to process.
Name of the tissue category used as positive distance, e.g. "stroma".
Name of the tissue category used as negative distance, e.g. "tumor".
Width of the bands, in microns
Conversion factor to microns.
list with three items:
|| Cell seg data with phenotypes updated per the
|| The distance map, a pixel image
densities item contains five columns:
||The supplied phenotypes.|
||The midpoint of the distance band.|
||The number of cells of the phenotype found within the band.|
||The area of the band, in square microns.|
||The density of cells of the phenotype in the band, in cells per square micron.|
density_bands uses a counting approach similar to a histogram.
First the image is divided into bands based on distance from the
specified boundary. Next, the number of cells of each phenotype
within each distance band is counted and the area of each band
is estimated. The density estimates are the ratios of the cell
counts to the area estimates.
Density estimates are in cells per square micron; multiply by 1,000,000 for cells per square millimeter.
The returned value includes the cell counts and area of each band, making it straightforward to aggregate across multiple fields from a single sample. The aggregate density is computed by summing the cell counts and areas across all fields from a sample, then dividing to compute density.
Other density estimation:
# Compute density for the sample data values <- density_bands(sample_cell_seg_path(), list("CD8+", "CD68+", "FoxP3+"), positive="Stroma", negative="Tumor") # Plot the densities in a single plot library(ggplot2) ggplot(values$densities, aes(midpoint, density*1000000, color=phenotype)) + geom_line(size=2) + labs(x='Distance from tumor boundary (microns)', y='Estimated cell density (cells per sq mm)')