A toolkit for working with phylogenetic data.
v0.18.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
counts.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_SEQUENCE_COUNTS_H_
2 #define GENESIS_SEQUENCE_COUNTS_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2017 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 
36 
37 #include <cstdint>
38 #include <string>
39 
40 namespace genesis {
41 namespace sequence {
42 
43 // =================================================================================================
44 // Forwardd Declarations
45 // =================================================================================================
46 
47 class Sequence;
48 class SequenceSet;
49 
50 // =================================================================================================
51 // Sequence Counts
52 // =================================================================================================
53 
85 {
86 public:
87 
88  // -------------------------------------------------------------------------
89  // Typedefs and Enums
90  // -------------------------------------------------------------------------
91 
100  using CountsIntType = uint32_t;
101 
102  // -------------------------------------------------------------------------
103  // Constructors and Rule of Five
104  // -------------------------------------------------------------------------
105 
113  SequenceCounts() = default;
114 
119  SequenceCounts( std::string const& characters, size_t length );
120 
124  ~SequenceCounts() = default;
125 
129  SequenceCounts( SequenceCounts const& ) = default;
130 
134  SequenceCounts( SequenceCounts&& ) = default;
135 
139  SequenceCounts& operator= ( SequenceCounts const& ) = default;
140 
144  SequenceCounts& operator= ( SequenceCounts&& ) = default;
145 
146  // -------------------------------------------------------------------------
147  // Accessors
148  // -------------------------------------------------------------------------
149 
155  size_t length() const;
156 
163  std::string characters() const;
164 
170 
177  CountsIntType count_of( char character, size_t site_index ) const;
178 
185  CountsIntType count_at( size_t character_index, size_t site_index ) const;
186 
187  // std::vector< CountsIntType> counts_at( size_t site_index ) const;
188 
189  // -------------------------------------------------------------------------
190  // Modifiers
191  // -------------------------------------------------------------------------
192 
196  void add_sequence( Sequence const& sequence );
197 
201  void add_sequence( std::string const& sites );
202 
207  void add_sequences( SequenceSet const& sequences );
208 
219  void clear();
220 
228  void clear_counts();
229 
230  // -------------------------------------------------------------------------
231  // Data Members
232  // -------------------------------------------------------------------------
233 
234 private:
235 
236  std::string characters_;
239  CountsIntType num_seqs_ = 0;
240 
241 };
242 
243 } // namespace sequence
244 } // namespace genesis
245 
246 #endif // include guard
Store counts of the occurence for certain characters of Sequences.
Definition: counts.hpp:84
CountsIntType added_sequences_count() const
Return the number of processed Sequences, i.e., how many Sequences were added in total.
Definition: counts.cpp:86
void add_sequence(Sequence const &sequence)
Process a single Sequence and add its counts to the existing ones.
Definition: counts.cpp:131
CountsIntType count_of(char character, size_t site_index) const
Return the count of a specific character at a given site.
Definition: counts.cpp:91
void clear()
Clear the object, that is, delete everything.
Definition: counts.cpp:173
uint32_t CountsIntType
Type of uint used for internally counting the freuqencies of Sequence sites.
Definition: counts.hpp:100
size_t length() const
Return the number of sites used for counting.
Definition: counts.cpp:75
void add_sequences(SequenceSet const &sequences)
Process a SequenceSet and add its counts to the existing ones for all contained Sequences.
Definition: counts.cpp:166
void clear_counts()
Reset all counts to 0.
Definition: counts.cpp:181
SequenceCounts & operator=(SequenceCounts const &)=default
Default copy assignment.
SequenceCounts()=default
Default constructor.
Store a set of Sequences.
std::string characters() const
Return the character set that is used for counting.
Definition: counts.cpp:80
~SequenceCounts()=default
Default destructor.
CountsIntType count_at(size_t character_index, size_t site_index) const
Return the count for a character and a site, given their indices.
Definition: counts.cpp:109