1#ifndef SCRAN_NORM_CENTER_SIZE_FACTORS_HPP
2#define SCRAN_NORM_CENTER_SIZE_FACTORS_HPP
4#include "tatami_stats/tatami_stats.hpp"
77template<
typename SizeFactor_>
79 static_assert(std::is_floating_point<SizeFactor_>::value);
85 auto& diag = (diagnostics == NULL ? tmpdiag : *diagnostics);
86 for (
size_t i = 0; i < num; ++i) {
87 auto val = size_factors[i];
88 if (!internal::is_invalid(val, diag)) {
94 mean = std::accumulate(size_factors, size_factors + num,
static_cast<SizeFactor_
>(0));
123template<
typename SizeFactor_>
127 for (
size_t i = 0; i < num; ++i){
128 size_factors[i] /= mean;
152template<
typename SizeFactor_,
typename Block_>
154 static_assert(std::is_floating_point<SizeFactor_>::value);
155 size_t ngroups = tatami_stats::total_groups(block, num);
156 std::vector<SizeFactor_> group_mean(ngroups);
157 std::vector<size_t> group_num(ngroups);
161 auto& diag = (diagnostics == NULL ? tmpdiag : *diagnostics);
162 for (
size_t i = 0; i < num; ++i) {
163 auto val = size_factors[i];
164 if (!internal::is_invalid(val, diag)) {
166 group_mean[b] += val;
171 for (
size_t i = 0; i < num; ++i) {
173 group_mean[b] += size_factors[i];
178 for (
size_t g = 0; g < ngroups; ++g) {
180 group_mean[g] /= group_num[g];
205template<
typename SizeFactor_,
typename Block_>
209 if (options.
block_mode == CenterBlockMode::PER_BLOCK) {
210 for (
size_t i = 0; i < num; ++i) {
211 const auto& div = group_mean[block[i]];
213 size_factors[i] /= div;
217 }
else if (options.
block_mode == CenterBlockMode::LOWEST) {
220 for (
auto m : group_mean) {
224 if (!found || m < min) {
232 for (
size_t i = 0; i < num; ++i) {
233 size_factors[i] /= min;
Scaling normalization of single-cell data.
Definition center_size_factors.hpp:18
SizeFactor_ center_size_factors_mean(size_t num, const SizeFactor_ *size_factors, SizeFactorDiagnostics *diagnostics, const CenterSizeFactorsOptions &options)
Definition center_size_factors.hpp:78
CenterBlockMode
Definition center_size_factors.hpp:23
SizeFactor_ center_size_factors(size_t num, SizeFactor_ *size_factors, SizeFactorDiagnostics *diagnostics, const CenterSizeFactorsOptions &options)
Definition center_size_factors.hpp:124
std::vector< SizeFactor_ > center_size_factors_blocked(size_t num, SizeFactor_ *size_factors, const Block_ *block, SizeFactorDiagnostics *diagnostics, const CenterSizeFactorsOptions &options)
Definition center_size_factors.hpp:206
std::vector< SizeFactor_ > center_size_factors_blocked_mean(size_t num, const SizeFactor_ *size_factors, const Block_ *block, SizeFactorDiagnostics *diagnostics, const CenterSizeFactorsOptions &options)
Definition center_size_factors.hpp:153
Sanitize invalid size factors.
Options for center_size_factors() and center_size_factors_blocked().
Definition center_size_factors.hpp:28
CenterBlockMode block_mode
Definition center_size_factors.hpp:46
bool ignore_invalid
Definition center_size_factors.hpp:60
Diagnostics for the size factors.
Definition sanitize_size_factors.hpp:17