|
| 1 | +test_that("code/run executes successfully with default CLI arguments", { |
| 2 | + # Create temporary workspace |
| 3 | + workspace <- tempfile("mosuite_filter_counts_test_") |
| 4 | + dir.create(workspace) |
| 5 | + on.exit(unlink(workspace, recursive = TRUE), add = TRUE) |
| 6 | + |
| 7 | + # Set up directory structure |
| 8 | + code_dir <- file.path(workspace, "code") |
| 9 | + data_dir <- file.path(workspace, "data") |
| 10 | + results_dir <- file.path(code_dir, "..", "results") |
| 11 | + dir.create(code_dir) |
| 12 | + dir.create(data_dir) |
| 13 | + dir.create(results_dir) |
| 14 | + |
| 15 | + # Get test data from package tests directory |
| 16 | + repo_root <- normalizePath(file.path(dirname(getwd()), "..")) |
| 17 | + test_data_file <- file.path(repo_root, "tests", "data", "moo-clean.rds") |
| 18 | + |
| 19 | + expect_true( |
| 20 | + file.exists(test_data_file), |
| 21 | + info = paste("Test data file should exist at", test_data_file) |
| 22 | + ) |
| 23 | + file.copy(test_data_file, file.path(data_dir, "moo.rds")) |
| 24 | + |
| 25 | + # Copy main.R and run script to workspace |
| 26 | + file.copy( |
| 27 | + file.path(repo_root, "code", "main.R"), |
| 28 | + file.path(code_dir, "main.R") |
| 29 | + ) |
| 30 | + file.copy( |
| 31 | + file.path(repo_root, "code", "run"), |
| 32 | + file.path(code_dir, "run") |
| 33 | + ) |
| 34 | + |
| 35 | + # Run the script from code directory |
| 36 | + old_wd <- getwd() |
| 37 | + setwd(code_dir) |
| 38 | + on.exit(setwd(old_wd), add = TRUE) |
| 39 | + |
| 40 | + # Execute run script with default CLI arguments |
| 41 | + exit_code <- system2( |
| 42 | + "bash", |
| 43 | + args = c( |
| 44 | + "run", |
| 45 | + "--count_type=clean", |
| 46 | + "--minimum_count_value_to_be_considered_nonzero=8", |
| 47 | + "--minimum_number_of_samples_with_nonzero_counts_in_total=7", |
| 48 | + "--minimum_number_of_samples_with_nonzero_counts_in_a_group=3", |
| 49 | + "--use_cpm_counts_to_filter=TRUE", |
| 50 | + "--use_group_based_filtering=FALSE", |
| 51 | + "--plot_corr_matrix_heatmap=FALSE" |
| 52 | + ) |
| 53 | + ) |
| 54 | + |
| 55 | + # Check for successful execution |
| 56 | + expect_equal(exit_code, 0, info = "run script should execute without error") |
| 57 | + expect_true( |
| 58 | + file.exists(file.path(results_dir, "moo", "moo-filt.rds")), |
| 59 | + info = "Output file moo-filt.rds should be created" |
| 60 | + ) |
| 61 | + |
| 62 | + # Validate output is a valid MOO object |
| 63 | + moo <- readr::read_rds(file.path(results_dir, "moo", "moo-filt.rds")) |
| 64 | + expect_true( |
| 65 | + S7::S7_inherits(moo, MOSuite::multiOmicDataSet), |
| 66 | + info = "Output should be an S7 multiOmicDataSet object" |
| 67 | + ) |
| 68 | +}) |
| 69 | + |
| 70 | +test_that("code/run executes with custom CLI arguments", { |
| 71 | + # Create temporary workspace |
| 72 | + workspace <- tempfile("mosuite_filter_counts_custom_test_") |
| 73 | + dir.create(workspace) |
| 74 | + on.exit(unlink(workspace, recursive = TRUE), add = TRUE) |
| 75 | + |
| 76 | + # Set up directory structure |
| 77 | + code_dir <- file.path(workspace, "code") |
| 78 | + data_dir <- file.path(workspace, "data") |
| 79 | + results_dir <- file.path(code_dir, "..", "results") |
| 80 | + dir.create(code_dir) |
| 81 | + dir.create(data_dir) |
| 82 | + dir.create(results_dir) |
| 83 | + |
| 84 | + # Get test data from package tests directory |
| 85 | + repo_root <- normalizePath(file.path(dirname(getwd()), "..")) |
| 86 | + test_data_file <- file.path(repo_root, "tests", "data", "moo-clean.rds") |
| 87 | + |
| 88 | + # Copy test data to workspace |
| 89 | + file.copy(test_data_file, file.path(data_dir, "moo.rds")) |
| 90 | + |
| 91 | + # Copy main.R and run script to workspace |
| 92 | + file.copy( |
| 93 | + file.path(repo_root, "code", "main.R"), |
| 94 | + file.path(code_dir, "main.R") |
| 95 | + ) |
| 96 | + file.copy( |
| 97 | + file.path(repo_root, "code", "run"), |
| 98 | + file.path(code_dir, "run") |
| 99 | + ) |
| 100 | + |
| 101 | + # Run the script from code directory |
| 102 | + old_wd <- getwd() |
| 103 | + setwd(code_dir) |
| 104 | + on.exit(setwd(old_wd), add = TRUE) |
| 105 | + |
| 106 | + # Execute run script with custom CLI arguments |
| 107 | + exit_code <- system2( |
| 108 | + "bash", |
| 109 | + args = c( |
| 110 | + "run", |
| 111 | + "--count_type=clean", |
| 112 | + "--minimum_count_value_to_be_considered_nonzero=5", |
| 113 | + "--minimum_number_of_samples_with_nonzero_counts_in_total=3", |
| 114 | + "--use_cpm_counts_to_filter=FALSE", |
| 115 | + "--plot_corr_matrix_heatmap=FALSE" |
| 116 | + ) |
| 117 | + ) |
| 118 | + |
| 119 | + # Check for successful execution |
| 120 | + expect_equal( |
| 121 | + exit_code, |
| 122 | + 0, |
| 123 | + info = "run script with custom args should execute without error" |
| 124 | + ) |
| 125 | + expect_true( |
| 126 | + file.exists(file.path(results_dir, "moo", "moo-filt.rds")), |
| 127 | + info = "Output file moo-filt.rds should be created with custom args" |
| 128 | + ) |
| 129 | + |
| 130 | + # Validate output is a valid MOO object |
| 131 | + moo <- readr::read_rds(file.path(results_dir, "moo", "moo-filt.rds")) |
| 132 | + expect_true( |
| 133 | + S7::S7_inherits(moo, MOSuite::multiOmicDataSet), |
| 134 | + info = "Output should be an S7 multiOmicDataSet object" |
| 135 | + ) |
| 136 | +}) |
0 commit comments