A library for working with phylogenetic and population genetic data.
v0.32.0
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-2019 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 
216  void add_sequences( SequenceSet const& sequences, bool use_abundances = true );
217 
228  void clear();
229 
237  void clear_counts();
238 
239  // -------------------------------------------------------------------------
240  // Data Members
241  // -------------------------------------------------------------------------
242 
243 private:
244 
245  std::string characters_;
248  CountsIntType num_seqs_ = 0;
249 
250 };
251 
252 } // namespace sequence
253 } // namespace genesis
254 
255 #endif // include guard
genesis::sequence::SiteCounts::SiteCounts
SiteCounts()=default
Default constructor.
genesis::sequence::SiteCounts::added_sequences_count
CountsIntType added_sequences_count() const
Return the number of processed Sequences, i.e., how many Sequences were added in total.
Definition: counts.cpp:86
genesis::sequence::SiteCounts::clear
void clear()
Clear the object, that is, delete everything.
Definition: counts.cpp:177
genesis::sequence::SiteCounts::count_of
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
genesis::sequence::Sequence
Definition: sequence/sequence.hpp:40
genesis::sequence::SiteCounts::add_sequences
void add_sequences(SequenceSet const &sequences, bool use_abundances=true)
Process a SequenceSet and add its counts to the existing ones for all contained Sequences.
Definition: counts.cpp:170
genesis::sequence::SiteCounts::add_sequence
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
genesis::utils::Matrix< CountsIntType >
genesis::sequence::SiteCounts
Store counts of the occurence for certain characters at the sites of Sequences.
Definition: counts.hpp:85
genesis::sequence::SiteCounts::operator=
SiteCounts & operator=(SiteCounts const &)=default
Default copy assignment.
char_lookup.hpp
genesis::sequence::SiteCounts::length
size_t length() const
Return the number of sites used for counting.
Definition: counts.cpp:75
genesis::sequence::SiteCounts::clear_counts
void clear_counts()
Reset all counts to 0.
Definition: counts.cpp:185
matrix.hpp
genesis::utils::CharLookup< unsigned char >
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::sequence::SequenceSet
Store a set of Sequences.
Definition: sequence_set.hpp:53
genesis::sequence::SiteCounts::~SiteCounts
~SiteCounts()=default
Default destructor.
genesis::sequence::SiteCounts::CountsIntType
uint32_t CountsIntType
Type of uint used for internally counting the freuqencies of Sequence sites.
Definition: counts.hpp:101
genesis::sequence::SiteCounts::count_at
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
genesis::sequence::SiteCounts::characters
std::string characters() const
Return the character set that is used for counting.
Definition: counts.cpp:80