scran_blocks
Blocking utilities for libscran
|
This repository contains utilities for blocked analyses for the other libscran repositories. Any uninteresting factor of variation (usually across the cells) can be used as a blocking factor, e.g., experimental batches, sample/patient of origin. In the presence of blocks, our general strategy is to perform the analysis within each block before combining our conclusions across blocks. This ensures that our results are not affected by the uninteresting differences between blocks.
The scran_blocks::average_vectors()
function will compute the element-wise averages of any number of equi-length arrays. This is typically used to average statistics across blocks, where each array contains the statistics for a single block over all genes.
If NaNs are present, they can be ignored:
We also support per-vector weights:
See the reference documentation for more details.
When combining statistics across blocks, it may be desirable to weight each block by its size, favoring larger blocks that can emit more stable statistics. This is done using the scran_blocks::compute_weights()
function that calculates a weight for each block based on its size.
The above code chunk uses a variable block weight that increases linearly with block size from 0 to 200, after which it is capped at 1. This VARIABLE
policy penalizes very small blocks to ensure that their unstable statistics do not overly influence the average. Blocks are equally weighted once they are "large enough", ensuring that the average is not dominated by a single very large block.
Users can also change the policy to NONE
, where weights are equal to the block size; or EQUAL
, where all blocks are equally weighted regardless of size (assuming they are non-empty). In such cases, the variable
argument is ignored. Check out the reference documentation for more details.
If you're using CMake, you just need to add something like this to your CMakeLists.txt
:
Then you can link to scran_blocks to make the headers available during compilation:
To install the library, use:
If you're not using CMake, the simple approach is to just copy the files in include/
- either directly or with Git submodules - and include their path during compilation with, e.g., GCC's -I
.