00001 #ifndef GAPSEQ_HEADER
00002 #define GAPSEQ_HEADER
00003
00004
00005
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <stdlib.h>
00020
00021 #ifdef _STANDARD_C_PLUS_PLUS
00022 #include <iostream>
00023 #include <list>
00024 #else
00025 #include <iostream.h>
00026 #include <list.h>
00027 #endif
00028
00029 #include <string>
00030 using namespace std;
00031 #ifndef NPOS
00032 #define NPOS string::npos
00033 #endif
00034
00035
00036
00037 #include"Monomer.hh"
00038 #include"Bioseq.hh"
00039 #include "Rangedimexc.hh"
00040
00041
00042
00043 namespace RazorBack {
00044
00049 class Gapseq_: public Bioseq_
00050 {
00051
00052 public:
00053
00055 static const char GAP;
00056 static const char* GAP3;
00057
00059 static const char GCG_GAP;
00060 static const char* GCG_GAP3;
00061 static const char GCG_ENDGAP;
00062 static const char* GCG_ENDGAP3;
00063
00064 private:
00065
00074 class Gap_
00075 {
00076 friend class Gapseq_;
00077
00078
00079 private:
00080 size_t Pos;
00081 size_t Len;
00082
00083
00084 public:
00085
00087 explicit Gap_(size_t P=0, size_t L=1): Pos(P), Len(L) {}
00088
00089 size_t pos() const { return Pos; }
00090 void pos(size_t P) { Pos=P; }
00091 size_t len() const { return Len; }
00092 void len(size_t L) { if (L) Len=L; }
00093 };
00094
00095
00096 list<Gap_> Gaplist;
00097 size_t Gaplen;
00098
00099
00100 public:
00101
00107 explicit Gapseq_(Monomer_::Type_ Mt=Monomer_::PROT):
00108 Bioseq_(Mt), Gaplist(), Gaplen(0) {}
00109
00114 explicit Gapseq_(const char* Codes):
00115 Bioseq_(Codes), Gaplist(), Gaplen(0) {}
00116
00118 Gapseq_(const Bioseq_& B):
00119 Bioseq_(B), Gaplist(), Gaplen(0) {}
00120
00122 Gapseq_(const Gapseq_& G):
00123 Bioseq_(G), Gaplist(G.Gaplist), Gaplen(G.Gaplen) {}
00124
00142 virtual
00143 char at_1(size_t Idx) const;
00144 virtual
00145 bool at_1(size_t Idx, char C);
00146
00156 virtual
00157 const char* at_3(size_t Idx) const;
00158 virtual
00159 bool at_3(size_t Idx, const char* Ccc);
00160
00169 const string& seq() const { return Bioseq_::seq(); }
00170 virtual
00171 void seq(const string& S)
00172 {
00173 if (!is_legal(S))
00174 cerr<<"\n? Gapseq_::seq(...): Illegal char(s) in sequence\n";
00175 else { sequence()=S; remove_gaps(); }
00176 }
00177
00190 string gapped_sequence(bool Gcg=false) const;
00191 void gapped_sequence(const string& Gseq, int Mtype=Monomer_::UNKNOWN);
00192
00194
00202 virtual
00203 bool is_legal(char C) const
00204 {
00205 return (C==GAP || monomer().is_legal(C, nocase()));
00206 }
00207 virtual
00208 bool is_legal(const char* Ccc) const
00209 {
00210 return (!strncmp(Ccc, GAP3, 3) || monomer().is_legal(Ccc, nocase()));
00211 }
00212 bool is_legal(const string& S) const { return Bioseq_::is_legal(S); }
00213
00215
00225 void insert_gaps(size_t Idx, size_t N);
00226
00234 void remove_gaps(size_t Idx);
00235 void remove_gaps()
00236 {
00237 Gaplen=0;
00238 Gaplist.erase(Gaplist.begin(), Gaplist.end());
00239 }
00240
00257 size_t net_pos(size_t Gross) const;
00258
00264 size_t gross_pos(size_t Net) const;
00265
00267 size_t net_length() const { return seq().length(); }
00268
00270 size_t gross_length() const { return seq().length()+Gaplen; }
00271
00272
00273
00292 virtual
00293 Errtype_ read_seq(istream& Inf, int Type=Monomer_::USER, int Format=ANYFORMAT);
00294
00301 virtual
00302 Errtype_ write_seq(ostream& Outf, int Format) const;
00303
00304
00305 protected:
00306
00307 virtual
00308 bool is_legal(int Mt, char C) const;
00309
00310 };
00311
00312
00313 }
00314
00315
00316
00317 #endif // GAPSEQ_HEADER