Skip to content

Commit

Permalink
Refine handling of positions with deletions and add respective options
Browse files Browse the repository at this point in the history
  • Loading branch information
lczech committed Sep 12, 2023
1 parent 9f41c89 commit 1fefbcb
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 31 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ include( "${CMAKE_CURRENT_LIST_DIR}/tools/cmake/DownloadDependency.cmake" )
# These are replaced by tools/cmake/update_dependencies.sh to the hashes that are currently checked out.
# Thus, do not replace the hashes manually!
SET( CLI11_COMMIT_HASH "5cb3efabce007c3a0230e4cc2e27da491c646b6c" ) #CLI11_COMMIT_HASH#
SET( genesis_COMMIT_HASH "9a25dfeffcb4fea481c5437725904ed4514da559" ) #genesis_COMMIT_HASH#
SET( genesis_COMMIT_HASH "1b12550964abb4c2bc421cd9547fe149b563830e" ) #genesis_COMMIT_HASH#

# Call the github download function, which takes four arguments:
# - LIBPATH : Path to the libracy dir where dependencies are stored.
Expand Down
8 changes: 4 additions & 4 deletions src/commands/analyze/fst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void setup_fst( CLI::App& app )
"--method",
options->method.value,
"FST method to use for the computation.\n(1) The unbiased pool-sequencing statistic "
"(in two variants, following the definition of Nei, and the definition of Hudson et al),"
"(in two variants, following the definition of Nei, and the definition of Hudson),"
"\n(2) the statistic by Kofler et al of PoPoolation2, or \n(3) the asymptotically unbiased "
"estimator of Karlsson et al (which is also implemented in PoPoolation2). "
"\nAll except for the Karlsson method also require `--pool-sizes` to be provided."
Expand Down Expand Up @@ -836,9 +836,9 @@ void run_fst( FstOptions const& options )
);
genesis::population::VariantFilter total_filter;
total_filter.only_snps = true;
if( state.method == FstMethod::kKarlsson ) {
total_filter.only_biallelic_snps = true;
}
// if( state.method == FstMethod::kKarlsson ) {
// total_filter.only_biallelic_snps = true;
// }
options.variant_input.add_combined_filter_and_transforms(
options.filter_numerical.make_total_filter( total_filter )
);
Expand Down
64 changes: 43 additions & 21 deletions src/options/variant_filter_numerical.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ void VariantFilterNumericalOptions::add_sample_filter_opts_to_app(
add_sample_count_filter_opts_to_app( sub, true, true, group );
add_sample_coverage_filter_opts_to_app( sub, true, true, group );
add_sample_snp_filter_opts_to_app( sub, true, true, group );

// TODO include?!
// CliOption<bool> sample_tolerate_deletions = false;
}


Expand All @@ -73,7 +70,9 @@ void VariantFilterNumericalOptions::add_sample_count_filter_opts_to_app(
sample_min_count.value,
"Minimum base count for a nucleotide (in `ACGT`) to be considered as an allele. "
"Counts below that are set to zero, and hence ignored as an allele/variant. "
"For example, singleton read sequencing errors can be filtered out this way."
"For example, singleton read sequencing errors can be filtered out this way. "
"This min count is also used for filtering base counts with "
"too many deletions, unless `--filter-sample-tolerate-deletions` is set."
);
sample_min_count.option->group( group );
}
Expand All @@ -89,6 +88,15 @@ void VariantFilterNumericalOptions::add_sample_count_filter_opts_to_app(
);
sample_max_count.option->group( group );
}

// Add tolerate deletions flag
sample_tolerate_deletions.option = sub->add_flag(
"--filter-sample-tolerate-deletions",
sample_tolerate_deletions.value,
"By default, we filter out any samples that have too many deletions (based on "
"`--filter-sample-min-count`). With this flag however, such samples are retained."
);
sample_tolerate_deletions.option->group( group );
}

