fastq_to_fasta
A template for creation of SeqAn3 apps, with a FASTQ to FASTA example app.
threshold.hpp
Go to the documentation of this file.
1// --------------------------------------------------------------------------------------------------
2// Copyright (c) 2006-2022, Knut Reinert & Freie Universität Berlin
3// Copyright (c) 2016-2022, Knut Reinert & MPI für molekulare Genetik
4// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
5// shipped with this file and also available at: https://github.com/seqan/raptor/blob/main/LICENSE.md
6// --------------------------------------------------------------------------------------------------
7
8#pragma once
9
12
13namespace raptor::threshold
14{
15
17{
18public:
19 threshold() = default;
20 threshold(threshold const &) = default;
21 threshold & operator=(threshold const &) = default;
22 threshold(threshold &&) = default;
23 threshold & operator=(threshold &&) = default;
24 ~threshold() = default;
25
27 {
28 uint8_t const kmer_size{arguments.shape.size()};
29 size_t const kmers_per_window = arguments.window_size - kmer_size + 1;
30
31 if (!std::isnan(arguments.percentage))
32 {
33 threshold_kind = threshold_kinds::percentage;
34 threshold_percentage = arguments.percentage;
35 }
36 else if (kmers_per_window == 1u)
37 {
38 threshold_kind = threshold_kinds::lemma;
39 size_t const kmer_lemma_minuend = arguments.pattern_size + 1u;
40 size_t const kmer_lemma_subtrahend = (arguments.errors + 1u) * kmer_size;
41 kmer_lemma = kmer_lemma_minuend > kmer_lemma_subtrahend ? kmer_lemma_minuend - kmer_lemma_subtrahend : 0;
42 }
43 else
44 {
45 threshold_kind = threshold_kinds::probabilistic;
46 size_t const kmers_per_pattern = arguments.pattern_size - kmer_size + 1;
47 minimal_number_of_minimizers = kmers_per_pattern / kmers_per_window;
48 maximal_number_of_minimizers = arguments.pattern_size - arguments.window_size + 1;
49 precomp_correction = precompute_correction(arguments);
50 precomp_thresholds = precompute_threshold(arguments);
51 }
52 }
53
54 size_t get(size_t const minimiser_count) const noexcept
55 {
56 switch (threshold_kind)
57 {
58 case threshold_kinds::lemma:
59 return kmer_lemma;
60 case threshold_kinds::percentage:
61 return static_cast<size_t>(minimiser_count * threshold_percentage);
62 default:
63 {
64 assert(threshold_kind == threshold_kinds::probabilistic);
65 size_t const index = std::clamp(minimiser_count, minimal_number_of_minimizers, maximal_number_of_minimizers)
66 - minimal_number_of_minimizers;
67 return precomp_thresholds[index] + precomp_correction[index];
68 }
69 }
70 }
71
72private:
73 enum class threshold_kinds
74 {
75 probabilistic,
76 lemma,
77 percentage
78 };
79
80 threshold_kinds threshold_kind{threshold_kinds::probabilistic};
81 std::vector<size_t> precomp_correction{};
82 std::vector<size_t> precomp_thresholds{};
83 size_t kmer_lemma{};
84 size_t minimal_number_of_minimizers{};
85 size_t maximal_number_of_minimizers{};
86 double threshold_percentage{};
87};
88
89} // namespace raptor::threshold
Definition: threshold.hpp:17
threshold(threshold const &)=default
threshold & operator=(threshold &&)=default
threshold(threshold_parameters const &arguments)
Definition: threshold.hpp:26
threshold(threshold &&)=default
threshold & operator=(threshold const &)=default
size_t get(size_t const minimiser_count) const noexcept
Definition: threshold.hpp:54
Definition: forward_strand_minimiser.hpp:19
std::vector< size_t > precompute_correction(threshold_parameters const &arguments)
Definition: precompute_correction.cpp:60
std::vector< size_t > precompute_threshold(threshold_parameters const &arguments)
Definition: precompute_threshold.cpp:61
Definition: threshold_parameters.hpp:18
uint32_t window_size
Definition: threshold_parameters.hpp:20
double percentage
Definition: threshold_parameters.hpp:26
uint8_t errors
Definition: threshold_parameters.hpp:25
uint64_t pattern_size
Definition: threshold_parameters.hpp:22
seqan3::shape shape
Definition: threshold_parameters.hpp:21