Skip to content

Commit f06dd79

Browse files
Merge pull request #6 from NIDAP-Community/dev-sovacool
fix: default regex & write basic tests
2 parents 8ad020b + 5fd5113 commit f06dd79

9 files changed

Lines changed: 134 additions & 13 deletions

File tree

‎.codeocean/app-panel.json‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"description": "Regular expression pattern for finding the counts file in data/",
3939
"type": "text",
4040
"value_type": "string",
41-
"default_value": "count.*.[ct]sv*"
41+
"default_value": "count.*\\\\.[ct]sv(\\\\.gz)?"
4242
},
4343
{
4444
"id": "GsdtoK1el4aJObcg",
@@ -48,7 +48,7 @@
4848
"description": "Regular expression pattern for finding the sample metadata file in data/",
4949
"type": "text",
5050
"value_type": "string",
51-
"default_value": "sample.*.[ct]sv*"
51+
"default_value": "count.*\\\\.[ct]sv(\\\\.gz)?"
5252
}
5353
]
5454
}

‎.github/PULL_REQUEST_TEMPLATE.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,4 @@ when referring to the issue so it will be closed automatically when the PR is me
2020
- [ ] This comment contains a description of changes with justifications, with any relevant issues linked.
2121
- [ ] Run the capsule in Code Ocean and ensure it completes successfully with no errors.
2222
- [ ] Update `CHANGELOG.md` with a short description of any user-facing changes and reference the PR number. Follow the style described in <https://style.tidyverse.org/news.html>
23+
- [ ] The `test` workflow succeeds on the latest commit.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: TechDev-project
2+
3+
on:
4+
issues:
5+
types:
6+
- opened
7+
pull_request:
8+
types:
9+
- opened
10+
11+
permissions:
12+
issues: write
13+
pull-requests: write
14+
contents: read
15+
16+
jobs:
17+
add-to-project:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Generate a token
21+
id: generate-token
22+
if: ${{ inputs.github-token == '' }}
23+
uses: actions/create-github-app-token@v2
24+
with:
25+
app-id: ${{ vars.CCBR_BOT_APP_ID }}
26+
private-key: ${{ secrets.CCBR_BOT_PRIVATE_KEY }}
27+
owner: CCBR
28+
29+
- uses: actions/add-to-project@v1.0.2
30+
with:
31+
project-url: https://github.com/orgs/CCBR/projects/17
32+
github-token: ${{ steps.generate-token.outputs.token }}
33+
34+
- name: add to MOSuite project
35+
uses: actions/add-to-project@v1.0.2
36+
with:
37+
project-url: https://github.com/orgs/CCBR/projects/32
38+
github-token: ${{ steps.generate-token.outputs.token }}

‎.github/workflows/test.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test
1+
name: test
22

33
on:
44
push:
Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Add to personal projects
1+
name: user-projects
22

33
on:
44
issues:
@@ -7,10 +7,17 @@ on:
77
pull_request:
88
types:
99
- assigned
10+
1011
permissions:
11-
issues: read
12-
pull-requests: read
12+
issues: write
13+
pull-requests: write
14+
1315
jobs:
1416
add-to-project:
15-
uses: CCBR/.github/.github/workflows/auto-add-user-project.yml@v0.1.0
16-
secrets: inherit
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: CCBR/actions/user-projects@main
20+
with:
21+
app-id: ${{ vars.CCBR_BOT_APP_ID }}
22+
app-private-key: ${{ secrets.CCBR_BOT_PRIVATE_KEY }}
23+
token-owner: "CCBR"

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# CodeOcean Capsule - MOSuite - create multiOmicDataset
22

