diff --git a/R/colocboost.R b/R/colocboost.R index 475cc87..379ca84 100644 --- a/R/colocboost.R +++ b/R/colocboost.R @@ -51,7 +51,7 @@ #' @param jk_equiv_corr The LD cutoff between overall best update jk-star and marginal best update jk-l for lth outcome #' @param jk_equiv_loglik The change of loglikelihood cutoff between overall best update jk-star and marginal best update jk-l for lth outcome #' @param coloc_thresh The cutoff of checking if the best update jk-star is the potential causal variable for outcome l if jk-l is not similar to jk-star (used in Delayed SEC). -#' @param lambda The ratio [0,1] for z^2 and z in fun_prior simplex, defult is 0.5 +#' @param lambda The ratio \[0,1\] for z^2 and z in fun_prior simplex, defult is 0.5 #' @param lambda_target_outcome The ratio for z^2 and z in fun_prior simplex for the target outcome, default is 1 #' @param func_simplex The data-driven local association simplex \eqn{\delta} for smoothing the weights. Default is "LD_z2z" is the elastic net for z-score and also weighted by LD. #' @param func_multi_test The alternative method to check the stop criteria. When \code{func_multi_test = "lfdr"}, boosting iterations will be stopped @@ -98,10 +98,7 @@ #' #' @importFrom stats na.omit #' @export -#' -#' @examples -#' colocboost(X=X, Y=Y) -#' + colocboost <- function(X = NULL, Y = NULL, # individual data sumstat = NULL, LD = NULL, # summary statistics: either Z, bhat, sebhat, N, var_Y, ###### - index dict for X match multiple Y / LD match multiple sumstat diff --git a/R/colocboost_output.R b/R/colocboost_output.R index cbc8b0f..065dcfc 100644 --- a/R/colocboost_output.R +++ b/R/colocboost_output.R @@ -23,10 +23,6 @@ #' \item{colocalized_variables}{List of colocalized variables} #' \item{colocalized_variables_vcp}{Variant colocalization probabilities for all colocalized variables} #' -#' @examples -#' get_cos_summary(cb_output) -#' get_cos_summary(cb_output, interest_outcome = c("Y1", "Y2")) -#' #' @keywords cb_get_functions #' @export get_cos_summary <- function(cb_output, @@ -124,9 +120,6 @@ get_cos_summary <- function(cb_output, #' \item{data_info}{A object with detailed information from input data} #' \item{model_info}{A object with detailed information for colocboost model} #' -#' @examples -#' get_strong_colocalization(cb_output, cos_npc_cutoff = 0.5, npc_outcome_cutoff = 0.25) -#' #' @keywords cb_get_functions #' @export get_strong_colocalization <- function(cb_output, @@ -359,9 +352,6 @@ get_strong_colocalization <- function(cb_output, #' \item{ucos_variables}{List of fine-mapped variables} #' \item{ucos_variables_pip}{Posterior inclusion probability (PIP) for all fine-mapped variables} #' -#' @examples -#' get_ucos_summary(cb_output) -#' #' @keywords cb_get_functions #' @noRd get_ucos_summary <- function(cb_output, outcome_names = NULL, gene_name = NULL){ diff --git a/R/colocboost_plot.R b/R/colocboost_plot.R index 0debc09..88d4689 100644 --- a/R/colocboost_plot.R +++ b/R/colocboost_plot.R @@ -38,9 +38,6 @@ #' @importFrom graphics abline axis legend mtext par points text #' @importFrom grDevices adjustcolor #' -#' @examples -#' colocboost_plot(cb_output) -#' #' @keywords cb_plot #' @export colocboost_plot <- function(cb_output, y = "log10p", diff --git a/R/colocboost_utils.R b/R/colocboost_utils.R index 25b78e2..d496555 100644 --- a/R/colocboost_utils.R +++ b/R/colocboost_utils.R @@ -472,5 +472,3 @@ get_merge_ordered_with_indices <- function(vector_list) { result } - - \ No newline at end of file diff --git a/R/data.R b/R/data.R new file mode 100644 index 0000000..13f910a --- /dev/null +++ b/R/data.R @@ -0,0 +1,27 @@ +#' Individual level data for 5 traits +#' +#' An example dataset with simulated genotypes and outcomes for 5 traits +#' +#' @format ## `Ind_5traits` +#' A list with 3 elements +#' \describe{ +#' \item{X}{List of genotype matrices} +#' \item{Y}{List of outcomes} +#' \item{TrueCausalVariants}{List of causal variants} +#' } +#' @source FINISH +"Ind_5traits" + +#' Summary level data for 5 traits +#' +#' An example dataset with simulated statistics and LD for 5 traits +#' +#' @format ## `Sumstat_5traits` +#' A list with 3 elements +#' \describe{ +#' \item{sumstat}{Summary statistics for 5 traits} +#' \item{LD}{Matrix of LD between variants} +#' \item{TrueCausalVariants}{List of causal variants} +#' } +#' @source FINISH +"Sumstat_5traits" diff --git a/man/Ind_5traits.Rd b/man/Ind_5traits.Rd new file mode 100644 index 0000000..f3b428f --- /dev/null +++ b/man/Ind_5traits.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{Ind_5traits} +\alias{Ind_5traits} +\title{Individual level data for 5 traits} +\format{ +\subsection{\code{Ind_5traits}}{ + +A list with 3 elements +\describe{ +\item{X}{List of genotype matrices} +\item{Y}{List of outcomes} +\item{TrueCausalVariants}{List of causal variants} +} +} +} +\source{ +FINISH +} +\usage{ +Ind_5traits +} +\description{ +An example dataset with simulated genotypes and outcomes for 5 traits +} +\keyword{datasets} diff --git a/man/Sumstat_5traits.Rd b/man/Sumstat_5traits.Rd new file mode 100644 index 0000000..84566f5 --- /dev/null +++ b/man/Sumstat_5traits.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/data.R +\docType{data} +\name{Sumstat_5traits} +\alias{Sumstat_5traits} +\title{Summary level data for 5 traits} +\format{ +\subsection{\code{Sumstat_5traits}}{ + +A list with 3 elements +\describe{ +\item{sumstat}{Summary statistics for 5 traits} +\item{LD}{Matrix of LD between variants} +\item{TrueCausalVariants}{List of causal variants} +} +} +} +\source{ +FINISH +} +\usage{ +Sumstat_5traits +} +\description{ +An example dataset with simulated statistics and LD for 5 traits +} +\keyword{datasets} diff --git a/man/colocboost.Rd b/man/colocboost.Rd index 9c13d46..a05ad1e 100644 --- a/man/colocboost.Rd +++ b/man/colocboost.Rd @@ -125,7 +125,7 @@ we need to have the higher learning rate to improve the computational efficiency \item{coloc_thresh}{The cutoff of checking if the best update jk-star is the potential causal variable for outcome l if jk-l is not similar to jk-star (used in Delayed SEC).} -\item{lambda}{The ratio \link{0,1} for z^2 and z in fun_prior simplex, defult is 0.5} +\item{lambda}{The ratio [0,1] for z^2 and z in fun_prior simplex, defult is 0.5} \item{lambda_target_outcome}{The ratio for z^2 and z in fun_prior simplex for the target outcome, default is 1} @@ -210,7 +210,3 @@ There is an additional step to help merge the confidence sets with small \code{b (default is 0.8) but within the same locus. This step addresses potential instabilities in linkage disequilibrium (LD) estimation that may arise from small sample sizes or discrepancies in minor allele frequencies (MAF) across different confidence sets. } -\examples{ -colocboost(X=X, Y=Y) - -} diff --git a/man/colocboost_plot.Rd b/man/colocboost_plot.Rd index 03900c5..27c1475 100644 --- a/man/colocboost_plot.Rd +++ b/man/colocboost_plot.Rd @@ -94,9 +94,5 @@ Visualization plot for each colcoalization event. } \description{ \code{colocboost_plot} generates visualization plots for colocalization events from a ColocBoost analysis. -} -\examples{ -colocboost_plot(cb_output) - } \keyword{cb_plot} diff --git a/man/get_cos_summary.Rd b/man/get_cos_summary.Rd index e6f84a5..042efa8 100644 --- a/man/get_cos_summary.Rd +++ b/man/get_cos_summary.Rd @@ -37,10 +37,5 @@ A summary table for colocalization events with the following columns: } \description{ \code{get_cos_summary} get the colocalization summary table with or without the outcomes of interest. -} -\examples{ -get_cos_summary(cb_output) -get_cos_summary(cb_output, interest_outcome = c("Y1", "Y2")) - } \keyword{cb_get_functions} diff --git a/man/get_strong_colocalization.Rd b/man/get_strong_colocalization.Rd index 68a483d..3e5aff5 100644 --- a/man/get_strong_colocalization.Rd +++ b/man/get_strong_colocalization.Rd @@ -37,9 +37,5 @@ A \code{"colocboost"} object with some or all of the following elements: } \description{ \code{get_strong_colocalization} get the colocalization by discarding the weaker colocalization events or colocalized outcomes -} -\examples{ -get_strong_colocalization(cb_output, cos_npc_cutoff = 0.5, npc_outcome_cutoff = 0.25) - } \keyword{cb_get_functions} diff --git a/tests/testthat.R b/tests/testthat.R index 9bbc0ce..12de635 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -9,4 +9,4 @@ library(testthat) library(colocboost) -test_check("colocboost") \ No newline at end of file +test_check("colocboost") diff --git a/tests/testthat/test_package.R b/tests/testthat/test_package.R deleted file mode 100644 index 2f913c7..0000000 --- a/tests/testthat/test_package.R +++ /dev/null @@ -1,176 +0,0 @@ -library(testthat) - -# Helper function to parse NAMESPACE file and extract exported functions -get_exported_functions <- function() { - # Locate the NAMESPACE file - if (file.exists("../../NAMESPACE")) { - namespace_path <- "../../NAMESPACE" - } else if (file.exists("../NAMESPACE")) { - namespace_path <- "../NAMESPACE" - } else { - # If running within package, try to find it in the package directory - package_dir <- find.package("colocboost", quiet = TRUE) - if (length(package_dir) > 0) { - namespace_path <- file.path(package_dir, "NAMESPACE") - if (!file.exists(namespace_path)) { - return(NULL) - } - } else { - return(NULL) - } - } - - # Read NAMESPACE file - ns_lines <- readLines(namespace_path) - - # Extract exported functions - export_lines <- ns_lines[grepl("^export\\(", ns_lines)] - exported_funcs <- gsub("export\\((.*)\\)", "\\1", export_lines) - - # Clean up any quotation marks - exported_funcs <- gsub("\"", "", exported_funcs) - exported_funcs <- gsub("\'", "", exported_funcs) - - return(exported_funcs) -} - -# Test that the package loads without errors -test_that("package loads without errors", { - expect_error(library(colocboost), NA) -}) - -# Test that exported functions exist -test_that("package has expected functions", { - exported_functions <- get_exported_functions() - - # If we couldn't parse the NAMESPACE, fall back to a minimal set - if (is.null(exported_functions) || length(exported_functions) == 0) { - warning("Could not parse NAMESPACE file, falling back to minimum expected functions") - exported_functions <- c("colocboost") - } - - # Test that each exported function exists - for (func in exported_functions) { - expect_true(exists(func, where = asNamespace("colocboost")), - info = paste0("Function '", func, "' should exist in the package")) - } - - # Print the functions we found for debugging - message("Tested for existence of the following exported functions:") - message(paste(exported_functions, collapse = ", ")) -}) - -# Test that package depends on required packages -test_that("package depends on required packages", { - # Get dependencies from DESCRIPTION file - get_dependencies <- function() { - desc_file <- NULL - if (file.exists("../../DESCRIPTION")) { - desc_file <- "../../DESCRIPTION" - } else if (file.exists("../DESCRIPTION")) { - desc_file <- "../DESCRIPTION" - } else { - package_dir <- find.package("colocboost", quiet = TRUE) - if (length(package_dir) > 0) { - desc_file <- file.path(package_dir, "DESCRIPTION") - } - } - - if (is.null(desc_file) || !file.exists(desc_file)) { - return(c("R", "Rfast", "matrixStats")) # Fallback - } - - desc <- readLines(desc_file) - - # Find Depends and Imports sections - deps_start <- grep("^(Depends|Imports):", desc) - deps_end <- c(deps_start[-1] - 1, length(desc)) - deps_end <- deps_end[1:length(deps_start)] - - # Extract dependencies - deps <- c() - for (i in 1:length(deps_start)) { - section <- desc[deps_start[i]:deps_end[i]] - section_text <- paste(section, collapse = " ") - - # Remove section header - section_text <- gsub("^(Depends|Imports):", "", section_text) - - # Extract package names - pkgs <- strsplit(section_text, ",")[[1]] - pkgs <- trimws(pkgs) - - # Remove version requirements - pkgs <- gsub("\\s*\\(.*\\)", "", pkgs) - - deps <- c(deps, pkgs) - } - - # Remove R from the list (it's always available) - deps <- setdiff(deps, "R (>= 4.0.0)") - deps <- c("R", deps) # Add R back in a standardized format - - return(deps) - } - - expected_deps <- get_dependencies() - - # Check if packages can be loaded - this is a better test than checking DESCRIPTION - for (pkg in expected_deps) { - if (pkg != "R") { # Skip R as it's always loaded - if (!requireNamespace(pkg, quietly = TRUE)) { - skip(paste("Package", pkg, "not available for testing")) - } - } - } - - # Basic test succeeded if we got here - expect_true(TRUE) -}) - -# Test that the package has the correct structure -test_that("package has correct S3 methods", { - # Check S3 methods using methods function if any expected - expect_true(is.function(colocboost), "colocboost should be a function") - - # Test that colocboost returns correct class - skip_on_cran() - - # Generate minimal test data - set.seed(123) - n <- 20 # Small sample for quick test - p <- 5 # Few variables - X <- matrix(rnorm(n*p), n, p) - colnames(X) <- paste0("X", 1:p) - Y <- matrix(rnorm(n*2), n, 2) - Y_list <- list(Y[,1], Y[,2]) - X_list <- list(X, X) - - # Run with minimal iterations - suppressWarnings({ - result <- colocboost(X = X_list, Y = Y_list, M = 2) - }) - - # Test class - expect_s3_class(result, "colocboost") -}) - -# Test documentation exists for key functions -test_that("documentation exists for key functions", { - # Get all exported functions - exported_functions <- get_exported_functions() - - # If we couldn't parse the NAMESPACE, fall back to a minimal set - if (is.null(exported_functions) || length(exported_functions) == 0) { - exported_functions <- c("colocboost", "colocboost_plot", "get_cos_summary") - } - - # Limit to a reasonable number to check - funcs_to_check <- exported_functions[1:min(length(exported_functions), 5)] - - # Check if help pages exist for key functions - for (func in funcs_to_check) { - expect_error(help(func), NA, - info = paste0("Documentation should exist for function '", func, "'")) - } -}) \ No newline at end of file diff --git a/tests/testthat/test_utils.R b/tests/testthat/test_utils.R index 272c6ab..0ce5891 100644 --- a/tests/testthat/test_utils.R +++ b/tests/testthat/test_utils.R @@ -181,4 +181,4 @@ test_that("get_merge_ordered_with_indices merges vectors", { vector_list2 <- list(vec1, vec1, vec2, vec3) result2 <- get_merge_ordered_with_indices(vector_list2) expect_equal(result2, c("a", "b", "c", "d", "e")) -}) \ No newline at end of file +})