This helper function takes a user-friendly list of single and multiple phenotype names and converts it to a named list of phenotype selectors for use with select_rows. By using parse_phenotypes a user does not have to know the (somewhat inscrutable) details of select_rows.

parse_phenotypes(...)

Arguments

...

Phenotypes to be decoded, or a list of same, optionally with names.

Value

A named list of phenotype selectors for use with select_rows.

Details

Each phenotype must be either a single phenotype name (e.g. CD3+ or CD8-) or two or more names separated by a slash (/) or comma (,).

Phenotypes containing slashes are interpreted as requiring all of the individual phenotypes. For example, "CD3+/CD8-" is a CD3+ cell which is also CD8-.

Phenotypes containing commas are interpreted as requiring any of the individual phenotypes. For example, "CD68+,CD163+" is a cell which is either CD68+ or CD163+ or both.

Additionally,

  • A phenotype without a + or - and containing either "Total" or "All" will be interpreted as meaning "All cells".

  • A phenotype starting with '~' will be interpreted as a formula expression. Formulas may be standalone phenotypes or combined with slash (/); they cannot be combined with comma (,).

Examples

# Create selectors for
# - All CD3+ cells
# - CD3+/CD8+ double-positive cells
# - CD3+/CD8- single-positive cells
# - CD3+ cells with membrane PDL-1 > 5
# - All cells regardless of phenotype
# - Macrophages, defined as either CD68+ OR CD163+
parse_phenotypes("CD3+", "CD3+/CD8+", "CD3+/CD8-",
                 "CD3+/PDL-1+"="CD3+/~`Membrane PDL-1 (Opal 520) Mean`>5",
                 "Total Cells", Macrophage="CD68+,CD163+")
#> $`CD3+`
#> [1] "CD3+"
#> 
#> $`CD3+/CD8+`
#> $`CD3+/CD8+`[[1]]
#> [1] "CD3+"
#> 
#> $`CD3+/CD8+`[[2]]
#> [1] "CD8+"
#> 
#> 
#> $`CD3+/CD8-`
#> $`CD3+/CD8-`[[1]]
#> [1] "CD3+"
#> 
#> $`CD3+/CD8-`[[2]]
#> [1] "CD8-"
#> 
#> 
#> $`CD3+/PDL-1+`
#> $`CD3+/PDL-1+`[[1]]
#> [1] "CD3+"
#> 
#> $`CD3+/PDL-1+`[[2]]
#> ~`Membrane PDL-1 (Opal 520) Mean` > 5
#> 
#> 
#> $`Total Cells`
#> [1] NA
#> 
#> $Macrophage
#> [1] "CD68+"  "CD163+"
#>