3+
## development version
4+
5+
- Throw a warning if multiple counts files or metadata files are found matching the patterns. (#6, @kelly-sovacool)
6+
- The results file is now saved to `results/moo/moo-raw.rds` to prevent collisions with other capsules. (#6, @kelly-sovacool)
7+
38
## v6.0
49

510
- Use MOSuite v0.3.0 docker container.

‎code/main.R‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#!/usr/bin/env Rscript
2-
rlang::global_entrace()
32
library(argparse)
43
library(glue)
54
library(MOSuite)
@@ -14,8 +13,8 @@ setup_capsule_environment()
1413
parser <- ArgumentParser(description = "Create multi-omic dataset from files")
1514

1615
parser$add_argument("--delim", type="character", required=FALSE, default=",")
17-
parser$add_argument("--regex_count", type="character", default="count.*.[ct]sv*")
18-
parser$add_argument("--regex_sample", type="character", default="sample.*.[ct]sv*")
16+
parser$add_argument("--regex_count", type="character", default="count.*\\.[ct]sv(\\.gz)?")
17+
parser$add_argument("--regex_sample", type="character", default="sample.*\\.[ct]sv(\\.gz)?")
1918

2019
args <- parser$parse_args()
2120

@@ -31,11 +30,14 @@ sample_meta_files <- Filter(\(x) str_detect(x, regex(regex_sample, ignore_case =
3130
# validate inputs
3231
if (length(count_files) == 0) {
3332
stop(glue("No counts data file was found. Please place a csv or tsv file in data/ that matches this regex: {regex_count}"))
33+
} else if (length(count_files) > 1) {
34+
warning(glue("Multiple counts data files were found matching {regex_count}: {paste(count_files, collapse=', ')}"))
3435
}
3536
if (length(sample_meta_files) == 0) {
3637
stop(glue("No sample metadata file was found. Please place a csv or tsv file in data/ that matches this regex: {regex_sample}"))
38+
} else if (length(sample_meta_files) > 1) {
39+
warning(glue("Multiple sample metadata files were found matching {regex_sample}: {paste(sample_meta_files, collapse=', ')}"))
3740
}
38-
3941
count_filename <- count_files[1]
4042
sample_metadata_filename <- sample_meta_files[1]
4143
message(glue("Counts data file: {count_filename}"))
@@ -47,4 +49,4 @@ moo <- create_multiOmicDataSet_from_files(
4749
feature_counts_filepath = count_filename,
4850
delim = args$delim
4951
)
50-
write_rds(moo, file.path(getOption("moo_plots_dir"), "..", "moo", "moo.rds"))
52+
write_rds(moo, file.path(getOption("moo_plots_dir"), "..", "moo", "moo-raw.rds"))

‎tests/testthat.R‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
library(testthat)
2+
test_dir(file.path('tests', 'testthat'), stop_on_failure = TRUE)

‎tests/testthat/test-main.R‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
counts_url <- 'https://raw.githubusercontent.com/CCBR/MOSuite/main/inst/extdata/nidap/Raw_Counts.csv.gz'
2+
sample_meta_url <- 'https://raw.githubusercontent.com/CCBR/MOSuite/main/inst/extdata/nidap/Sample_Metadata_Bulk_RNA-seq_Training_Dataset_CCBR.csv.gz'
3+
4+
test_that("code/run executes successfully with default CLI arguments", {
5+
# Create temporary workspace
6+
workspace <- tempfile("mosuite_create_test_")
7+
dir.create(workspace)
8+
on.exit(unlink(workspace, recursive = TRUE), add = TRUE)
9+
10+
# Set up directory structure
11+
code_dir <- file.path(workspace, "code")
12+
data_dir <- file.path(workspace, "data")
13+
results_dir <- file.path(code_dir, "..", "results")
14+
dir.create(code_dir)
15+
dir.create(data_dir)
16+
dir.create(results_dir)
17+
dir.create(file.path(results_dir, "figures"), recursive = TRUE)
18+
dir.create(file.path(results_dir, "moo"), recursive = TRUE)
19+
20+
# Download test data
21+
counts_file <- file.path(data_dir, "Raw_Counts.csv.gz")
22+
sample_meta_file <- file.path(data_dir, "Sample_Metadata.csv.gz")
23+
24+
tryCatch({
25+
download.file(counts_url, counts_file, quiet = TRUE, mode = "wb", timeout = 30)
26+
download.file(sample_meta_url, sample_meta_file, quiet = TRUE, mode = "wb", timeout = 30)
27+
}, error = function(e) {
28+
skip(paste("Could not download test data:", e$message))
29+
})
30+
31+
expect_true(file.exists(counts_file), "Counts file should be downloaded")
32+
expect_true(file.exists(sample_meta_file), "Sample metadata file should be downloaded")
33+
34+
# Copy main.R and run script to workspace
35+
repo_root <- normalizePath(file.path(dirname(getwd()), ".."))
36+
file.copy(file.path(repo_root, "code", "main.R"), file.path(code_dir, "main.R"))
37+
file.copy(file.path(repo_root, "code", "run"), file.path(code_dir, "run"))
38+
39+
# Run the script from code directory
40+
old_wd <- getwd()
41+
setwd(code_dir)
42+
on.exit(setwd(old_wd), add = TRUE)
43+
44+
# Execute run script with explicit CLI arguments
45+
exit_code <- system2(
46+
"bash",
47+
args = c(
48+
"run",
49+
"--delim=,",
50+
"--regex_count=count.*\\.[ct]sv\\(\\.gz\\)?",
51+
"--regex_sample=sample.*\\.[ct]sv\\(\\.gz\\)?"
52+
)
53+
)
54+
55+
# Check for successful execution
56+
expect_equal(exit_code, 0, info = "run script should execute without error")
57+
expect_true(file.exists(file.path(results_dir, "moo", "moo-raw.rds")),
58+
"Output file moo-raw.rds should be created")
59+
60+
# Validate output is a valid MOO object
61+
moo <- readr::read_rds(file.path(results_dir, "moo", "moo-raw.rds"))
62+
expect_true(
63+
S7::S7_inherits(moo, MOSuite::multiOmicDataSet),
64+
info = "Output should be an S7 multiOmicDataSet object"
65+
)
66+
})

0 commit comments

Comments
 (0)