Mercurial > repos > goeckslab > celesta
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 2:41aaffbb9473 | 3:283636dbfba5 |
|---|---|
| 15 | 15 |
| 16 # define command line args | 16 # define command line args |
| 17 option_list <- list( | 17 option_list <- list( |
| 18 make_option(c("-r", "--rds"), action = "store", default = "celestaobj.rds", type = "character", | 18 make_option(c("-r", "--rds"), action = "store", default = "celestaobj.rds", type = "character", |
| 19 help = "Path to CelestaObj RDS"), | 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", | 20 make_option(c("-c", "--celltypes"), action = "store", default = NA, type = "character", |
| 23 help = "Comma-separated list of cell types to plot"), | 21 help = "Comma-separated list of cell types to plot"), |
| 24 make_option(c("-s", "--size"), action = "store", default = 1, type = "double", | 22 make_option(c("-s", "--size"), action = "store", default = 1, type = "double", |
| 25 help = "Point size for plotting"), | 23 help = "Point size for plotting"), |
| 26 make_option(c("--width"), action = "store", default = 12, type = "integer", | 24 make_option(c("--width"), action = "store", default = 12, type = "integer", |
| 35 opt <- parse_args(OptionParser(option_list = option_list)) | 33 opt <- parse_args(OptionParser(option_list = option_list)) |
| 36 | 34 |
| 37 CelestaObj <- readRDS(opt$rds) | 35 CelestaObj <- readRDS(opt$rds) |
| 38 cell_types_to_plot <- strsplit(opt$celltypes, ",")[[1]] | 36 cell_types_to_plot <- strsplit(opt$celltypes, ",")[[1]] |
| 39 | 37 |
| 40 # read prior marker info | 38 # get indices of cell types to plot from the prior marker table |
| 41 prior <- read.csv(opt$prior, row.names = 1) | 39 cell_type_indices <- which(CelestaObj@prior_info[, 1] %in% cell_types_to_plot) |
| 42 | 40 |
| 43 # get indices of cell types to plot from the prior marker table | 41 print("Cell types selected for plotting:") |
| 44 cell_type_indices <- which(row.names(prior) %in% cell_types_to_plot) | |
| 45 | |
| 46 print(cell_types_to_plot) | 42 print(cell_types_to_plot) |
| 43 print("Indices of cell types selected for plotting:") | |
| 47 print(cell_type_indices) | 44 print(cell_type_indices) |
| 48 | |
| 49 print(row.names(prior)) | |
| 50 | 45 |
| 51 # create output directory if it doesn"t already exist | 46 # create output directory if it doesn"t already exist |
| 52 dir.create("cell_assign_plots") | 47 dir.create("cell_assign_plots") |
| 53 | 48 |
| 54 # create the cell type plot | 49 # create the cell type plot |
| 55 g <- PlotCellsAnyCombination(cell_type_assignment_to_plot = CelestaObj@final_cell_type_assignment[, (CelestaObj@total_rounds + 1)], | 50 g <- PlotCellsAnyCombination(cell_type_assignment_to_plot = CelestaObj@final_cell_type_assignment[, (CelestaObj@total_rounds + 1)], |
| 56 coords = CelestaObj@coords, | 51 coords = CelestaObj@coords, |
| 57 prior_info = prior_marker_info, | 52 prior_info = CelestaObj@prior_info, |
| 58 cell_number_to_use = cell_type_indices, | 53 cell_number_to_use = cell_type_indices, |
| 59 test_size = 1, | 54 test_size = opt$size, |
| 60 save_plot = FALSE) | 55 save_plot = FALSE) |
| 61 | 56 |
| 62 # create a unique output name for the plot based on the input cell types | 57 # 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 = "") | 58 cell_types_cleaned <- paste(make_clean_names(cell_types_to_plot), collapse = "") |
| 64 output_name <- paste(c("plot_cells_", cell_types_cleaned, ".png"), collapse = "") | 59 output_name <- paste(c("plot_cells_", cell_types_cleaned, ".png"), collapse = "") |
| 65 | 60 |
| 66 # save to subdir | 61 # save to subdir |
| 67 # FIXME: may want to expose plotting params to galaxy | |
| 68 ggsave( | 62 ggsave( |
| 69 path = "cell_assign_plots", | 63 path = "cell_assign_plots", |
| 70 filename = output_name, | 64 filename = output_name, |
| 71 plot = g, | 65 plot = g, |
| 72 width = opt$width, | 66 width = opt$width, |
