Conversation
…s by removing unnecessary variables to optimize performance and reduce memory usage.
…ptimize performance based on nCores
…reporting in runSCORPION function
…n, normalizeNetwork, and tanimoto functions for improved performance and memory efficiency
…parallel processing with mori integration
There was a problem hiding this comment.
Pull request overview
This PR bumps SCORPION to v1.3.3 and focuses on reducing memory overhead and improving performance, primarily by refining parallel execution paths and avoiding large temporary matrix allocations in core math routines.
Changes:
- Optimize parallel network construction and memory usage in
runSCORPION()(pre-splitting expression matrices, optionalmorishared-memory broadcasting, more aggressive cleanup). - Refactor normalization/similarity/correlation routines to reduce peak memory by avoiding full-size
outer()temporaries. - Refine
testEdges()behavior/documentation (log2FoldChange semantics, parallel maxSize handling) and add tests aroundmori.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/testthat/test_mori_sharing.R | Adds tests validating optional mori shared-memory behavior and parity with non-mori execution. |
| tests/testthat/test_edge_statistics.R | Updates expectations to use log2FoldChange instead of diffMean. |
| README.md | Updates documented output columns for testEdges() results. |
| R/testEdges.R | Adjusts parallel execution options cleanup and updates log2 fold-change calculation/output columns. |
| R/tanimotoSimilarity.R | Reworks normalization to avoid allocating large outer() temporaries. |
| R/scorpion.R | Controls BLAS threading via RhpcBLASctl to respect nCores. |
| R/runSCORPION.R | Pre-splits GEX by group for parallelism, adds optional mori sharing, and streams weight extraction to reduce memory pressure. |
| R/runPANDA.R | Streamlines iterative updates and frees intermediates to reduce memory. |
| R/removeBatch.R | Adds pseudo-inverse fallback for rank-deficient batch design matrices. |
| R/normalizeNetwork.R | Refactors normalization to avoid full-matrix broadcast temporaries. |
| R/makeSuperCells.R | Frees large intermediate objects earlier to reduce memory footprint. |
| R/fastCorrelation.R | Avoids full-size outer product in denominator by doing column-wise normalization. |
| man/testEdges.Rd | Updates Rd docs to match testEdges() output changes. |
| DESCRIPTION | Bumps version and adds mori to Suggests. |
| .Rbuildignore | Adds tests/* ignore pattern. |
Files not reviewed (1)
- man/testEdges.Rd: Generated file
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+562
to
566
| # limma-style log2 fold change: limma's logFC is the model coefficient, i.e. the | ||
| # difference of group means on log2-scale input (defined for all reals, incl. | ||
| # negative means). Treating edge weights as log2-scale, this equals diffMean. | ||
| log2FC <- meanEdge1 - meanEdge2 | ||
|
|
| LICENSE | ||
| inst/hg38* | ||
| README.md | ||
| tests/* No newline at end of file |
Comment on lines
+271
to
+274
| # Pre-convert to data.frame once so workers receive the converted objects | ||
| # instead of converting on every call | ||
| tfMotifs <- as.data.frame(tfMotifs) | ||
| ppiNet <- as.data.frame(ppiNet) |
Comment on lines
+17
to
+19
| has_zero_var <- any(std1 == 0) || any(std2 == 0) | ||
|
|
||
| if (!has_zero_var) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces several performance, memory, and usability improvements across the SCORPION package, especially targeting parallel processing, memory usage, and normalization routines. It also adds support for the optional
moripackage to optimize parallel data sharing, improves resource cleanup, and refines core statistical calculations.Parallelization and memory management improvements:
runSCORPION.R, gene expression matrices are pre-split by group before parallel processing, reducing memory footprint and serialization overhead. The optionalmoripackage is supported for OS-backed shared memory, allowing efficient sharing of large data frames (tfMotifs,ppiNet) across worker processes. Thefuture.globals.maxSizeoption is set toInfduring parallel execution to allow large objects to be exported. [1] [2] [3]testEdges.R, thefuture.globals.maxSizeoption is also set toInfduring parallel execution, and is properly restored after processing. [1] [2]runSCORPION.R,makeSuperCells.R, andrunPANDA.R. [1] [2] [3] [4] [5] [6] [7]Performance and algorithmic improvements:
normalizeNetwork.R,fastCorrelation.R, andtanimotoSimilarity.Rhave been refactored to avoid creating large temporary matrices, replacing full-matrix operations with column-wise loops. This reduces peak memory usage and improves speed, especially for large datasets. [1] [2] [3] [4] [5]runPANDA.Rhave been streamlined for clarity and efficiency, and now use direct updates rather than storing intermediate variables.Batch correction and usability:
removeBatch.Rnow robustly handles singleton and collinear batches by using the Moore-Penrose pseudo-inverse when necessary, preventing errors due to singular design matrices. It also skips correction if there is only one batch level.Statistical calculation refinements:
testEdges.R, the calculation of log2 fold change for two-sample tests now follows the limma convention, using the difference of group means on log2-scale input, and the output data frame omits the redundantdiffMeancolumn. [1] [2] [3]Other improvements:
moripackage is added toSuggestsin the DESCRIPTION file. The.Rbuildignoreis updated to ignore thetests/directory. [1] [2] [3]RhpcBLASctlin bothrunSCORPION.Randscorpion.Rto respect thenCoresparameter. [1] [2]These changes collectively improve the speed, robustness, and scalability of SCORPION for large single-cell datasets.
References:
[1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25]