From 4cf30cb49f58ce6dc05a398f488fb7e4b5ddc20c Mon Sep 17 00:00:00 2001 From: Ally Hawkins Date: Wed, 15 Jan 2025 12:35:06 -0600 Subject: [PATCH] account for entire projects with cell lines --- .../usr/bin/combine-celltype-tables.R | 50 +++++++++++-------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/modules/cell-type-consensus/resources/usr/bin/combine-celltype-tables.R b/modules/cell-type-consensus/resources/usr/bin/combine-celltype-tables.R index f562fd6..dc79f5f 100755 --- a/modules/cell-type-consensus/resources/usr/bin/combine-celltype-tables.R +++ b/modules/cell-type-consensus/resources/usr/bin/combine-celltype-tables.R @@ -91,25 +91,31 @@ blueprint_df <- data.frame( # Create combined TSV ---------------------------------------------------------- -# read in TSV files and combine into a single df -all_cells_df <- all_files |> - purrr::map(readr::read_tsv) |> - dplyr::bind_rows() |> - # add columns for panglao ontology and consensus - # first add panglao ontology - dplyr::left_join(panglao_ref_df, by = c("cellassign_celltype_annotation" = "original_panglao_name")) |> - # now add in all the blueprint columns - dplyr::left_join(blueprint_df, by = c("singler_celltype_ontology" = "blueprint_ontology")) |> - # then add consensus labels - dplyr::left_join(consensus_ref_df, - by = c( - "singler_celltype_ontology" = "blueprint_ontology", - "cellassign_celltype_annotation" = "original_panglao_name", - "panglao_ontology" - ) - ) |> - # use unknown for NA annotation but keep ontology ID as NA - dplyr::mutate(consensus_annotation = dplyr::if_else(is.na(consensus_annotation), "Unknown", consensus_annotation)) - -# export file -readr::write_tsv(all_cells_df, opt$output_file) +# account for all samples being cell lines and no cell type annotations being present +if (length(all_files) == 0) { + # make an empty filtered file + file.create(opt$output_file) +} else { + # read in TSV files and combine into a single df + all_cells_df <- all_files |> + purrr::map(readr::read_tsv) |> + dplyr::bind_rows() |> + # add columns for panglao ontology and consensus + # first add panglao ontology + dplyr::left_join(panglao_ref_df, by = c("cellassign_celltype_annotation" = "original_panglao_name")) |> + # now add in all the blueprint columns + dplyr::left_join(blueprint_df, by = c("singler_celltype_ontology" = "blueprint_ontology")) |> + # then add consensus labels + dplyr::left_join(consensus_ref_df, + by = c( + "singler_celltype_ontology" = "blueprint_ontology", + "cellassign_celltype_annotation" = "original_panglao_name", + "panglao_ontology" + ) + ) |> + # use unknown for NA annotation but keep ontology ID as NA + dplyr::mutate(consensus_annotation = dplyr::if_else(is.na(consensus_annotation), "Unknown", consensus_annotation)) + + # export file + readr::write_tsv(all_cells_df, opt$output_file) +}