From 7ac9ee488b36c8d2bddf4cb50530d87e16e7918b Mon Sep 17 00:00:00 2001 From: Ally Hawkins <54039191+allyhawkins@users.noreply.github.com> Date: Fri, 20 Oct 2023 13:14:43 -0500 Subject: [PATCH] track singler label in singler objects --- bin/add_celltypes_to_sce.R | 8 ++++++-- bin/classify_SingleR.R | 2 ++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/add_celltypes_to_sce.R b/bin/add_celltypes_to_sce.R index fb3cf0a3..85337b52 100755 --- a/bin/add_celltypes_to_sce.R +++ b/bin/add_celltypes_to_sce.R @@ -62,6 +62,9 @@ if(!is.null(opt$singler_results)){ } singler_results <- readr::read_rds(opt$singler_results) + + # get label type from metadata of singler object + label_type <- metadata(singler_results)$reference_label # create a tibble with annotations and barcode # later we'll add the annotations into colData by joining on barcodes column @@ -71,8 +74,8 @@ if(!is.null(opt$singler_results)){ ) # map ontology labels to cell type names, as needed - # we can tell if ontologies were used because this will exist: - if ("cell_ontology_df" %in% names(singler_results)) { + # label type will be label.ont if ontology is present + if (label_type == "label.ont") { # end up with columns: barcode, singler_celltype_annotation, singler_celltype_ontology colData(sce) <- annotations_df |> @@ -100,6 +103,7 @@ if(!is.null(opt$singler_results)){ # add singler info to metadata metadata(sce)$singler_results <- singler_results metadata(sce)$singler_reference <- metadata(singler_results)$reference_name + metadata(sce)$singler_reference_label <- label_type # add note about cell type method to metadata metadata(sce)$celltype_methods <- c(metadata(sce)$celltype_methods, "singler") diff --git a/bin/classify_SingleR.R b/bin/classify_SingleR.R index 54862131..1337df0e 100755 --- a/bin/classify_SingleR.R +++ b/bin/classify_SingleR.R @@ -94,6 +94,8 @@ singler_results <- SingleR::classifySingleR( # add reference name to singler_results DataFrame metadata metadata(singler_results)$reference_name <- reference_name +# add label name to metadata +metadata(singler_results)$reference_label <- metadata(singler_model)$reference_label # export results ---------------