diff --git a/R/feature_selection.R b/R/feature_selection.R index 6c9c170..a78f9e2 100644 --- a/R/feature_selection.R +++ b/R/feature_selection.R @@ -72,7 +72,6 @@ find_variable_events <- function(m1_matrix, m2_matrix, min_row_sum = 50, n_threa sum_deviances <- Reduce(`+`, deviance_results) rez <- data.table::data.table(events = names(sum_deviances), sum_deviance = as.numeric(sum_deviances)) return(rez) - cat("All Done!\n") } #' Find Variable Genes Using Variance or Deviance-Based Metrics @@ -118,7 +117,7 @@ find_variable_events <- function(m1_matrix, m2_matrix, min_row_sum = 50, n_threa #' @importClassesFrom Matrix dgCMatrix dsCMatrix dgTMatrix dsTMatrix #' @export find_variable_genes <- function(gene_expression_matrix, method = "vst", n_threads = 1, verbose = TRUE, ...) { - # addinng the vst method as the deafult + # adding the vst method as the default method <- match.arg(method, choices = c("vst", "sum_deviance")) # Verify that gene_expression_matrix is a sparse Matrix @@ -168,7 +167,7 @@ find_variable_genes <- function(gene_expression_matrix, method = "vst", n_thread deviances_list <- vector("list", length(libraries)) names(deviances_list) <- libraries - # Getting the sim devinaces fir NB model + # Getting the sum deviances for NB model deviances_list <- lapply(libraries, function(lib) { filter <- which(meta[, ID] == lib) gene_expression_matrix_sub <- gene_expression_matrix[, filter, drop = FALSE] diff --git a/R/zzz.R b/R/zzz.R index a951322..4b44563 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -12,12 +12,3 @@ "=======================================================================================================\n" ) } - - -.onLoad <- function(libname, pkgname) { - required_pkgs <- c("Rcpp", "RcppEigen", "RcppArmadillo", "Matrix", "data.table") - missing_pkgs <- required_pkgs[!vapply(required_pkgs, requireNamespace, quietly = TRUE, FUN.VALUE = logical(1))] - if (length(missing_pkgs)) { - install.packages(missing_pkgs, dependencies = TRUE) - } -} diff --git a/README.md b/README.md index e869dbe..ccc42fe 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ [![R-CMD-check](https://github.com/csglab/splikit/actions/workflows/R-CMD-check.yml/badge.svg)](https://github.com/csglab/splikit/actions/workflows/R-CMD-check.yml) [![Documentation](https://img.shields.io/badge/Docs-Learn%20More-blue.svg)](https://csglab.github.io/splikit/) -## **Requirments** +## **Requirements** - [R version 3.5.0](http://www.r-project.org/) or later. - R libraries: [Rcpp](https://cran.r-project.org/web/packages/Rcpp/index.html), [RcppArmadillo](https://cran.r-project.org/web/packages/RcppArmadillo/index.html), [Matrix](https://cran.r-project.org/web/packages/Matrix/index.html), [data.table](https://cran.r-project.org/web/packages/data.table/index.html) diff --git a/src/Makevars.linux b/src/Makevars.linux index 4952079..a02c158 100644 --- a/src/Makevars.linux +++ b/src/Makevars.linux @@ -1,4 +1,4 @@ ## src/Makevars (Linux) CXX_STD = CXX14 -PKG_CXXFLAGS += -O3 -march=native -pipe -fopenmp +PKG_CXXFLAGS += -O3 -pipe -fopenmp PKG_LIBS += -fopenmp $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) diff --git a/src/calcDeviances.cpp b/src/calcDeviances.cpp index 4f5d1f2..d4e618a 100755 --- a/src/calcDeviances.cpp +++ b/src/calcDeviances.cpp @@ -1,5 +1,6 @@ // calcDeviances_ratio.cpp #include +#include #ifdef _OPENMP #include #endif @@ -15,9 +16,10 @@ arma::vec calcDeviances_ratio(const arma::sp_mat& M1, int n_cols = M1.n_cols; arma::vec dev(n_rows, arma::fill::zeros); - // Notify about OpenMP availability only once - static bool has_printed = false; - if (!has_printed) { + // Notify about OpenMP availability only once (thread-safe) + static std::atomic has_printed(false); + bool expected = false; + if (has_printed.compare_exchange_strong(expected, true)) { if (num_threads <= 1) { #ifdef _OPENMP Rcpp::Rcout << "Note: OpenMP is available. " @@ -33,7 +35,6 @@ arma::vec calcDeviances_ratio(const arma::sp_mat& M1, Rcpp::Rcout << "OpenMP not detected: running in single-thread mode.\n"; #endif } - has_printed = true; } // Set the number of threads if OpenMP is available diff --git a/src/deviance_gene.cpp b/src/deviance_gene.cpp index dbd8acc..e17c0ce 100644 --- a/src/deviance_gene.cpp +++ b/src/deviance_gene.cpp @@ -1,4 +1,5 @@ #include +#include #ifdef _OPENMP #include #endif @@ -13,9 +14,10 @@ arma::vec calcNBDeviancesWithThetaEstimation(const arma::sp_mat& gene_expression int n_cols = gene_expression.n_cols; // number of cells arma::vec dev(n_rows, arma::fill::zeros); - // Notify about OpenMP availability only once - static bool has_printed = false; - if (!has_printed) { + // Notify about OpenMP availability only once (thread-safe) + static std::atomic has_printed(false); + bool expected = false; + if (has_printed.compare_exchange_strong(expected, true)) { #ifdef _OPENMP if (num_threads > 1) { Rcpp::Rcout << "OpenMP is available. Using " << num_threads << " threads for NB deviance calculation.\n"; @@ -25,7 +27,6 @@ arma::vec calcNBDeviancesWithThetaEstimation(const arma::sp_mat& gene_expression Rcpp::Rcout << "OpenMP is not available. Running in single-threaded mode.\n"; } #endif - has_printed = true; } #ifdef _OPENMP