Skip to content

Commit

Permalink
enum class instead of enum
Browse files Browse the repository at this point in the history
  • Loading branch information
eaasna committed Apr 4, 2024
1 parent d41fd5c commit 4fa94a8
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 22 deletions.
3 changes: 1 addition & 2 deletions include/utilities/threshold/basics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ inline uint64_t combinations(size_t const k, size_t const n)
return 0;
}

enum search_kind {LEMMA, HEURISTIC, STELLAR};
enum class search_kind {LEMMA, HEURISTIC, STELLAR};

} //namespace valik

24 changes: 14 additions & 10 deletions include/utilities/threshold/search_kmer_profile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct search_error_profile
{
param_set params;
search_pattern pattern;
search_kind search_type{LEMMA};
search_kind search_type{search_kind::LEMMA};
double fnr;
double fp_per_pattern;
uint64_t max_segment_len;
Expand All @@ -44,7 +44,7 @@ struct search_error_profile
search_error_profile(param_set const & best_params, search_pattern const & eps_pattern, search_kind const which_search) :
params(best_params), pattern(eps_pattern), search_type(which_search)
{
if (which_search != STELLAR)
if (which_search != search_kind::STELLAR)
throw std::runtime_error("Provide FNR, FPR and maximum segment length.");
fnr = 0.0;
}
Expand All @@ -59,15 +59,19 @@ struct search_error_profile

void print()
{
if (search_type == STELLAR)
std::cout << "stellar-only" << "\tN/A\t" << fnr << "\tN/A\tN/A\n";
else
switch (search_type)
{
if (search_type == HEURISTIC)
std::cout << "heuristic";
else
std::cout << "kmer lemma";
std::cout << '\t' << std::to_string(params.t) << '\t' << fnr << '\t' << fp_per_pattern << '\t' << max_segment_len << '\n';
case search_kind::STELLAR: std::cout << "stellar-only" << "\tN/A\t" << fnr << "\tN/A\tN/A\n"; break;
default:
{
switch (search_type)
{
case search_kind::HEURISTIC: std::cout << "heuristic"; break;
case search_kind::LEMMA: std::cout << "kmer lemma"; break;
default: break;
}
std::cout << '\t' << std::to_string(params.t) << '\t' << fnr << '\t' << fp_per_pattern << '\t' << max_segment_len << '\n';
}
}
}
};
Expand Down
7 changes: 4 additions & 3 deletions include/valik/search/search_local.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ bool search_local(search_arguments & arguments, search_time_statistics & time_st
param_space space;
param_set params(arguments.shape_size, arguments.threshold, space);
filtering_request request(pattern, ref_meta, query_meta.value());
if ((request.fpr(params) > 0.2) && (arguments.search_type != STELLAR))
if ((request.fpr(params) > 0.2) && (arguments.search_type != search_kind::STELLAR))
std::cerr << "WARNING: Prefiltering will be inefficient for a high error rate.\n";

if (arguments.verbose)
Expand All @@ -102,8 +102,9 @@ bool search_local(search_arguments & arguments, search_time_statistics & time_st
std::cout << "kmer size " << std::to_string(arguments.shape_size) << '\n';
switch (arguments.search_type)
{
case HEURISTIC: std::cout << "heuristic "; break;
case LEMMA: std::cout << "k-mer lemma "; break;
case search_kind::LEMMA: std::cout << "k-mer lemma "; break;
//case search_kind::MINIMISER: std::cout << "minimiser "; break;
case search_kind::HEURISTIC: std::cout << "heuristic "; break;
default: break;
}
std::cout << "threshold ";
Expand Down
2 changes: 1 addition & 1 deletion include/valik/shared.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ struct search_profile_arguments
bool split_query{false};
bool manual_parameters{false};
//!TODO: make fourth option: MINIMISER
search_kind search_type{LEMMA};
search_kind search_type{search_kind::LEMMA};
double fnr;

protected:
Expand Down
3 changes: 2 additions & 1 deletion src/argument_parsing/search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ void init_search_parser(sharg::parser & parser, search_arguments & arguments)
.long_id = "max-queued-carts",
.description = "Maximal number of carts that are full and are waiting to be processed.",
.advanced = true});
//!TODO: add section for stellar options
parser.add_option(arguments.disableThresh,
sharg::config{.short_id = '\0',
.long_id = "disableThresh",
Expand Down Expand Up @@ -324,7 +325,7 @@ void run_search(sharg::parser & parser)
search_error_profile error_profile = search_profile.get_error_profile(arguments.errors);
// seg_count is inferred in metadata constructor
arguments.search_type = error_profile.search_type;
if (arguments.search_type == STELLAR)
if (arguments.search_type == search_kind::STELLAR)
{
std::cout << "Can not prefilter matches of length " << std::to_string(error_profile.pattern.l) <<
" with " << std::to_string(error_profile.pattern.e) << " errors. Searching without prefiltering.\n";
Expand Down
10 changes: 6 additions & 4 deletions src/threshold/find.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,14 @@ search_kmer_profile find_thresholds_for_kmer_size(metadata const & ref_meta,
for (uint8_t errors{0}; errors <= max_errors && errors <= space.max_errors; errors++)
{
search_pattern pattern(errors, ref_meta.pattern_size);
search_kind search_type{LEMMA};
search_kind search_type{search_kind::LEMMA};
auto best_params = param_set(attr.k, kmer_lemma_threshold(pattern.l, attr.k, errors), space);

//!TODO: determine suitable parameters
if ((best_params.t < 4) ||
(1 - pow(1 - ref_meta.pattern_spurious_match_prob(best_params), 5e3) > 0.05))
((1 - pow(1 - ref_meta.pattern_spurious_match_prob(best_params), 5e3)) > 0.05))
{
search_type = HEURISTIC;
search_type = search_kind::HEURISTIC;
double best_score = pattern.l;
for (uint8_t t{1}; t <= space.max_thresh; t++)
{
Expand All @@ -117,10 +118,11 @@ search_kmer_profile find_thresholds_for_kmer_size(metadata const & ref_meta,
}
}

//!TODO: find segment length cutoff
uint64_t max_len = ref_meta.max_segment_len(best_params);
if ((pattern.l * 100) > max_len)
{
search_type = STELLAR;
search_type = search_kind::STELLAR;
kmer_thresh.add_error_rate(errors, {best_params, pattern, search_type});
}
else
Expand Down
2 changes: 1 addition & 1 deletion src/valik_search.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void valik_search(search_arguments & arguments)
runtime_to_compile_time([&]<bool is_compressed, bool is_split, bool stellar_only>()
{
failed = search_local<is_compressed, is_split, stellar_only>(arguments, time_statistics);
}, arguments.compressed, arguments.split_query, (arguments.search_type == STELLAR));
}, arguments.compressed, arguments.split_query, (arguments.search_type == search_kind::STELLAR));
}

// Consolidate matches (not necessary when searching a metagenomic database)
Expand Down

0 comments on commit 4fa94a8

Please sign in to comment.