1#ifndef SCRAN_NORM_CENTER_SIZE_FACTORS_HPP
2#define SCRAN_NORM_CENTER_SIZE_FACTORS_HPP
4#include "tatami_stats/tatami_stats.hpp"
73template<
typename SizeFactor_>
75 static_assert(std::is_floating_point<SizeFactor_>::value);
81 auto& diag = (diagnostics == NULL ? tmpdiag : *diagnostics);
82 for (
size_t i = 0; i < num; ++i) {
83 auto val = size_factors[i];
84 if (!internal::is_invalid(val, diag)) {
90 mean = std::accumulate(size_factors, size_factors + num,
static_cast<SizeFactor_
>(0));
119template<
typename SizeFactor_>
123 for (
size_t i = 0; i < num; ++i){
124 size_factors[i] /= mean;
148template<
typename SizeFactor_,
typename Block_>
150 static_assert(std::is_floating_point<SizeFactor_>::value);
151 size_t ngroups = tatami_stats::total_groups(block, num);
152 std::vector<SizeFactor_> group_mean(ngroups);
153 std::vector<size_t> group_num(ngroups);
157 auto& diag = (diagnostics == NULL ? tmpdiag : *diagnostics);
158 for (
size_t i = 0; i < num; ++i) {
159 auto val = size_factors[i];
160 if (!internal::is_invalid(val, diag)) {
162 group_mean[b] += val;
167 for (
size_t i = 0; i < num; ++i) {
169 group_mean[b] += size_factors[i];
174 for (
size_t g = 0; g < ngroups; ++g) {
176 group_mean[g] /= group_num[g];
201template<
typename SizeFactor_,
typename Block_>
205 if (options.
block_mode == CenterBlockMode::PER_BLOCK) {
206 for (
size_t i = 0; i < num; ++i) {
207 const auto& div = group_mean[block[i]];
209 size_factors[i] /= div;
213 }
else if (options.
block_mode == CenterBlockMode::LOWEST) {
216 for (
auto m : group_mean) {
220 if (!found || m < min) {
228 for (
size_t i = 0; i < num; ++i) {
229 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:74
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:120
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:202
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:149
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:42
bool ignore_invalid
Definition center_size_factors.hpp:56
Diagnostics for the size factors.
Definition sanitize_size_factors.hpp:17