Skip to content

Commit

Permalink
Merge pull request #361 from hms-dbmi-cellenics/fix-factor-active-ident
Browse files Browse the repository at this point in the history
make rename_active_ident work with factor+character
  • Loading branch information
alexvpickering authored Feb 23, 2024
2 parents ab93e1b + 6bcbdb3 commit 025ce7a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pipeline-runner/R/seurat-3-upload_seurat_to_aws.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ upload_seurat_to_aws <- function(input, pipeline_config, prev_out) {
rename_active_ident <- function(meta) {

# determine columns that are duplicates of active.ident
test_vals <- meta$active.ident
test_vals <- as.character(meta$active.ident)
dup.cols <- c()
for (col in setdiff(colnames(meta), 'active.ident')) {
col_vals <- meta[[col]]
col_vals <- as.character(meta[[col]])
if (identical(test_vals, col_vals))
dup.cols <- c(dup.cols, col)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -344,3 +344,21 @@ test_that("rename_active_ident does not rename active.ident when there isn't a d
meta_renamed <- rename_active_ident(meta)
expect_identical(meta, meta_renamed)
})

test_that("rename_active_ident works when one column is factor and the other is character", {

meta <- data.frame(
active.ident = c('cluster1', 'cluster2', 'cluster3'),
cell_type = factor(c('cluster1', 'cluster2', 'cluster3')),
other_clustering = c('clusterA', 'clusterA', 'clusterB')
)

expected_name <- 'cell_type'

meta_renamed <- rename_active_ident(meta)

expect_equal(colnames(meta_renamed)[1], expected_name)
expect_false('active.ident' %in% colnames(meta_renamed))
expect_equal(colnames(meta_renamed), c('cell_type', 'other_clustering'))
})

0 comments on commit 025ce7a

Please sign in to comment.