A library for working with phylogenetic and population genetic data.
v0.32.0
variant_filter_numerical.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_POPULATION_FILTER_VARIANT_FILTER_NUMERICAL_H_
2 #define GENESIS_POPULATION_FILTER_VARIANT_FILTER_NUMERICAL_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2024 Lucas Czech
7 
8  This program is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License as published by
10  the Free Software Foundation, either version 3 of the License, or
11  (at your option) any later version.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 
21  Contact:
22  Lucas Czech <lucas.czech@sund.ku.dk>
23  University of Copenhagen, Globe Institute, Section for GeoGenetics
24  Oster Voldgade 5-7, 1350 Copenhagen K, Denmark
25 */
26 
39 
40 #include <functional>
41 #include <iosfwd>
42 #include <memory>
43 #include <stdexcept>
44 #include <string>
45 #include <utility>
46 #include <vector>
47 
48 namespace genesis {
49 namespace population {
50 
51 // =================================================================================================
52 // Variant Filter Numerical Params
53 // =================================================================================================
54 
56 {
57  // -------------------------------------------
58  // Numeric
59  // -------------------------------------------
60 
69  size_t min_read_depth = 0;
70 
81  size_t max_read_depth = 0;
82 
93 
94  // -------------------------------------------
95  // SNP vs Invariant
96  // -------------------------------------------
97 
106  bool only_snps = false;
107 
118  bool only_biallelic_snps = false;
119 
128  size_t snp_min_count = 0;
129 
139  size_t snp_max_count = 0;
140 
155 };
156 
157 // =================================================================================================
158 // Variant Filter Numerical Functions
159 // =================================================================================================
160 
161 // --------------------------------------------------------------------------------------
162 // apply_variant_filter_numerical
163 // --------------------------------------------------------------------------------------
164 
174  Variant& variant,
175  VariantFilterNumericalParams const& params,
176  VariantFilterStats& stats
177 );
178 
186  Variant& variant,
187  VariantFilterNumericalParams const& params
188 );
189 
190 // --------------------------------------------------------------------------------------
191 // make_variant_filter_numerical_excluding
192 // --------------------------------------------------------------------------------------
193 
207  VariantFilterNumericalParams const& params
208 ) {
209  return [params]( Variant& variant ){
210  return apply_variant_filter_numerical( variant, params );
211  };
212 }
213 
220  VariantFilterNumericalParams const& params,
221  VariantFilterStats& stats
222 ) {
223  return [params, &stats]( Variant& variant ){
224  return apply_variant_filter_numerical( variant, params, stats );
225  };
226 }
227 
228 // --------------------------------------------------------------------------------------
229 // make_variant_filter_numerical_tagging
230 // --------------------------------------------------------------------------------------
231 
244 inline std::function<void(Variant&)> make_variant_filter_numerical_tagging(
245  VariantFilterNumericalParams const& params
246 ) {
247  return [params]( Variant& variant ){
248  apply_variant_filter_numerical( variant, params );
249  };
250 }
251 
257 inline std::function<void(Variant&)> make_variant_filter_numerical_tagging(
258  VariantFilterNumericalParams const& params,
259  VariantFilterStats& stats
260 ) {
261  return [params, &stats]( Variant& variant ){
262  apply_variant_filter_numerical( variant, params, stats );
263  };
264 }
265 
273 inline std::function<void(Variant&)> make_variant_filter_numerical_tagging(
274  SampleCountsFilterNumericalParams const& sample_count_params,
275  VariantFilterNumericalParams const& variant_params,
276  bool all_need_pass = false
277 ) {
278  return [sample_count_params, variant_params, all_need_pass]( Variant& variant ){
280  variant, sample_count_params, all_need_pass
281  );
282  apply_variant_filter_numerical( variant, variant_params );
283  };
284 }
285 
296 inline std::function<void(Variant&)> make_variant_filter_numerical_tagging(
297  SampleCountsFilterNumericalParams const& sample_count_params,
298  VariantFilterNumericalParams const& variant_params,
299  VariantFilterStats& variant_stats,
300  SampleCountsFilterStats& sample_count_stats,
301  bool all_need_pass = false
302 ) {
303  return [variant_params, sample_count_params, &variant_stats, &sample_count_stats, all_need_pass](
304  Variant& variant
305  ){
307  variant, sample_count_params, variant_stats, sample_count_stats, all_need_pass
308  );
309  apply_variant_filter_numerical( variant, variant_params, variant_stats );
310  };
311 }
312 
313 } // namespace population
314 } // namespace genesis
315 
316 #endif // include guard
genesis::population::VariantFilterNumericalParams::snp_max_count
size_t snp_max_count
Maximum count for each nucleotide to be considered a SNP for the whole Variant.
Definition: variant_filter_numerical.hpp:139
genesis::population::SampleCountsFilterNumericalParams
Filter settings to filter and transform SampleCounts.
Definition: sample_counts_filter_numerical.hpp:123
sample_counts_filter_numerical.hpp
genesis::population::VariantFilterNumericalParams
Definition: variant_filter_numerical.hpp:55
genesis::population::VariantFilterNumericalParams::snp_min_count
size_t snp_min_count
Minimum count for each nucleotide to be considered a SNP for the whole Variant.
Definition: variant_filter_numerical.hpp:128
genesis::population::VariantFilterNumericalParams::only_biallelic_snps
bool only_biallelic_snps
Filter if the Variant does not have exactly two alleles.
Definition: variant_filter_numerical.hpp:118
genesis::population::VariantFilterNumericalParams::deletions_count_limit
size_t deletions_count_limit
Maximum number of deletions at a position before being filtered out.
Definition: variant_filter_numerical.hpp:92
sample_counts_filter.hpp
genesis::population::make_variant_filter_numerical_excluding
std::function< bool(Variant &)> make_variant_filter_numerical_excluding(VariantFilterNumericalParams const &params)
Return a functional to numerically filter Variants in an VariantInputStream, excluding the ones that ...
Definition: variant_filter_numerical.hpp:206
sample_counts.hpp
genesis::population::VariantFilterNumericalParams::max_read_depth
size_t max_read_depth
Maximum read depth expected for the whole Variant to be considered covered.
Definition: variant_filter_numerical.hpp:81
genesis::population::apply_sample_counts_filter_numerical
bool apply_sample_counts_filter_numerical(SampleCounts &sample, SampleCountsFilterNumericalParams const &params, SampleCountsFilterStats &stats)
Filter a given SampleCounts based on the numerical properties of the counts.
Definition: sample_counts_filter_numerical.cpp:115
genesis::population::make_variant_filter_numerical_tagging
std::function< void(Variant &)> make_variant_filter_numerical_tagging(VariantFilterNumericalParams const &params)
Return a functional to numerically filter Variants in an VariantInputStream, tagging the ones that do...
Definition: variant_filter_numerical.hpp:244
genesis::population::Variant
A single variant at a position in a chromosome, along with SampleCounts for a set of samples.
Definition: variant.hpp:65
genesis
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
Definition: placement/formats/edge_color.cpp:42
genesis::population::VariantFilterNumericalParams::min_read_depth
size_t min_read_depth
Minimum read depth expected for the whole Variant to be considered covered.
Definition: variant_filter_numerical.hpp:69
variant_filter.hpp
genesis::population::FilterStats
Counts of how many entries with a particular Filter Tag occured in some data.
Definition: filter_stats.hpp:61
variant.hpp
genesis::population::apply_variant_filter_numerical
bool apply_variant_filter_numerical(Variant &variant, VariantFilterNumericalParams const &params, VariantFilterStats &stats)
Filter a given Variant based on the numerical properties of the counts.
Definition: variant_filter_numerical.cpp:50
genesis::population::VariantFilterNumericalParams::only_snps
bool only_snps
Filter if the Variant does not have two or more alleles.
Definition: variant_filter_numerical.hpp:106
genesis::population::VariantFilterNumericalParams::snp_min_allele_frequency
double snp_min_allele_frequency
Minimum allele frequency that needs to be achieved.
Definition: variant_filter_numerical.hpp:154