|
A library for working with phylogenetic and population genetic data.
v0.32.0
|
|
Go to the documentation of this file. 1 #ifndef GENESIS_POPULATION_FUNCTION_WINDOW_AVERAGE_H_
2 #define GENESIS_POPULATION_FUNCTION_WINDOW_AVERAGE_H_
51 namespace population {
151 size_t window_length = 0;
152 for(
auto const& chr_len : window.
chromosomes() ) {
153 window_length += chr_len.second;
155 return window_length;
159 return window.
width();
168 std::shared_ptr<GenomeLocusSet> provided_loci
171 if( !provided_loci ) {
172 throw std::invalid_argument(
173 "Cannot comput window average denominator from provided loci mask, "
174 "as no such mask was provided."
180 auto get_chr_loci_count_ = [&provided_loci]( std::string
const& chr,
size_t first,
size_t last )
183 if( first == 0 || last == 0 || first > last ) {
184 throw std::invalid_argument(
187 "\" for computing provided loci mask window denominator."
193 throw std::runtime_error(
194 "Cannot compute provided loci on chromosome \"" + chr +
195 "\", as the provided loci mask does not contain the chromosome."
203 throw std::invalid_argument(
204 "Invvalid provided loci mask with bit 0 set."
209 if( last >= bv.size() ) {
210 throw std::runtime_error(
211 "Cannot compute provided loci on chromosome \"" + chr +
212 "\", as the provided loci mask for the chromosome has length " +
213 std::to_string( bv.size() - 1 ) +
", but the window covers positions " +
220 return bv.count( first, last + 1 );
230 size_t loci_count = 0;
231 for(
auto const& chr_len : window.
chromosomes() ) {
232 loci_count += get_chr_loci_count_( chr_len.first, 1, chr_len.second );
240 return get_chr_loci_count_(
260 std::shared_ptr<GenomeLocusSet> provided_loci,
276 throw std::invalid_argument(
277 "Invalid stat counts with sample_counts_filter_stats.sum() > "
278 "variant_filter_stats[VariantFilterTag::kPassed]"
291 return variant_filter_stats.
sum() - missing;
303 return valid_non_snps + valid_snps;
315 throw std::invalid_argument(
"Invalid WindowAveragePolicy" );
318 return std::numeric_limits<double>::quiet_NaN();
324 #endif // include guard
utils::Bitvector const & chromosome_positions(std::string const &chromosome) const
For a given chromosome, return the Bitvector that stores its positions.
size_t get_window_provided_loci_count(BaseWindow< D > const &window, std::shared_ptr< GenomeLocusSet > provided_loci)
Get the count of provided loci in a window.
bool has_chromosome(std::string const &chromosome) const
Return whether a chromosome is stored.
@ kPassed
SampleCounts has passed all filters.
std::unordered_map< std::string, size_t > const & chromosomes() const
Get the list of all chromosomes along the genome, with their length.
VariantFilterCategoryStats variant_filter_stats_category_counts(VariantFilterStats const &stats)
Generate summary counts for a VariantFilterStats counter.
@ kInvariant
Postion is not a SNP according to the SNP filters.
std::string to_string(GenomeLocus const &locus)
@ kMissingInvalid
Position is missing or otherwise invalid.
size_t width() const
Get the width of the Window.
std::string const & chromosome() const
Get the chromosome name that this Window belongs to.
@ kWindowLength
Use the window length.
@ kSum
Simply report the total sum, with no averaging, i.e., the absolute value of the metric.
bool is_whole_genome() const
Return if this instance is intended to be used for a whole genome stream.
SampleCountsFilterCategoryStats sample_counts_filter_stats_category_counts(SampleCountsFilterStats const &stats)
Generate summary counts for a SampleCountsFilterStats counter.
@ kPassed
Sample has passed all filters.
Container namespace for all symbols of genesis in order to keep them separate when used as a library.
double window_average_denominator(WindowAveragePolicy policy, BaseWindow< D > const &window, std::shared_ptr< GenomeLocusSet > provided_loci, VariantFilterStats const &variant_filter_stats, SampleCountsFilterStats const &sample_counts_filter_stats)
Get the denoninator to use for averaging an estimator across a window.
@ kAvailableLoci
Use the number of positions for which there was data at all, independent of all filter settings....
size_t get_window_length(BaseWindow< D > const &window)
Get the length of a given Window.
WindowAveragePolicy
Select the method to use for computing window averages of statistic estimators.
@ kValidSnps
Use the number of SNPs only.
size_t first_position() const
Get the first position in the chromosome of the Window, that is, where the Window starts.
@ kValidLoci
Use the number of positions that passed all quality and numerical filters, excluding the SNP-related ...
Counts of how many entries with a particular Filter Tag occured in some data.
size_t last_position() const
Get the last position in the chromosome of the Window, that is, where the Window ends.
Base class for Window and WindowView, to share common functionality.
@ kProvidedLoci
Use exactly the provided loci as set in the window of a GenomeLocusSet.
@ kPassed
Variant has passed all filters.