scran_qc
Simple quality control on single-cell data
Loading...
Searching...
No Matches
choose_filter_thresholds.hpp
Go to the documentation of this file.
1#ifndef SCRAN_QC_CHOOSE_FILTER_THRESHOLDS_HPP
2#define SCRAN_QC_CHOOSE_FILTER_THRESHOLDS_HPP
3
4#include <vector>
5#include <limits>
6#include <cmath>
7
8#include "find_median_mad.hpp"
9
15namespace scran_qc {
16
25 bool lower = true;
26
31 bool upper = true;
32
38 double num_mads = 3;
39
45 double min_diff = 0;
46
56 bool log = false;
57};
58
63template<typename Float_>
79
83namespace internal {
84
85template<typename Float_>
87 if (was_logged) {
88 if (std::isinf(val)) {
89 if (val < 0) {
90 return 0;
91 }
92 } else {
93 return std::exp(val);
94 }
95 }
96 return val;
97}
98
99template<bool lower_, typename Float_>
100std::vector<Float_> strip_threshold(const std::vector<ChooseFilterThresholdsResults<Float_> >& res) {
101 std::vector<Float_> output;
102 output.reserve(res.size());
103 for (const auto& r : res) {
104 if constexpr(lower_) {
105 output.push_back(r.lower);
106 } else {
107 output.push_back(r.upper);
108 }
109 }
110 return output;
111}
112
113}
132template<typename Float_>
134 static_assert(std::is_floating_point<Float_>::value);
136 Float_& lthresh = output.lower;
137 Float_& uthresh = output.upper;
138 lthresh = -std::numeric_limits<Float_>::infinity();
139 uthresh = std::numeric_limits<double>::infinity();
140
141 auto median = mm.median;
142 auto mad = mm.mad;
143 if (!std::isnan(median) && !std::isnan(mad)) {
144 auto delta = std::max(static_cast<Float_>(options.min_diff), options.num_mads * mad);
145 if (options.lower) {
146 lthresh = internal::unlog_threshold(median - delta, options.log);
147 }
148 if (options.upper) {
149 uthresh = internal::unlog_threshold(median + delta, options.log);
150 }
151 }
152
153 return output;
154}
155
169template<typename Index_, typename Float_>
176
192template<typename Index_, typename Value_, typename Float_>
199
216template<typename Float_>
217std::vector<ChooseFilterThresholdsResults<Float_> > choose_filter_thresholds_blocked(
218 const std::vector<FindMedianMadResults<Float_> > mms,
220{
221 std::vector<ChooseFilterThresholdsResults<Float_> > output;
222 output.reserve(mms.size());
223 for (auto& mm : mms) {
225 }
226 return output;
227}
228
245template<typename Index_, typename Value_, typename Block_, typename Float_>
258
259}
260
261#endif
Temporary data structures for find_median_mad_blocked().
Definition find_median_mad.hpp:172
Compute the median and MAD from an array of values.
Simple quality control for single-cell data.
Definition adt_quality_control.hpp:20
std::vector< ChooseFilterThresholdsResults< Float_ > > choose_filter_thresholds_blocked(const std::vector< FindMedianMadResults< Float_ > > mms, const ChooseFilterThresholdsOptions &options)
Definition choose_filter_thresholds.hpp:217
FindMedianMadResults< Float_ > find_median_mad(Index_ num, Float_ *metrics, const FindMedianMadOptions &options)
Definition find_median_mad.hpp:79
ChooseFilterThresholdsResults< Float_ > choose_filter_thresholds(const FindMedianMadResults< Float_ > &mm, const ChooseFilterThresholdsOptions &options)
Definition choose_filter_thresholds.hpp:133
std::vector< FindMedianMadResults< Output_ > > find_median_mad_blocked(Index_ num, const Value_ *metrics, const Block_ *block, FindMedianMadWorkspace< Output_, Index_ > *workspace, const FindMedianMadOptions &options)
Definition find_median_mad.hpp:261
Options for choose_filter_thresholds().
Definition choose_filter_thresholds.hpp:20
bool upper
Definition choose_filter_thresholds.hpp:31
bool log
Definition choose_filter_thresholds.hpp:56
double num_mads
Definition choose_filter_thresholds.hpp:38
double min_diff
Definition choose_filter_thresholds.hpp:45
bool lower
Definition choose_filter_thresholds.hpp:25
Results of compute_adt_qc_metrics().
Definition choose_filter_thresholds.hpp:64
Float_ upper
Definition choose_filter_thresholds.hpp:77
Float_ lower
Definition choose_filter_thresholds.hpp:70
Options for find_median_mad().
Definition find_median_mad.hpp:22