A toolkit for working with phylogenetic data.
v0.20.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-2018 Lucas Czech and HITS gGmbH
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 
86 {
87 public:
88 
89  // -------------------------------------------------------------------------
90  // Typedefs and Enums
91  // -------------------------------------------------------------------------
92 
101  using CountsIntType = uint32_t;
102 
103  // -------------------------------------------------------------------------
104  // Constructors and Rule of Five
105  // -------------------------------------------------------------------------
106 
114  SiteCounts() = default;
115 
120  SiteCounts( std::string const& characters, size_t length );
121 
125  ~SiteCounts() = default;
126 
130  SiteCounts( SiteCounts const& ) = default;
131 
135  SiteCounts( SiteCounts&& ) = default;
136 
140  SiteCounts& operator= ( SiteCounts const& ) = default;
141 
145  SiteCounts& operator= ( SiteCounts&& ) = default;
146 
147  // -------------------------------------------------------------------------
148  // Accessors
149  // -------------------------------------------------------------------------
150 
156  size_t length() const;
157 
164  std::string characters() const;
165 
171 
178  CountsIntType count_of( char character, size_t site_index ) const;
179 
186  CountsIntType count_at( size_t character_index, size_t site_index ) const;
187 
188  // std::vector< CountsIntType> counts_at( size_t site_index ) const;
189 
190  // -------------------------------------------------------------------------
191  // Modifiers
192  // -------------------------------------------------------------------------
193 
200  void add_sequence( Sequence const& sequence, bool use_abundance = true );
201 
207  void add_sequence( std::string const& sites, CountsIntType weight = 1 );
208 
213  void add_sequences( SequenceSet const& sequences );
214 
225  void clear();
226 
234  void clear_counts();
235 
236  // -------------------------------------------------------------------------
237  // Data Members
238  // -------------------------------------------------------------------------
239 
240 private:
241 
242  std::string characters_;
245  CountsIntType num_seqs_ = 0;
246 
247 };
248 
249 } // namespace sequence
250 } // namespace genesis
251 
252 #endif // include guard
void clear()
Clear the object, that is, delete everything.
Definition: counts.cpp:177
Store counts of the occurence for certain characters at the sites of Sequences.
Definition: counts.hpp:85
SiteCounts()=default
Default constructor.
void add_sequence(Sequence const &sequence, bool use_abundance=true)
Process a single Sequence and add its counts to the existing ones.
Definition: counts.cpp:131
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_sequences(SequenceSet const &sequences)
Process a SequenceSet and add its counts to the existing ones for all contained Sequences.
Definition: counts.cpp:170
SiteCounts & operator=(SiteCounts const &)=default
Default copy assignment.
void clear_counts()
Reset all counts to 0.
Definition: counts.cpp:185
~SiteCounts()=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
Store a set of Sequences.
size_t length() const
Return the number of sites used for counting.
Definition: counts.cpp:75
uint32_t CountsIntType
Type of uint used for internally counting the freuqencies of Sequence sites.
Definition: counts.hpp:101
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
std::string characters() const
Return the character set that is used for counting.
Definition: counts.cpp:80