From e2b68eca2e2bbbdaeacb0df6efcac2574a29e2b6 Mon Sep 17 00:00:00 2001 From: Andrew D Smith Date: Thu, 20 Nov 2025 15:15:42 -0800 Subject: [PATCH] src/radmeth/radmeth_model.hpp: adding pseudocount to methylation levels (n_meth) --- src/radmeth/radmeth_model.hpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/radmeth/radmeth_model.hpp b/src/radmeth/radmeth_model.hpp index 5fe721e6..64c5da63 100644 --- a/src/radmeth/radmeth_model.hpp +++ b/src/radmeth/radmeth_model.hpp @@ -60,6 +60,7 @@ template struct Regression { static double tolerance; // 1e-3; static double stepsize; // 0.001; static std::uint32_t max_iter; // 250; + static constexpr double pseudocount = 1.0 / 256.0; Design design; std::string rowname; @@ -155,6 +156,15 @@ Regression::parse(const std::string &line) { mc.push_back(mc1); } + const auto add_pseudocount = [&](auto x) { + x.n_meth = x.n_reads > 0.0 ? pseudocount / 2.0 + + x.n_meth * (1.0 - pseudocount / x.n_reads) + : 0.0; + return x; + }; + + std::transform(std::begin(mc), std::end(mc), std::begin(mc), add_pseudocount); + if (failed) throw std::runtime_error("failed to parse counts from:\n" + line); }