1#ifndef SCRAN_FILTER_CELLS_H
2#define SCRAN_FILTER_CELLS_H
4#include "../utils/macros.hpp"
6#include "tatami/tatami.hpp"
94 template<
class MAT,
typename IDX =
int,
typename X = u
int8_t>
95 std::shared_ptr<MAT>
run(std::shared_ptr<MAT> mat,
const X* filter) {
96 size_t NC = mat->ncol();
100 for (
size_t i = 0; i < NC; ++i) {
101 num += (filter[i] != 0);
104 std::vector<IDX> retained;
105 retained.reserve(discard ? (NC - num) : num);
107 for (
size_t i = 0; i < NC; ++i) {
108 if (discard == (filter[i] == 0)) {
109 retained.push_back(i);
113 return tatami::make_DelayedSubset<1>(mat, retained);
134 template<
class MAT,
typename IDX =
int,
typename X = u
int8_t>
135 std::shared_ptr<MAT>
run(std::shared_ptr<MAT> mat,
const std::vector<X*>& filters) {
136 size_t NC = mat->ncol();
138 std::vector<uint8_t> finalvec(NC, intersect);
140 for (
auto filter : filters) {
141 for (
size_t i = 0; i < NC; ++i) {
142 finalvec[i] &=
static_cast<uint8_t
>(filter[i] != 0);
146 for (
auto filter : filters) {
147 for (
size_t i = 0; i < NC; ++i) {
148 finalvec[i] |=
static_cast<uint8_t
>(filter[i] != 0);
153 IDX num = std::accumulate(finalvec.begin(), finalvec.end(),
static_cast<IDX
>(0));
154 std::vector<IDX> retained;
155 retained.reserve(discard ? (NC - num) : num);
157 for (
size_t i = 0; i < NC; ++i) {
158 if (discard == (finalvec[i] == 0)) {
159 retained.push_back(i);
163 return tatami::make_DelayedSubset<1>(mat, retained);
Filter out low-quality cells.
Definition FilterCells.hpp:26
std::shared_ptr< MAT > run(std::shared_ptr< MAT > mat, const std::vector< X * > &filters)
Definition FilterCells.hpp:135
FilterCells & set_intersect(bool i=Defaults::intersect)
Definition FilterCells.hpp:74
std::shared_ptr< MAT > run(std::shared_ptr< MAT > mat, const X *filter)
Definition FilterCells.hpp:95
FilterCells & set_retain()
Definition FilterCells.hpp:53
FilterCells & set_discard(bool d=Defaults::discard)
Definition FilterCells.hpp:63
Functions for single-cell RNA-seq analyses.
Definition AggregateAcrossCells.hpp:18
Default choices for all parameters.
Definition FilterCells.hpp:31
static constexpr bool discard
Definition FilterCells.hpp:35
static constexpr bool intersect
Definition FilterCells.hpp:40