Skip to contents

This function is a wrapper around tidytof's tof_metacluster_* function family. It performs metaclustering on CyTOF data using a user-specified method (of 5 choices) and each method's corresponding input parameters.

Usage

tof_metacluster(
  tof_tibble,
  cluster_col,
  metacluster_cols = where(tof_is_numeric),
  central_tendency_function = stats::median,
  ...,
  augment = TRUE,
  method = c("consensus", "hierarchical", "kmeans", "phenograph", "flowsom")
)

Arguments

tof_tibble

A `tof_tbl` or `tibble`.

cluster_col

An unquoted column name indicating which column in `tof_tibble` stores the cluster ids for the cluster to which each cell belongs. Cluster labels can be produced via any method the user chooses - including manual gating, any of the functions in the `tof_cluster_*` function family, or any other method.

metacluster_cols

Unquoted column names indicating which columns in `tof_tibble` to use in computing the metaclusters. Defaults to all numeric columns in `tof_tibble`. Supports tidyselect helpers.

central_tendency_function

The function that should be used to calculate the measurement of central tendency for each cluster before metaclustering. This function will be used to compute a summary statistic for each input cluster in `cluster_col` across all columns specified by `metacluster_cols`, and the resulting vector (one for each cluster) will be used as the input for metaclustering. Defaults to median.

...

Additional arguments to pass to the `tof_metacluster_*` function family member corresponding to the chosen `method`.

augment

A boolean value indicating if the output should column-bind the metacluster ids of each cell as a new column in `tof_tibble` (TRUE; the default) or if a single-column tibble including only the metacluster ids should be returned (FALSE).

method

A string indicating which clustering method should be used. Valid values include "consensus", "hierarchical", "kmeans", "phenograph", and "flowsom".

Value

A `tof_tbl` or `tibble` If augment = FALSE, it will have a single column encoding the metacluster ids for each cell in `tof_tibble`. If augment = TRUE, it will have ncol(tof_tibble) + 1 columns: each of the (unaltered) columns in `tof_tibble` plus an additional column encoding the metacluster ids.

Examples

sim_data <-
    dplyr::tibble(
        cd45 = rnorm(n = 1000),
        cd38 = rnorm(n = 1000),
        cd34 = rnorm(n = 1000),
        cd19 = rnorm(n = 1000),
        cluster_id = sample(letters, size = 1000, replace = TRUE)
    )

tof_metacluster(
    tof_tibble = sim_data,
    cluster_col = cluster_id,
    clustering_algorithm = "consensus",
    method = "flowsom"
)
#> # A tibble: 1,000 × 6
#>      cd45    cd38   cd34    cd19 cluster_id .flowsom_metacluster
#>     <dbl>   <dbl>  <dbl>   <dbl> <chr>      <chr>               
#>  1 -0.350 -1.50    2.82  -0.573  g          2                   
#>  2  1.64  -0.422   0.543  2.31   i          3                   
#>  3  1.06  -0.0543  0.877 -0.444  l          3                   
#>  4  0.644 -1.12   -1.12  -0.604  k          4                   
#>  5  1.34   0.606  -0.631  0.0561 p          2                   
#>  6 -1.20   0.484  -0.166  0.0976 l          3                   
#>  7  0.781 -0.699   0.619 -0.693  x          2                   
#>  8 -0.230 -0.0746  0.793 -0.805  f          4                   
#>  9 -0.504  1.05   -1.39   1.01   h          2                   
#> 10  0.511  0.492  -2.11   0.543  x          2                   
#> # ℹ 990 more rows

tof_metacluster(
    tof_tibble = sim_data,
    cluster_col = cluster_id,
    method = "phenograph"
)
#> # A tibble: 1,000 × 6
#>      cd45    cd38   cd34    cd19 cluster_id .phenograph_metacluster
#>     <dbl>   <dbl>  <dbl>   <dbl> <chr>      <chr>                  
#>  1 -0.350 -1.50    2.82  -0.573  g          2                      
#>  2  1.64  -0.422   0.543  2.31   i          1                      
#>  3  1.06  -0.0543  0.877 -0.444  l          1                      
#>  4  0.644 -1.12   -1.12  -0.604  k          3                      
#>  5  1.34   0.606  -0.631  0.0561 p          2                      
#>  6 -1.20   0.484  -0.166  0.0976 l          1                      
#>  7  0.781 -0.699   0.619 -0.693  x          4                      
#>  8 -0.230 -0.0746  0.793 -0.805  f          3                      
#>  9 -0.504  1.05   -1.39   1.01   h          2                      
#> 10  0.511  0.492  -2.11   0.543  x          4                      
#> # ℹ 990 more rows