comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:8001319743c0
1 # ---------------------------------------------------------------------------------
2 # Plot assigned cell type combinations with CELESTA
3 # ---------------------------------------------------------------------------------
4
5 suppressWarnings(suppressMessages(library(janitor)))
6 suppressWarnings(suppressMessages(library(optparse)))
7 suppressWarnings(suppressMessages(library(dplyr)))
8 suppressWarnings(suppressMessages(library(anndataR)))
9 suppressWarnings(suppressMessages(library(Rmixmod)))
10 suppressWarnings(suppressMessages(library(spdep)))
11 suppressWarnings(suppressMessages(library(ggplot2)))
12 suppressWarnings(suppressMessages(library(reshape2)))
13 suppressWarnings(suppressMessages(library(zeallot)))
14 suppressWarnings(suppressMessages(library(CELESTA)))
15
16 # define command line args
17 option_list <- list(
18 make_option(c("-r", "--rds"), action = "store", default = "celestaobj.rds", type = "character",
19 help = "Path to CelestaObj RDS"),
20 make_option(c("-p", "--prior"), action = "store", default = NA, type = "character",
21 help = "Path to prior marker info file"),
22 make_option(c("-c", "--celltypes"), action = "store", default = NA, type = "character",
23 help = "Comma-separated list of cell types to plot"),
24 make_option(c("-s", "--size"), action = "store", default = 1, type = "double",
25 help = "Point size for plotting"),
26 make_option(c("--width"), action = "store", default = 12, type = "integer",
27 help = "Width of plot (inches)"),
28 make_option(c("--height"), action = "store", default = 12, type = "integer",
29 help = "Height of plot (inches)"),
30 make_option(c("--dpi"), action = "store", default = 300, type = "integer",
31 help = "DPI (dots per inch) of plot")
32 )
33
34 # parse args
35 opt <- parse_args(OptionParser(option_list = option_list))
36
37 CelestaObj <- readRDS(opt$rds)
38 cell_types_to_plot <- strsplit(opt$celltypes, ",")[[1]]
39
40 # read prior marker info
41 prior <- read.csv(opt$prior, row.names = 1)
42
43 # get indices of cell types to plot from the prior marker table
44 cell_type_indices <- which(row.names(prior) %in% cell_types_to_plot)
45
46 print(cell_types_to_plot)
47 print(cell_type_indices)
48
49 print(row.names(prior))
50
51 # create output directory if it doesn"t already exist
52 dir.create("cell_assign_plots")
53
54 # create the cell type plot
55 g <- PlotCellsAnyCombination(cell_type_assignment_to_plot = CelestaObj@final_cell_type_assignment[, (CelestaObj@total_rounds + 1)],
56 coords = CelestaObj@coords,
57 prior_info = prior_marker_info,
58 cell_number_to_use = cell_type_indices,
59 test_size = 1,
60 save_plot = FALSE)
61
62 # create a unique output name for the plot based on the input cell types
63 cell_types_cleaned <- paste(make_clean_names(cell_types_to_plot), collapse = "")
64 output_name <- paste(c("plot_cells_", cell_types_cleaned, ".png"), collapse = "")
65
66 # save to subdir
67 # FIXME: may want to expose plotting params to galaxy
68 ggsave(
69 path = "cell_assign_plots",
70 filename = output_name,
71 plot = g,
72 width = opt$width,
73 height = opt$height,
74 units = "in",
75 dpi = opt$dpi
76 )