From 6a6c4f99f7d35f7b200900bb6cfd6a46a7ee6c8e Mon Sep 17 00:00:00 2001 From: Andrew D Smith Date: Sun, 23 Jun 2024 13:13:12 -0700 Subject: [PATCH] src/utils/unxcounts.cpp: fixed a bug in which all non-covered cytosines were being reported even when the data was assumed to be CpG-only. --- src/utils/unxcounts.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/unxcounts.cpp b/src/utils/unxcounts.cpp index ec6d104..0cff2d0 100644 --- a/src/utils/unxcounts.cpp +++ b/src/utils/unxcounts.cpp @@ -226,9 +226,11 @@ write_missing_cpg(const uint32_t &name_size, const string &chrom, const auto buf_end = buf.data() + size(buf); // chrom name is already in the buffer so move past it auto cursor = buf.data() + name_size + 1; - for (auto pos = start_pos; pos < end_pos; ++pos) { - const char base = chrom[pos]; - if (is_cytosine(base)) { + for (auto pos = start_pos; pos < end_pos - 1; ++pos) { + // When this function is called, the "end_pos" is either the chrom + // size or the position of a base known to be a C. So we never + // have to allow pos+1 to equal end_pos. + if (is_cytosine(chrom[pos]) && is_guanine(chrom[pos+1])) { #pragma GCC diagnostic push #pragma GCC diagnostic error "-Wstringop-overflow=0" auto [ptr, ec] = to_chars(cursor, buf_end, pos);