Skip to content
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
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@
^pixi.toml
^pixi.lock
^\.pixi
^.covrignore
21 changes: 12 additions & 9 deletions .github/environment/pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ platforms = ["linux-64", "osx-64", "osx-arm64"]
libc = { family="glibc", version="2.17" }

[tasks]
devtools_document = "R -e 'devtools::document()'"
devtools_test = "R -e 'devtools::test()'"
codecov = "R -e 'covr::codecov(quiet = FALSE)'"
rcmdcheck = "R -e 'rcmdcheck::rcmdcheck()'"
bioccheck_git_clone = "R -e 'BiocCheck::BiocCheckGitClone()'"
bioccheck = "R -e 'BiocCheck::BiocCheck()'"
use_major_version = "R -e 'usethis::use_version(which = \"major\", push = FALSE)'"
use_minor_version = "R -e 'usethis::use_version(which = \"minor\", push = FALSE)'"
use_patch_version = "R -e 'usethis::use_version(which = \"patch\", push = FALSE)'"
devtools_document = "cd $GITHUB_WORKSPACE; R -e 'devtools::document()'"
devtools_test = "cd $GITHUB_WORKSPACE; R -e 'devtools::test()'"
codecov = "cd $GITHUB_WORKSPACE; R -e 'covr::codecov(quiet = FALSE)'"
rcmdcheck = "cd $GITHUB_WORKSPACE; R -e 'rcmdcheck::rcmdcheck()'"
bioccheck_git_clone = "cd $GITHUB_WORKSPACE; R -e 'BiocCheck::BiocCheckGitClone()'"
bioccheck = "cd $GITHUB_WORKSPACE; R -e 'BiocCheck::BiocCheck()'"
use_major_version = "cd $GITHUB_WORKSPACE; R -e 'usethis::use_version(which = \"major\", push = FALSE)'"
use_minor_version = "cd $GITHUB_WORKSPACE; R -e 'usethis::use_version(which = \"minor\", push = FALSE)'"
use_patch_version = "cd $GITHUB_WORKSPACE; R -e 'usethis::use_version(which = \"patch\", push = FALSE)'"

[feature.r43]
dependencies = {"r-base" = "4.3.*"}
Expand All @@ -27,6 +27,9 @@ dependencies = {"r-base" = "4.4.*"}
r43 = {features = ["r43"]}
r44 = {features = ["r44"]}

[target.linux-64.dependencies]
"gcc" = "*"

[dependencies]
"gsl" = "*"
"bioconductor-bioccheck" = "*"
Expand Down
33 changes: 22 additions & 11 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,31 @@ jobs:
fetch-depth: 0

- name: Create TOML from recipe
run: .github/workflows/create_toml_from_yaml.sh ${GITHUB_WORKSPACE}
run: |
.github/workflows/create_toml_from_yaml.sh ${GITHUB_WORKSPACE}
mkdir /tmp/pixi
mv ${GITHUB_WORKSPACE}/pixi.toml /tmp/pixi

- name: Setup pixi
uses: prefix-dev/setup-pixi@v0.9.2
with:
manifest-path: /tmp/pixi/pixi.toml

- name: Run unit tests
run: pixi run --environment ${{ matrix.environment }} devtools_test
run: pixi run --environment ${{ matrix.environment }} --manifest-path /tmp/pixi/pixi.toml devtools_test

- name: Check unit test code coverage
run: pixi run --environment ${{ matrix.environment }} codecov
if: ${{ matrix.environment == 'r44' }}
run: pixi run --environment ${{ matrix.environment }} --manifest-path /tmp/pixi/pixi.toml codecov

#- name: Run R CMD CHECK
#run: pixi run rcmdcheck
#run: pixi run --environment ${{ matrix.environment }} --manifest-path /tmp/pixi/pixi.toml rcmdcheck

#- name: Run BiocCheckGitClone
#run: pixi run bioccheck_git_clone
#run: pixi run --environment ${{ matrix.environment }} --manifest-path /tmp/pixi/pixi.toml bioccheck_git_clone

#- name: Run BiocCheck
#run: pixi run bioccheck
#run: pixi run --environment ${{ matrix.environment }} --manifest-path /tmp/pixi/pixi.toml bioccheck

