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

Markov.h

Go to the documentation of this file.
00001 /* seqpp/Markov.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 SEQPP_MARKOV_H
00029 #define SEQPP_MARKOV_H
00030 
00031 #include <seqpp/PhasedMarkov.h>
00032 #include <seqpp/arnoldi.h>
00033 
00043 class Markov : public PhasedMarkov
00044 {
00045  public :
00046  
00048   /*
00049     \param markov_file description of an input model in a file (generated by print method) 
00050     \param calc_rank calculus of the convergence rank if true
00051     Exple of file:
00052     \code
00053     # 4 <- Order of the phased Markov chain<br>
00054     # 3 <- Phase<br>
00055     # 4 <- Alphabet size<br>
00056     # 10 steps <- Convergence to the stationnary distribution (!!Optionnal!!)<br>
00057     # Transition matrix:<br>
00058     ...<br>
00059     # Stationnary Probability: (!!Optionnal!!)<<br>
00060     ...
00061     \endcode
00062   */
00063   Markov( const char * ConfFile, 
00064           bool calc_rank = false );
00066 
00071   Markov( const SequenceSet & seqset,
00072           bool calc_rank = false,
00073           const string& prior_alpha_file = string() );
00074 
00076 
00081   Markov( const Sequence & seq,
00082           bool calc_rank = false,
00083           const string& prior_alpha_file = string() );
00084 
00086   Markov( const Markov & );
00087   
00089   Markov();
00090 
00092 
00099   Markov( short size, short order, bool alloc=true,
00100           const string& prior_alpha_file = string() ):PhasedMarkov(size,order,1,alloc, prior_alpha_file) 
00101   {//cout<<"Markov constr. 6"<<endl;
00102     if (alloc){
00103       _Pi=_Pis[0];_container=_containers[0];
00104     }
00105     else{
00106       _Pi = NULL; _container=NULL;
00107     }
00108     _Mu=NULL;_PowPi=NULL;
00109   }
00110 
00112 
00117   Markov(const Markov &M1, const Markov &M2,const float p);
00118 
00120 
00138   Markov( const gsl_rng * r,
00139           short size, short order,
00140           bool calc_rank = false)
00141     : PhasedMarkov( r, size, order, 1, calc_rank ){
00142     _Pi=_Pis[0];_container=_containers[0];_Mu=NULL;_PowPi=NULL;
00143   };
00144 
00146 
00153   Markov( unsigned long * count,
00154           short size, short order,
00155           const string& prior_alpha_file = string(),
00156           bool calc_rank = false );
00157 
00159   virtual Markov::~Markov();
00160 
00161   //---------------------------------------
00163 
00169   template <class TSeq>
00170   void estimate( const TSeq & tseq,
00171                  unsigned long beg, unsigned long end,
00172                  bool calc_rank ) {
00173     this->PhasedMarkov::estimate( tseq, 1,0, beg, end, calc_rank );
00174   }
00175 
00177 
00182   void estimate( unsigned long * count, bool decal_required, bool calc_rank= false ){
00183     this->PhasedMarkov::estimate( &count, decal_required, calc_rank );
00184   }
00185 
00187 
00191   void estimate( const string& count_file, bool calc_rank= false )
00192   {
00193     this->PhasedMarkov::estimate( count_file, calc_rank );
00194   }
00195 
00196 
00197   //---------------------------------------
00199   const double * markov_matrix() const{
00200     return PhasedMarkov::markov_matrix(0);
00201   } 
00202 
00204 
00223   void draw_markov_matrix(const  gsl_rng * r){
00224     PhasedMarkov::draw_markov_matrices(r);
00225   }
00226 
00228   void free_markov_matrix(){
00229     PhasedMarkov::free_markov_matrices();
00230   }
00232   /*
00233     \param force "true" to force the calculation, even if the law already exists. Default => "false". 
00234   */ 
00235   void compute_stat_law( bool force=false ){
00236     PhasedMarkov::compute_stat_laws( force );
00237     _Mu = _Mus[0];
00238   }  
00240   void free_stat_law(){
00241     PhasedMarkov::free_stat_laws();
00242     _Mu = NULL;
00243   }
00245   const double * stat_law() const{
00246     return PhasedMarkov::stat_law(0);
00247   }
00248   //--------------------------------------- 
00250   virtual int compute_rank(); 
00251   
00253   void compute_power();
00254    
00256   int free_power();
00257 
00259 
00265   // double proba_step( const string & w1, const string & w2, int step ) const;
00267 
00272   //double proba_step( const vector<short> & w1, const vector<short> & w2, int step ) const;
00273 
00275 
00281   double proba_step( long w1, long w2, int step ){
00282     compute_rank();
00283     compute_power();
00284       if (step<=_rank)
00285         return(_PowPi[step-1][w1][w2]);
00286       else 
00287         return(_Mu[w2]);
00288   }
00289    
00290   //---------------------------------------
00292   bool isPi() const { return(_Pi != NULL);};
00294   bool isPow() const { return(_PowPi != NULL);};
00296   bool isMu()  const { return(_Mu != NULL);};
00297 
00299 
00302   double & operator() (int index){ 
00303     return(_Pi[index]); 
00304   }
00306 
00309   double Mu(int index) const { 
00310     return(_Mu[index]); 
00311   }
00312 
00313 protected :
00314   
00316   double *_Pi;
00318   double *_container;
00319   
00321   double *_Mu; 
00322   
00324   double ***_PowPi;
00325 }; 
00326 #endif/*SEQPP_MARKOV_H*/
00327 



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