Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
Checks: 'cert-*,cppcoreguidelines-*,performance-*,clang-diagnostic-*,clang-analyzer-*,-clang-diagnostic-unqualified-std-cast-call,-clang-diagnostic-unknown-warning-option,-clang-analyzer-unix.BlockInCriticalSection'
Checks: "
cert-*,
cppcoreguidelines-*,
performance-*,
clang-diagnostic-*,
clang-analyzer-*,
-clang-diagnostic-unqualified-std-cast-call,
-clang-diagnostic-unknown-warning-option,
-clang-analyzer-unix.BlockInCriticalSection,
-cppcoreguidelines-pro-bounds-avoid-unchecked-container-access,
"
WarningsAsErrors: '*'
HeaderFileExtensions:
- ''
Expand All @@ -17,11 +27,13 @@ FormatStyle: none
CheckOptions:
cert-dcl16-c.NewSuffixes: 'L;LL;LU;LLU'
cert-err33-c.AllowCastToVoid: 'true'
cert-err33-c.CheckedFunctions: '::aligned_alloc;::asctime_s;::at_quick_exit;::atexit;::bsearch;::bsearch_s;::btowc;::c16rtomb;::c32rtomb;::calloc;::clock;::cnd_broadcast;::cnd_init;::cnd_signal;::cnd_timedwait;::cnd_wait;::ctime_s;::fclose;::fflush;::fgetc;::fgetpos;::fgets;::fgetwc;::fopen;::fopen_s;::fprintf;::fprintf_s;::fputc;::fputs;::fputwc;::fputws;::fread;::freopen;::freopen_s;::fscanf;::fscanf_s;::fseek;::fsetpos;::ftell;::fwprintf;::fwprintf_s;::fwrite;::fwscanf;::fwscanf_s;::getc;::getchar;::getenv;::getenv_s;::gets_s;::getwc;::getwchar;::gmtime;::gmtime_s;::localtime;::localtime_s;::malloc;::mbrtoc16;::mbrtoc32;::mbsrtowcs;::mbsrtowcs_s;::mbstowcs;::mbstowcs_s;::memchr;::mktime;::mtx_init;::mtx_lock;::mtx_timedlock;::mtx_trylock;::mtx_unlock;::printf_s;::putc;::putwc;::raise;::realloc;::remove;::rename;::scanf;::scanf_s;::setlocale;::setvbuf;::signal;::snprintf;::snprintf_s;::sprintf;::sprintf_s;::sscanf;::sscanf_s;::strchr;::strerror_s;::strftime;::strpbrk;::strrchr;::strstr;::strtod;::strtof;::strtoimax;::strtok;::strtok_s;::strtol;::strtold;::strtoll;::strtoul;::strtoull;::strtoumax;::strxfrm;::swprintf;::swprintf_s;::swscanf;::swscanf_s;::thrd_create;::thrd_detach;::thrd_join;::thrd_sleep;::time;::timespec_get;::tmpfile;::tmpfile_s;::tmpnam;::tmpnam_s;::tss_create;::tss_get;::tss_set;::ungetc;::ungetwc;::vfprintf;::vfprintf_s;::vfscanf;::vfscanf_s;::vfwprintf;::vfwprintf_s;::vfwscanf;::vfwscanf_s;::vprintf_s;::vscanf;::vscanf_s;::vsnprintf;::vsnprintf_s;::vsprintf;::vsprintf_s;::vsscanf;::vsscanf_s;::vswprintf;::vswprintf_s;::vswscanf;::vswscanf_s;::vwprintf_s;::vwscanf;::vwscanf_s;::wcrtomb;::wcschr;::wcsftime;::wcspbrk;::wcsrchr;::wcsrtombs;::wcsrtombs_s;::wcsstr;::wcstod;::wcstof;::wcstoimax;::wcstok;::wcstok_s;::wcstol;::wcstold;::wcstoll;::wcstombs;::wcstombs_s;::wcstoul;::wcstoull;::wcstoumax;::wcsxfrm;::wctob;::wctrans;::wctype;::wmemchr;::wprintf_s;::wscanf;::wscanf_s;'
cert-err33-c.CheckedFunctions: '*'
cert-oop54-cpp.WarnOnlyIfThisHasSuspiciousField: 'false'
cert-str34-c.DiagnoseSignedUnsignedCharComparisons: 'false'
cppcoreguidelines-non-private-member-variables-in-classes.IgnorePublicMemberVariables: 'true'
cppcoreguidelines-rvalue-reference-param-not-moved.AllowPartialMove: 'true'
cppcoreguidelines-avoid-magic-numbers.IgnoredIntegerValues: '1;2;3;4;10'
cppcoreguidelines-avoid-magic-numbers.IgnoredFloatingPointValues: '1.0;2.0;10.0;100.0'
google-readability-braces-around-statements.ShortStatementLines: '1'
google-readability-function-size.StatementThreshold: '800'
google-readability-namespace-comments.ShortNamespaceLines: '10'
Expand Down
11 changes: 6 additions & 5 deletions src/duplication_results.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <limits>
#include <numeric>
#include <ranges>
#include <span>
#include <string>
#include <tuple>
#include <unordered_map>
Expand All @@ -35,7 +36,7 @@