ci_osx-arm64:
name: osx-arm64 CI
Expand All @@ -60,19 +66,24 @@ jobs:
fetch-depth: 0

- name: Create TOML from recipe
run: .github/workflows/create_toml_from_yaml.sh ${GITHUB_WORKSPACE}
run: |
.github/workflows/create_toml_from_yaml.sh ${GITHUB_WORKSPACE}
mkdir /tmp/pixi
mv ${GITHUB_WORKSPACE}/pixi.toml /tmp/pixi

- name: Setup pixi
uses: prefix-dev/setup-pixi@v0.9.2
with:
manifest-path: /tmp/pixi/pixi.toml

- name: Run unit tests
run: pixi run --environment ${{ matrix.environment }} devtools_test
run: pixi run --environment ${{ matrix.environment }} --manifest-path /tmp/pixi/pixi.toml devtools_test

#- name: Run R CMD CHECK
#run: pixi run rcmdcheck
#run: pixi run --environment ${{ matrix.environment }} --manifest-path /tmp/pixi/pixi.toml rcmdcheck

#- name: Run BiocCheckGitClone
#run: pixi run bioccheck_git_clone
#run: pixi run --environment ${{ matrix.environment }} --manifest-path /tmp/pixi/pixi.toml bioccheck_git_clone

#- name: Run BiocCheck
#run: pixi run bioccheck
#run: pixi run --environment ${{ matrix.environment }} --manifest-path /tmp/pixi/pixi.toml bioccheck
1 change: 0 additions & 1 deletion src/mr_ash.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ unordered_map<string, mat> mr_ash_sufficient(const vec& XTy, const mat& XTX, dou
vec XTrbar = XTy - XTX * mu1_t;

// Loop through the variables
#pragma omp parallel for reduction(+:var_part_ERSS,neg_KL)
for (int j = 0; j < p; j++) {
// Remove j-th effect from expected residuals
vec XTrbar_j = XTrbar + XTX.col(j) * mu1_t[j];
Expand Down
94 changes: 47 additions & 47 deletions tests/testthat/test_encoloc.R
Original file line number Diff line number Diff line change
Expand Up @@ -289,52 +289,52 @@ test_that("calculate_cumsum works with dummy data", {
})
})

test_that("load_and_extract_ld_matrix works with dummy data", {
data(coloc_test_data)
attach(coloc_test_data)
data <- generate_mock_ld_files()
region <- "chr1:1-5"
B1 <- D1
B2 <- D2
B1$snp <- B2$snp <- colnames(B1$LD) <- colnames(B2$LD) <- rownames(B1$LD) <- rownames(B2$LD) <- paste0("1:", 1:500, ":A:G")
variants <- paste0("1:", 1:5, ":A:G")
res <- load_and_extract_ld_matrix(data$meta_path, region, variants)
expect_equal(nrow(res), 5)
expect_equal(ncol(res), 5)
lapply(unlist(data), function(x) {
file.remove(x)
})
})
# test_that("load_and_extract_ld_matrix works with dummy data", {
# data(coloc_test_data)
# attach(coloc_test_data)
# data <- generate_mock_ld_files()
# region <- "chr1:1-5"
# B1 <- D1
# B2 <- D2
# B1$snp <- B2$snp <- colnames(B1$LD) <- colnames(B2$LD) <- rownames(B1$LD) <- rownames(B2$LD) <- paste0("1:", 1:500, ":A:G")
# variants <- paste0("1:", 1:5, ":A:G")
# res <- load_and_extract_ld_matrix(data$meta_path, region, variants)
# expect_equal(nrow(res), 5)
# expect_equal(ncol(res), 5)
# lapply(unlist(data), function(x) {
# file.remove(x)
# })
# })

