1#ifndef SCRAN_SANITIZE_SIZE_FACTORS_HPP
2#define SCRAN_SANITIZE_SIZE_FACTORS_HPP
44template<
typename SizeFactor_>
69template<
typename SizeFactor_>
70SizeFactor_ find_smallest_valid_factor(
size_t num,
const SizeFactor_* size_factors) {
71 SizeFactor_ smallest = 1;
74 for (
size_t i = 0; i < num; ++i) {
75 auto s = size_factors[i];
76 if (std::isfinite(s) && s > 0) {
77 if (!found || smallest > s) {
87template<
typename SizeFactor_>
88double find_largest_valid_factor(
size_t num,
const SizeFactor_* size_factors) {
89 SizeFactor_ largest = 1;
92 for (
size_t i = 0; i < num; ++i) {
93 auto s = size_factors[i];
94 if (std::isfinite(s) && s > 0) {
95 if (!found || largest < s) {
121template<
typename SizeFactor_>
124 for (
size_t i = 0; i < num; ++i) {
125 internal::is_invalid(size_factors[i], output);
196template<
typename SizeFactor_>
198 SizeFactor_ smallest = -1;
202 throw std::runtime_error(
"detected negative size factor");
204 smallest = internal::find_smallest_valid_factor(num, size_factors);
205 for (
size_t i = 0; i < num; ++i) {
206 auto& s = size_factors[i];
215 if (options.
handle_zero == SanitizeAction::ERROR) {
216 throw std::runtime_error(
"detected size factor of zero");
217 }
else if (options.
handle_zero == SanitizeAction::SANITIZE) {
219 smallest = internal::find_smallest_valid_factor(num, size_factors);
221 for (
size_t i = 0; i < num; ++i) {
222 auto& s = size_factors[i];
231 if (options.
handle_nan == SanitizeAction::ERROR) {
232 throw std::runtime_error(
"detected NaN size factor");
233 }
else if (options.
handle_nan == SanitizeAction::SANITIZE) {
234 for (
size_t i = 0; i < num; ++i) {
235 auto& s = size_factors[i];
245 throw std::runtime_error(
"detected infinite size factor");
247 auto largest = internal::find_largest_valid_factor(num, size_factors);
248 for (
size_t i = 0; i < num; ++i) {
249 auto& s = size_factors[i];
270template<
typename SizeFactor_>
Scaling normalization of single-cell data.
Definition center_size_factors.hpp:18
void sanitize_size_factors(size_t num, SizeFactor_ *size_factors, const SizeFactorDiagnostics &status, const SanitizeSizeFactorsOptions &options)
Definition sanitize_size_factors.hpp:197
SizeFactorDiagnostics check_size_factor_sanity(size_t num, const SizeFactor_ *size_factors)
Definition sanitize_size_factors.hpp:122
SanitizeAction
Definition sanitize_size_factors.hpp:137
Options for sanitize_size_factors().
Definition sanitize_size_factors.hpp:142
SanitizeAction handle_zero
Definition sanitize_size_factors.hpp:154
SanitizeAction handle_nan
Definition sanitize_size_factors.hpp:167
SanitizeAction handle_negative
Definition sanitize_size_factors.hpp:161
SanitizeAction handle_infinite
Definition sanitize_size_factors.hpp:174
Diagnostics for the size factors.
Definition sanitize_size_factors.hpp:17
bool has_negative
Definition sanitize_size_factors.hpp:21
bool has_infinite
Definition sanitize_size_factors.hpp:36
bool has_zero
Definition sanitize_size_factors.hpp:26
bool has_nan
Definition sanitize_size_factors.hpp:31