A toolkit for working with phylogenetic data.
v0.24.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 
204  iterator begin()
205  {
206  return sites_.begin();
207  }
208 
209  iterator end()
210  {
211  return sites_.end();
212  }
213 
214  const_iterator begin() const
215  {
216  return sites_.cbegin();
217  }
218 
219  const_iterator end() const
220  {
221  return sites_.cend();
222  }
223 
224  const_iterator cbegin() const
225  {
226  return sites_.cbegin();
227  }
228 
229  const_iterator cend() const
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
char site_at(size_t index) const
Sequence(std::string const &label, std::string const &sites, size_t abundance=1)
void label(std::string const &value)
void phred_scores(std::vector< unsigned char > const &value)
void sites(std::string &&value)
const_iterator cbegin() const
const_iterator begin() const
void swap(SequenceSet &lhs, SequenceSet &rhs)
std::string::const_iterator const_iterator
std::vector< unsigned char > const & phred_scores() const
void sites(std::string const &value)
Container namespace for all symbols of genesis in order to keep them separate when used as a library...
std::string const & label() const
std::vector< unsigned char > & phred_scores()
size_t size() const
Alias for length().
const_iterator cend() const
void swap(Sequence &other)
std::string::iterator iterator
void label(std::string &&value)
Sequence & operator=(Sequence const &)=default
char & operator[](size_t index)
void phred_scores(std::vector< unsigned char > &&value)
size_t length() const
Return the length (number of sites) of this sequence.
std::string const & sites() const
const_iterator end() const