1#ifndef SCRAN_CENTER_SIZE_FACTORS_HPP
2#define SCRAN_CENTER_SIZE_FACTORS_HPP
4#include "../utils/macros.hpp"
6#include "../utils/blocking.hpp"
8#include "SanitizeSizeFactors.hpp"
108 for (
size_t i = 0; i < n; ++i) {
109 const auto& current = size_factors[i];
113 }
else if (current == 0) {
118 }
else if (std::isnan(current)) {
121 }
else if (std::isinf(current)) {
132 for (
size_t i = 0; i < n; ++i){
133 size_factors[i] /= mean;
156 template<
typename T,
typename B>
159 return run(n, size_factors);
163 std::vector<double> group_mean(ngroups);
164 std::vector<double> group_num(ngroups);
167 for (
size_t i = 0; i < n; ++i) {
168 const auto& current = size_factors[i];
172 }
else if (current == 0) {
177 }
else if (std::isinf(current)) {
180 }
else if (std::isnan(current)) {
185 const auto& b = block[i];
186 group_mean[b] += size_factors[i];
190 for (
size_t g = 0; g < ngroups; ++g) {
192 group_mean[g] /= group_num[g];
196 if (block_mode == PER_BLOCK) {
197 for (
size_t i = 0; i < n; ++i) {
198 const auto& div = group_mean[block[i]];
200 size_factors[i] /= div;
204 }
else if (block_mode == LOWEST) {
207 double min = std::numeric_limits<double>::infinity();
208 for (
size_t b = 0; b < ngroups; ++b) {
209 const auto& div = group_mean[b];
210 if (div && div < min) {
215 if (std::isfinite(min)) {
216 for (
size_t i = 0; i < n; ++i) {
217 size_factors[i] /= min;
Center size factors prior to scaling normalization.
Definition CenterSizeFactors.hpp:27
SizeFactorValidity run(size_t n, T *size_factors) const
Definition CenterSizeFactors.hpp:103
BlockMode
Definition CenterSizeFactors.hpp:32
SizeFactorValidity run_blocked(size_t n, T *size_factors, const B *block) const
Definition CenterSizeFactors.hpp:157
CenterSizeFactors & set_block_mode(BlockMode b=Defaults::block_mode)
Definition CenterSizeFactors.hpp:69
CenterSizeFactors & set_ignore_zeros(bool i=Defaults::ignore_zeros)
Definition CenterSizeFactors.hpp:85
Functions for single-cell RNA-seq analyses.
Definition AggregateAcrossCells.hpp:18
size_t count_ids(size_t length, const Id_ *ids)
Definition blocking.hpp:29
Default parameter settings.
Definition CenterSizeFactors.hpp:37
static constexpr BlockMode block_mode
Definition CenterSizeFactors.hpp:41
static constexpr bool ignore_zeros
Definition CenterSizeFactors.hpp:46
Validity of size factors.
Definition SanitizeSizeFactors.hpp:12
bool has_nan
Definition SanitizeSizeFactors.hpp:26
bool has_zero
Definition SanitizeSizeFactors.hpp:21
bool has_infinite
Definition SanitizeSizeFactors.hpp:31
bool has_negative
Definition SanitizeSizeFactors.hpp:16