Skip to content
Merged
20 changes: 17 additions & 3 deletions src/adapter_matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,15 @@ adapter_matcher::report(const std::uint64_t n_reads,
r += '\n';

auto cumulative = adap_counts;
#if __cpp_lib_ranges_zip
for (auto [prev, curr] : cumulative | std::views::pairwise)
std::ranges::transform(curr, prev, std::begin(curr), std::plus{});
#else
for (auto prev = 0LU, curr = 1LU; curr < std::size(cumulative);
++prev, ++curr)
std::ranges::transform(cumulative[curr], cumulative[prev],
std::begin(cumulative[curr]), std::plus{});
#endif

const auto n_pos = max_read_len + 1 >= adapter_size
? max_read_len - adapter_size + 1
Expand All @@ -96,7 +103,7 @@ adapter_matcher::report(const std::uint64_t n_reads,
const auto fmt_pct_of_reads = [n_reads](const auto c) {
return std::format("\t{:.6g}", pct(as_frac(c, n_reads)));
};
for (const auto [idx, cumul] : std::views::enumerate(cumulative))
for (const auto [idx, cumul] : falco::views::enumerate(cumulative))
r += std::format("{}{}\n", make_group_tag(groups[idx]),
to_flat(cumul, fmt_pct_of_reads));
return r + end_module_tag;
Expand Down Expand Up @@ -130,9 +137,15 @@ name: "{}",
return make_group_tag(g); // ADS: purposely unquoted
});
auto cumulative = adap_counts;
#if __cpp_lib_ranges_zip
for (auto [prev, curr] : cumulative | std::views::pairwise)
std::ranges::transform(curr, prev, std::begin(curr), std::plus{});

