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

Partition.h

Go to the documentation of this file.
00001 /* Partition.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  */
00019 
00028 #ifndef PARTITION_H
00029 #define PARTITION_H
00030 
00031 #include <seqpp/Partition_box.h>
00032 #include <seqpp/Translator.h>
00033 #include <list>
00034 #include <set>
00035 #include <map>
00036 
00037 
00042 class Partition_rep : public Partition_box< vector< short > > 
00043 {
00044  private : 
00045 
00047   short _countref;
00048 
00049 
00051   vector< vector< short > > _list_possib;
00053   vector< vector<short> >  _synonymous;
00054   void default_synonymous(){
00055     for (int i=0; i<_size; i++){
00056       vector<short> tmp;
00057       tmp.push_back( i );
00058       _synonymous.push_back( tmp );
00059     }
00060   }
00061 
00063   int _motifdefault;
00065   bool _motifdefault_skip;
00066 
00068   vector< short > _tmpvpart;
00069   vector< short > _tmpv;
00070   set< short > _tmpset;
00071   set< short >::const_iterator _tmpiter;
00072   map< vector<short> , int > _tmpvecmap;
00073   
00074   void list_possible_elements_r( short numbound,         
00075                  list< short > & ,
00076                  list< short >::iterator & it );
00077 
00078 
00080   virtual void processing( short numfalse, const vector<short> & vec );
00081 
00083   void init_tmpvecmap();
00085   void free_tmpvecmap(){
00086     _tmpvecmap.clear();
00087   }
00088 
00089  public :
00090   
00092   Partition_rep() 
00093     : Partition_box< vector< short > >()
00094     {_countref=0;}
00095 
00097 
00100   Partition_rep( short alphabet_size );
00101   
00103 
00124   Partition_rep( const Translator & alphabet,
00125                  const string & pfile );
00126   
00128   virtual ~Partition_rep()
00129   {};
00130   
00131 
00133   short countref() const{
00134     return _countref;
00135   }
00137   Partition_rep& operator ++ (int) {
00138     _countref++;
00139     return *this;
00140   }
00142   Partition_rep& operator -- (int) {
00143     _countref--;
00144     return *this;
00145   }
00146 
00147 
00148 
00150   const vector< vector< short > > & list_possible_elements( );
00151 
00153   const vector< vector<short> > & synonymous() const{
00154     return _synonymous;
00155   }
00156 
00158   long tell_nbposs() const{
00159     return _list_possib.size();
00160   }
00161 
00163   short  tell_size() const{
00164     return _size;
00165   }
00166   
00168   bool create_default();
00170   int motifdefault() const{
00171     return _motifdefault;
00172   }  
00174   bool motifdefault_skip() const{
00175     return _motifdefault_skip;
00176   }
00177   
00178 };
00179 
00180 
00181 
00182 
00217 class Partition{
00219   Partition_rep * _rep; 
00220 
00221   Partition(Partition_rep& rep){
00222     _rep = &rep;
00223     (*_rep)++;
00224   }
00225 
00226  public:
00228   Partition(){
00229     _rep = new Partition_rep();
00230   }
00232 
00235   Partition( short alphabet_size ){
00236     _rep = new Partition_rep(alphabet_size);
00237   } 
00239 
00260   Partition( const Translator & alphabet,
00261              const string & pfile ){
00262     _rep = new Partition_rep(alphabet, pfile);
00263   }
00265   Partition(const Partition& part){
00266     _rep = part._rep;
00267     (*_rep)++;
00268   } 
00270   ~Partition(){
00271     if (_rep->countref()>1)
00272       (*_rep)--;
00273     else
00274       delete _rep;
00275   }
00277   Partition& operator=(Partition & part){
00278     if (this != &part){
00279       // delete
00280       if (_rep->countref()>1)
00281         (*_rep)--;
00282       else
00283         delete _rep;
00284       // new
00285       _rep = part._rep;
00286       (*_rep)++;
00287     }
00288     return (*this);
00289   }
00290 
00292   const vector< vector< short > > & list_possible_elements( ){
00293     return _rep->list_possible_elements( );
00294   }
00296   const vector< vector<short> > & synonymous() const{
00297     return _rep->synonymous();
00298   }  
00300   const vector< int >& nbpartition_with_nbelement() const{
00301     return _rep->nbpartition_with_nbelement();
00302   }
00304   const vector< int >& compute_nbpartition_with_nbelement(){
00305     return _rep->compute_nbpartition_with_nbelement();
00306   }
00307   
00309   long tell_nbposs() const{
00310     return _rep->tell_nbposs();
00311   }
00313   short  tell_size() const{
00314     return _rep->tell_size();
00315   }  
00317   bool create_default(){
00318     return _rep->create_default();
00319   }
00321   int motifdefault() const{
00322     return _rep->motifdefault();
00323   }
00325   bool motifdefault_skip() const{
00326     return _rep->motifdefault_skip();
00327   }
00329   long tell_cardinal() const{
00330     return _rep->tell_cardinal();
00331   } 
00332 
00336   class const_iterator : public Partition_rep::const_iterator {
00337   public:
00338     const_iterator( )
00339       : Partition_rep::const_iterator( ) {}
00340     const_iterator( const Partition_rep & p, long currpart )
00341       : Partition_rep::const_iterator( p, currpart ) {}
00342   };
00343 
00345   const_iterator begin() const{
00346     return const_iterator( *_rep, 0 );
00347   }
00349   const_iterator end() const{
00350     return const_iterator( *_rep, _rep->tell_cardinal() );
00351   } 
00352 };
00353 #endif//PARTITION_H



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


Generated on Thu Aug 4 18:34:04 2005 for seqpp by doxygen 1.3.9.1