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
5 changes: 2 additions & 3 deletions R/feature_selection.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
9 changes: 0 additions & 9 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/Makevars.linux
Original file line number Diff line number Diff line change
@@ -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)
9 changes: 5 additions & 4 deletions src/calcDeviances.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// calcDeviances_ratio.cpp
#include <RcppArmadillo.h>
#include <atomic>
#ifdef _OPENMP
#include <omp.h>
#endif
Expand All @@ -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<bool> 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. "
Expand All @@ -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
Expand Down
9 changes: 5 additions & 4 deletions src/deviance_gene.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <RcppArmadillo.h>
#include <atomic>
#ifdef _OPENMP
#include <omp.h>
#endif
Expand All @@ -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<bool> 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";
Expand All @@ -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
Expand Down
Loading