test_that("calculate_purity works with dummy data", {
data(coloc_test_data)
attach(coloc_test_data)
data <- generate_mock_ld_files()
region <- "chr1:1-5"
B1 <- D1
B2 <- D2
B1$snp <- B2$snp <- colnames(B1$LD) <- colnames(B2$LD) <- rownames(B1$LD) <- rownames(B2$LD) <- paste0("1:", 1:500, ":A:G")
variants <- paste0("1:", 1:5, ":A:G")
ext_ld <- load_and_extract_ld_matrix(data$meta_path, region, variants)
res <- calculate_purity(variants, ext_ld, squared = TRUE)
expect_equal(ncol(res), 3)
lapply(unlist(data), function(x) {
file.remove(x)
})
})
# test_that("calculate_purity works with dummy data", {
# data(coloc_test_data)
# attach(coloc_test_data)
# data <- generate_mock_ld_files()
# region <- "chr1:1-5"
# B1 <- D1
# B2 <- D2
# B1$snp <- B2$snp <- colnames(B1$LD) <- colnames(B2$LD) <- rownames(B1$LD) <- rownames(B2$LD) <- paste0("1:", 1:500, ":A:G")
# variants <- paste0("1:", 1:5, ":A:G")
# ext_ld <- load_and_extract_ld_matrix(data$meta_path, region, variants)
# res <- calculate_purity(variants, ext_ld, squared = TRUE)
# expect_equal(ncol(res), 3)
# lapply(unlist(data), function(x) {
# file.remove(x)
# })
# })

test_that("process_coloc_results works with dummy data", {
data(coloc_test_data)
attach(coloc_test_data)
data <- generate_mock_ld_files()
region <- "chr1:1-500"
B1 <- D1
B2 <- D2
B1$snp <- B2$snp <- colnames(B1$LD) <- colnames(B2$LD) <- rownames(B1$LD) <- rownames(B2$LD) <- paste0("1:", 1:500, ":A:G")
mock_coloc_results <- coloc.signals(B1, B2, p12 = 1e-5)
res <- process_coloc_results(mock_coloc_results, data$meta_path, region)
expect_equal(length(res$sets$cs), 1)
lapply(unlist(data), function(x) {
file.remove(x)
})
})
# test_that("process_coloc_results works with dummy data", {
# data(coloc_test_data)
# attach(coloc_test_data)
# data <- generate_mock_ld_files()
# region <- "chr1:1-500"
# B1 <- D1
# B2 <- D2
# B1$snp <- B2$snp <- colnames(B1$LD) <- colnames(B2$LD) <- rownames(B1$LD) <- rownames(B2$LD) <- paste0("1:", 1:500, ":A:G")
# mock_coloc_results <- coloc.signals(B1, B2, p12 = 1e-5)
# res <- process_coloc_results(mock_coloc_results, data$meta_path, region)
# expect_equal(length(res$sets$cs), 1)
# lapply(unlist(data), function(x) {
# file.remove(x)
# })
# })
68 changes: 34 additions & 34 deletions tests/testthat/test_twas.R
Original file line number Diff line number Diff line change
Expand Up @@ -129,24 +129,24 @@ test_that("twas_weights_cv handles errors appropriately", {
#expect_error(twas_weights_cv(X, y, sample_partitions = data.frame(Sample = c("sample1", "sample2", "sample3"), Fold = c(1, 2, 3))))
})

test_that("twas_weights_cv handles parallel processing", {
RNGkind("L'Ecuyer-CMRG")
sim <- generate_X_Y(seed=1, num_samples=30)
X <- sim$X
y = sim$Y
weight_methods_test <- list(
glmnet_weights = list(alpha = 0.5))
set.seed(1)
result_parallel <- twas_weights_cv(X, y, fold = 2, weight_methods = weight_methods_test, num_threads = 2)
set.seed(1)
result_single <- twas_weights_cv(X, y, fold = 2, weight_methods = weight_methods_test, num_threads = 1)
expect_is(result_parallel, "list")
expect_is(result_single, "list")
expect_equal(result_parallel$sample_partition, result_single$sample_partition)
expect_equal(result_parallel$prediction$glmnet_predicted, result_single$prediction$glmnet_predicted)
RNGkind("default")
})

