Derives the identifier of the analysis unit — the spatial unit that is
the unit of replication — for every row of a cell table, merging the
files that belong to the same unit according to a cr_merge_rules()
set.
Usage
cr_assign_units(
x,
key_vars,
replicate_var = "replicate",
rules = cr_merge_rules(),
id_col = "well_id",
sep = "|",
call = rlang::caller_env()
)Arguments
- x
A data frame of cells (or of files) carrying the design columns and a replicate index.
- key_vars
Character vector of column names that, together with the replicate index, identify one unit.
- replicate_var
Name of the replicate index column. Default
"replicate".- rules
A
cr_merge_rules()object.- id_col
Name of the unit identifier column to add. Default
"well_id".- sep
Separator used to build the identifier. Default
"|".- call
The execution environment of the calling function. Used for error reporting; experts only.
Value
x with two columns added: replicate_merged (the replicate
index after merging) and the unit identifier named by id_col. The
number of units is attached as the "n_units" attribute.
Details
The unit identifier is the combination of key_vars and the merged
replicate index. Files that share it are one unit; files that do not
are separate replicates. Because a unit may be assembled from more
than one file, cr_unit_map() should be used afterwards to see which
units were merged and from how many files.
See also
cr_unit_map(), cr_merge_rules(),
cr_centroid_overlap().
Other import:
cr_centroid_overlap(),
cr_column_map(),
cr_extract_markers(),
cr_filename_grammar(),
cr_marker_rules(),
cr_merge_rules(),
cr_parse_paths(),
cr_path_spec(),
cr_read_cellprofiler(),
cr_read_cells(),
cr_read_design(),
cr_read_export(),
cr_read_exports(),
cr_read_qupath(),
cr_read_segmantr(),
cr_unit_map()
Examples
files <- tibble::tibble(
compound = "CompoundA",
plate = "Plate_1",
mode = "treated",
replicate = c("1", "1.1", "2", "2.2"),
merge_unit = c(FALSE, TRUE, FALSE, FALSE),
reacquisition = FALSE
)
units <- cr_assign_units(files, key_vars = c("compound", "plate", "mode"))
units[, c("replicate", "replicate_merged", "well_id")]
#> # A tibble: 4 × 3
#> replicate replicate_merged well_id
#> <chr> <chr> <chr>
#> 1 1 1 CompoundA|Plate_1|treated|1
#> 2 1.1 1 CompoundA|Plate_1|treated|1
#> 3 2 2 CompoundA|Plate_1|treated|2
#> 4 2.2 2.2 CompoundA|Plate_1|treated|2.2