Mercurial > repos > goeckslab > celesta
annotate celesta_plot_cells.R @ 3:283636dbfba5 draft default tip
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 36453551b1045adf20925d4eb6b5816c64475728
author | goeckslab |
---|---|
date | Thu, 19 Sep 2024 17:17:51 +0000 |
parents | 8001319743c0 |
children |
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("-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
|
21 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
|
22 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
|
23 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
|
24 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
|
25 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
|
26 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
|
27 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
|
28 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
|
29 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
|
30 ) |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
31 |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
32 # parse args |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
33 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
|
34 |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
35 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
|
36 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
|
37 |
3
283636dbfba5
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 36453551b1045adf20925d4eb6b5816c64475728
goeckslab
parents:
0
diff
changeset
|
38 # get indices of cell types to plot from the prior marker table |
283636dbfba5
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 36453551b1045adf20925d4eb6b5816c64475728
goeckslab
parents:
0
diff
changeset
|
39 cell_type_indices <- which(CelestaObj@prior_info[, 1] %in% cell_types_to_plot) |
0
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
40 |
3
283636dbfba5
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 36453551b1045adf20925d4eb6b5816c64475728
goeckslab
parents:
0
diff
changeset
|
41 print("Cell types selected for plotting:") |
0
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
42 print(cell_types_to_plot) |
3
283636dbfba5
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 36453551b1045adf20925d4eb6b5816c64475728
goeckslab
parents:
0
diff
changeset
|
43 print("Indices of cell types selected for plotting:") |
0
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
44 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
|
45 |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
46 # 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
|
47 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
|
48 |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
49 # 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
|
50 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
|
51 coords = CelestaObj@coords, |
3
283636dbfba5
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 36453551b1045adf20925d4eb6b5816c64475728
goeckslab
parents:
0
diff
changeset
|
52 prior_info = CelestaObj@prior_info, |
0
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
53 cell_number_to_use = cell_type_indices, |
3
283636dbfba5
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 36453551b1045adf20925d4eb6b5816c64475728
goeckslab
parents:
0
diff
changeset
|
54 test_size = opt$size, |
0
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
55 save_plot = FALSE) |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
56 |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
57 # 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
|
58 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
|
59 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
|
60 |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
61 # save to subdir |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
62 ggsave( |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
63 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
|
64 filename = output_name, |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
65 plot = g, |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
66 width = opt$width, |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
67 height = opt$height, |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
68 units = "in", |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
69 dpi = opt$dpi |
8001319743c0
planemo upload for repository https://github.com/goeckslab/tools-mti/tree/main/tools/celesta commit 0ec46718dfd00f37ccae4e2fa133fa8393fe6d92
goeckslab
parents:
diff
changeset
|
70 ) |