Version 4.0.0
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 
00042 template <class TSequence> class PrimarySequenceSet
00043 {
00044   protected :
00045     
00047     const Translator *_transl; 
00048     
00050   short _nmodal;
00051 
00053   int _nb_seq;
00054   
00056   unsigned long _total_length;
00057     
00059   unsigned long _length_max;
00060     
00062   TSequence * * _array_seq;
00063   
00064     
00065   public : 
00067   PrimarySequenceSet(){
00068     _transl=NULL;_nmodal=0;_nb_seq=0;_total_length=0;_length_max;_array_seq=NULL;
00069   }
00070 
00072   virtual ~PrimarySequenceSet(){  
00073     //if (DEBUG>0)
00074     // cout<<">>>>>>>>>> Delete PrimarySequenceSet ----------"<<endl;      
00075     for ( int i=0 ; i<_nb_seq ; i++ )
00076       delete _array_seq[i];
00077     delete [] _array_seq;
00078     delete _transl;      
00079     //if (DEBUG>0)
00080     //cout<<">>>>>>>>>> END Delete PrimarySequenceSet ----------"<<endl;
00081   }
00082 
00083   //Methods --------------------------------
00084   
00086   const Translator &  get_translator() const{
00087     return *_transl;
00088   }
00089   
00091   short tell_alphabet_size () const{
00092     return _transl->tell_alphabet_size() ;
00093   } 
00094 
00096   short tell_nb_inv () const{
00097     return (*_transl).tell_nb_inv();
00098   }
00099 
00100   //----------------------------------------
00101   
00103   TSequence &  get_sequence ( int i ) const{
00104     return *_array_seq[i];
00105   }
00107   TSequence &  operator() ( int i ) const{
00108     return *_array_seq[i];
00109   }
00110 
00112   int tell_nb_sequence () const{
00113     return _nb_seq;
00114   }
00115   
00117   virtual unsigned long tell_length ()const{
00118     return _total_length;
00119   }
00120    
00122   unsigned long tell_length_max () const{
00123     return _length_max;
00124   }
00125 
00127   unsigned long tell_length_seq( int i ) const{
00128     if ( (i>=_nb_seq) || (i<0) ){  // avant: (i>0)
00129       cout<<"PrimarySequenceSet::tell_length_seq: Out Of Sequences Index"
00130           << "  i = " << i
00131           <<endl; 
00132       return 0;
00133     }
00134     else 
00135       return _array_seq[i]->tell_length();
00136   }
00137    
00139   string tell_seq_name(int i) const{
00140     if (i>=_nb_seq){
00141       cout<<"PrimarySequenceSet::tell_seq_name: Out Of Sequences Index"<<endl; 
00142       return NULL;
00143     }
00144     else 
00145       return _array_seq[i]->tell_seq_name();
00146   }
00147 
00149   string tell_file_name( int i ) const{
00150     if (i>=_nb_seq){
00151       cout<<"PrimarySequenceSet::tell_file_name: Out Of Sequences Index"<<endl; 
00152       return NULL;
00153     }
00154     else 
00155       return _array_seq[i]->tell_file_name();
00156   } 
00157 
00159   void weight_matrix( double ** wmat ) const{
00160   unsigned long ul, l = _array_seq[0]->tell_length();
00161   bool stop = false;
00162   int i=0, nbok, x;
00163   short size = _array_seq[0]->tell_alphabet_size();
00164   while( (!stop)&&(i<_nb_seq) ){
00165     if (_array_seq[i++]->tell_length() != l)
00166       stop = false;    
00167   }
00168   if (stop)
00169     cerr<<"for weigth matrix : sequence with different lengths!";
00170   else
00171     for (ul = 0; ul<l; ul++){
00172       nbok = _nb_seq;
00173       for (i=0; i<_nb_seq; i++){
00174         x = _array_seq[i]->tell_int(ul);
00175         if ( x<0 )
00176           nbok--;
00177         else
00178           wmat[x][ul]++;
00179       }
00180       for (i=0; i<size; i++)
00181         if (nbok>0)
00182           wmat[i][ul] /= nbok;
00183     }
00184 }  
00185 }; 
00186 
00187 
00188 
00189 #endif /* SEQPP_PRIMARYSEQUENCESET_H */



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


Generated on Sun Apr 3 14:16:10 2005 for seqpp by doxygen 1.3.9.1