A library for working with phylogenetic and population genetic data.
v0.27.0
base_counts.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_POPULATION_BASE_COUNTS_H_
2 #define GENESIS_POPULATION_BASE_COUNTS_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2022 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 <lczech@carnegiescience.edu>
23  Department of Plant Biology, Carnegie Institution For Science
24  260 Panama Street, Stanford, CA 94305, USA
25 */
26 
34 #include <array>
35 #include <string>
36 #include <vector>
37 
38 namespace genesis {
39 namespace population {
40 
41 // =================================================================================================
42 // Base Counts
43 // =================================================================================================
44 
54 struct BaseCounts
55 {
59  size_t a_count = 0;
60 
64  size_t c_count = 0;
65 
69  size_t g_count = 0;
70 
74  size_t t_count = 0;
75 
79  size_t n_count = 0;
80 
84  size_t d_count = 0;
85 
89  void clear()
90  {
91  a_count = 0;
92  c_count = 0;
93  g_count = 0;
94  t_count = 0;
95  n_count = 0;
96  d_count = 0;
97  }
98 };
99 
100 // =================================================================================================
101 // Sorted Base Counts
102 // =================================================================================================
103 
111 {
115  struct BaseCount
116  {
117  char base;
118  size_t count;
119 
121  : base('N')
122  , count(0)
123  {}
124 
125  BaseCount( char b, size_t c )
126  : base(b)
127  , count(c)
128  {}
129  };
130 
131  SortedBaseCounts() = default;
132 
134  char b0, size_t c0, char b1, size_t c1, char b2, size_t c2, char b3, size_t c3
135  )
136  : data( std::array<BaseCount, 4>{
137  BaseCount{ b0, c0 }, BaseCount{ b1, c1 }, BaseCount{ b2, c2 }, BaseCount{ b3, c3 },
138  })
139  {}
140 
141  BaseCount& operator[]( size_t index )
142  {
143  return data[index];
144  }
145 
146  BaseCount const& operator[]( size_t index ) const
147  {
148  return data[index];
149  }
150 
151  std::array<BaseCount, 4> data;
152 };
153 
154 } // namespace population
155 } // namespace genesis
156 
157 #endif // include guard
genesis::population::SortedBaseCounts::BaseCount::BaseCount
BaseCount()
Definition: base_counts.hpp:120
genesis::population::SortedBaseCounts::operator[]
BaseCount & operator[](size_t index)
Definition: base_counts.hpp:141
genesis::population::BaseCounts::d_count
size_t d_count
Count of all deleted (*) nucleotides that are present in the sample.
Definition: base_counts.hpp:84
genesis::population::SortedBaseCounts::BaseCount
Combination of a nucleotide base and its count.
Definition: base_counts.hpp:115
genesis::population::SortedBaseCounts
Ordered array of base counts for the four nucleotides.
Definition: base_counts.hpp:110
genesis::population::BaseCounts::t_count
size_t t_count
Count of all T nucleotides that are present in the sample.
Definition: base_counts.hpp:74
genesis::population::SortedBaseCounts::BaseCount::BaseCount
BaseCount(char b, size_t c)
Definition: base_counts.hpp:125
genesis::population::BaseCounts::g_count
size_t g_count
Count of all G nucleotides that are present in the sample.
Definition: base_counts.hpp:69
genesis::population::BaseCounts::clear
void clear()
Reset all counts to 0.
Definition: base_counts.hpp:89
genesis::population::BaseCounts::a_count
size_t a_count
Count of all A nucleotides that are present in the sample.
Definition: base_counts.hpp:59
genesis::population::SortedBaseCounts::SortedBaseCounts
SortedBaseCounts()=default
genesis::population::SortedBaseCounts::SortedBaseCounts
SortedBaseCounts(char b0, size_t c0, char b1, size_t c1, char b2, size_t c2, char b3, size_t c3)
Definition: base_counts.hpp:133
genesis::population::BaseCounts::n_count
size_t n_count
Count of all N (undetermined/any) nucleotides that are present in the sample.
Definition: base_counts.hpp:79
genesis::population::SortedBaseCounts::BaseCount::base
char base
Definition: base_counts.hpp:117
genesis::population::SortedBaseCounts::data
std::array< BaseCount, 4 > data
Definition: base_counts.hpp:151
genesis::population::BaseCounts::c_count
size_t c_count
Count of all C nucleotides that are present in the sample.
Definition: base_counts.hpp:64
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::BaseCounts
One set of nucleotide base counts, for example for a given sample that represents a pool of sequenced...
Definition: base_counts.hpp:54
genesis::population::SortedBaseCounts::operator[]
BaseCount const & operator[](size_t index) const
Definition: base_counts.hpp:146
genesis::population::SortedBaseCounts::BaseCount::count
size_t count
Definition: base_counts.hpp:118