This is a batch version of count_within(). Given the path to a directory containing cell seg data files, 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_batch(base_path, pairs, radius, category = NA,
phenotype_rules = NULL, verbose = TRUE)

## Arguments

base_path Path to a directory containing at least one _cell_seg_data.txt file. A list of pairs of phenotypes. Each entry is a two-element vector. The result will contain values for each pair. The radius or radii to search within. Optional tissue categories to restrict both from and to phenotypes. (Optional) A named list. Item names are phenotype names and must match entries in pairs. Item values are selectors for select_rows(). If TRUE, display progress.

## Value

A tibble containing these columns:

slide_id

Slide ID from the data files, if available.

source

Base file name of the source file with _cell_seg_data.txt stripped off for brevity.

category

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

from

From phenotype.

to

To phenotype.

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.

# 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_batch(base_path, pairs, radius, phenotype_rules=rules)