#else
for (auto prev = 0LU, curr = 1LU; curr < std::size(cumulative);
++prev, ++curr)
std::ranges::transform(cumulative[curr], cumulative[prev],
std::begin(cumulative[curr]), std::plus{});
#endif
const auto n_pos = max_read_len + 1 >= adapter_size
? max_read_len - adapter_size + 1
: max_read_len;
Expand All @@ -145,7 +158,8 @@ name: "{}",
};
std::vector<std::string> html_by_adapter;
const auto adapter_names = adapter_set::instance().adapter_names;
for (const auto [adap_id, adap_name] : std::views::enumerate(adapter_names)) {
for (const auto [adap_id, adap_name] :
falco::views::enumerate(adapter_names)) {
const auto make_y = [&](const auto &cumul) {
return pct_of_reads(cumul[adap_id]);
};
Expand Down
5 changes: 2 additions & 3 deletions src/adapter_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,9 @@ adapter_set::adapter_set(const run_mode &m, const std::string &filename) {

[[nodiscard]] auto
adapter_set::validate() const -> std::tuple<bool, std::string> {
const auto &adapters = instance().adapters;
if (adapters.empty())
if (instance().adapters.empty())
return {true, std::string{}};
const auto adap_len = std::size(adapters.front());
const auto adap_len = std::size(instance().adapters.front());
if (!std::ranges::all_of(instance().adapters, [&](const auto &a) {
return std::size(a) == adap_len;
}))
Expand Down
2 changes: 2 additions & 0 deletions src/adapter_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <variant>
#include <vector>

// ADS: all this code assumes all adapters for a given run of falco have the
// same length
struct adapter_set {
static constexpr auto min_adapter_size = 6;
static constexpr auto max_adapter_size = 16;
Expand Down
13 changes: 11 additions & 2 deletions src/base_groups.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,17 @@ make_base_groups(const std::uint64_t n_bases, const std::uint64_t n_initial,
static constexpr auto make_groups = [](const auto n, const auto offset,
const auto scale) {
const auto f = [scale, offset](const auto x) { return offset + x * scale; };
#if __cpp_lib_ranges_zip
return std::views::transform(std::views::iota(0LU, n + 1), f) |
std::views::adjacent_transform<2>(make_one_group);
#else
const auto x = std::views::transform(std::views::iota(0LU, n + 1), f) |
std::ranges::to<std::vector>();
std::vector<base_group_t> r(n);
for (auto i = 0U; i < n; ++i)
r[i] = make_one_group(x[i], x[i + 1]);
return r;
#endif
};
if (n_bases <= n_initial + n_groups_target)
return make_groups(n_bases, 0, 1) | std::ranges::to<std::vector>();
Expand All @@ -63,8 +72,8 @@ make_base_groups(const std::uint64_t n_bases, const std::uint64_t n_initial,
}

[[nodiscard]] auto
get_default_base_groups(const std::uint64_t n_bases,
const bool make_groups) -> base_group_vec {
get_default_base_groups(const std::uint64_t n_bases, const bool make_groups)
-> base_group_vec {
static constexpr auto default_n_initial = 9UL;
static constexpr auto default_n_groups_target = 75UL - default_n_initial;
return make_groups ? make_base_groups(n_bases, default_n_initial,
Expand Down
4 changes: 2 additions & 2 deletions src/base_groups.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ apply_base_groups(const base_group_vec &groups, auto &rows) {
auto group_itr = std::cbegin(groups);
auto current_row = 0U;
for (const auto [idx, row] :
std::views::enumerate(rows) | std::views::drop(1)) {
falco::views::enumerate(rows) | std::views::drop(1)) {
if (static_cast<std::uint64_t>(idx) < group_itr->second)
add(rows[current_row], row);
else {
Expand All @@ -56,7 +56,7 @@ apply_base_groups(const base_group_vec &groups, auto &rows, const auto &adder) {
auto group_itr = std::cbegin(groups);
auto current_row = 0U;
for (const auto [idx, row] :
std::views::enumerate(rows) | std::views::drop(1)) {
falco::views::enumerate(rows) | std::views::drop(1)) {
if (static_cast<std::uint64_t>(idx) < group_itr->second)
adder(rows[current_row], row);
else {
Expand Down
3 changes: 2 additions & 1 deletion src/contaminants.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: MIT; Copyright 2026 Andrew D Smith

#include "contaminants.hpp"
#include "falco_utils.hpp"

#include <algorithm>
#include <cctype>
Expand Down Expand Up @@ -244,7 +245,7 @@ match_contaminant(const std::string &query) -> std::int64_t {
auto best_match = 0L;
auto best_match_len = 0L;
for (const auto &[idx, seq] :
std::views::enumerate(std::views::elements<1>(contaminants))) {
falco::views::enumerate(std::views::elements<1>(contaminants))) {
const auto n_match =
std::max(get_overlap(query, seq), get_overlap(seq, query));
if (n_match > best_match) {
Expand Down
9 changes: 5 additions & 4 deletions src/duplication_results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <ranges>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

Expand Down Expand Up @@ -179,7 +180,7 @@ overrepresented_report(const std::vector<overrep_t> &overrep,
make_bins(const auto &breaks, const auto &hist) {
std::vector<std::uint64_t> binned(std::size(breaks), 0);
auto b_itr = std::cbegin(breaks);
for (const auto [i, h] : std::views::enumerate(hist)) {
for (const auto [i, h] : falco::views::enumerate(hist)) {
// ADS: clang-tidy false positive?
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
b_itr += (b_itr < std::cend(breaks) && i >= *b_itr);
Expand Down Expand Up @@ -229,12 +230,12 @@ duplication_results::get_dups_summary(const std::uint64_t n_reads) const
std::vector<std::uint64_t> hist_dedup(max_dup + 1);
for (const auto n_copies : std::views::values(dups))
++hist_dedup[n_copies];
for (auto [idx, val] : std::views::enumerate(hist_dedup))
for (auto [idx, val] : falco::views::enumerate(hist_dedup))
val = static_cast<std::uint64_t>(
get_corrected_count(count_at_limit, n_reads, idx, val));
auto hist_mass =
std::views::transform(
std::views::enumerate(hist_dedup),
falco::views::enumerate(hist_dedup),
[](const auto x) { return std::get<0>(x) * std::get<1>(x); }) |
std::ranges::to<std::vector>();
return dup_summary_t{
Expand All @@ -255,7 +256,7 @@ duplication_results::get_dups_summary() const -> dup_summary_t {
++hist_dedup[n_copies];
auto hist_mass =
std::views::transform(
std::views::enumerate(hist_dedup),
falco::views::enumerate(hist_dedup),
[](const auto x) { return std::get<0>(x) * std::get<1>(x); }) |
std::ranges::to<std::vector>();
return dup_summary_t{
Expand Down
1 change: 1 addition & 0 deletions src/duplication_results.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <numeric>
#include <ranges>
#include <string>
#include <utility>
#include <vector>

class run_mode;
Expand Down
12 changes: 8 additions & 4 deletions src/falco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Use these as templates. Copy and modify them to customize your analysis.
#include "adapter_set.hpp"
#include "bam_file.hpp"
#include "contaminants.hpp"
#include "duplication_results.hpp"
#include "falco_analyzer.hpp"
#include "falco_config.hpp"
#include "falco_file_format.hpp"
Expand All @@ -49,12 +50,12 @@ Use these as templates. Copy and modify them to customize your analysis.
#include "fastq_bgzf_file.hpp"
#include "fastq_file.hpp"
#include "fastq_gz_file.hpp"
#include "file_info.hpp"
#include "get_binary_dir.hpp"
#include "original_duplicates.hpp"
#include "quality_score.hpp"
#include "reads_file.hpp" // IWYU pragma: keep
#include "results_collector.hpp"
#include "results_summary.hpp"
#include "run_mode.hpp"
#include "sam_file.hpp"
#include "tile_processor.hpp"

Expand All @@ -73,17 +74,20 @@ Use these as templates. Copy and modify them to customize your analysis.
#include <fstream>
#include <functional>
#include <iterator>
#include <limits>
#include <map>
#include <memory>
#include <print>
#include <ranges>
#include <stdexcept>
#include <string>
#include <thread>
#include <type_traits>
#include <tuple>
#include <utility>
#include <vector>

struct results_collector;

static auto
write_file(const auto &filename, const auto &data) {
std::ofstream out(filename);
Expand Down Expand Up @@ -141,7 +145,7 @@ make_reads_files(const std::vector<file_info> &infos,
[[nodiscard]] static auto
get_file_info(const auto &infiles) {
std::vector<file_info> infos;
for (const auto [file_id, infile] : std::views::enumerate(infiles)) {
for (const auto [file_id, infile] : falco::views::enumerate(infiles)) {
const auto [input_format, format_description] = get_file_format(infile);
const auto tile_id_position = get_tile_info(infile);
const bool has_tiles = (tile_id_position != 0);
Expand Down
3 changes: 2 additions & 1 deletion src/falco_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "bamrec.hpp"
#include "bgzf_block.hpp"
#include "duplication_results.hpp"
#include "falco_utils.hpp"
#include "file_info.hpp"
#include "fqrec.hpp"
#include "reads_file.hpp"
Expand Down Expand Up @@ -48,7 +49,7 @@ analyze(const std::uint32_t n_threads, const run_mode &mode,
for (const auto th_id : std::views::iota(0u, n_threads))
workers.emplace_back([&, n_threads, th_id] {
auto &res = results[th_id];
for (const auto [file_id, info] : std::views::enumerate(infos))
for (const auto [file_id, info] : falco::views::enumerate(infos))
res[file_id].init(mode, info, dups_init[file_id]);
while (true) {
auto tq_lock = tq.wait_and_acquire_lock();
Expand Down
6 changes: 4 additions & 2 deletions src/falco_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@

#include <algorithm>
#include <array>
#include <cctype>
#include <charconv>
#include <format>
#include <fstream>
#include <iterator>
#include <map>
#include <ranges>
#include <sstream>
#include <stdexcept>
#include <string>
#include <system_error>
#include <unordered_map>
#include <utility>
#include <vector>

[[nodiscard]] auto
Expand Down
2 changes: 1 addition & 1 deletion src/falco_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#include <string>

struct run_mode;
class run_mode;

// ADS: run mode is an out-param because it might be partially set already
auto
Expand Down
18 changes: 13 additions & 5 deletions src/falco_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
#include <cstdint>
#include <ctime> // for std::localtime
#include <format>
#include <iomanip> // for std::put_time
#include <span>
#include <sstream>
#include <string>
#include <tuple>
#include <vector>
Expand Down Expand Up @@ -56,7 +58,8 @@ get_theoretical_distribution(const std::vector<double> &gc,
const auto sd_term = [&](const auto &x) {
return cntr_sq(std::get<0>(x)) * std::get<1>(x);
};
const auto id_gc = std::views::enumerate(gc) | std::views::transform(sd_term);
const auto id_gc =
falco::views::enumerate(gc) | std::views::transform(sd_term);
const auto sd = std::sqrt(as_frac(
std::reduce(std::cbegin(id_gc), std::cend(id_gc)), total_count - 1));
const auto to_normal = [&](const auto val) {
Expand Down Expand Up @@ -98,9 +101,16 @@ smooth_gc_content(const std::vector<double> &data,
for (auto w = 1; w < (window_size + 1) / 2; ++w)
smoothed.push_back(get_mean(
std::ranges::subrange(std::cbegin(data), std::cbegin(data) + w)));
#if __cpp_lib_ranges_slide
for (const auto &window : data | std::views::slide(window_size))
// cppcheck-suppress useStlAlgorithm
smoothed.push_back(get_mean(window));
#else
for (auto i = 0LU; i < std::size(data); ++i)
// cppcheck-suppress useStlAlgorithm
smoothed.push_back(get_mean(std::ranges::subrange(
std::cbegin(data) + i, std::cbegin(data) + i + window_size)));
#endif
for (auto w = (window_size + 1) / 2; w > 1; --w)
smoothed.push_back(get_mean(
std::ranges::subrange(std::cend(data) - w + 1, std::cend(data))));
Expand Down Expand Up @@ -145,10 +155,8 @@ combine_gc_content_for_lengths(const std::vector<falco::gc_content_array> &gcs)
}

[[nodiscard]] auto
get_program_start_time()
-> std::chrono::time_point<std::chrono::high_resolution_clock,
std::chrono::nanoseconds> {
static const auto start_time = std::chrono::high_resolution_clock::now();
get_program_start_time() -> std::chrono::time_point<std::chrono::system_clock> {
static const auto start_time = std::chrono::system_clock::now();
return start_time;
}

Expand Down
Loading