00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00027 #ifndef SEQPP_PRIMARYSEQUENCESET_H
00028 #define SEQPP_PRIMARYSEQUENCESET_H
00029
00030 #include <seqpp/Sequence.h>
00031 #include <seqpp/Translator.h>
00032 #include <iomanip>
00033
00041 template <class TSequence> class PrimarySequenceSet
00042 {
00043 protected :
00044
00046 const Translator *_transl;
00047
00049 short _nmodal;
00050
00052 int _nb_seq;
00053
00055 unsigned long _total_length;
00056
00058 unsigned long _length_max;
00059
00061 TSequence * * _array_seq;
00062
00063 public :
00065 PrimarySequenceSet(){
00066 _transl=NULL;_nmodal=0;_nb_seq=0;_total_length=0;_length_max=0;_array_seq=NULL;
00067 }
00068
00070 virtual ~PrimarySequenceSet(){
00071
00072
00073 for ( int i=0 ; i<_nb_seq ; i++ )
00074 delete _array_seq[i];
00075 delete [] _array_seq;
00076 delete _transl;
00077
00078
00079 }
00080
00081
00082
00084 const Translator & get_translator() const{
00085 return *_transl;
00086 }
00087
00089 short tell_alphabet_size () const{
00090 return _transl->tell_alphabet_size() ;
00091 }
00092
00094 short tell_nb_inv () const{
00095 return (*_transl).tell_nb_inv();
00096 }
00097
00098
00099
00101 TSequence & get_sequence ( int i ) const{
00102 return *_array_seq[i];
00103 }
00105 TSequence & operator() ( int i ) const{
00106 return *_array_seq[i];
00107 }
00108
00110 int tell_nb_sequence () const{
00111 return _nb_seq;
00112 }
00113
00115 virtual unsigned long tell_length ()const{
00116 return _total_length;
00117 }
00118
00120 unsigned long tell_length_max () const{
00121 return _length_max;
00122 }
00123
00125 unsigned long tell_length_seq( int i ) const{
00126 if ( (i>=_nb_seq) || (i<0) ){
00127 cout<<"PrimarySequenceSet::tell_length_seq: Out Of Sequences Index"
00128 << " i = " << i
00129 <<endl;
00130 return 0;
00131 }
00132 else
00133 return _array_seq[i]->tell_length();
00134 }
00135
00137 string tell_seq_name(int i) const{
00138 if (i>=_nb_seq){
00139 cout<<"PrimarySequenceSet::tell_seq_name: Out Of Sequences Index"<<endl;
00140 return NULL;
00141 }
00142 else
00143 return _array_seq[i]->tell_seq_name();
00144 }
00145
00147 string tell_file_name( int i ) const{
00148 if (i>=_nb_seq){
00149 cout<<"PrimarySequenceSet::tell_file_name: Out Of Sequences Index"<<endl;
00150 return NULL;
00151 }
00152 else
00153 return _array_seq[i]->tell_file_name();
00154 }
00155
00157 void weight_matrix( double ** wmat ) const{
00158 unsigned long ul, l = _array_seq[0]->tell_length();
00159 bool stop = false;
00160 int i=0, nbok, x;
00161 short size = _array_seq[0]->tell_alphabet_size();
00162 while( (!stop)&&(i<_nb_seq) ){
00163 if (_array_seq[i++]->tell_length() != l)
00164 stop = false;
00165 }
00166 if (stop)
00167 cerr<<"for weigth matrix : sequence with different lengths!";
00168 else
00169 for (ul = 0; ul<l; ul++){
00170 nbok = _nb_seq;
00171 for (i=0; i<_nb_seq; i++){
00172 x = _array_seq[i]->tell_int(ul);
00173 if ( x<0 )
00174 nbok--;
00175 else
00176 wmat[x][ul]++;
00177 }
00178 for (i=0; i<size; i++)
00179 if (nbok>0)
00180 wmat[i][ul] /= nbok;
00181 }
00182 }
00183 };
00184 #endif