1#ifndef SCRAN_QC_ADT_QUALITY_CONTROL_HPP
2#define SCRAN_QC_ADT_QUALITY_CONTROL_HPP
40template<
typename Sum_ =
double,
typename Detected_ =
int>
91template<
typename Value_,
typename Index_,
typename Subset_,
typename Sum_,
typename Detected_>
94 const std::vector<Subset_>& subsets,
113template<
typename Sum_ =
double,
typename Detected_ =
int>
149template<
typename Sum_ =
double,
typename Detected_ =
int,
typename Value_ =
double,
typename Index_ =
int,
typename Subset_ = const u
int8_t*>
152 const std::vector<Subset_>& subsets,
155 auto NC = mat.
ncol();
159 output.
sum.resize(NC);
160 x.
sum = output.
sum.data();
165 size_t nsubsets = subsets.size();
168 for (
size_t s = 0; s < nsubsets; ++s) {
205template<
typename Float_,
class Host_,
typename Sum_,
typename Detected_,
typename BlockSource_>
207 constexpr bool unblocked = std::is_same<BlockSource_, bool>::value;
208 auto buffer = [&]() {
209 if constexpr(unblocked) {
210 return std::vector<Float_>(n);
221 opts.min_diff = -std::log(1 -
options.detected_min_drop);
222 host.get_detected() = [&]() {
242 host.get_subset_sum()[
s] = [&]() {
253template<
class Host_,
typename Sum_,
typename Detected_,
typename BlockSource_,
typename Output_>
255 constexpr bool unblocked = std::is_same<BlockSource_, bool>::value;
258 const auto& detected =
host.get_detected();
259 for (
size_t i = 0;
i <
n; ++
i) {
264 return detected[
block[
i]];
274 for (
size_t i = 0;
i <
n; ++
i) {
287template<
typename Sum_,
typename Detected_>
293 for (
const auto&
s :
metrics.subset_sum) {
294 buffer.subset_sum.push_back(
s.data());
310template<
typename Float_ =
double>
325 return my_subset_sum;
340 return my_subset_sum;
345 std::vector<Float_> my_subset_sum;
360 template<
typename Sum_,
typename Detected_,
typename Output_>
375 template<
typename Sum_,
typename Detected_,
typename Output_>
390 template<
typename Output_ = u
int8_t,
typename Sum_ =
double,
typename Detected_ =
int>
419template<
typename Float_ =
double,
typename Sum_,
typename Detected_>
436template<
typename Float_ =
double,
typename Sum_,
typename Detected_>
447template<
typename Float_ =
double>
464 return my_subset_sum;
481 return my_subset_sum;
485 std::vector<Float_> my_sum;
486 std::vector<Float_> my_detected;
487 std::vector<std::vector<Float_> > my_subset_sum;
504 template<
typename Index_,
typename Sum_,
typename Detected_,
typename Block_,
typename Output_>
522 template<
typename Sum_,
typename Detected_,
typename Block_,
typename Output_>
540 template<
typename Output_ = u
int8_t,
typename Sum_ =
double,
typename Detected_ =
int,
typename Block_ =
int>
565template<
typename Float_ =
double,
typename Sum_,
typename Detected_,
typename Block_>
589template<
typename Float_ =
double,
typename Sum_,
typename Detected_,
typename Block_>
Define QC filter thresholds using a MAD-based approach.
Filter on ADT-based QC metrics with blocking.
Definition adt_quality_control.hpp:448
std::vector< Output_ > filter(const ComputeAdtQcMetricsResults< Sum_, Detected_ > &metrics, const Block_ *block) const
Definition adt_quality_control.hpp:541
std::vector< std::vector< Float_ > > & get_subset_sum()
Definition adt_quality_control.hpp:480
std::vector< Float_ > & get_detected()
Definition adt_quality_control.hpp:471
void filter(const ComputeAdtQcMetricsResults< Sum_, Detected_ > &metrics, const Block_ *block, Output_ *output) const
Definition adt_quality_control.hpp:523
const std::vector< Float_ > & get_detected() const
Definition adt_quality_control.hpp:454
const std::vector< std::vector< Float_ > > & get_subset_sum() const
Definition adt_quality_control.hpp:463
void filter(Index_ num, const ComputeAdtQcMetricsBuffers< Sum_, Detected_ > &metrics, const Block_ *block, Output_ *output) const
Definition adt_quality_control.hpp:505
Filter for high-quality cells using ADT-based metrics.
Definition adt_quality_control.hpp:311
void filter(const ComputeAdtQcMetricsResults< Sum_, Detected_ > &metrics, Output_ *output) const
Definition adt_quality_control.hpp:376
void filter(size_t num, const ComputeAdtQcMetricsBuffers< Sum_, Detected_ > &metrics, Output_ *output) const
Definition adt_quality_control.hpp:361
Float_ & get_detected()
Definition adt_quality_control.hpp:331
std::vector< Output_ > filter(const ComputeAdtQcMetricsResults< Sum_, Detected_ > &metrics) const
Definition adt_quality_control.hpp:391
Float_ get_detected() const
Definition adt_quality_control.hpp:316
const std::vector< Float_ > & get_subset_sum() const
Definition adt_quality_control.hpp:324
std::vector< Float_ > & get_subset_sum()
Definition adt_quality_control.hpp:339
virtual Index_ ncol() const=0
Simple quality control for single-cell data.
Definition adt_quality_control.hpp:20
AdtQcBlockedFilters< Float_ > compute_adt_qc_filters_blocked(size_t num, const ComputeAdtQcMetricsBuffers< Sum_, Detected_ > &metrics, const Block_ *block, const ComputeAdtQcFiltersOptions &options)
Definition adt_quality_control.hpp:566
AdtQcFilters< Float_ > compute_adt_qc_filters(size_t num, const ComputeAdtQcMetricsBuffers< Sum_, Detected_ > &metrics, const ComputeAdtQcFiltersOptions &options)
Definition adt_quality_control.hpp:420
std::vector< ChooseFilterThresholdsResults< Float_ > > choose_filter_thresholds_blocked(const std::vector< FindMedianMadResults< Float_ > > mms, const ChooseFilterThresholdsOptions &options)
Definition choose_filter_thresholds.hpp:217
void compute_adt_qc_metrics(const tatami::Matrix< Value_, Index_ > &mat, const std::vector< Subset_ > &subsets, const ComputeAdtQcMetricsBuffers< Sum_, Detected_ > &output, const ComputeAdtQcMetricsOptions &options)
Definition adt_quality_control.hpp:92
void per_cell_qc_metrics(const tatami::Matrix< Value_, Index_ > &mat, const std::vector< Subset_ > &subsets, const PerCellQcMetricsBuffers< Sum_, Detected_, Value_, Index_ > &output, const PerCellQcMetricsOptions &options)
Definition per_cell_qc_metrics.hpp:810
ChooseFilterThresholdsResults< Float_ > choose_filter_thresholds(const FindMedianMadResults< Float_ > &mm, const ChooseFilterThresholdsOptions &options)
Definition choose_filter_thresholds.hpp:133
Compute per-cell quality control metrics.
Options for choose_filter_thresholds().
Definition choose_filter_thresholds.hpp:20
Options for compute_adt_qc_filters().
Definition adt_quality_control.hpp:180
double detected_min_drop
Definition adt_quality_control.hpp:191
double detected_num_mads
Definition adt_quality_control.hpp:185
double subset_sum_num_mads
Definition adt_quality_control.hpp:197
Buffers for compute_adt_qc_metrics().
Definition adt_quality_control.hpp:41
Detected_ * detected
Definition adt_quality_control.hpp:52
std::vector< Sum_ * > subset_sum
Definition adt_quality_control.hpp:59
Sum_ * sum
Definition adt_quality_control.hpp:46
Options for compute_adt_qc_metrics().
Definition adt_quality_control.hpp:25
int num_threads
Definition adt_quality_control.hpp:30
Results of compute_adt_qc_metrics().
Definition adt_quality_control.hpp:114
std::vector< Detected_ > detected
Definition adt_quality_control.hpp:123
std::vector< Sum_ > sum
Definition adt_quality_control.hpp:118
std::vector< std::vector< Sum_ > > subset_sum
Definition adt_quality_control.hpp:129
Buffers for per_cell_qc_metrics().
Definition per_cell_qc_metrics.hpp:75
Sum_ * sum
Definition per_cell_qc_metrics.hpp:90
Detected_ * detected
Definition per_cell_qc_metrics.hpp:96
std::vector< Sum_ * > subset_sum
Definition per_cell_qc_metrics.hpp:116
Options for per_cell_qc_metrics().
Definition per_cell_qc_metrics.hpp:22
int num_threads
Definition per_cell_qc_metrics.hpp:63