|
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. See the reference documentation for more details.
The parallel_means() function will compute the element-wise mean 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:
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 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 SIZE, 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.
Much like parallel_means(), we can compute the element-wise quantile for any number of equi-length arrays with parallel_quantiles(). This is again used to average statistics across blocks, where a quantile probability of 0.5 yields the element-wise median.
This function computes the type 7 quantile for each gene. Weighted quantiles are currently not supported, mostly because it's too hard to do correctly (at least, for a continuous quantile function).
FetchContentIf 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:
find_package()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.