xinhe-lab / ctwas

package for the causal TWAS project
https://xinhe-lab.github.io/ctwas/
MIT License
32 stars 12 forks source link

Add imports for all functions called explicitly from other packages #24

Closed pcarbo closed 3 months ago

pcarbo commented 3 months ago

I noticed that many of the functions used in other packages are not explicitly imported with @importFrom statements. For example, in commit 27b8c2df I added this above function "anno_finemap_res" because data.table::rbindlist() is used in this function:

#' @importFrom data.table rbindlist

This isn't always strictly necessary but it is helpful to avoid issues. Note the one exception to this is for packages that are conditionally loaded, e.g., Rfast.

Here is a list of functions for which importFrom statements may be missing:

ctwas_EM.R:    EM_susie_res_list <- parallel::mclapply(region_ids, function(region_id){
ctwas_compute_gene_z.R:  z_gene <- parallel::mclapply(names(weights), function(id) {
ctwas_convert_geno_to_LD_matrix.R:    region_info$chr <- readr::parse_number(region_info$chr)
ctwas_convert_geno_to_LD_matrix.R:        R_snp <- Rfast::cora(X.g)
ctwas_convert_geno_to_LD_matrix.R:          R_snp_variances <- Rfast::colVars(X.g)
ctwas_convert_regionlist_to_region_data.R:  logging::loginfo("Convert the data structure from regionlist to region data")
ctwas_convert_regionlist_to_region_data.R:  logging::loginfo("%d regions in region_data", length(region_data))
ctwas_convert_regionlist_to_region_data.R:  logging::loginfo("Add z-scores to region_data...")
ctwas_diagnose_LD_mismatch.R:  condz_list <- parallel::mclapply(region_ids, function(region_id){
ctwas_diagnose_LD_mismatch.R:  condz_stats <- data.table::rbindlist(condz_list, idcol = "region_id")
ctwas_diagnose_LD_mismatch.R:    R_snp <- suppressWarnings(as.matrix(Matrix::bdiag(R_snp)))
ctwas_finemapping.R:        R_snp <- suppressWarnings(as.matrix(Matrix::bdiag(R_snp)))
ctwas_finemapping.R:  finemap_region_res_list <- parallel::mclapply(region_ids, function(region_id){
ctwas_harmonize_data.R:    snp_info <- as.data.frame(data.table::rbindlist(snp_info, idcol = "region_id"))
ctwas_harmonize_data.R:    snp_info <- as.data.frame(data.table::rbindlist(snp_info, idcol = "region_id"))
ctwas_merge_regions.R:  logging::loginfo("Merged %d boundary genes into %d regions", nrow(boundary_genes), nrow(merged_region_info))
ctwas_plots.R:        R_snp <- suppressWarnings(as.matrix(Matrix::bdiag(R_snp)))
ctwas_plots.R:  loc <- locuszoomr::locus(
ctwas_plots.R:  cowplot::plot_grid(p_pvalue, p_pip, p_qtl, p_genes, ncol = 1,
ctwas_preprocess_regions.R:  snp_info <- parallel::mclapply(region_ids, function(region_id){
ctwas_preprocess_weights.R:    snp_info_df <- as.data.frame(data.table::rbindlist(snp_info, idcol = "region_id"))
ctwas_preprocess_weights.R:    context <- tools::file_path_sans_ext(basename(weight_file))
ctwas_preprocess_weights.R:    cl <- parallel::makeCluster(ncore, outfile = "")
ctwas_preprocess_weights.R:    doParallel::registerDoParallel(cl)
ctwas_preprocess_weights.R:              R_snp <- suppressWarnings({as.matrix(Matrix::bdiag(R_snp))})
ctwas_preprocess_z_snp.R:    snp_info <- as.data.frame(data.table::rbindlist(snp_info, idcol = "region_id"))
ctwas_region_data.R:    snp_info <- as.data.frame(data.table::rbindlist(snp_info, idcol = "region_id"))
ctwas_region_data.R:          logging::loginfo("Trim region %s with SNPs more than %s", region_id, maxSNP)
ctwas_region_data.R:          logging::loginfo("Trim region %s with SNPs more than %s", region_id, maxSNP)
ctwas_region_data.R:  logging::loginfo("Adding z-scores to region_data ...")
ctwas_region_data.R:  region_data2 <- parallel::mclapply(region_ids, function(region_id){
ctwas_region_data.R:  logging::loginfo("Adjusting for boundary genes ...")
ctwas_region_data.R:    snp_info <- as.data.frame(data.table::rbindlist(snp_info, idcol = "region_id"))
ctwas_region_data.R:    snp_info <- as.data.frame(data.table::rbindlist(snp_info, idcol = "region_id"))
ctwas_region_data.R:  region_data <- parallel::mclapply(region_ids, function(region_id){
ctwas_simulations.R:      expr <- data.table::data.table(NULL)
ctwas_simulations.R:      geneinfo <- data.table::data.table(NULL)
ctwas_simulations.R:    data.table::fwrite(expr, file = exprf,
ctwas_simulations.R:    data.table::fwrite(geneinfo, file = exprvarf, sep = "\t", quote = F)
ctwas_simulations.R:  sqlite <- RSQLite::dbDriver("SQLite")
ctwas_simulations.R:    db = RSQLite::dbConnect(sqlite, weight)
ctwas_simulations.R:    query <- function(...) RSQLite::dbGetQuery(db, ...)
ctwas_simulations.R:    RSQLite::dbDisconnect(db)
ctwas_simulations.R:  cl <- parallel::makeCluster(ncore, outfile = "")
ctwas_simulations.R:  doParallel::registerDoParallel(cl)
ctwas_simulations.R:      weight_name <- tools::file_path_sans_ext(basename(weight))
ctwas_simulations.R:      db = RSQLite::dbConnect(sqlite, weight)
ctwas_simulations.R:      query <- function(...) RSQLite::dbGetQuery(db, ...)
ctwas_simulations.R:      RSQLite::dbDisconnect(db)
ctwas_simulations.R:  parallel::stopCluster(cl)
ctwas_simulations.R:        R_snp <- suppressWarnings({as.matrix(Matrix::bdiag(R_snp))})
ctwas_simulations.R:  exprvar <- try(data.table::fread(exprvarf, header = T))
ctwas_simulations.R:    return(as.matrix(data.table::fread(exprf, header = F,
ctwas_summarize_finemap_res.R:    snp_info <- as.data.frame(data.table::rbindlist(snp_info, idcol = "region_id"))
ctwas_summarize_parameters.R:    outlist$convergence_plot <- cowplot::plot_grid(p_pi, p_sigma2, p_enrich, p_pve)
ctwas_susie_rss.R:    # following the default in susieR::susie_rss
ctwas_utils.R:  snp_info <- as.data.frame(data.table::fread(file, header = TRUE))
ctwas_utils.R:    weight_name <- tools::file_path_sans_ext(basename(weight_file))
ctwas_utils.R:    sqlite <- RSQLite::dbDriver("SQLite")
ctwas_utils.R:    db = RSQLite::dbConnect(sqlite, weight_file)
ctwas_utils.R:    query <- function(...) RSQLite::dbGetQuery(db, ...)
ctwas_utils.R:      predictdb_LD_file <- paste0(tools::file_path_sans_ext(weight_file), ".txt.gz")
ctwas_utils.R:    RSQLite::dbDisconnect(db)
ctwas_utils.R:    weight_name <- tools::file_path_sans_ext(basename(weight_file))
ctwas_utils.R:    cl <- parallel::makeCluster(ncore, outfile = "", type = "FORK")
ctwas_utils.R:    doParallel::registerDoParallel(cl)
ctwas_utils.R:            left_join(tibble::as_tibble(snps) %>% select(-cm), by = "rsid")
ctwas_utils.R:      parallel::stopCluster(cl)
ctwas_utils.R:    file_ext_lower <- tolower(tools::file_ext(file))
ctwas_utils.R:    res <- as.matrix(data.table::fread(file))
ctwas_utils.R:        pvar <- data.table::fread(pvarf, header = F)
ctwas_utils.R:        data.table::fwrite(pvar, file = pvarf2 , sep="\t", quote = F)
ctwas_utils.R:      pvar <- data.table::fread(pvarf, header = F)
ctwas_utils.R:      data.table::fwrite(pvar, file = pvarf2 , sep="\t", quote = F)
ctwas_utils.R:  pvar <- pgenlibr::NewPvar(pvarf)
ctwas_utils.R:    pgen <- pgenlibr::NewPgen(pgenf, pvar = pvar)
ctwas_utils.R:    fam <- data.table::fread(famf, header = F)
ctwas_utils.R:    pgen <- pgenlibr::NewPgen(pgenf, pvar = pvar, raw_sample_ct = raw_s_ct)
ctwas_utils.R:    variantidx <- 1: pgenlibr::GetVariantCt(pgen)}
ctwas_utils.R:  pgenlibr::ReadList(pgen,
ctwas_utils.R:  pvar <- data.table::fread(pvarf, skip = "#CHROM")
ctwas_utils.R:  pvar <- dplyr::rename(pvar, "chrom" = "#CHROM", "pos" = "POS",
ctwas_utils.R:  bim <- data.table::fread(bimf)
susie_set_X_attributes.R:# @details This should give the same result as matrixStats::colSds(X),
susie_susie_utils.R:    get_upper_tri = Rfast::upper_tri
susie_susie_utils.R:    get_median    = Rfast::med
susie_susie_utils.R:    get_median    = stats::median
kevinlkx commented 3 months ago

Thanks so much. I have just added importFrom statements for most of these functions, except using conditional loading for Rfast.

pcarbo commented 3 months ago

It looks like you accidentally added Rfast imports. I removed those.