|
| 1 | +setup_cli_workspace <- function(prefix = "mosuite_plot_expr_heatmap_test_") { |
| 2 | + workspace <- tempfile(prefix) |
| 3 | + dir.create(workspace) |
| 4 | + |
| 5 | + code_dir <- file.path(workspace, "code") |
| 6 | + data_dir <- file.path(workspace, "data") |
| 7 | + results_dir <- file.path(workspace, "results") |
| 8 | + dir.create(code_dir, recursive = TRUE) |
| 9 | + dir.create(data_dir, recursive = TRUE) |
| 10 | + dir.create(file.path(results_dir, "figures"), recursive = TRUE) |
| 11 | + dir.create(file.path(results_dir, "moo"), recursive = TRUE) |
| 12 | + |
| 13 | + repo_root <- normalizePath( |
| 14 | + file.path(testthat::test_path(), "..", ".."), |
| 15 | + mustWork = TRUE |
| 16 | + ) |
| 17 | + |
| 18 | + test_data_file <- file.path( |
| 19 | + repo_root, |
| 20 | + "code", |
| 21 | + "MOSuite", |
| 22 | + "tests", |
| 23 | + "testthat", |
| 24 | + "data", |
| 25 | + "moo.rds" |
| 26 | + ) |
| 27 | + |
| 28 | + expect_true( |
| 29 | + file.exists(test_data_file), |
| 30 | + info = paste("Test data file should exist at", test_data_file) |
| 31 | + ) |
| 32 | + file.copy(test_data_file, file.path(data_dir, "moo.rds"), overwrite = TRUE) |
| 33 | + |
| 34 | + file.copy( |
| 35 | + file.path(repo_root, "code", "main.R"), |
| 36 | + file.path(code_dir, "main.R"), |
| 37 | + overwrite = TRUE |
| 38 | + ) |
| 39 | + |
| 40 | + # Keep main.R behavior the same while pointing to this checkout's MOSuite package. |
| 41 | + main_copy <- file.path(code_dir, "main.R") |
| 42 | + main_lines <- readLines(main_copy) |
| 43 | + main_lines <- gsub( |
| 44 | + 'devtools::load_all("/code/MOSuite")', |
| 45 | + sprintf( |
| 46 | + 'devtools::load_all("%s")', |
| 47 | + file.path(repo_root, "code", "MOSuite") |
| 48 | + ), |
| 49 | + main_lines, |
| 50 | + fixed = TRUE |
| 51 | + ) |
| 52 | + writeLines(main_lines, main_copy) |
| 53 | + |
| 54 | + list( |
| 55 | + workspace = workspace, |
| 56 | + code_dir = code_dir, |
| 57 | + results_dir = results_dir, |
| 58 | + repo_root = repo_root |
| 59 | + ) |
| 60 | +} |
| 61 | + |
| 62 | +expect_plot_created <- function(results_dir) { |
| 63 | + plot_path <- file.path(results_dir, "figures", "heatmap", "expr_heatmap.png") |
| 64 | + expect_true(file.exists(plot_path), info = "Heatmap plot should be created") |
| 65 | + expect_true( |
| 66 | + file.info(plot_path)$size > 0, |
| 67 | + info = "Heatmap plot should be non-empty" |
| 68 | + ) |
| 69 | +} |
| 70 | + |
| 71 | +common_cli_args <- c( |
| 72 | + "--count_type=clean", |
| 73 | + "--display_gene_names=FALSE", |
| 74 | + "--display_sample_names=TRUE" |
| 75 | +) |
0 commit comments