Mercurial > repos > goeckslab > celesta
diff celesta_plot_cells.R @ 0:8001319743c0 draft
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
author | goeckslab |
---|---|
date | Wed, 28 Aug 2024 12:46:48 +0000 |
parents | |
children | 283636dbfba5 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/celesta_plot_cells.R Wed Aug 28 12:46:48 2024 +0000 @@ -0,0 +1,76 @@ +# --------------------------------------------------------------------------------- +# Plot assigned cell type combinations with CELESTA +# --------------------------------------------------------------------------------- + +suppressWarnings(suppressMessages(library(janitor))) +suppressWarnings(suppressMessages(library(optparse))) +suppressWarnings(suppressMessages(library(dplyr))) +suppressWarnings(suppressMessages(library(anndataR))) +suppressWarnings(suppressMessages(library(Rmixmod))) +suppressWarnings(suppressMessages(library(spdep))) +suppressWarnings(suppressMessages(library(ggplot2))) +suppressWarnings(suppressMessages(library(reshape2))) +suppressWarnings(suppressMessages(library(zeallot))) +suppressWarnings(suppressMessages(library(CELESTA))) + +# define command line args +option_list <- list( + make_option(c("-r", "--rds"), action = "store", default = "celestaobj.rds", type = "character", + help = "Path to CelestaObj RDS"), + make_option(c("-p", "--prior"), action = "store", default = NA, type = "character", + help = "Path to prior marker info file"), + make_option(c("-c", "--celltypes"), action = "store", default = NA, type = "character", + help = "Comma-separated list of cell types to plot"), + make_option(c("-s", "--size"), action = "store", default = 1, type = "double", + help = "Point size for plotting"), + make_option(c("--width"), action = "store", default = 12, type = "integer", + help = "Width of plot (inches)"), + make_option(c("--height"), action = "store", default = 12, type = "integer", + help = "Height of plot (inches)"), + make_option(c("--dpi"), action = "store", default = 300, type = "integer", + help = "DPI (dots per inch) of plot") +) + +# parse args +opt <- parse_args(OptionParser(option_list = option_list)) + +CelestaObj <- readRDS(opt$rds) +cell_types_to_plot <- strsplit(opt$celltypes, ",")[[1]] + +# read prior marker info +prior <- read.csv(opt$prior, row.names = 1) + +# get indices of cell types to plot from the prior marker table +cell_type_indices <- which(row.names(prior) %in% cell_types_to_plot) + +print(cell_types_to_plot) +print(cell_type_indices) + +print(row.names(prior)) + +# create output directory if it doesn"t already exist +dir.create("cell_assign_plots") + +# create the cell type plot +g <- PlotCellsAnyCombination(cell_type_assignment_to_plot = CelestaObj@final_cell_type_assignment[, (CelestaObj@total_rounds + 1)], + coords = CelestaObj@coords, + prior_info = prior_marker_info, + cell_number_to_use = cell_type_indices, + test_size = 1, + save_plot = FALSE) + +# create a unique output name for the plot based on the input cell types +cell_types_cleaned <- paste(make_clean_names(cell_types_to_plot), collapse = "") +output_name <- paste(c("plot_cells_", cell_types_cleaned, ".png"), collapse = "") + +# save to subdir +# FIXME: may want to expose plotting params to galaxy +ggsave( + path = "cell_assign_plots", + filename = output_name, + plot = g, + width = opt$width, + height = opt$height, + units = "in", + dpi = opt$dpi +)