gsdecon
C++ port of the GSDecon algorithm
Loading...
Searching...
No Matches
compute.hpp
Go to the documentation of this file.
1#ifndef GSDECON_COMPUTE_HPP
2#define GSDECON_COMPUTE_HPP
3
4#include <algorithm>
5#include <numeric>
6
7#include "tatami/tatami.hpp"
8#include "irlba/irlba.hpp"
9#include "scran_pca/scran_pca.hpp"
10#include "sanisizer/sanisizer.hpp"
11
12#include "Options.hpp"
13#include "Results.hpp"
14#include "utils.hpp"
15
21namespace gsdecon {
22
44template<typename Value_, typename Index_, typename Float_>
45void compute(const tatami::Matrix<Value_, Index_>& matrix, const Options& options, const Buffers<Float_>& output) {
46 if (internal::check_edge_cases(matrix, options.rank, output)) {
47 return;
48 }
49
50 scran_pca::SimplePcaOptions sopt;
51 sopt.number = options.rank;
52 sopt.scale = options.scale;
53 sopt.realize_matrix = options.realize_matrix;
54 sopt.num_threads = options.num_threads;
55 sopt.irlba_options = options.irlba_options;
56 const auto res = scran_pca::simple_pca(matrix, sopt);
57
58 const Float_ shift = std::accumulate(res.center.begin(), res.center.end(), static_cast<Float_>(0)) / matrix.nrow();
59 std::fill_n(output.scores, matrix.ncol(), shift);
60 internal::process_output(res.rotation, res.components, options.scale, res.scale, output);
61}
62
76template<typename Float_ = double, typename Value_, typename Index_>
78 Results<Float_> output;
79 sanisizer::resize(output.weights, matrix.nrow()
80#ifdef SCRAN_QC_TEST_INIT
81 , SCRAN_QC_TEST_INIT
82#endif
83 );
84 sanisizer::resize(output.scores, matrix.ncol()
85#ifdef SCRAN_QC_TEST_INIT
86 , SCRAN_QC_TEST_INIT
87#endif
88 );
89
90 Buffers<Float_> buffers;
91 buffers.weights = output.weights.data();
92 buffers.scores = output.scores.data();
93
94 compute(matrix, options, buffers);
95 return output;
96}
97
98}
99
100#endif
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
void compute(const tatami::Matrix< Value_, Index_ > &matrix, const Options &options, const Buffers< Float_ > &output)
Definition compute.hpp:45
Buffers for the results of compute() and compute_blocked().
Definition Results.hpp:18
Float_ * scores
Definition Results.hpp:23
Float_ * weights
Definition Results.hpp:29
Options for compute() and compute_blocked().
Definition Options.hpp:17
bool realize_matrix
Definition Options.hpp:63
int rank
Definition Options.hpp:33
int num_threads
Definition Options.hpp:57
irlba::Options irlba_options
Definition Options.hpp:68
bool scale
Definition Options.hpp:40
Results of compute() and compute_blocked().
Definition Results.hpp:37
std::vector< Float_ > weights
Definition Results.hpp:49
std::vector< Float_ > scores
Definition Results.hpp:42