static constexpr auto n_bins = 16;

static constexpr auto bin_breaks = std::array{
static constexpr auto bin_breaks_impl = std::array{
1,
2,
3,
Expand All @@ -54,11 +55,12 @@ static constexpr auto bin_breaks = std::array{
10'000,
std::numeric_limits<int>::max(),
};
static constexpr std::span bin_breaks = bin_breaks_impl;

// clang-format off

// ADS: previously for plots: std::array{"1", "2", ..., "5k+", "10k+"}
static constexpr auto bin_labels = std::array{
static constexpr auto bin_labels_impl = std::array{
"0",
"1",
"2",
Expand All @@ -77,6 +79,7 @@ static constexpr auto bin_labels = std::array{
">5k",
">10k",
};
static constexpr std::span bin_labels = bin_labels_impl;

// clang-format on

Expand Down Expand Up @@ -181,9 +184,7 @@ 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] : 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);
b_itr += (b_itr != std::cend(breaks) && i >= *b_itr);
binned[std::distance(std::cbegin(breaks), b_itr)] += h;
}
return binned;
Expand Down
2 changes: 1 addition & 1 deletion src/falco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ main(int argc, char *argv[]) {
if (argc >= 2)
app.footer(std::format(description, falco::get_share_dir()));

// NOLINTNEXTLINE (cppcoreguidelines-avoid-magic-numbers)
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
app.get_formatter()->long_option_alignment_ratio(0.2);
app.set_help_flag("-h,--help", "Print more detailed help");
app.set_version_flag("--version", VERSION, "Print program version");
Expand Down
7 changes: 3 additions & 4 deletions src/falco_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,10 @@ load_config_and_set_graders(const std::string &filename,
continue;
const auto get_cutoff = [&](const std::string &label0) {
const auto x = json_in[label][label0].get<std::string>();
const auto beg = std::data(x);
const auto end = beg + std::size(x); // NOLINT(*-pointer-arithmetic)
double val{};
const auto res = std::from_chars(beg, end, val);
if (res.ec != std::errc{})
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
if (std::from_chars(std::data(x), std::data(x) + std::size(x), val)
.ec != std::errc{})
throw std::runtime_error("error parsing cutoff: " + x);
return val;
};
Expand Down
54 changes: 26 additions & 28 deletions src/falco_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include <array>
#include <cmath>
#include <compare>
#include <cstdint>
#include <ctime> // for std::localtime
#include <format>
Expand All @@ -17,7 +18,6 @@
[[nodiscard]] auto
size_to_units(const std::int64_t s, const std::string &suffix) -> std::string {
const auto as_frac_2 = [](const auto a, const auto b) {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
return std::floor(10 * as_frac(a, b)) / 10;
};
if (s >= gigabytes)
Expand Down Expand Up @@ -63,10 +63,9 @@ get_theoretical_distribution(const std::vector<double> &gc,
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) {
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
return std::exp(-cntr_sq(val) / (2.0 * sd * sd));
};
auto normed = std::views::iota(0u, n_bins) |
auto normed = std::views::iota(0U, n_bins) |
std::views::transform(to_normal) |
std::ranges::to<std::vector>();
const auto denom = std::reduce(std::cbegin(normed), std::cend(normed));
Expand Down Expand Up @@ -103,52 +102,51 @@ smooth_gc_content(const std::vector<double> &data,
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)));
const auto lim = std::cend(data) - window_size;
for (auto itr = std::cbegin(data); itr != lim; ++itr)
smoothed.push_back(get_mean(std::ranges::subrange(itr, itr + window_size)));
#endif
const auto d_end = std::cend(data);
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))));
smoothed.push_back(get_mean(std::ranges::subrange(d_end - w + 1, d_end)));
return smoothed;
}

