libsequence  1.9.5
Seq.cc
1 /*
2 
3 Copyright (C) 2003-2009 Kevin Thornton, krthornt[]@[]uci.edu
4 
5 Remove the brackets to email me.
6 
7 This file is part of libsequence.
8 
9 libsequence is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 libsequence is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 long with libsequence. If not, see <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #include <cassert>
25 #include <algorithm>
26 #include <functional>
27 #include <Sequence/Seq.hpp>
28 #include <Sequence/SeqFunctors.hpp>
29 
30 namespace Sequence
31 {
32  Seq::Seq(void) : name{}, seq{}
36  {
37  }
38 
39  std::string
40  Seq::substr(std::string::size_type beg, std::string::size_type len) const
44  {
45  return seq.substr(beg, len);
46  }
47 
48  std::string
49  Seq::substr(std::string::size_type beg) const
53  {
54  return seq.substr(beg);
55  }
56 
57  Seq::size_type
58  Seq::length(void) const
62  {
63  return seq.length();
64  }
65 
66  Seq::size_type
67  Seq::size(void) const
71  {
72  return seq.size();
73  }
74 
75  Seq::reference Seq::operator[](const size_type &i)
80  {
81  assert(i < seq.length());
82  return seq[i];
83  }
84 
85  Seq::const_reference Seq::operator[](const size_type &i) const
90  {
91  assert(i < seq.length());
92  return seq[i];
93  }
94 
95  bool
96  Seq::operator==(const Seq &rhs) const
102  {
103  return (this->seq == rhs.seq);
104  }
105 
106  bool
107  Seq::operator!=(const Seq &rhs) const
113  {
114  return (this->seq != rhs.seq);
115  }
116 
117  Seq::operator std::string() const
121  {
122  return seq;
123  }
124 
125  Seq::size_type
130  {
131  size_type ngap
132  = size_type(std::count(seq.begin(), seq.end(), '-'));
133  return (seq.length() - ngap);
134  }
135 
136  bool
137  Seq::IsGapped(void) const
142  {
143  return (seq.find('-') != std::string::npos);
144  }
145 
146  void
147  Seq::Subseq(const unsigned &beg, const unsigned &length)
157  {
158  assert(beg < seq.length() && (beg + length < seq.length()));
159  seq.assign(seq.begin() + beg, seq.begin() + beg + length);
160  }
161 
162  void
170  {
171  std::for_each(seq.begin(), seq.end(), ComplementBase());
172  }
173 
174  void
183  {
184  std::reverse(seq.begin(), seq.end());
185  std::for_each(seq.begin(), seq.end(), ComplementBase());
186  }
187 
193  {
194  return seq.begin();
195  }
196 
202  {
203  return seq.end();
204  }
205 
207  Seq::begin() const
211  {
212  return seq.begin();
213  }
214 
216  Seq::end() const
220  {
221  return seq.end();
222  }
223 
225  Seq::cbegin() const
229  {
230  return seq.cbegin();
231  }
232 
234  Seq::cend() const
238  {
239  return seq.cend();
240  }
241 
242  const char *
243  Seq::c_str(void) const
248  {
249  return seq.c_str();
250  }
251 
252  //non-member functions
253  std::ostream &
254  operator<<(std::ostream &s, const Seq &c)
255  {
256  return c.print(s);
257  }
258 
259  std::istream &
260  operator>>(std::istream &s, Seq &c)
261  {
262  return c.read(s);
263  }
264 } //ns Sequence
265 
class Sequence::Seq, an abstract base class for Sequences
bool operator!=(const Seq &rhs) const
Definition: Seq.cc:107
Abstract interface to sequence objects.
Definition: Seq.hpp:46
void Complement(void)
Definition: Seq.cc:163
std::string::const_iterator const_iterator
Definition: Seq.hpp:83
void Subseq(const unsigned &, const unsigned &)
Definition: Seq.cc:147
size_type size(void) const
Definition: Seq.cc:67
const char * c_str(void) const
Definition: Seq.cc:243
The namespace in which this library resides.
iterator begin()
Definition: Seq.cc:189
void Revcom(void)
Definition: Seq.cc:175
virtual std::ostream & print(std::ostream &s) const =0
std::ostream & operator<<(std::ostream &s, const AlignStream< T > &c)
virtual std::istream & read(std::istream &s)=0
iterator end()
Definition: Seq.cc:198
const_iterator cbegin() const
Definition: Seq.cc:225
std::string substr(std::string::size_type beg, std::string::size_type len) const
Definition: Seq.cc:40
size_type length(void) const
Definition: Seq.cc:58
size_type UngappedLength(void) const
Definition: Seq.cc:126
std::istream & operator>>(std::istream &s, AlignStream< T > &c)
bool IsGapped(void) const
Definition: Seq.cc:137
Seq(void)
Definition: Seq.cc:32
const_iterator cend() const
Definition: Seq.cc:234
bool operator==(const Seq &rhs) const
Definition: Seq.cc:96
std::string::iterator iterator
Definition: Seq.hpp:77
reference operator[](const size_type &i)
Definition: Seq.cc:75