A library for working with phylogenetic and population genetic data.
v0.32.0
sequence/sequence.hpp
Go to the documentation of this file.
1 #ifndef GENESIS_SEQUENCE_SEQUENCE_H_
2 #define GENESIS_SEQUENCE_SEQUENCE_H_
3 
4 /*
5  Genesis - A toolkit for working with phylogenetic data.
6  Copyright (C) 2014-2020 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 
34 #include <string>
35 #include <vector>
36 
37 namespace genesis {
38 namespace sequence {
39 
40 class Sequence
41 {
42 public:
43 
44  // -------------------------------------------------------------------------
45  // Typedefs and Enums
46  // -------------------------------------------------------------------------
47 
48  typedef std::string::iterator iterator;
49  typedef std::string::const_iterator const_iterator;
50 
51  // -------------------------------------------------------------------------
52  // Constructors and Rule of Five
53  // -------------------------------------------------------------------------
54 
55  Sequence() = default;
56 
57  Sequence( std::string const& label, std::string const& sites, size_t abundance = 1 )
58  : label_(label)
59  , sites_(sites)
60  , abundance_(abundance)
61  {}
62 
63  ~Sequence() = default;
64 
65  Sequence( Sequence const& ) = default;
66  Sequence( Sequence&& ) = default;
67 
68  Sequence& operator= ( Sequence const& ) = default;
69  Sequence& operator= ( Sequence&& ) = default;
70 
71  void swap( Sequence& other )
72  {
73  using std::swap;
74  swap( label_, other.label_ );
75  swap( sites_, other.sites_ );
76  }
77 
78  void clear()
79  {
80  label_.clear();
81  sites_.clear();
82  phred_scores_.clear();
83  abundance_ = 1;
84  }
85 
86  // -------------------------------------------------------------------------
87  // Properties
88  // -------------------------------------------------------------------------
89 
90  std::string& label()
91  {
92  return label_;
93  }
94 
95  std::string const& label() const
96  {
97  return label_;
98  }
99 
100  void label( std::string const& value )
101  {
102  label_ = value;
103  }
104 
105  void label( std::string&& value )
106  {
107  label_ = std::move( value );
108  }
109 
110  std::string& sites()
111  {
112  return sites_;
113  }
114 
115  std::string const& sites() const
116  {
117  return sites_;
118  }
119 
120  void sites( std::string const& value )
121  {
122  sites_ = value;
123  }
124 
125  void sites( std::string && value )
126  {
127  sites_ = std::move( value );
128  }
129 
130  std::vector<unsigned char>& phred_scores()
131  {
132  return phred_scores_;
133  }
134 
135  std::vector<unsigned char> const& phred_scores() const
136  {
137  return phred_scores_;
138  }
139 
140  void phred_scores( std::vector<unsigned char> const& value )
141  {
142  phred_scores_ = value;
143  }
144 
145  void phred_scores( std::vector<unsigned char>&& value )
146  {
147  phred_scores_ = std::move( value );
148  }
149 
150  size_t abundance() const
151  {
152  return abundance_;
153  }
154 
155  void abundance( size_t value )
156  {
157  abundance_ = value;
158  }
159 
160  // -------------------------------------------------------------------------
161  // Accessors
162  // -------------------------------------------------------------------------
163 
167  size_t length() const
168  {
169  return sites_.size();
170  }
171 
175  size_t size() const
176  {
177  return sites_.size();
178  }
179 
180  char& site_at( size_t index )
181  {
182  return sites_.at(index);
183  }
184 
185  char site_at( size_t index ) const
186  {
187  return sites_.at(index);
188  }
189 
190  char& operator [] (size_t index)
191  {
192  return sites_[index];
193  }
194 
195  char operator [] (size_t index) const
196  {
197  return sites_[index];
198  }
199 
200  // -------------------------------------------------------------------------
201  // Iterators
202  // -------------------------------------------------------------------------
203 
205  {
206  return sites_.begin();
207  }
208 
210  {
211  return sites_.end();
212  }
213 
215  {
216  return sites_.cbegin();
217  }
218 
220  {
221  return sites_.cend();
222  }
223 
225  {
226  return sites_.cbegin();
227  }
228 
230  {
231  return sites_.cend();
232  }
233 
234  // -------------------------------------------------------------------------
235  // Data Members
236  // -------------------------------------------------------------------------
237 
238 private:
239 
240  std::string label_;
241  std::string sites_;
242 
243  std::vector<unsigned char> phred_scores_;
244  size_t abundance_ = 1;
245 
246 };
247 
248 } // namespace sequence
249 } // namespace genesis
250 
251 #endif // include guard
genesis::placement::swap
void swap(Sample &lhs, Sample &rhs)
Definition: sample.cpp:104
genesis::sequence::Sequence::clear
void clear()
Definition: sequence/sequence.hpp:78
genesis::sequence::Sequence::operator[]
char & operator[](size_t index)
Definition: sequence/sequence.hpp:190
genesis::sequence::Sequence::operator=
Sequence & operator=(Sequence const &)=default
genesis::sequence::Sequence::iterator
std::string::iterator iterator
Definition: sequence/sequence.hpp:48
genesis::sequence::Sequence::end
const_iterator end() const
Definition: sequence/sequence.hpp:219
genesis::sequence::Sequence
Definition: sequence/sequence.hpp:40
genesis::sequence::Sequence::label
void label(std::string const &value)
Definition: sequence/sequence.hpp:100
genesis::sequence::Sequence::phred_scores
std::vector< unsigned char > const & phred_scores() const
Definition: sequence/sequence.hpp:135
genesis::sequence::Sequence::begin
const_iterator begin() const
Definition: sequence/sequence.hpp:214
genesis::sequence::Sequence::phred_scores
void phred_scores(std::vector< unsigned char > &&value)
Definition: sequence/sequence.hpp:145
genesis::sequence::Sequence::end
iterator end()
Definition: sequence/sequence.hpp:209
genesis::sequence::Sequence::cend
const_iterator cend() const
Definition: sequence/sequence.hpp:229
genesis::sequence::Sequence::swap
void swap(Sequence &other)
Definition: sequence/sequence.hpp:71
genesis::sequence::Sequence::sites
void sites(std::string &&value)
Definition: sequence/sequence.hpp:125
genesis::sequence::Sequence::Sequence
Sequence(std::string const &label, std::string const &sites, size_t abundance=1)
Definition: sequence/sequence.hpp:57
genesis::sequence::Sequence::site_at
char site_at(size_t index) const
Definition: sequence/sequence.hpp:185
genesis::sequence::Sequence::label
std::string & label()
Definition: sequence/sequence.hpp:90
genesis::sequence::Sequence::Sequence
Sequence()=default
genesis::sequence::Sequence::abundance
size_t abundance() const
Definition: sequence/sequence.hpp:150
genesis::sequence::Sequence::site_at
char & site_at(size_t index)
Definition: sequence/sequence.hpp:180
genesis::sequence::Sequence::length
size_t length() const
Return the length (number of sites) of this sequence.
Definition: sequence/sequence.hpp:167
genesis::sequence::Sequence::~Sequence
~Sequence()=default
genesis::sequence::Sequence::sites
std::string const & sites() const
Definition: sequence/sequence.hpp:115
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::Sequence::phred_scores
std::vector< unsigned char > & phred_scores()
Definition: sequence/sequence.hpp:130
genesis::sequence::Sequence::size
size_t size() const
Alias for length().
Definition: sequence/sequence.hpp:175
genesis::sequence::Sequence::sites
std::string & sites()
Definition: sequence/sequence.hpp:110
genesis::sequence::Sequence::begin
iterator begin()
Definition: sequence/sequence.hpp:204
genesis::sequence::Sequence::phred_scores
void phred_scores(std::vector< unsigned char > const &value)
Definition: sequence/sequence.hpp:140
genesis::sequence::Sequence::const_iterator
std::string::const_iterator const_iterator
Definition: sequence/sequence.hpp:49
genesis::sequence::Sequence::abundance
void abundance(size_t value)
Definition: sequence/sequence.hpp:155
genesis::sequence::Sequence::cbegin
const_iterator cbegin() const
Definition: sequence/sequence.hpp:224
genesis::sequence::Sequence::label
std::string const & label() const
Definition: sequence/sequence.hpp:95
genesis::sequence::Sequence::sites
void sites(std::string const &value)
Definition: sequence/sequence.hpp:120
genesis::sequence::Sequence::label
void label(std::string &&value)
Definition: sequence/sequence.hpp:105