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

PhasedPMarkov.h

Go to the documentation of this file.
00001 /* seqpp/PhasedPMarkov.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_PHASEDPMARKOV_H
00029 #define SEQPP_PHASEDPMARKOV_H
00030 
00031 #include <seqpp/PhasedMarkov.h>
00032 #include <seqpp/pmm_tree.h>
00033 
00046 class PhasedPMarkov : public PhasedMarkov
00047 {
00048  protected : 
00050   pmm_tree * _pmmtree;
00051 
00052  public:
00054 
00062   PhasedPMarkov( const SequenceSet & seqset,
00063                  short phase, short initial_phase = 0,
00064                  double prior_alpha = -1.,
00065                  double penalty = 0.,
00066                  const string & xmlfile = string() )
00067     :  PhasedMarkov(  seqset.tell_alphabet_size(), seqset.tell_order(), phase )
00068   { 
00069     Partition p( seqset.tell_alphabet_size() );
00070     seqset.count_p_occurencies( phase, initial_phase ); 
00071     estimate( seqset.get_p_count(), true, seqset.get_translator(), p, phase, initial_phase, prior_alpha, penalty, xmlfile );
00072   }
00074 
00083   PhasedPMarkov( const Sequence & seq,
00084                  short phase, short initial_phase = 0,
00085                  double prior_alpha = -1.,
00086                  double penalty = 0., 
00087                  const Translator & trans = Translator(),
00088                  const string & xmlfile = string() )
00089     : PhasedMarkov(  seq.tell_alphabet_size(), seq.tell_order(), phase )
00090   {
00091     Partition p( seq.tell_alphabet_size() );
00092     seq.count_p_occurencies( phase, initial_phase ); 
00093     estimate( seq.get_p_count(), true, trans, p, phase, initial_phase, prior_alpha, penalty, xmlfile );
00094   }
00095   
00097 
00113   PhasedPMarkov( const string & partitionfile,
00114                  const SequenceSet & seqset,
00115                  short phase, short initial_phase = 0,
00116                  double prior_alpha = -1.,
00117                  double penalty = 0.,
00118                  const string & xmlfile = string() )
00119     :  PhasedMarkov(  seqset.tell_alphabet_size(), seqset.tell_order(), phase )
00120   {     
00121     Partition p( seqset.get_translator(), partitionfile ); 
00122     seqset.count_p_occurencies( phase, initial_phase ); 
00123     estimate( seqset.get_p_count(), true, seqset.get_translator(), p, phase, initial_phase, prior_alpha, penalty ,xmlfile );
00124   }
00125 
00127 
00144   PhasedPMarkov( const string & partitionfile,
00145                  const Translator & trans,
00146                  const Sequence & seq,
00147                  short phase, short initial_phase = 0,
00148                  double prior_alpha = -1.,
00149                  double penalty = 0., 
00150                  const string & xmlfile = string() )
00151      :  PhasedMarkov(  seq.tell_alphabet_size(), seq.tell_order(), phase )
00152   {
00153     Partition p( trans, partitionfile );
00154     seq.count_p_occurencies( phase, initial_phase ); 
00155     estimate( seq.get_p_count(), true, trans, p, phase, initial_phase,  prior_alpha, penalty, xmlfile );    
00156   }
00157 
00159 
00170   PhasedPMarkov( unsigned long * * count,
00171                  short size, short order,
00172                  short phase, short initial_phase = 0,
00173                  double prior_alpha = -1., 
00174                  double penalty = 0.,
00175                  const Translator & trans = Translator(),
00176                  const string & xmlfile = string() )
00177     :  PhasedMarkov( size, order, phase )
00178   {
00179     //cout<<"PhasedPMarkov constr. 5"<<endl;
00180     Partition p( size );   
00181     estimate( count, false, trans, p, phase, initial_phase, prior_alpha, penalty, xmlfile );
00182   }
00183 
00185 
00203   PhasedPMarkov( const string & partitionfile,
00204                  const Translator & trans,
00205                  unsigned long * * count,
00206                  short order,
00207                  short phase, short initial_phase = 0,
00208                  double prior_alpha = -1., 
00209                  double penalty = 0.,
00210                  const string & xmlfile = string() )
00211      :  PhasedMarkov(  trans.tell_alphabet_size(), order, phase )
00212   {
00213     Partition p( trans, partitionfile );
00214     estimate( count, false, trans, p, phase, initial_phase, prior_alpha, penalty, xmlfile );    
00215   }
00216 
00217 
00219   void estimate( unsigned long * * count, bool decal_required, 
00220                  const Translator & trans, Partition & p,
00221                  short phase, short initial_phase, 
00222                  double prior_alpha ,
00223                  double penalty ,
00224                  const string & xmlfile )
00225  {
00226    _pmmtree = new pmm_tree( _size, p, _order, prior_alpha, penalty );
00227    
00228    /*
00229    _pmmtree->expanded_tree(*count, decal_required, p);
00230    exit(1);
00231    */
00232 
00233    /*
00234      cout<<"TIME cost in 0( ("<< p.tell_nbposs()<<"^"<<_order 
00235      <<"*("<<p.tell_cardinal()<<"+1) )"
00236      <<endl; 
00237    */
00238    //cout<<"nb poss: "<<p.tell_nbposs()<<" cardinal: "<<p.tell_cardinal()<<endl;
00239 
00240    _nb_param = 0;   
00241 #ifdef HAVE_LIBXML2
00242    if (xmlfile.size() != 0){
00243      xmlDocPtr doc=xmlNewDoc(BAD_CAST "1.0");
00244      xmlNodePtr root_node=xmlNewNode(NULL,BAD_CAST "treeset");
00245      xmlDocSetRootElement(doc,root_node); 
00246      for (int i=0; i<phase; i++){ 
00247        cout<<"In select"<<endl;
00248        _pmmtree->select( count[i],
00249                          decal_required, p ); 
00250        cout<<"In tree2matrix"<<endl;
00251        _pmmtree->tree_to_matrix( _Pis[i] );
00252        //cout<<"nbleaves: "<<_pmmtree->nb_leaves()<<endl;
00253        _nb_param += _pmmtree->nb_leaves() * (_size-1);
00254        std::stringstream treenamestream;
00255        treenamestream <<"phase "<<i;
00256        _pmmtree->save( trans, root_node, treenamestream.str() );
00257      }
00258      xmlSaveFormatFileEnc(xmlfile.c_str(),doc,"ISO-8859-1",1);
00259      xmlFreeDoc(doc); 
00260    }
00261    else{
00262      for (int i=0; i<phase; i++){
00263        _pmmtree->select( count[i],
00264                          decal_required, p );
00265        
00266        _pmmtree->tree_to_matrix( _Pis[i] );
00267        
00268        _nb_param += _pmmtree->nb_leaves() * (_size-1);
00269      }
00270    }
00271 #endif
00272 #ifndef HAVE_LIBXML2
00273    if (xmlfile.size() != 0){
00274      cerr<<"in PhasedPMarkov: no libxml2 detected to fill "<<xmlfile<<endl;
00275    }
00276    for (int i=0; i<phase; i++){    
00277      _pmmtree->select( count[i],
00278                        decal_required, p );
00279      _pmmtree->tree_to_matrix( _Pis[i] );
00280 
00281      _nb_param += _pmmtree->nb_leaves() * (_size-1);
00282    }
00283 #endif
00284    
00285    delete _pmmtree;
00286  }
00287  
00289  ~PhasedPMarkov(){} 
00290 };
00291 #endif



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


Generated on Wed Mar 23 09:25:57 2005 for seqpp by doxygen 1.3.9.1