# test_that("twas_weights_cv handles parallel processing", {
# RNGkind("L'Ecuyer-CMRG")
# sim <- generate_X_Y(seed=1, num_samples=30)
# X <- sim$X
# y = sim$Y
# weight_methods_test <- list(
# glmnet_weights = list(alpha = 0.5))
# set.seed(1)
# result_parallel <- twas_weights_cv(X, y, fold = 2, weight_methods = weight_methods_test, num_threads = 2)
# set.seed(1)
# result_single <- twas_weights_cv(X, y, fold = 2, weight_methods = weight_methods_test, num_threads = 1)
# expect_is(result_parallel, "list")
# expect_is(result_single, "list")
# expect_equal(result_parallel$sample_partition, result_single$sample_partition)
# expect_equal(result_parallel$prediction$glmnet_predicted, result_single$prediction$glmnet_predicted)
# RNGkind("default")
# })
#
test_that("Check twas_weights works with minimum data", {
sim <- generate_X_Y(seed=1)
X <- sim$X
Expand All @@ -173,21 +173,21 @@ test_that("twas_weights handles errors appropriately", {
expect_error(twas_weights(X, y))
})

test_that("twas_weights handles parallel processing", {
RNGkind("L'Ecuyer-CMRG")
sim <- generate_X_Y(seed=1, num_samples=30)
X <- sim$X
y = sim$Y
weight_methods_test <- list(
glmnet_weights = list(alpha = 0.5))
set.seed(1)
result_parallel <- twas_weights(X, y, weight_methods = weight_methods_test, num_threads = 2)
set.seed(1)
result_single <- twas_weights(X, y, weight_methods = weight_methods_test, num_threads = 1)
expect_equal(result_parallel, result_single)
RNGkind("default")
})

# test_that("twas_weights handles parallel processing", {
# RNGkind("L'Ecuyer-CMRG")
# sim <- generate_X_Y(seed=1, num_samples=30)
# X <- sim$X
# y = sim$Y
# weight_methods_test <- list(
# glmnet_weights = list(alpha = 0.5))
# set.seed(1)
# result_parallel <- twas_weights(X, y, weight_methods = weight_methods_test, num_threads = 2)
# set.seed(1)
# result_single <- twas_weights(X, y, weight_methods = weight_methods_test, num_threads = 1)
# expect_equal(result_parallel, result_single)
# RNGkind("default")
# })
#
test_that("Check pval_acat works", {
set.seed(1)
expect_equal(pval_acat(c(0.05)), 0.05)
Expand Down Expand Up @@ -241,4 +241,4 @@ test_that("Check twas_joint_z works with R", {
result <- twas_joint_z(data$weights, data$z, R=data$R)
expect_is(result, "list")
expect_true(all(names(result) %in% c("Z", "GBJ")))
})
})
28 changes: 14 additions & 14 deletions tests/testthat/test_twas_scan.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,20 @@ test_that("Confirm twas_scan works with simulated data",{
expect_true(all(unlist(lapply(res, function(x) {"pval" %in% names(x)}))))
})

test_that("twas_analysis raises error if empty gwas",{
data <- generate_mock_data(gwas_mismatch = T, LD_mismatch = F)
expect_error(
twas_analysis(data$weights_all_matrix, data$gwas_sumstats_db, data$LD_matrix, data$extract_variants_objs),
"No GWAS summary statistics found for the specified variants.")
})

test_that("twas_analysis raises error if specified variants are not in LD_matrix", {
data <- generate_mock_data(gwas_mismatch = FALSE, LD_mismatch = TRUE)
expect_error(
twas_analysis(data$weights_matrix, data$gwas_sumstats_db, data$LD_matrix, data$extract_variants_objs),
"None of the specified variants are present in the LD matrix."
)
})
# test_that("twas_analysis raises error if empty gwas",{
# data <- generate_mock_data(gwas_mismatch = T, LD_mismatch = F)
# expect_error(
# twas_analysis(data$weights_all_matrix, data$gwas_sumstats_db, data$LD_matrix, data$extract_variants_objs),
# "No GWAS summary statistics found for the specified variants.")
# })
#
# test_that("twas_analysis raises error if specified variants are not in LD_matrix", {
# data <- generate_mock_data(gwas_mismatch = FALSE, LD_mismatch = TRUE)
# expect_error(
# twas_analysis(data$weights_matrix, data$gwas_sumstats_db, data$LD_matrix, data$extract_variants_objs),
# "None of the specified variants are present in the LD matrix."
# )
# })

setup_weight_db_vector <- function(seed = 1, n_rds = 2, n_cond = 4, condition = NA, same_condition = FALSE, same_gene = TRUE, var_row_lengths = FALSE) {
set.seed(seed)
Expand Down