Version 4.1.5
Main Page | Class Hierarchy | Class List | File List | Class Members | Related Pages

PrimarySequenceSet.h

Go to the documentation of this file.
00001 /* seqpp/PrimarySequenceSet.h
00002  *
00003  * Copyright (C) 2003 Laboratoire Statistique & Génome
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or (at
00008  * your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful, but
00011  * WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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     //if (DEBUG>0)
00072     // cout<<">>>>>>>>>> Delete PrimarySequenceSet ----------"<<endl;      
00073     for ( int i=0 ; i<_nb_seq ; i++ )
00074       delete _array_seq[i];
00075     delete [] _array_seq;
00076     delete _transl;      
00077     //if (DEBUG>0)
00078     //cout<<">>>>>>>>>> END Delete PrimarySequenceSet ----------"<<endl;
00079   }
00080 
00081   //Methods --------------------------------
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) ){  // avant: (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 /* SEQPP_PRIMARYSEQUENCESET_H */



Download seq++ 4.1.5
Download previous versions
Statistique & Genome Home


Generated on Thu Aug 4 20:33:12 2005 for seqpp by doxygen 1.3.9.1