From d138e9534b8eb541c2923d6d95dff8603072f698 Mon Sep 17 00:00:00 2001 From: Andrew D Smith Date: Thu, 26 Nov 2026 12:54:01 -0800 Subject: [PATCH 1/6] src/results_summary.cpp: removing assertions on kmer_results being non-empty before trying to format kmer results because we might have no significant kmers --- src/results_summary.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/results_summary.cpp b/src/results_summary.cpp index 7bdcf00..4d22ecb 100644 --- a/src/results_summary.cpp +++ b/src/results_summary.cpp @@ -134,10 +134,8 @@ results_summary::get_report() const -> std::string { if (mode.do_gc_content()) sections.emplace("gc_sequence", gc_sequence_report(gc_content, grades)); - if (mode.do_kmers()) { - assert(!kmer_results.empty()); + if (mode.do_kmers()) sections.emplace("kmer", kmer_report(kmer_results, grades)); - } if (mode.do_length()) sections.emplace("sequence_length", @@ -201,10 +199,8 @@ results_summary::get_html() -> std::string { if (mode.do_gc_content()) sections.emplace("gc_sequence", gc_sequence_html(gc_content, grades)); - if (mode.do_kmers()) { - assert(!kmer_results.empty()); + if (mode.do_kmers()) sections.emplace("kmer", kmer_html(kmer_results, grades)); - } if (mode.do_length()) sections.emplace("sequence_length", sequence_length_html(lengths, grades)); From 396c03786dce4a890505b3aae9cb169fa27ead8a Mon Sep 17 00:00:00 2001 From: Andrew D Smith Date: Thu, 26 Nov 2026 12:54:45 -0800 Subject: [PATCH 2/6] src/kmer_counter.cpp: the p-value used for the k-mer grade is set to 1.0 when no significant kmers are found --- src/kmer_counter.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/kmer_counter.cpp b/src/kmer_counter.cpp index e950555..980e5a1 100644 --- a/src/kmer_counter.cpp +++ b/src/kmer_counter.cpp @@ -186,7 +186,7 @@ kmer_counter::decode_kmer(auto word, const auto n_bases) -> std::string { [[nodiscard]] auto get_grade_kmer(const std::vector &results) -> std::string { static constexpr auto label = "kmer"; - const auto pval = results.front().pval; + const auto pval = results.empty() ? 1.0 : results.front().pval; const auto neg_log_p_val = pval > 0.0 ? -std::log10(pval) : std::numeric_limits::max(); return grader_set::get_grade(label, neg_log_p_val); From 43fdc6f20c5b4e3bbb4b2f9beee63724feca9773 Mon Sep 17 00:00:00 2001 From: Andrew D Smith Date: Thu, 26 Nov 2026 12:55:45 -0800 Subject: [PATCH 3/6] src/html.cpp: adding check for kmer result being empty and if so, not attempting to generate a plot, which would crash --- src/html.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/html.cpp b/src/html.cpp index cdf5833..9b971d6 100644 --- a/src/html.cpp +++ b/src/html.cpp @@ -448,6 +448,12 @@ y: [{}], type: "line", name: "{}", }})"; + const auto grade = grades.grade(label); + const auto title = grades.get_title(label); + if (results.empty()) + return fmt::format( + html_module_fmt, grade, label, title, grade, + R""(
\n
No overrepresented kmers
)""); const auto get_pos = [&](const auto &x) { return x.pos; }; const auto xlim = std::ranges::max(std::views::transform(results, get_pos)); auto mostly0 = std::vector(xlim, 0.0); // change one position each kmer @@ -461,8 +467,6 @@ name: "{}", return fmt::format(kmer_line_format, fmt::join(xvals, ", "), fmt::join(mostly0, ", "), k.decode()); }; - const auto grade = grades.grade(label); - const auto title = grades.get_title(label); // NOLINTBEGIN(clang-analyzer-optin.cplusplus.UninitializedObject) return fmt::format( html_module_fmt, grade, label, title, grade, From c3719e05ebeec1b9106103bb3d4b2bf9682a00d4 Mon Sep 17 00:00:00 2001 From: Andrew D Smith Date: Thu, 26 Nov 2026 16:17:32 -0800 Subject: [PATCH 4/6] src/html.cpp: fixing the length of the mostly0 and xvals vectors in kmer_html and some clang-tidy excludes --- src/html.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/html.cpp b/src/html.cpp index 9b971d6..6c124af 100644 --- a/src/html.cpp +++ b/src/html.cpp @@ -139,6 +139,7 @@ name: "Theoretical distribution" const auto theor = get_theoretical_distribution( gc_content, static_cast(total_count)); const auto gc_smoothed = smooth_gc_content(gc_content, smoothing_window); + // NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject) const auto lines_data = fmt::format(gc_fmt, x, gc_smoothed, x, theor); const auto grade = grades.grade(label); @@ -414,6 +415,7 @@ yaxis: {{title: "tile", type: "category"}}, // z: one formatted vector of quality z scores per tile const auto format1 = [](const auto &c) { // ADS: note the format and precision (3) here + // NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject) return fmt::format("[{:.3f}]", fmt::join(c, ",")); // inner lists }; const auto z = std::views::transform(centered | std::views::values, format1); @@ -453,11 +455,11 @@ name: "{}", if (results.empty()) return fmt::format( html_module_fmt, grade, label, title, grade, - R""(
\n
No overrepresented kmers
)""); + R"(
\n
No overrepresented kmers
)"); const auto get_pos = [&](const auto &x) { return x.pos; }; const auto xlim = std::ranges::max(std::views::transform(results, get_pos)); - auto mostly0 = std::vector(xlim, 0.0); // change one position each kmer - const auto xvals = std::views::iota(0u, xlim); + auto mostly0 = std::vector(xlim + 1, 0.0); // change one position each kmer + const auto xvals = std::views::iota(0U, xlim + 1); auto prev = 0; const auto format1 = [&](const auto &k) { // x: positions in read; y: zeros except at 'pos' for the kmer @@ -467,12 +469,11 @@ name: "{}", return fmt::format(kmer_line_format, fmt::join(xvals, ", "), fmt::join(mostly0, ", "), k.decode()); }; - // NOLINTBEGIN(clang-analyzer-optin.cplusplus.UninitializedObject) + // NOLINTNEXTLINE(clang-analyzer-optin.cplusplus.UninitializedObject) return fmt::format( html_module_fmt, grade, label, title, grade, fmt::format( plot_format, fmt::format("[{}]", fmt::join(std::views::transform(results, format1), ",\n")))); - // NOLINTEND(clang-analyzer-optin.cplusplus.UninitializedObject) } From 195270ca0476e878f9b47593716d6bc07adcd31c Mon Sep 17 00:00:00 2001 From: Andrew D Smith Date: Thu, 26 Nov 2026 16:19:57 -0800 Subject: [PATCH 5/6] data/test_scripts/kmers.sh: adding more data files for kmers tests for regression testing --- data/test_scripts/kmers.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/data/test_scripts/kmers.sh b/data/test_scripts/kmers.sh index 69a617e..dbf7856 100644 --- a/data/test_scripts/kmers.sh +++ b/data/test_scripts/kmers.sh @@ -4,18 +4,20 @@ # Test k-mer analysis with BAM input and one thread prog=./falco -infile=test_data/bam_1.bam -outdir=bam_kmers_out -if [[ -e "${infile}" ]]; then - ${prog} --kmers -o ${outdir} ${infile} +infile1=test_data/bam_1.bam +infile2=test_data/fastq_bgzip_1.fq.gz +infile3=test_data/fastq_bgzip_2.fq.gz +outdir=kmers_out +if [[ -e "${infile1}" ||-e "${infile2}" || -e "${infile3}" ]]; then + ${prog} --kmers -o ${outdir} ${infile1} ${infile2} ${infile3} x=$(md5sum --ignore-missing -c test_data/md5sum.txt | \ grep "${outdir}" | \ grep -c "OK$") - if [[ "${x}" != "1" ]]; then + if [[ "${x}" != "3" ]]; then exit 1; fi rm -r ${outdir} else - echo "${infile} not found; skipping remaining tests"; + echo "input files for kmer tests not found; skipping remaining tests"; exit 77; fi From 34b666e32c0e262fa4714e28e03060033badae4f Mon Sep 17 00:00:00 2001 From: Andrew D Smith Date: Thu, 26 Nov 2026 16:20:22 -0800 Subject: [PATCH 6/6] data/test_data/md5sum.txt: updating test hashes for changes to kmers tests --- data/test_data/md5sum.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/data/test_data/md5sum.txt b/data/test_data/md5sum.txt index 49b53d9..8ab4726 100644 --- a/data/test_data/md5sum.txt +++ b/data/test_data/md5sum.txt @@ -1,7 +1,6 @@ bcf8363f788e54d38a5ec758042959ce ./fastq_plain_out/fastq_1/fastqc_data.txt 41a799d28bdc2e35e17546fe2af146cb ./preseq_out/bam_1/fastqc_data.txt 39b50a91a778f9713d6b510af435a9f0 ./sam_stdin_out/sam_stdin/fastqc_data.txt -037cb6bad120661ac15ccf6020cb82b1 ./bam_kmers_out/bam_1/fastqc_data.txt 41a799d28bdc2e35e17546fe2af146cb ./bam_out/bam_1/fastqc_data.txt 55d98514eda63c2cf4b900a0fb7b074b ./fastq_bgzf_mult_out/fastq_bgzip_1/fastqc_data.txt 39a5df25471d6f250de7b31a03325254 ./fastq_bgzf_mult_out/fastq_bgzip_2/fastqc_data.txt @@ -19,3 +18,6 @@ c36524a785c41cd0dbd18b23173e88c6 ./fastq_iupac_out/fastq_1_iupac/fastqc_data.tx 3c25a00c6744c680059103a6643d1b27 ./iupac_dups_out/iupac_dups_bam/fastqc_data.txt 672381b9141cb7b217c39b2b5455cb6c ./iupac_dups_out/iupac_dups/fastqc_data.txt 8a141f57a21f8f0f1bbc4b80e3a2ec47 ./sam_out/sam_1/fastqc_data.txt +037cb6bad120661ac15ccf6020cb82b1 ./kmers_out/bam_1/fastqc_data.txt +a6b078d60d45ba2e34edd7cff517b19e ./kmers_out/fastq_bgzip_1/fastqc_data.txt +bcf6ed7982eb16b61725bcc823c7eaad ./kmers_out/fastq_bgzip_2/fastqc_data.txt