scran
C++ library for basic single-cell RNA-seq analyses
Loading...
Searching...
No Matches
PerCellCrisprQcMetrics.hpp
Go to the documentation of this file.
1#ifndef SCRAN_PER_CELL_CRISPR_QC_METRICS_HPP
2#define SCRAN_PER_CELL_CRISPR_QC_METRICS_HPP
3
4#include "../utils/macros.hpp"
5
6#include <vector>
7#include <limits>
8
9#include "tatami/base/Matrix.hpp"
10#include "PerCellQcMetrics.hpp"
11#include "utils.hpp"
12
19namespace scran {
20
42public:
46 struct Defaults {
50 static constexpr int num_threads = 1;
51 };
52
58 num_threads = n;
59 return *this;
60 }
61
62private:
63 int num_threads = Defaults::num_threads;
64
65
66public:
72 template<typename Float = double, typename Integer = int>
73 struct Buffers {
77 Float* sums = NULL;
78
82 Integer* detected = NULL;
83
87 Float* max_proportion = NULL;
88
92 Integer* max_index = NULL;
93 };
94
95public:
107 template<class Matrix, typename Float, typename Integer>
108 void run(const Matrix* mat, Buffers<Float, Integer>& output) const {
109 size_t NC = mat->ncol();
110
111 // Calling the general-purpose PerCellQcMetrics function.
112 PerCellQcMetrics general;
113 general.set_num_threads(num_threads);
114
116 tmp.total = output.sums;
117 tmp.detected = output.detected;
118 tmp.max_count = output.max_proportion;
119 tmp.max_index = output.max_index;
120
121 // Make sure that sums are computed one way or another.
122 std::vector<Float> placeholder;
123 if (!tmp.total && tmp.subset_total.size()) {
124 placeholder.resize(NC);
125 tmp.total = placeholder.data();
126 }
127
128 general.run(mat, {}, tmp);
129
130 // Computing the proportion safely.
131 quality_control::safe_divide(NC, output.max_proportion, tmp.total);
132 return;
133 }
134
135public:
142 struct Results {
146 Results() {}
147
148 Results(size_t ncells) : sums(ncells), detected(ncells), max_proportion(ncells), max_index(ncells) {}
156 std::vector<double> sums;
157
161 std::vector<int> detected;
162
166 std::vector<double> max_proportion;
167
171 std::vector<int> max_index;
172 public:
179 Buffers<> output;
180 populate_buffers(output, *this);
181 return output;
182 }
183
190 populate_buffers(output, *this);
191 return output;
192 }
193
194 private:
195 template<class SomeBuffer, class Results>
196 static void populate_buffers(SomeBuffer& x, Results& y) {
197 x.sums = y.sums.data();
198 x.detected = y.detected.data();
199 x.max_proportion = y.max_proportion.data();
200 x.max_index = y.max_index.data();
201 return;
202 }
203 };
204
205public:
215 template<class Matrix>
216 Results run(const Matrix* mat) const {
217 Results output(mat->ncol());
218 auto buffers = output.buffers();
219 run(mat, buffers);
220 return output;
221 }
222};
223
224}
225
226#endif
Compute a variety of per-cell quality control metrics from a count matrix.
Compute per-cell quality control metrics from a CRISPR guide count matrix.
Definition PerCellCrisprQcMetrics.hpp:41
PerCellCrisprQcMetrics & set_num_threads(int n=Defaults::num_threads)
Definition PerCellCrisprQcMetrics.hpp:57
Results run(const Matrix *mat) const
Definition PerCellCrisprQcMetrics.hpp:216
void run(const Matrix *mat, Buffers< Float, Integer > &output) const
Definition PerCellCrisprQcMetrics.hpp:108
Compute a variety of per-cell quality control metrics from a count matrix.
Definition PerCellQcMetrics.hpp:45
PerCellQcMetrics & set_num_threads(int n=Defaults::num_threads)
Definition PerCellQcMetrics.hpp:292
Results run(const Matrix *mat, const std::vector< Subset > &subsets) const
Definition PerCellQcMetrics.hpp:313
Functions for single-cell RNA-seq analyses.
Definition AggregateAcrossCells.hpp:18
Buffers for direct storage of the calculated statistics.
Definition PerCellCrisprQcMetrics.hpp:73
Float * max_proportion
Definition PerCellCrisprQcMetrics.hpp:87
Float * sums
Definition PerCellCrisprQcMetrics.hpp:77
Integer * max_index
Definition PerCellCrisprQcMetrics.hpp:92
Integer * detected
Definition PerCellCrisprQcMetrics.hpp:82
Default parameters.
Definition PerCellCrisprQcMetrics.hpp:46
static constexpr int num_threads
Definition PerCellCrisprQcMetrics.hpp:50
Result store for QC metric calculations.
Definition PerCellCrisprQcMetrics.hpp:142
std::vector< int > detected
Definition PerCellCrisprQcMetrics.hpp:161
Buffers< const double, const int > buffers() const
Definition PerCellCrisprQcMetrics.hpp:188
Buffers buffers()
Definition PerCellCrisprQcMetrics.hpp:178
std::vector< int > max_index
Definition PerCellCrisprQcMetrics.hpp:171
std::vector< double > max_proportion
Definition PerCellCrisprQcMetrics.hpp:166
std::vector< double > sums
Definition PerCellCrisprQcMetrics.hpp:156
Buffers for direct storage of the calculated statistics.
Definition PerCellQcMetrics.hpp:111
Float * max_count
Definition PerCellQcMetrics.hpp:144
Integer * max_index
Definition PerCellQcMetrics.hpp:138
std::vector< Float * > subset_total
Definition PerCellQcMetrics.hpp:152
Integer * detected
Definition PerCellQcMetrics.hpp:132
Float * total
Definition PerCellQcMetrics.hpp:126