Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved hybrid test case #133

Merged
merged 9 commits into from
Aug 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/r-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ jobs:
run: wget -P tests/testdata/filtered -i tests/remote-files/filtered.txt
- name: Fetch features test data
run: wget -P tests/testdata/features -i tests/remote-files/features.txt
- name: Fetch features test data
run: wget -P tests/testdata/hybrid -i tests/remote-files/hybrid.txt
- name: Run devtools::check()
run: |
conda activate recetox-aplcms
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- added tests with realistic testdata for `extract_features.R` [#42](https://github.com/RECETOX/recetox-aplcms/pull/42), [#54](https://github.com/RECETOX/recetox-aplcms/pull/54)
- added tests for `feature.align.R` ([#40](https://github.com/RECETOX/recetox-aplcms/pull/40)), and `adjust.time.R` ([#39](https://github.com/RECETOX/recetox-aplcms/pull/40))
- added CI to repository's GitHub Actions [#45](https://github.com/RECETOX/recetox-aplcms/pull/45),[#49](https://github.com/RECETOX/recetox-aplcms/pull/49)
- added additional test cases for hybrid [#133](https://github.com/RECETOX/recetox-aplcms/pull/133)
### Changed
- refactored `feature.align.R` [#63](https://github.com/RECETOX/recetox-aplcms/pull/63)[#88](https://github.com/RECETOX/recetox-aplcms/pull/88)[#102](https://github.com/RECETOX/recetox-aplcms/pull/102)
- refactored `adjust.time.R` [#64](https://github.com/RECETOX/recetox-aplcms/pull/64)[#102](https://github.com/RECETOX/recetox-aplcms/pull/102)
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export(find.turn.point)
export(find_local_maxima)
export(get_custom_rt_tol)
export(get_mzrange_bound_indices)
export(get_num_workers)
export(get_rt_region_indices)
export(get_times_to_use)
export(hybrid)
Expand Down
16 changes: 16 additions & 0 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,20 @@ compute_mz_sd <- function(feature_groups) {
}
}
return(mz_sd)
}

#' @export
get_num_workers <- function() {
xtrojak marked this conversation as resolved.
Show resolved Hide resolved
# CRAN limits the number of cores available to packages to 2
# source https://stackoverflow.com/questions/50571325/r-cran-check-fail-when-using-parallel-functions#50571533
chk <- Sys.getenv("_R_CHECK_LIMIT_CORES_", "")

if (nzchar(chk) && chk == "TRUE") {
# use 2 cores in CRAN/Travis/AppVeyor
num_workers <- 2L
} else {
# use all cores in devtools::test()
num_workers <- parallel::detectCores()
}
return(num_workers)
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ wget -P tests/testdata/recovered/recovered-extracted -i tests/remote-files/recov
wget -P tests/testdata/recovered/recovered-corrected -i tests/remote-files/recovered-corrected.txt
wget -P tests/testdata/filtered -i tests/remote-files/filtered.txt
wget -P tests/testdata/features -i tests/remote-files/features.txt
wget -P tests/testdata/hybrid -i tests/remote-files/hybrid.txt

```

The `hybrid` and `unsupervised` tests of recetox-aplcms are [reported](https://github.com/RECETOX/recetox-aplcms/issues/24) to be OS specific and may fail depending on the platrform they are run on. To ensure reproducibility during development process you can run the tests in a designated Docker container as follows:
Expand Down
3 changes: 3 additions & 0 deletions tests/remote-files/hybrid.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://gitlab.ics.muni.cz/umsa/umsa-files/-/raw/master/testdata/recetox-aplcms/hybrid/RCX_shortened_recovered_feature_sample_table.parquet
https://gitlab.ics.muni.cz/umsa/umsa-files/-/raw/master/testdata/recetox-aplcms/hybrid/known_table.parquet
https://gitlab.ics.muni.cz/umsa/umsa-files/-/raw/master/testdata/recetox-aplcms/hybrid/mbr_recovered_feature_sample_table.parquet
2 changes: 2 additions & 0 deletions tests/remote-files/input.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
https://gitlab.ics.muni.cz/umsa/umsa-files/-/raw/master/testdata/recetox-aplcms/input/mbr_test0.mzml
https://gitlab.ics.muni.cz/umsa/umsa-files/-/raw/master/testdata/recetox-aplcms/input/mbr_test1.mzml
https://gitlab.ics.muni.cz/umsa/umsa-files/-/raw/master/testdata/recetox-aplcms/input/mbr_test2.mzml
https://gitlab.ics.muni.cz/umsa/umsa-files/-/raw/master/testdata/recetox-aplcms/input/RCX_06_shortened.mzML
https://gitlab.ics.muni.cz/umsa/umsa-files/-/raw/master/testdata/recetox-aplcms/input/RCX_07_shortened.mzML
https://gitlab.ics.muni.cz/umsa/umsa-files/-/raw/master/testdata/recetox-aplcms/input/RCX_08_shortened.mzML
Binary file not shown.
Binary file removed tests/testdata/known_table.parquet
Binary file not shown.
26,908 changes: 0 additions & 26,908 deletions tests/testdata/mbr_test0.mzml

This file was deleted.

26,908 changes: 0 additions & 26,908 deletions tests/testdata/mbr_test1.mzml

This file was deleted.

26,908 changes: 0 additions & 26,908 deletions tests/testdata/mbr_test2.mzml

This file was deleted.

48 changes: 24 additions & 24 deletions tests/testthat/test-hybrid.R
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
get_num_workers <- function() {
# CRAN limits the number of cores available to packages to 2
# source https://stackoverflow.com/questions/50571325/r-cran-check-fail-when-using-parallel-functions#50571533
chk <- Sys.getenv("_R_CHECK_LIMIT_CORES_", "")

if (nzchar(chk) && chk == "TRUE") {
# use 2 cores in CRAN/Travis/AppVeyor
num_workers <- 2L
} else {
# use all cores in devtools::test()
num_workers <- parallel::detectCores()
}
return(num_workers)
}
patrick::with_parameters_test_that("basic hybrid test", {
if(ci_skip == TRUE) skip_on_ci()

test_that("basic hybrid test", {
test_files <- c('../testdata/mbr_test0.mzml',
'../testdata/mbr_test1.mzml',
'../testdata/mbr_test2.mzml')

expected <- arrow::read_parquet('../testdata/hybrid_recovered_feature_sample_table.parquet')
known_table <- arrow::read_parquet('../testdata/known_table.parquet')
testdata <- file.path("..", "testdata")

test_files <- sapply(files, function(x) {
file.path(testdata, "input", x)
})

known_table <- arrow::read_parquet(
file.path(testdata, "hybrid", "known_table.parquet")
)

actual <- hybrid(test_files, known_table, cluster = get_num_workers())

actual$recovered_feature_sample_table <- actual$recovered_feature_sample_table |> dplyr::arrange_all()
expected <- expected |> dplyr::arrange_all()
expected <- arrow::read_parquet(
file.path(testdata, "hybrid", paste0(.test_name, "_recovered_feature_sample_table.parquet"))
)

expect_equal(actual$recovered_feature_sample_table, expected)
})
}, patrick::cases(
mbr = list(
files = c("mbr_test0.mzml", "mbr_test1.mzml", "mbr_test2.mzml"),
ci_skip = TRUE
hechth marked this conversation as resolved.
Show resolved Hide resolved
),
RCX_shortened = list(
files = c("RCX_06_shortened.mzML", "RCX_07_shortened.mzML", "RCX_08_shortened.mzML"),
ci_skip = FALSE
)
))
6 changes: 3 additions & 3 deletions tests/testthat/test-unsupervised.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
test_that("basic unsupervised test", {
test_files <- c('../testdata/mbr_test0.mzml',
'../testdata/mbr_test1.mzml',
'../testdata/mbr_test2.mzml')
test_files <- c('../testdata/input/mbr_test0.mzml',
'../testdata/input/mbr_test1.mzml',
'../testdata/input/mbr_test2.mzml')

expected <- arrow::read_parquet('../testdata/unsupervised_recovered_feature_sample_table.parquet')

Expand Down