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