Skip to content

Instantly share code, notes, and snippets.

@MVesuviusC
Last active May 23, 2023 13:47
Show Gist options
  • Save MVesuviusC/5328972136ed5de5fd09b882747e8a61 to your computer and use it in GitHub Desktop.
Save MVesuviusC/5328972136ed5de5fd09b882747e8a61 to your computer and use it in GitHub Desktop.
Compare the commands run to generate two seurat objects
# compare the contents of the commands slot between test and combined_data
cmp_seurat_cmds <- function(sobj_a,
sobj_b,
sobj_a_name = "sobj_a",
sobj_b_name = "sobj_b",
verbose = FALSE) {
# Making a list here as not all of the contents of the arguments fit into a tibble
# A list can accept any data type
diff_list <- list()
for (step_ran in names(sobj_a@commands)) {
for (argument in names(as.list(sobj_a@commands[[step_ran]]))) {
a_val <- as.list(sobj_a@commands[[step_ran]])[[argument]]
b_val <- as.list(sobj_b@commands[[step_ran]])[[argument]]
if (!identical(a_val, b_val)) {
a_val <- ifelse(is.null(a_val), "not set", a_val)
b_val <- ifelse(is.null(b_val), "not set", b_val)
diff_list[[step_ran]][[argument]][[sobj_a_name]] <- a_val
diff_list[[step_ran]][[argument]][[sobj_b_name]] <- b_val
if (verbose) {
message(paste0(step_ran,
" argument ", argument,
" does not match: ",
"(", sobj_a_name, " value:", a_val, ")",
", (", sobj_b_name, " value:", b_val, ")"))
}
}
}
}
return(diff_list)
}
test_a <- pbmc_small
test_b <- pbmc_small %>%
process_seurat()
outs <- cmp_seurat_cmds(test_a,
test_b,
"original",
"reprocessed",
verbose = TRUE)
str(outs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment