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
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
^pkgdown$
^\.github$
^build_pkgdown_site\.R$
^CLAUDE\.md$
^\.claude$
16 changes: 8 additions & 8 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Package: splikit
Title: A Toolkit for Analysing RNA Splicing in Single-Cell RNA Sequencing Data
Title: Analysing RNA Splicing in scRNA-Seq Data
Version: 2.0.0
Authors@R:
person("Arsham", "Mikaeili Namini", , "arsham.mikaeilinamini@mail.mcgill.ca", role = c("aut", "cre"),
comment = c(ORCID = "0000-0002-9453-6951"))
Description: A toolkit designed for the analysis of high-dimensional single-cell
splicing data. Provides a framework to extract and work with ratio-based
data structures derived from single-cell RNA sequencing experiments.
Offers both a modern R6 object-oriented interface and direct matrix
manipulation functions. Core functionalities are implemented in C++ via
'Rcpp' to ensure high performance and scalability on large datasets.
Description: Provides analysis of high-dimensional single-cell splicing data.
Offers a framework to extract and work with ratio-based data structures
derived from single-cell RNA sequencing experiments. Provides both a modern
R6 object-oriented interface and direct matrix manipulation functions. Core
functionalities are implemented in C++ via 'Rcpp' to ensure high performance
and scalability on large datasets.
URL: https://csglab.github.io/splikit/, https://github.com/csglab/splikit
BugReports: https://github.com/csglab/splikit/issues
License: MIT + file LICENSE
Expand All @@ -19,6 +19,6 @@ RoxygenNote: 7.3.3
Imports: Matrix, data.table, methods, stats, Rcpp, R6
LinkingTo: Rcpp, RcppArmadillo
Suggests: testthat (>= 3.0.0), knitr, rmarkdown
Config/testthat/edition: 3
VignetteBuilder: knitr
Config/testthat/edition: 3
Depends: R (>= 4.1.0)
8 changes: 3 additions & 5 deletions R/SplikitObject.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,14 @@ SplikitObject <- R6::R6Class("SplikitObject",
#' @param batch_size Number of groups per batch for memory management (default: 5000).
#' @param memory_threshold Maximum rows before switching to batched processing.
#' @param force_fast Force fast processing regardless of size (default: FALSE).
#' @param multi_thread Use parallel processing for batched operations (default: FALSE).
#' @param n_threads Number of threads for C++ OpenMP parallelization (default: 1).
#' @param n_threads Number of threads for parallel processing (default: 1).
#' @param use_cpp Use fast C++ implementation (default: TRUE).
#' @param verbose Print progress messages (default: FALSE).
#'
#' @return Self (invisibly), for method chaining.
makeM2 = function(batch_size = 5000, memory_threshold = 2e9,
force_fast = FALSE, multi_thread = FALSE,
n_threads = 1, use_cpp = TRUE, verbose = FALSE) {
force_fast = FALSE, n_threads = 1,
use_cpp = TRUE, verbose = FALSE) {

if (is.null(self$m1)) {
private$error("M1 matrix not initialized")
Expand All @@ -136,7 +135,6 @@ SplikitObject <- R6::R6Class("SplikitObject",
batch_size = batch_size,
memory_threshold = memory_threshold,
force_fast = force_fast,
multi_thread = multi_thread,
n_threads = n_threads,
use_cpp = use_cpp,
verbose = verbose
Expand Down
31 changes: 15 additions & 16 deletions R/feature_selection.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' @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 verbose Logical. If \code{TRUE}, prints progress and informational messages. Default is \code{FALSE}.
#' @param ... Additional arguments to be passed.
#'
#' @return A \code{data.table} containing the events and their corresponding sum deviance values.
Expand All @@ -19,8 +19,7 @@
#' # printing the results
#' print(HVE[order(-sum_deviance)])
#' @export
find_variable_events <- function(m1_matrix, m2_matrix = NULL, min_row_sum = 50, n_threads=1, verbose=TRUE, ...) {

find_variable_events <- function(m1_matrix, m2_matrix = NULL, min_row_sum = 50, n_threads = 1, verbose = FALSE, ...) {

# Handle SplikitObject input
if (inherits(m1_matrix, "SplikitObject")) {
Expand Down Expand Up @@ -72,7 +71,7 @@ find_variable_events <- function(m1_matrix, m2_matrix = NULL, min_row_sum = 50,
meta <- temp_current_barcodes

libraries <- unique(meta$ID)
cat("There are", length(libraries), "libraries detected...\n")
if (verbose) message("There are ", length(libraries), " libraries detected...")

# Initialize deviance sum vector
sum_deviances <- numeric(nrow(m1_matrix))
Expand All @@ -90,8 +89,8 @@ find_variable_events <- function(m1_matrix, m2_matrix = NULL, min_row_sum = 50,
})
deviance_values <- c(deviance_values)
names(deviance_values) <- rownames(M1_sub)
if(verbose) {
cat("Calculating the deviances for sample", lib, "has been completed!\n")
if (verbose) {
message("Calculating the deviances for sample ", lib, " has been completed!")
}
return(deviance_values)
})
Expand All @@ -115,7 +114,7 @@ find_variable_events <- function(m1_matrix, m2_matrix = NULL, min_row_sum = 50,
#' \code{"vst"} uses a variance-stabilizing transformation to identify variable genes.
#' \code{"sum_deviance"} computes per-library deviances and combines them with a row variance metric.
#' @param n_threads If OpenMP is available for your device, the function suggests using multi-thread processing for even faster computation (only for sum_deviance method).
#' @param verbose Logical. If \code{TRUE} (default), prints progress and informational messages.
#' @param verbose Logical. If \code{TRUE}, prints progress and informational messages. Default is \code{FALSE}.
#' @param ... Additional arguments (currently unused).
#'
#' @return A \code{data.table} containing gene names (column \code{events}) and computed metrics.
Expand All @@ -128,9 +127,9 @@ find_variable_events <- function(m1_matrix, m2_matrix = NULL, min_row_sum = 50,
#'
#' # getting high variable genes
#' HVG_VST <- find_variable_genes(toy_obj$gene_expression, method = "vst")
#' HVG_DEV <- find_variable_genes(toy_obj$gene_expression,
#' method = "sum_deviance")
#'
#' # sum_deviance method
#' HVG_DEV <- find_variable_genes(toy_obj$gene_expression, method = "sum_deviance")
#'
#' # Using multi-threading for faster computation (sum_deviance method only)
#' HVG_DEV_MT <- find_variable_genes(toy_obj$gene_expression,
#' method = "sum_deviance",
Expand All @@ -145,7 +144,7 @@ find_variable_events <- function(m1_matrix, m2_matrix = NULL, min_row_sum = 50,
#' @import Matrix
#' @importClassesFrom Matrix dgCMatrix dsCMatrix dgTMatrix dsTMatrix
#' @export
find_variable_genes <- function(gene_expression_matrix, method = "vst", n_threads = 1, verbose = TRUE, ...) {
find_variable_genes <- function(gene_expression_matrix, method = "vst", n_threads = 1, verbose = FALSE, ...) {
# adding the vst method as the default
method <- match.arg(method, choices = c("vst", "sum_deviance"))

Expand All @@ -155,7 +154,7 @@ find_variable_genes <- function(gene_expression_matrix, method = "vst", n_thread
}

if (method == "vst") {
if(verbose) cat("The method we are using is vst (Seurat)...\n")
if (verbose) message("The method we are using is vst (Seurat)...")
if (!exists("standardizeSparse_variance_vst")) {
stop("The function 'standardizeSparse_variance_vst' is not available. Check your C++ source files.")
}
Expand All @@ -167,7 +166,7 @@ find_variable_genes <- function(gene_expression_matrix, method = "vst", n_thread
rez <- data.table::data.table(events = rownames(gene_expression_matrix),
standardize_variance = rez_vector)
} else {
if(verbose) cat("The method we are using is like deviance summarion per library...\n")
if (verbose) message("The method we are using is like deviance summarion per library...")

# Filter rows based on minimum row sum criteria
to_keep_features <- which(rowSums(gene_expression_matrix) > 0)
Expand All @@ -182,7 +181,7 @@ find_variable_genes <- function(gene_expression_matrix, method = "vst", n_thread
meta <- temp_current_barcodes

libraries <- unique(meta$ID)
cat("There are", length(libraries), "libraries detected...\n")
if (verbose) message("There are ", length(libraries), " libraries detected...")

# Initialize deviance sum vector with gene names
sum_deviances <- numeric(nrow(gene_expression_matrix))
Expand All @@ -207,8 +206,8 @@ find_variable_genes <- function(gene_expression_matrix, method = "vst", n_thread
})
deviance_values <- c(deviance_values)
names(deviance_values) <- rownames(gene_expression_matrix_sub)
if(verbose) {
cat("Calculating the deviances for sample", lib, "has been completed!\n")
if (verbose) {
message("Calculating the deviances for sample ", lib, " has been completed!")
}
return(deviance_values)
})
Expand Down
Loading