View source: R/operations_agg_strata.R
| rename_strata | R Documentation |
Use rename_strata() to replace automatic stratum labels with names that are
clear in figures and result tables, such as "Control", "Treated", or
"Tumour tissue".
Use this function after agg_strata() when labels such as "Strata1" do not
describe the biological groups. The unit being changed is the stratum label.
Stratum membership and the repertoires, receptors, cells, and chains remain
unchanged.
The function returns a new ImmunData object. The original object is not changed.
rename_strata(
idata,
names,
unnamed = c("error", "auto", "keep"),
auto_prefix = "Strata"
)
idata |
An ImmunData object with strata already created by
|
names |
A named character vector or a data frame. New labels matched to
Every new label must be non-empty and unique. |
unnamed |
A character string. What to do when |
auto_prefix |
A non-empty character string. Prefix used to generate
labels when |
The names of a named character vector are the stratum IDs, not the current
labels. Inspect idata$strata to find the ID for each biological group.
The mapping cannot contain unknown or repeated IDs, and the resulting labels must be unique across strata.
A new ImmunData object with the requested labels in its $strata
and $repertoires tables. All biological group assignments and repertoire
summaries are preserved.
The readable strata_name is stored in the repertoire and strata tables. The
underlying chain annotations keep only imd_strata_id, so renaming a stratum
does not rewrite or regroup chain-level data.
agg_strata(), agg_repertoires()
library(immundata)
library(dplyr)
options(immundata.verbose = FALSE)
# Create treatment strata for the sample repertoires in the test data
treatment_groups <- get_test_idata() |>
agg_repertoires(c("Response", "Therapy")) |>
agg_strata(schema = "Therapy")
# Replace automatic labels with names suitable for a figure
labeled_groups <- treatment_groups |>
rename_strata(
names = c("1" = "CAR-T arm", "2" = "ICI arm")
)
labeled_groups$strata |>
select(Therapy, imd_strata_id, strata_name) |>
arrange(imd_strata_id)
# Expected result:
# Therapy imd_strata_id strata_name
# CAR-T 1 CAR-T arm
# ICI 2 ICI arm
# Only the labels changed. Each sample repertoire remains in the same
# treatment stratum.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.