[[nodiscard]] auto
combine_gc_content_for_lengths(const std::vector<falco::gc_content_array> &gcs)
combine_gc_content_for_lengths(const std::vector<falco::gc_content_t> &gcs)
-> std::vector<double> {
static constexpr auto histogram_size = 101;
std::vector<double> hist(histogram_size);
for (auto i = 0U; i < std::size(gcs); ++i) {
if (std::reduce(std::cbegin(gcs[i]), std::cend(gcs[i])) == 0)
for (const auto &gc : gcs) {
if (std::ranges::none_of(gc, [](const auto x) { return x > 0.0; }))
continue;
const auto increm = as_frac(histogram_size, std::size(gcs[i]));
for (auto gc_idx = 0U; gc_idx < std::size(gcs[i]); ++gc_idx) {
const auto curr_percent = gc_idx * increm;
const auto next_percent = (gc_idx + 1) * increm;
const auto increment = as_frac(histogram_size, std::size(gc));
for (auto gc_idx = 0U; gc_idx < std::size(gc); ++gc_idx) {
const auto curr_percent = gc_idx * increment;
const auto next_percent = (gc_idx + 1) * increment;
const auto start_in_hist =
static_cast<std::uint64_t>(std::floor(curr_percent));
static_cast<std::int64_t>(std::floor(curr_percent));
// ADS: below, not sure best way to do this for all edge cases
const auto stop_in_hist =
static_cast<std::uint64_t>(std::min(static_cast<double>(histogram_size),
std::ceil(next_percent))) -
static_cast<std::int64_t>(std::min(static_cast<double>(histogram_size),
std::ceil(next_percent))) -
1;
assert(stop_in_hist < histogram_size);
const auto splits = start_in_hist != stop_in_hist;
const auto frac_left =
splits ? static_cast<double>(start_in_hist) + 1.0 - curr_percent
: increm;
: increment;
const auto frac_right =
splits ? next_percent - static_cast<double>(stop_in_hist) : increm;
for (auto h_idx = start_in_hist; h_idx <= stop_in_hist; ++h_idx) {
const auto contrib = (h_idx == start_in_hist) ? frac_left
: (h_idx == stop_in_hist) ? frac_right
: 1.0;
hist[h_idx] += contrib * as_frac(gcs[i][gc_idx], increm);
}
splits ? next_percent - static_cast<double>(stop_in_hist) : increment;
const auto hist_begin = std::begin(hist) + start_in_hist;
const auto hist_end = std::cbegin(hist) + stop_in_hist;
const auto gc_val = as_frac(gc[gc_idx], increment);
for (auto hist_itr = hist_begin; hist_itr <= hist_end; ++hist_itr)
*hist_itr += gc_val * ((hist_itr == hist_begin) ? frac_left
: (hist_itr == hist_end) ? frac_right
: 1.0);
}
}
return hist;
Expand Down
Loading