1#ifndef GSDECON_BLOCKED_HPP
2#define GSDECON_BLOCKED_HPP
9#include "scran_pca/scran_pca.hpp"
10#include "sanisizer/sanisizer.hpp"
50template<
typename Value_,
typename Index_,
typename Block_,
typename Float_>
53 const Block_*
const block,
54 const std::size_t num_blocks,
58 if (check_edge_cases(matrix, options.
rank, output)) {
64 scran_pca::BlockedPcaOptions bopt;
65 bopt.number = options.
rank;
66 bopt.scale = options.
scale;
72 bopt.center_scores_by_block =
true;
73 const auto res = scran_pca::blocked_pca(matrix, block, num_blocks, bopt);
76 static_assert(!Eigen::MatrixXd::IsRowMajor);
77 const auto nfeat = res.center.cols();
78 const auto nblocks = res.center.rows();
79 auto block_means = sanisizer::create<std::vector<Float_> >(nblocks);
81 for (I<
decltype(nfeat)> f = 0; f < nfeat; ++f) {
82 for (I<
decltype(nblocks)> b = 0; b < nblocks; ++b) {
83 block_means[b] += res.center.coeff(b, f);
86 for (
auto& b : block_means) {
90 const auto ncells = res.components.cols();
91 for (I<
decltype(ncells)> c = 0; c < ncells; ++c) {
92 output.
scores[c] = block_means[block[c]];
94 process_output(res.rotation, res.components, options.
scale, res.scale, output);
116template<
typename Float_ =
double,
typename Value_,
typename Index_,
typename Block_>
119 const Block_*
const block,
120 const std::size_t num_blocks,
125#ifdef SCRAN_QC_TEST_INIT
129 sanisizer::resize(output.
scores, matrix.
ncol()
130#ifdef SCRAN_QC_TEST_INIT
Options for the gsdecon algorithm.
Classes for storing the results.
virtual Index_ ncol() const=0
virtual Index_ nrow() const=0
Gene set scoring with gsdecon.
Definition blocked.hpp:21
irlba::Metrics compute_blocked(const tatami::Matrix< Value_, Index_ > &matrix, const Block_ *const block, const std::size_t num_blocks, const Options &options, const Buffers< Float_ > &output)
Definition blocked.hpp:51
Buffers for the results of compute() and compute_blocked().
Definition Results.hpp:20
Float_ * scores
Definition Results.hpp:25
Float_ * weights
Definition Results.hpp:31
Options for compute() and compute_blocked().
Definition Options.hpp:18
bool realize_matrix
Definition Options.hpp:64
int rank
Definition Options.hpp:34
scran_blocks::WeightPolicy block_weight_policy
Definition Options.hpp:46
scran_blocks::VariableWeightParameters variable_block_weight_parameters
Definition Options.hpp:52
irlba::Options< Eigen::VectorXd > irlba_options
Definition Options.hpp:69
int num_threads
Definition Options.hpp:58
bool scale
Definition Options.hpp:41
Results of compute() and compute_blocked().
Definition Results.hpp:39
std::vector< Float_ > weights
Definition Results.hpp:51
std::vector< Float_ > scores
Definition Results.hpp:44
irlba::Metrics metrics
Definition Results.hpp:56