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
14 changes: 7 additions & 7 deletions .github/workflows/R-CMD-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ jobs:
strategy:
matrix:
config:
- { os: ubuntu-latest, r: '4.5' }
- { os: ubuntu-latest, r: '4.4' }
- { os: windows-latest, r: '4.5' }
- { os: windows-latest, r: '4.4' }
- { os: macos-latest, r: '4.5' }
- { os: macos-latest, r: '4.4' }
- { os: ubuntu-latest, r: 'release' }
- { os: ubuntu-latest, r: 'oldrel-1' }
- { os: windows-latest, r: 'release' }
- { os: windows-latest, r: 'oldrel-1' }
- { os: macos-latest, r: 'release' }
- { os: macos-latest, r: 'oldrel-1' }
name: R ${{ matrix.config.r }} - ${{ matrix.config.os }}

steps:
- uses: actions/checkout@v3

Expand Down
26 changes: 11 additions & 15 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: splikit
Title: A toolkit for analysing RNA splicing in scRNA-seq data
Version: 1.0.3
Version: 1.0.4
Authors@R:
person("Arsham", "Mikaeili Namini", , "arsham.mikaeilinamini@mail.mcgill.ca", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-9453-6951"))
Expand All @@ -14,18 +14,14 @@ License: MIT + file LICENSE
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Imports:
Matrix,
data.table,
methods,
stats,
Rcpp,
RcppArmadillo,
RcppEigen
LinkingTo:
Rcpp,
RcppArmadillo,
RcppEigen
Suggests:
testthat (>= 3.0.0)
Imports: Matrix, data.table, methods, stats, Rcpp, RcppArmadillo,
RcppEigen
LinkingTo: Rcpp, RcppArmadillo, RcppEigen
Suggests: testthat (>= 3.0.0)
Config/testthat/edition: 3
NeedsCompilation: yes
Packaged: 2025-05-09 22:41:00 UTC; arsham79
Author: Arsham Mikaeili Namini [aut, cre]
(<https://orcid.org/0000-0002-9453-6951>)
Maintainer: Arsham Mikaeili Namini <arsham.mikaeilinamini@mail.mcgill.ca>
Depends: R (>= 3.5.0)
76 changes: 38 additions & 38 deletions R/feature_selection.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#'
#' @param m1_matrix A matrix representing the inclusion matrix. Rows are events, columns are barcodes.
#' @param m2_matrix A matrix representing the exclusion matrix. Rows are events, columns are barcodes.
#' @param n_threads If the module OpenPM is available for your device, the function suggests using multi-thread processing for even faster computation.
#' @param min_row_sum A numeric value specifying the minimum row sum threshold for filtering events. Defaults to 50.
#' @param verbose Logical. If \code{TRUE} (default), prints progress and informational messages.
#' @param n_threads If the module OpenPM is available for your device, the function suggests using multi-thread processing for even faster computation.
#' @param ... Additional arguments to be passed.
#'
#' @return A \code{data.table} containing the events and their corresponding sum deviance values.
Expand All @@ -19,31 +19,16 @@
#' # printing the results
#' print(HVE[order(-sum_deviance)])
#' @export
find_variable_events <- function(m1_matrix, m2_matrix, min_row_sum = 50, verbose=TRUE, n_threads=1, ...) {

# Load necessary libraries
if (!requireNamespace("data.table", quietly = TRUE)) {
stop("The 'data.table' package is required but not installed.")
}

if (!requireNamespace("Rcpp", quietly = TRUE)) {
stop("The 'Rcpp' package is required but not installed.")
}

if (!requireNamespace("Matrix", quietly = TRUE)) {
stop("The 'Matrix' package is required but not installed.")
}
find_variable_events <- function(m1_matrix, m2_matrix, min_row_sum = 50, n_threads=1, verbose=TRUE, ...) {

# Check if matrices are sparse
if (!(inherits(m1_matrix, "Matrix") && inherits(m2_matrix, "Matrix"))) {
stop("Both 'm1_matrix' and 'm2_matrix' must be sparse matrices of class 'Matrix'.")
}

# Check matrix compatibility
if (!identical(colnames(m1_matrix), colnames(m2_matrix))) {
stop("The colnames (barcodes) of inclusion and exclusion matrices are not identical.")
}

if (!identical(rownames(m1_matrix), rownames(m2_matrix))) {
stop("The rownames (junction events) of inclusion and exclusion matrices are not identical.")
}
Expand All @@ -65,24 +50,26 @@ find_variable_events <- function(m1_matrix, m2_matrix, min_row_sum = 50, verbose
sum_deviances <- numeric(nrow(m1_matrix))
names(sum_deviances) <- rownames(m1_matrix)

for (lib in libraries) {
deviance_results <- lapply(libraries, function(lib) {
filter <- which(meta[, ID] == lib)
M1_sub <- m1_matrix[, filter, drop = FALSE]
M2_sub <- m2_matrix[, filter, drop = FALSE]

# Calculate deviances using the C++ function
deviance_values <- tryCatch({
calcDeviances_ratio(M1_sub, M2_sub, n_threads)
}, error = function(e) {
stop("Error in calcDeviances_ratio function: ", e$message)
})

deviance_values <- c(deviance_values)
names(deviance_values) <- rownames(M1_sub)
sum_deviances <- sum_deviances + deviance_values
if(verbose){cat("Calculating the deviances for sample", lib, "has been completed!\n")}
}
if(verbose) {
cat("Calculating the deviances for sample", lib, "has been completed!\n")
}
return(deviance_values)
})

# Combine all results
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")
Expand Down Expand Up @@ -166,25 +153,38 @@ find_variable_genes <- function(gene_expression_matrix, method = "vst", ...) {
sum_deviances <- numeric(nrow(gene_expression_matrix))
names(sum_deviances) <- rownames(gene_expression_matrix)

# Loop over each library to compute deviances
for (lib in libraries) {
filter <- which(meta[, ID] == lib)
gene_expression_matrix_sub <- gene_expression_matrix[, filter, drop = FALSE]

# Calculate deviances using the C++ function
deviance_values <- tryCatch({
calcNBDeviancesWithThetaEstimation(as(gene_expression_matrix_sub, "dgCMatrix"))

}, error = function(e) {
stop("Error in calcNBDeviancesWithThetaEstimation function: ", e$message)
calculate_all_deviances <- function(gene_expression_matrix, meta, ID) {
# Get unique libraries
libraries <- unique(meta[, ID])

# Initialize results list
deviances_list <- vector("list", length(libraries))
names(deviances_list) <- libraries

# Getting the sim devinaces fir NB model
deviances_list <- lapply(libraries, function(lib) {
filter <- which(meta[, ID] == lib)
gene_expression_matrix_sub <- gene_expression_matrix[, filter, drop = FALSE]
deviance_values <- tryCatch({
calcNBDeviancesWithThetaEstimation(as(gene_expression_matrix_sub, "dgCMatrix"))
}, error = function(e) {
stop("Error in calcNBDeviancesWithThetaEstimation function: ", e$message)
})
deviance_values <- c(deviance_values)
names(deviance_values) <- rownames(gene_expression_matrix_sub)
cat("Calculating the deviances for sample", lib, "has been completed!\n")
return(deviance_values)
})

deviance_values <- c(deviance_values)
names(deviance_values) <- rownames(gene_expression_matrix_sub)
sum_deviances <- sum_deviances + deviance_values
cat("Calculating the deviances for sample", lib, "has been completed!\n")
# Sum deviances across all libraries
sum_deviances <- Reduce(`+`, deviances_list)

return(sum_deviances)
}

# Then use it:
sum_deviances <- calculate_all_deviances(gene_expression_matrix, meta, ID)

# Compute row variance using the previously defined function
row_var <- tryCatch({
splikit::get_rowVar(M = gene_expression_matrix)
Expand Down
4 changes: 2 additions & 2 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
" at McGill University, Montreal. Distributed under the MIT License.\n",
" For documentation and examples, see the package vignette.\n",
"-------------------------------------------------------------------------------------------------------\n",
" Bienvenue dans Splikit — Développé par le Laboratoire de génomique computationnelle et statistique\n",
" de l’Université McGill, à Montréal. Distribué sous licence MIT.\n",
" Bienvenue dans Splikit — Developpe par le Laboratoire de genomique computationnelle et statistique\n",
" de l’Universite McGill, a Montreal. Distribue sous licence MIT.\n",
" Pour la documentation et des exemples, consultez la vignette du package.\n",
"=======================================================================================================\n"
)
Expand Down
6 changes: 3 additions & 3 deletions man/find_variable_events.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions src/Makevars.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## src/Makevars (Linux)
CXX_STD = CXX14
PKG_CXXFLAGS += -O3 -march=native -pipe -fopenmp
PKG_LIBS += -fopenmp $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS)
Loading