A toolkit for working with phylogenetic data.
v0.22.1
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-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 
34 #include <string>
35 
36 namespace genesis {
37 namespace sequence {
38 
39 class Sequence
40 {
41 public:
42 
43  // -------------------------------------------------------------------------
44  // Typedefs and Enums
45  // -------------------------------------------------------------------------
46 
47  typedef std::string::iterator iterator;
48  typedef std::string::const_iterator const_iterator;
49 
50  // -------------------------------------------------------------------------
51  // Constructors and Rule of Five
52  // -------------------------------------------------------------------------
53 
54  Sequence() = default;
55 
56  Sequence( std::string const& label, std::string const& sites, size_t abundance = 1 )
57  : label_(label)
58  , sites_(sites)
59  , abundance_(abundance)
60  {}
61 
62  ~Sequence() = default;
63 
64  Sequence( Sequence const& ) = default;
65  Sequence( Sequence&& ) = default;
66 
67  Sequence& operator= ( Sequence const& ) = default;
68  Sequence& operator= ( Sequence&& ) = default;
69 
70  void swap( Sequence& other )
71  {
72  using std::swap;
73  swap( label_, other.label_ );
74  swap( sites_, other.sites_ );
75  }
76 
77  // -------------------------------------------------------------------------
78  // Properties
79  // -------------------------------------------------------------------------
80 
81  std::string const& label() const
82  {
83  return label_;
84  }
85 
86  void label( std::string const& value )
87  {
88  label_ = value;
89  }
90 
91  std::string const& sites() const
92  {
93  return sites_;
94  }
95 
96  void sites( std::string const& value )
97  {
98  sites_ = value;
99  }
100 
101  void sites( std::string && value )
102  {
103  sites_ = std::move(value);
104  }
105 
106  std::string& sites()
107  {
108  return sites_;
109  }
110 
111  size_t abundance() const
112  {
113  return abundance_;
114  }
115 
116  void abundance( size_t value )
117  {
118  abundance_ = value;
119  }
120 
121  void clear()
122  {
123  label_ = "";
124  sites_ = "";
125  abundance_ = 1;
126  }
127 
128  // -------------------------------------------------------------------------
129  // Accessors
130  // -------------------------------------------------------------------------
131 
135  size_t length() const
136  {
137  return sites_.size();
138  }
139 
143  size_t size() const
144  {
145  return sites_.size();
146  }
147 
148  char& site_at( size_t index )
149  {
150  return sites_.at(index);
151  }
152 
153  char site_at( size_t index ) const
154  {
155  return sites_.at(index);
156  }
157 
158  char& operator [] (size_t index)
159  {
160  return sites_[index];
161  }
162 
163  char operator [] (size_t index) const
164  {
165  return sites_[index];
166  }
167 
168  // -------------------------------------------------------------------------
169  // Iterators
170  // -------------------------------------------------------------------------
171 
172  iterator begin()
173  {
174  return sites_.begin();
175  }
176 
177  iterator end()
178  {
179  return sites_.end();
180  }
181 
182  const_iterator begin() const
183  {
184  return sites_.cbegin();
185  }
186 
187  const_iterator end() const
188  {
189  return sites_.cend();
190  }
191 
192  const_iterator cbegin() const
193  {
194  return sites_.cbegin();
195  }
196 
197  const_iterator cend() const
198  {
199  return sites_.cend();
200  }
201 
202  // -------------------------------------------------------------------------
203  // Data Members
204  // -------------------------------------------------------------------------
205 
206 private:
207 
208  std::string label_;
209  std::string sites_;
210  size_t abundance_ = 1;
211 
212 };
213 
214 } // namespace sequence
215 } // namespace genesis
216 
217 #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 sites(std::string &&value)
const_iterator cbegin() const
const_iterator begin() const
void swap(SequenceSet &lhs, SequenceSet &rhs)
std::string::const_iterator const_iterator
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
size_t size() const
Alias for length().
const_iterator cend() const
void swap(Sequence &other)
std::string::iterator iterator
Sequence & operator=(Sequence const &)=default
char & operator[](size_t index)
size_t length() const
Return the length (number of sites) of this sequence.
std::string const & sites() const
const_iterator end() const