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

PMarkov.h

Go to the documentation of this file.
00001 /* seqpp/PMarkov.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_PMARKOV_H
00029 #define SEQPP_PMARKOV_H
00030 
00031 #include <seqpp/Markov.h>
00032 #include <seqpp/PhasedPMarkov.h>
00033 #include <seqpp/pmm_tree.h>
00034 
00045 class PMarkov :  public Markov
00046 {
00047  protected :
00049   pmm_tree * _pmmtree;
00050 
00051  public:
00053 
00059   PMarkov( const SequenceSet & seqset,
00060            double prior_alpha = -1, 
00061          double penalty = 0.,
00062            const string & xmlfile = string() )
00063     :  Markov( seqset.tell_alphabet_size(), seqset.tell_order() )
00064   { 
00065     Partition p( seqset.tell_alphabet_size() );
00066     seqset.count_occurencies(); 
00067     estimate( seqset.get_count(), true, seqset.get_translator(), p, prior_alpha, penalty, xmlfile );
00068   }
00069 
00071 
00078   PMarkov( const Sequence & seq, 
00079            double prior_alpha = -1,
00080            double penalty = 0.,
00081            const Translator & trans = Translator(),
00082            const string & xmlfile = string() )
00083     : Markov(  seq.tell_alphabet_size(), seq.tell_order() )
00084   { 
00085     Partition p( seq.tell_alphabet_size() );
00086     seq.count_occurencies(); 
00087     estimate( seq.get_count(), true, trans, p, prior_alpha, penalty, xmlfile );
00088   }
00089 
00091 
00105   PMarkov( const string & partitionfile,
00106            const SequenceSet & seqset, 
00107            double prior_alpha = -1,
00108            double penalty = 0.,
00109            const string & xmlfile = string() )
00110     : Markov(  seqset.tell_alphabet_size(), seqset.tell_order() )
00111   {
00112     Partition p( seqset.get_translator(), partitionfile );
00113     seqset.count_occurencies(); 
00114     estimate( seqset.get_count(), true, seqset.get_translator(), p, prior_alpha, penalty, xmlfile ); 
00115   }
00116 
00118 
00133   PMarkov( const string & partitionfile,
00134            const Translator & trans, 
00135            const Sequence & seq,
00136            double prior_alpha = -1,
00137            double penalty = 0.,
00138            const string & xmlfile = string() )
00139     : Markov(  seq.tell_alphabet_size(), seq.tell_order() )
00140   {
00141     Partition p( trans, partitionfile );
00142     seq.count_occurencies(); 
00143     estimate( seq.get_count(), true, trans, p, prior_alpha, penalty, xmlfile );    
00144  }
00145 
00147 
00156   PMarkov( unsigned long * count,
00157            short size, short order,
00158            double prior_alpha = -1,
00159            double penalty = 0.,            
00160            const Translator & trans = Translator(),        
00161            const string & xmlfile = string() )
00162     : Markov( size, order )    
00163   {
00164     //cout<<"PMarkov constr."<<endl;
00165     Partition p( size );   
00166     estimate( count, false, trans, p, prior_alpha, penalty, xmlfile );
00167   }
00168 
00170 
00186   PMarkov( const string & partitionfile,
00187            const Translator & trans,
00188            unsigned long * count, 
00189            short order,
00190            double prior_alpha = -1,
00191            double penalty = 0., 
00192            const string & xmlfile = string() )
00193     : Markov( trans.tell_alphabet_size(), order )
00194   {
00195     Partition p( trans, partitionfile );
00196     estimate( count, false, trans, p, prior_alpha, penalty, xmlfile );    
00197   }
00198 
00199 
00201   void estimate( unsigned long * count, bool decal_required, 
00202                  const Translator & trans, Partition & p, 
00203                  double prior_alpha ,
00204                  double penalty = 0.,
00205                  const string & xmlfile = string() )
00206   {
00207    _pmmtree = new pmm_tree( _size, p, _order, prior_alpha );
00208    _nb_param = 0;   
00209 #ifdef HAVE_LIBXML2
00210    if (xmlfile.size() != 0){
00211      xmlDocPtr doc=xmlNewDoc(BAD_CAST "1.0");
00212      xmlNodePtr root_node=xmlNewNode(NULL,BAD_CAST "treeset");
00213      xmlDocSetRootElement(doc,root_node);
00214      _pmmtree->select( count,
00215                        decal_required, p );
00216      _pmmtree->tree_to_matrix( _Pi );
00217      //cout<<"nbleaves: "<<_pmmtree->nb_leaves()<<endl;
00218      _nb_param += _pmmtree->nb_leaves() * (_size-1);
00219      std::stringstream treenamestream;
00220      _pmmtree->save( trans, root_node, treenamestream.str() );
00221      xmlSaveFormatFileEnc(xmlfile.c_str(),doc,"ISO-8859-1",1);
00222      xmlFreeDoc(doc); 
00223    }
00224    else{
00225      _pmmtree->select( count,
00226                        decal_required, p );
00227      
00228      _pmmtree->tree_to_matrix( _Pi );
00229      _nb_param += _pmmtree->nb_leaves() * (_size-1);
00230    }
00231 #endif
00232 #ifndef HAVE_LIBXML2
00233    if (xmlfile.size() != 0){
00234      cerr<<"in PMarkov: no libxml2 detected to fill "<<xmlfile<<endl;
00235    } 
00236    _pmmtree->select( count,
00237                      decal_required, p );   
00238    _pmmtree->tree_to_matrix( _Pi );
00239    _nb_param += _pmmtree->nb_leaves() * (_size-1);
00240 #endif
00241       
00242    delete _pmmtree;
00243   }
00244 
00245 
00246   ~PMarkov(){
00247     //cout<<"destr.Pmarkov"<<endl;
00248   }
00249 };
00250 #endif



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