Skip to content

Commit

Permalink
Added new method-specific renaming of cell-types
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanspeh committed May 13, 2024
1 parent c545ea4 commit 6cf46fe
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export(find_suspicious_names)
export(fix_cell_names)
export(fix_cell_names_legacy)
export(get_rmse)
export(pivot_longer_deconvolution)
export(plot_deconvolution_celltype_corrs)
Expand Down
16 changes: 11 additions & 5 deletions R/process_deconvolution.R
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ process_immunedeconv <- function(cell_mix){
#'
#' @return A vector of standardised cell names
#'
#' @export
#' @examples
#' fix_cell_names(c("NK","B.Naive", "B.Memory"), method = "abis")
#'
fix_cell_names_legacy <- function(cell_names){
stopifnot("cell_names must be character vector" = is.character(cell_names))

Expand Down Expand Up @@ -84,8 +88,8 @@ fix_cell_names_legacy <- function(cell_names){
grepl(paste(Monocytes, collapse = "|"), cell_names, ignore.case = TRUE) ~ "monocytes",
grepl(paste(Basophils, collapse = "|"), cell_names, ignore.case = TRUE) ~ "basophils",
grepl(paste(Neutrophils, collapse = "|"), cell_names, ignore.case = TRUE) ~ "neutrophils",
grepl(paste(conventional_DCs, collapse = "|"), cell_names, ignore.case = TRUE) ~ "conventional_DCs",
grepl(paste(plasmacytoid_DCs, collapse = "|"), cell_names, ignore.case = TRUE) ~ "plasmacytoid_DCs",
grepl(paste(conventional_DCs, collapse = "|"), cell_names, ignore.case = TRUE) ~ "conventional_dendritic_cells",
grepl(paste(plasmacytoid_DCs, collapse = "|"), cell_names, ignore.case = TRUE) ~ "lymphoid_dendritic_cells",
grepl(paste(NK_cells, collapse = "|"), cell_names, ignore.case = TRUE) ~ "NK_cells",
grepl(paste(T_gd_cells, collapse = "|"), cell_names, ignore.case = TRUE) ~ "T_gd_cells",
.default = paste("Other, original was: ", cell_names))
Expand All @@ -104,16 +108,18 @@ fix_cell_names_legacy <- function(cell_names){
#'
#' @examples
#' fix_cell_names(c("NK","B.Naive", "B.Memory"), method = "abis")
#'
fix_cell_names <- function(cell_names, method){
if(!method%in%cell_types$method) stop(paste0("Method must be one of: ", paste(unique(cell_types$method), collapse = ", ")))
cell_types <- dplyr::filter(cell_types, method == method)
cell_types$general_name[match(cell_names, cell_types$method_name)]
newnames <- cell_types$general_name[match(cell_names, cell_types$method_name)]
# If there are T_regs and T_cells_CD4 in dataset, T_cells_CD4 has the be renamed to non_regs since T_cell_CD4 is parent of T_reg
if("T_regs" %in% newnames & "T_cells_CD4" %in% newnames) newnames[newnames == "T_cells_CD4"] <- "T_cells_CD4_non_regs"
newnames
}








1 change: 1 addition & 0 deletions man/fix_cell_names.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/fix_cell_names_legacy.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-process_deconvolution.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test_that("can standardise celltypes with legacy function", {

standardised <- c("B_cells","B_cells","B_cells", "B_cells",
"T_cells_CD4", "T_cells_CD4", "T_cells_CD8", "T_cells_CD8",
"neutrophils", "monocytes", "conventional_DCs")
"neutrophils", "monocytes", "conventional_dendritic_cells")
expect_equal(fix_cell_names_legacy(cells), standardised) })


Expand Down

0 comments on commit 6cf46fe

Please sign in to comment.