This is a wrapper around count_within() which supports counting multiple phenotype pairs and tissue categories within a single field. For each given tissue category, pair of 'from' phenotype and 'to' phenotype, and radius, it counts the number of 'from' cells having a 'to' cell within radius microns.

count_within_many(csd, pairs, radius, category = NA,
  phenotype_rules = NULL, verbose = TRUE)

Arguments

csd

A cell seg data table.

pairs

A list of pairs of phenotypes. Each entry is a two-element vector. The result will contain values for each pair.

radius

The radius or radii to search within.

category

Optional tissue categories to restrict both from and to phenotypes.

phenotype_rules

(Optional) A named list. Item names are phenotype names and must match entries in pairs. Item values are selectors for select_rows().

verbose

If TRUE, display progress.

Value

A data_frame containing these columns:

slide_id

Slide ID from the data, if available.

source

Source field name.

field

Name of the individual field, if available.

category

Tissue category, if provided as a parameter, or "all".

from

From phenotype.

to

To phenotype.

radius, from_count, to_count, from_with, within_mean

Results from count_within for this data file and tissue category.

Details

The category parameter may be a single category or a list of categories.

See the tutorial Selecting cells within a cell segmentation table for more on the use of pairs and phenotype_rules.

See also

Examples

csd <- sample_cell_seg_data # Count tumor cells near macrophages, and tumor cells near CD8 separately, # in tumor and stroma tissue categories separately. pairs <- list(c('CK+', 'CD68+'), c('CK+', 'CD8+')) radius <- c(10, 25) category <- list('Tumor', 'Stroma') count_within_many(csd, pairs, radius, category)
#> Processing Set4_1-6plex_[16142,55840].im3
#> # A tibble: 8 x 10 #> slide_id source category from to radius from_count to_count from_with #> <chr> <chr> <chr> <chr> <chr> <dbl> <int> <int> <int> #> 1 Set4_1-~ Set4_~ Tumor CK+ CD68+ 10 2192 101 79 #> 2 Set4_1-~ Set4_~ Tumor CK+ CD68+ 25 2192 101 397 #> 3 Set4_1-~ Set4_~ Tumor CK+ CD8+ 10 2192 51 63 #> 4 Set4_1-~ Set4_~ Tumor CK+ CD8+ 25 2192 51 320 #> 5 Set4_1-~ Set4_~ Stroma CK+ CD68+ 10 65 316 6 #> 6 Set4_1-~ Set4_~ Stroma CK+ CD68+ 25 65 316 34 #> 7 Set4_1-~ Set4_~ Stroma CK+ CD8+ 10 65 177 4 #> 8 Set4_1-~ Set4_~ Stroma CK+ CD8+ 25 65 177 22 #> # ... with 1 more variable: within_mean <dbl>
# Count tumor cells near any T cell in all tissue categories. # Use `phenotype_rules` to define the T cell phenotype pairs <- c('CK+', 'T cell') rules <- list( 'T cell'=c('CD8+', 'FoxP3+')) count_within_many(csd, pairs, radius, phenotype_rules=rules)
#> Processing Set4_1-6plex_[16142,55840].im3
#> # A tibble: 2 x 10 #> slide_id source category from to radius from_count to_count from_with #> <chr> <chr> <chr> <chr> <chr> <dbl> <int> <int> <int> #> 1 Set4_1-~ Set4_~ all CK+ T ce~ 10 2257 456 150 #> 2 Set4_1-~ Set4_~ all CK+ T ce~ 25 2257 456 824 #> # ... with 1 more variable: within_mean <dbl>