A library for working with phylogenetic and population genetic data.
v0.27.0
af_spectrum.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_POPULATION_WINDOW_AF_SPECTRUM_H_
2 #define GENESIS_POPULATION_WINDOW_AF_SPECTRUM_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2020 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@h-its.org>
23  Exelixis Lab, Heidelberg Institute for Theoretical Studies
24  Schloss-Wolfsbrunnenweg 35, D-69118 Heidelberg, Germany
25 */
26 
34 #ifdef GENESIS_HTSLIB
35 
36 #include <functional>
37 #include <string>
38 #include <utility>
39 #include <vector>
40 
45 
46 namespace genesis {
47 namespace population {
48 
49 // =================================================================================================
50 // Allele Frequency Window
51 // =================================================================================================
52 
57 {
58 public:
59 
60  // -------------------------------------------------------------------------
61  // Typedefs and Enums
62  // -------------------------------------------------------------------------
63 
67 
68  // -------------------------------------------------------------------------
69  // Constructors and Rule of Five
70  // -------------------------------------------------------------------------
71 
72  AlleleFrequencyWindow( size_t width, size_t number_of_bins = 100 );
74 
75  AlleleFrequencyWindow( AlleleFrequencyWindow const& ) = default;
77 
80 
81  // -------------------------------------------------------------------------
82  // Event Plugin Functionals
83  // -------------------------------------------------------------------------
84 
85  std::function<void( Spectrum const& )> on_chromosome_start;
86  std::function<void( Spectrum const& )> on_chromosome_finish;
87 
88  // -------------------------------------------------------------------------
89  // Settings
90  // -------------------------------------------------------------------------
91 
92  size_t number_of_bins() const
93  {
94  return number_of_bins_;
95  }
96 
97  bool skip_invalid_records() const
98  {
99  return skip_invalid_records_;
100  }
101 
103  {
104  skip_invalid_records_ = value;
105  return *this;
106  }
107 
108  // -------------------------------------------------------------------------
109  // Window Processing
110  // -------------------------------------------------------------------------
111 
112  void run_vcf( std::string const& vcf_file );
113 
114  void enqueue( std::string const& chromosome, size_t position, double frequency );
115  void enqueue( VcfRecord const& record );
116 
117  // -------------------------------------------------------------------------
118  // Internal Members
119  // -------------------------------------------------------------------------
120 
121 private:
122 
123  void on_chromosome_start_( std::string const& chromosome, AFWindow::Accumulator& );
124 
125  void on_chromosome_finish_( std::string const& chromosome, AFWindow::Accumulator& );
126 
127  void on_emission_( AFWindow const& window );
128 
129  // -------------------------------------------------------------------------
130  // Data Members
131  // -------------------------------------------------------------------------
132 
133 private:
134 
135  size_t number_of_bins_;
136  bool skip_invalid_records_ = true;
137 
138  SlidingWindowGenerator<double> window_generator_;
139  std::vector<Spectrum> spectra_;
140 
141 };
142 
143 } // namespace population
144 } // namespace genesis
145 
146 #endif // htslib guard
147 #endif // include guard
genesis::population::AlleleFrequencyWindow::AlleleFrequencyWindow
AlleleFrequencyWindow(size_t width, size_t number_of_bins=100)
Definition: af_spectrum.cpp:52
genesis::population::AlleleFrequencyWindow::~AlleleFrequencyWindow
~AlleleFrequencyWindow()
Definition: af_spectrum.cpp:70
genesis::population::AlleleFrequencyWindow
Definition: af_spectrum.hpp:56
genesis::population::Window
Window over the chromosomes of a genome.
Definition: window.hpp:104
genesis::population::AlleleFrequencyWindow::on_chromosome_start
std::function< void(Spectrum const &)> on_chromosome_start
Definition: af_spectrum.hpp:85
genesis::population::AlleleFrequencyWindow::AFWindow
Window< double > AFWindow
Definition: af_spectrum.hpp:64
genesis::population::AlleleFrequencyWindow::operator=
AlleleFrequencyWindow & operator=(AlleleFrequencyWindow const &)=default
heatmap_colorization.hpp
genesis::population::AlleleFrequencyWindow::skip_invalid_records
bool skip_invalid_records() const
Definition: af_spectrum.hpp:97
genesis::population::AlleleFrequencyWindow::number_of_bins
size_t number_of_bins() const
Definition: af_spectrum.hpp:92
genesis::population::AlleleFrequencyWindow::skip_invalid_records
self_type & skip_invalid_records(bool value)
Definition: af_spectrum.hpp:102
genesis::population::Window::Accumulator
A Accumulator
Definition: window.hpp:113
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::AlleleFrequencyWindow::enqueue
void enqueue(std::string const &chromosome, size_t position, double frequency)
Definition: af_spectrum.cpp:86
window.hpp
genesis::population::HeatmapColorization::Spectrum
Definition: heatmap_colorization.hpp:64
genesis::population::AlleleFrequencyWindow::on_chromosome_finish
std::function< void(Spectrum const &)> on_chromosome_finish
Definition: af_spectrum.hpp:86
genesis::population::VcfRecord
Capture the information of a single SNP/variant line in a VCF/BCF file.
Definition: vcf_record.hpp:107
vcf_record.hpp
genesis::population::AlleleFrequencyWindow::run_vcf
void run_vcf(std::string const &vcf_file)
Definition: af_spectrum.cpp:79
sliding_window_generator.hpp
genesis::population::SlidingWindowGenerator< double >