scran
C++ library for basic single-cell RNA-seq analyses
Loading...
Searching...
No Matches
ChooseHvgs.hpp
Go to the documentation of this file.
1#ifndef SCRAN_CHOOSE_HVGS_HPP
2#define SCRAN_CHOOSE_HVGS_HPP
3
4#include "../utils/macros.hpp"
5
6#include <vector>
7#include <algorithm>
8#include <numeric>
9#include <cstdint>
10
17namespace scran {
18
26public:
30 struct Defaults {
34 static constexpr size_t top = 4000;
35 };
36
37private:
38 size_t top = Defaults::top;
39
40public:
51 top = t;
52 return *this;
53 }
54
55public:
67 template<typename V, typename T>
68 void run(size_t n, const V* statistic, T* output) const {
69 std::vector<size_t> collected(n);
70 std::iota(collected.begin(), collected.end(), 0);
71 std::sort(collected.begin(), collected.end(), [&](size_t l, size_t r) -> bool { return statistic[l] > statistic[r]; });
72
73 auto limit = std::min(n, top);
74 std::fill(output, output + n, false);
75 for (size_t i = 0; i < limit; ++i) {
76 output[collected[i]] = true;
77 }
78 }
79
89 template<typename T = uint8_t, typename V>
90 std::vector<T> run(size_t n, const V* statistic) const {
91 std::vector<T> output(n);
92 run(n, statistic, output.data());
93 return output;
94 }
95};
96
97}
98#endif
Choose highly variable genes for downstream analyses.
Definition ChooseHvgs.hpp:25
ChooseHvgs & set_top(size_t t=Defaults::top)
Definition ChooseHvgs.hpp:50
void run(size_t n, const V *statistic, T *output) const
Definition ChooseHvgs.hpp:68
std::vector< T > run(size_t n, const V *statistic) const
Definition ChooseHvgs.hpp:90
Functions for single-cell RNA-seq analyses.
Definition AggregateAcrossCells.hpp:18
Default paramater settings.
Definition ChooseHvgs.hpp:30
static constexpr size_t top
Definition ChooseHvgs.hpp:34