From 5a5ece2845fcad2783a5d9d04ba39c9686727025 Mon Sep 17 00:00:00 2001 From: Niema Moshiri Date: Wed, 12 Jul 2023 12:51:56 -0700 Subject: [PATCH] Fixed bug when handling insertions that are in minority count but have high enough count --- .gitignore | 10 ++++++++++ common.h | 2 +- count.cpp | 14 ++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 619aafc..66ae1e1 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,16 @@ viral_consensus viral_consensus_debug +# input files +*.sam +*.bam +*.cram + +# output files +*.json +*.tsv +*.fa + # Prerequisites *.d diff --git a/common.h b/common.h index eac7cc4..50081f9 100644 --- a/common.h +++ b/common.h @@ -13,7 +13,7 @@ #include // global definitions/constants -#define VERSION "0.0.1" +#define VERSION "0.0.2" // definitions/constants for argparsing #define DEFAULT_NUM_THREADS 1 diff --git a/count.cpp b/count.cpp index 0994c3b..8329628 100644 --- a/count.cpp +++ b/count.cpp @@ -150,7 +150,21 @@ counts_t compute_counts(const char* const in_reads_fn, std::string const & ref, while(pos < tmp_uint32) { curr_base_qual = qqual[qpos]; if(curr_base_qual >= min_qual && (!primer_trim || (!is_reverse && pos >= min_max_primer_inds[src->core.pos].second) || (is_reverse && pos < min_max_primer_inds[src->core.pos].first))) { + // increment the count of the base at this position ++counts.pos_counts[pos][BASE_TO_NUM[(int)qseq[qpos]]]; + + // increment the insertion count of "" (no insertion) after this position (except the last position) + if(pos < tmp_uint32) { + ins_counts_it = counts.ins_counts.find(pos); + if(ins_counts_it == counts.ins_counts.end()) { + ins_counts_it = counts.ins_counts.emplace(pos, std::unordered_map()).first; + } + ins_counts_pos_it = ins_counts_it->second.find(""); + if(ins_counts_pos_it == ins_counts_it->second.end()) { + ins_counts_pos_it = ins_counts_it->second.emplace("", 0).first; + } + ++(ins_counts_pos_it->second); + } } ++qpos; ++pos; }