scran_qc
Simple quality control on single-cell data
Loading...
Searching...
No Matches
format_filters.hpp
Go to the documentation of this file.
1#ifndef SCRAN_QC_FORMAT_FILTERS_HPP
2#define SCRAN_QC_FORMAT_FILTERS_HPP
3
4#include <vector>
5#include <algorithm>
6#include <cstdint>
7
13namespace scran_qc {
14
28template<typename Index_, typename Keep_>
29void filter_index(Index_ num, const Keep_* filter, std::vector<Index_>& output) {
30 output.clear();
31 for (Index_ i = 0; i < num; ++i) {
32 if (filter[i]) {
33 output.push_back(i);
34 }
35 }
36}
37
49template<typename Index_, typename Keep_>
50std::vector<Index_> filter_index(Index_ num, const Keep_* filter) {
51 std::vector<Index_> output;
52#ifdef SCRAN_QC_TEST_INIT
53 output.resize(10, SCRAN_QC_TEST_INIT);
54#endif
55 filter_index(num, filter, output);
56 return output;
57}
58
73template<typename Keep_, typename Output_>
74void combine_filters(size_t num, const std::vector<Keep_*>& filters, Output_* output) {
75 std::copy_n(filters.front(), num, output);
76 for (size_t f = 1, nfilters = filters.size(); f < nfilters; ++f) {
77 auto filt = filters[f];
78 for (size_t i = 0; i < num; ++i) {
79 output[i] = output[i] && filt[i];
80 }
81 }
82}
83
96template<typename Output_ = uint8_t, typename Keep_ = uint8_t>
97std::vector<Output_> combine_filters(size_t num, const std::vector<const Keep_*>& filters) {
98 std::vector<Output_> output(num
101#endif
102 );
104 return output;
105}
106
118template<typename Index_, typename Keep_>
119void combine_filters_index(Index_ num, const std::vector<const Keep_*>& filters, std::vector<Index_>& output) {
120 output.clear();
121
122 size_t nfilters = filters.size();
123 for (Index_ i = 0; i < num; ++i) {
124 bool keep = true;
125 for (size_t f = 0; f < nfilters; ++f) {
126 if (!filters[f][i]) {
127 keep = false;
128 break;
129 }
130 }
131 if (keep) {
132 output.push_back(i);
133 }
134 }
135}
136
149template<typename Index_, typename Keep_>
150std::vector<Index_> combine_filters_index(Index_ num, const std::vector<const Keep_*>& filters) {
151 std::vector<Index_> output;
152#ifdef SCRAN_QC_TEST_INIT
153 output.resize(10, SCRAN_QC_TEST_INIT);
154#endif
156 return output;
157}
158
159}
160
161#endif
Temporary data structures for find_median_mad_blocked().
Definition find_median_mad.hpp:176
Simple quality control for single-cell data.
Definition adt_quality_control.hpp:20
void combine_filters(size_t num, const std::vector< Keep_ * > &filters, Output_ *output)
Definition format_filters.hpp:74
void filter_index(Index_ num, const Keep_ *filter, std::vector< Index_ > &output)
Definition format_filters.hpp:29
void combine_filters_index(Index_ num, const std::vector< const Keep_ * > &filters, std::vector< Index_ > &output)
Definition format_filters.hpp:119