void VariantFilterNumericalOptions::add_sample_coverage_filter_opts_to_app(
Expand Down Expand Up @@ -251,33 +259,43 @@ void VariantFilterNumericalOptions::add_total_snp_filter_opts_to_app(

void VariantFilterNumericalOptions::add_total_snp_count_opts_to_app(
CLI::App* sub,
bool add_total_min_count_for_snp,
bool add_total_max_count_for_snp,
bool add_total_min_count,
bool add_total_max_count,
std::string const& group
) {
// Add min count for snps filter
if( add_total_min_count_for_snp ) {
total_min_count_for_snp.option = sub->add_option(
"--filter-total-snp-min-count",
total_min_count_for_snp.value,
if( add_total_min_count ) {
total_min_count.option = sub->add_option(
"--filter-total-min-count",
total_min_count.value,
"When filtering for positions that are SNPs, use this minimum count (summed across all "
"samples) to identify what is considered a SNP. Positions where the counts are below "
"this are filtered out."
"this are filtered out. This min count is also used for filtering positions with "
"too many deletions, unless `--filter-total-tolerate-deletions` is set."
);
total_min_count_for_snp.option->group( group );
total_min_count.option->group( group );
}

// Add max count for snps filter
if( add_total_max_count_for_snp ) {
total_max_count_for_snp.option = sub->add_option(
"--filter-total-snp-max-count",
total_max_count_for_snp.value,
if( add_total_max_count ) {
total_max_count.option = sub->add_option(
"--filter-total-max-count",
total_max_count.value,
"When filtering for positions that are SNPs, use this maximum count (summed across all "
"samples) to identify what is considered a SNP. Positions where the counts are above "
"this are filtered out; probably not relevant in practice, but offered for completeness."
);
total_max_count_for_snp.option->group( group );
total_max_count.option->group( group );
}

// Add tolerate deletions flag
total_tolerate_deletions.option = sub->add_flag(
"--filter-total-tolerate-deletions",
total_tolerate_deletions.value,
"By default, we filter out any positions that have too many deletions (based on "
"`--filter-total-min-count`). With this flag however, such positions are retained."
);
total_tolerate_deletions.option->group( group );
}

void VariantFilterNumericalOptions::add_total_freq_filter_opts_to_app(
Expand Down Expand Up @@ -405,18 +423,22 @@ VariantFilterNumericalOptions::get_total_filter(
filter.only_biallelic_snps = total_only_biallelic_snps.value;
any_provided = true;
}
if( total_min_count_for_snp.option && *total_min_count_for_snp.option ) {
filter.min_count_for_snp = total_min_count_for_snp.value;
if( total_min_count.option && *total_min_count.option ) {
filter.min_count = total_min_count.value;
any_provided = true;
}
if( total_max_count_for_snp.option && *total_max_count_for_snp.option ) {
filter.max_count_for_snp = total_max_count_for_snp.value;
if( total_max_count.option && *total_max_count.option ) {
filter.max_count = total_max_count.value;
any_provided = true;
}
if( total_min_frequency.option && *total_min_frequency.option ) {
filter.min_frequency = total_min_frequency.value;
any_provided = true;
}
if( total_tolerate_deletions.option && *total_tolerate_deletions.option ) {
filter.tolerate_deletions = total_tolerate_deletions.value;
any_provided = true;
}

return std::make_pair( filter, any_provided );
}
Expand Down
9 changes: 5 additions & 4 deletions src/options/variant_filter_numerical.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,8 @@ class VariantFilterNumericalOptions

void add_total_snp_count_opts_to_app(
CLI::App* sub,
bool add_total_min_count_for_snp = true,
bool add_total_max_count_for_snp = true,
bool add_total_min_count = true,
bool add_total_max_count = true,
std::string const& group = "Numerical Filters"
);

Expand Down Expand Up @@ -220,9 +220,10 @@ class VariantFilterNumericalOptions
CliOption<size_t> total_max_coverage = 0;
CliOption<bool> total_only_snps = false;
CliOption<bool> total_only_biallelic_snps = false;
CliOption<size_t> total_min_count_for_snp = 0;
CliOption<size_t> total_max_count_for_snp = 0;
CliOption<size_t> total_min_count = 0;
CliOption<size_t> total_max_count = 0;
CliOption<double> total_min_frequency = 0.0;
CliOption<bool> total_tolerate_deletions = false;

private:

Expand Down

0 comments on commit 1fefbcb

Please sign in to comment.