For each clone barcode, convert the absolute count to proportion. If `grouping_col` is specified, the proportion will be calculated with respect to the total number of cells in each group.

convert_count_to_proportion(count_data, count_column, grouping_col = NA)

Arguments

count_data

A data.table containing clone barcode count data.

count_column

A character string specifying the column storing clone barcode counts.

grouping_col

A character string, default NA. If provided, the projection is repeated for each group defined by this column.

Value

A modified data.table with a new column representing the proportion.

Examples

library(data.table)

toy_clone_counts <- data.table(
sample_name = c(rep("test1", 2), rep("test2", 3)),
read_count = c(1, 5, 10, 15, 20)
)

convert_count_to_proportion(
    count_data = toy_clone_counts,
    grouping_col = "sample_name",
    count_column = "read_count"
)
#>    sample_name read_count read_proportion
#> 1:       test1          1       0.1666667
#> 2:       test1          5       0.8333333
#> 3:       test2         10       0.2222222
#> 4:       test2         15       0.3333333
#> 5:       test2         20       0.4444444