00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include <cassert>
00025 #include <algorithm>
00026 #include <Sequence/Seq.hpp>
00027 #include <Sequence/SeqFunctors.hpp>
00028
00029 namespace Sequence
00030 {
00031 Seq::Seq (void) : SeqBase()
00035 {
00036 }
00037
00038 Seq::Seq (const char *name, const char *seq): SeqBase(name,seq)
00039 {
00040 }
00041
00042 Seq::Seq (const Seq & seq) : SeqBase(seq.first,seq.second) {}
00044
00045 std::string Seq::GetName (void) const
00049 {
00050 return first;
00051 }
00052
00053 std::string Seq::GetSeq (void) const
00057 {
00058 return second;
00059 }
00060
00061 std::string Seq::substr(unsigned beg,unsigned len) const
00065 {
00066 return second.substr(beg,len);
00067 }
00068
00069 std::string Seq::substr(unsigned beg) const
00073 {
00074 return second.substr(beg);
00075 }
00076
00077 Seq::size_type Seq::length (void) const
00081 {
00082 return second.length ();
00083 }
00084
00085 Seq::reference
00086 Seq::operator[] (const size_type & i)
00091 {
00092 assert(i < second.length ());
00093 return second[i];
00094 }
00095
00096 Seq::const_reference
00097 Seq::operator[] (const size_type & i) const
00102 {
00103 assert(i < second.length ());
00104 return second[i];
00105 }
00106
00107 bool Seq::operator==(const Seq & rhs) const
00113 {
00114 return (this->second==rhs.second);
00115 }
00116
00117 bool Seq::operator!=(const Seq & rhs) const
00123 {
00124 return (this->second!=rhs.second);
00125 }
00126
00127 Seq::operator std::string() const
00131 {
00132 return second;
00133 }
00134
00135 Seq::size_type
00136 Seq::UngappedLength (void) const
00140 {
00141 size_type ngap = std::count(second.begin(),second.end(),'-');
00142 return (second.length () - ngap);
00143 }
00144
00145 bool Seq::IsGapped (void) const
00150 {
00151 return (second.find('-') != std::string::npos);
00152 }
00153
00154 void Seq::Subseq (unsigned beg, unsigned length)
00164 {
00165 assert ( beg < second.length() && (beg+length < second.length()));
00166 second.assign(second.begin()+beg,second.begin()+beg+length);
00167 }
00168
00169 void Seq::Complement(void)
00176 {
00177 std::for_each(second.begin(),second.end(),ComplementBase());
00178 }
00179
00180 void Seq::Revcom (void)
00188 {
00189 std::reverse(second.begin(),second.end());
00190 std::for_each(second.begin(),second.end(),ComplementBase());
00191 }
00192
00193 Seq::iterator Seq::begin()
00197 {
00198 return second.begin();
00199 }
00200
00201 Seq::iterator Seq::end()
00205 {
00206 return second.end();
00207 }
00208
00209 Seq::const_iterator Seq::begin() const
00213 {
00214 return second.begin();
00215 }
00216
00217 Seq::const_iterator Seq::end() const
00221 {
00222 return second.end();
00223 }
00224
00225 const char *Seq::c_str(void) const
00230 {
00231 return second.c_str();
00232 }
00233 }
00234