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 <cstddef>
7
8#include "sanisizer/sanisizer.hpp"
9
10#include "utils.hpp"
11
17namespace scran_qc {
18
32template<typename Keep_, typename Index_>
33void filter_index(const std::size_t num, const Keep_* const filter, std::vector<Index_>& output) {
34 output.clear();
35 for (decltype(I(num)) i = 0; i < num; ++i) {
36 if (filter[i]) {
37 output.push_back(i);
38 }
39 }
40}
41
53template<typename Index_, typename Keep_>
54std::vector<Index_> filter_index(const std::size_t num, const Keep_* const filter) {
55 std::vector<Index_> output;
56#ifdef SCRAN_QC_TEST_INIT
57 output.resize(10, SCRAN_QC_TEST_INIT);
58#endif
59 filter_index(num, filter, output);
60 return output;
61}
62
77template<typename Keep_, typename Output_>
78void combine_filters(const std::size_t num, const std::vector<Keep_*>& filters, Output_* const output) {
79 std::copy_n(filters.front(), num, output);
80 const auto nfilters = filters.size();
81 for (decltype(I(nfilters)) f = 1; f < nfilters; ++f) {
82 const auto filt = filters[f];
83 for (decltype(I(num)) i = 0; i < num; ++i) {
84 output[i] = output[i] && filt[i];
85 }
86 }
87}
88
101template<typename Output_ = unsigned char, typename Keep_>
102std::vector<Output_> combine_filters(const std::size_t num, const std::vector<const Keep_*>& filters) {
103 auto output = sanisizer::create<std::vector<Output_> >(num
104#ifdef SCRAN_QC_TEST_INIT
105 , SCRAN_QC_TEST_INIT
106#endif
107 );
108 combine_filters(num, filters, output.data());
109 return output;
110}
111
122template<typename Index_, typename Keep_>
123void combine_filters_index(const Index_ num, const std::vector<const Keep_*>& filters, std::vector<Index_>& output) {
124 output.clear();
125
126 const auto nfilters = filters.size();
127 for (decltype(I(num)) i = 0; i < num; ++i) {
128 bool keep = true;
129 for (decltype(I(nfilters)) f = 0; f < nfilters; ++f) {
130 if (!filters[f][i]) {
131 keep = false;
132 break;
133 }
134 }
135 if (keep) {
136 output.push_back(i);
137 }
138 }
139}
140
153template<typename Index_, typename Keep_>
154std::vector<Index_> combine_filters_index(const Index_ num, const std::vector<const Keep_*>& filters) {
155 std::vector<Index_> output;
156#ifdef SCRAN_QC_TEST_INIT
157 output.resize(10, SCRAN_QC_TEST_INIT);
158#endif
159 combine_filters_index(num, filters, output);
160 return output;
161}
162
163}
164
165#endif
Simple quality control for single-cell data.
Definition adt_quality_control.hpp:23
void combine_filters(const std::size_t num, const std::vector< Keep_ * > &filters, Output_ *const output)
Definition format_filters.hpp:78
void filter_index(const std::size_t num, const Keep_ *const filter, std::vector< Index_ > &output)
Definition format_filters.hpp:33
void combine_filters_index(const Index_ num, const std::vector< const Keep_ * > &filters, std::vector< Index_ > &output)
Definition format_filters.hpp:123