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

Translator.h

Go to the documentation of this file.
00001 /* seqpp/Translator.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 
00029 #ifndef SEQPP_TRANSLATOR_H
00030 #define SEQPP_TRANSLATOR_H
00031 
00032 #include <seqpp/const.h>
00033 using namespace s_s;
00034 #include <iostream>
00035 #include <fstream>
00036 #include <string>
00037 #include <map>
00038 #include <vector>
00039 
00040 using namespace std;
00041 
00042 
00105 class Translator
00106 {
00107  public:
00108 
00110 
00113   Translator ( const string & alpha_file );
00114   
00116 
00121   Translator ( const string & line2parse, short mode,
00122                bool case_sensivity = true );
00123 
00125   Translator( const Translator & t );
00126  
00128   Translator() {
00129     _i2s=NULL;_i2lab=NULL;_Ci2i=NULL;
00130     _alphabet_size = 0;_alphabet_mode = 0;_nb_inv = 0;
00131    _complementary_ok = false;_label_ok = false;_tmp = NULL;
00132   }
00133 
00135   ~Translator ();
00136 
00138   short tell_alphabet_size () const{
00139     return _alphabet_size;
00140   }
00141 
00143   short tell_nb_inv () const{
00144     return _nb_inv;
00145   }
00146 
00148   short tell_alphabet_mode () const{
00149     return _alphabet_mode;
00150   }
00151 
00153   bool is_complementary_ok() const{
00154     return _complementary_ok;
00155   }
00156 
00158   bool is_label_ok() const{
00159     return _label_ok;
00160   }
00161  
00162   //--------------------------------------------- 
00163   //--------------------------------------------- 
00164   //---------------------------------------------
00165   //---------------------------------------------
00166   //----------------------------------------------
00168 
00172   short int char_to_int( const char * source ) const; 
00174 
00177   short int str_to_int( const string& source ) const;
00178 
00184   short complementary_char_to_int(const char * source ) const;
00189   short int complementary_str_to_int( const string& source ) const;
00190 
00191 
00193 
00196   short complementary_int(short source) const{
00197     return _Ci2i[source];
00198   }
00199 
00200   //---------------------------------------------
00206   void int_to_char(char * dest,
00207                    short source) const;
00209   /*
00210     \param source integer to translate
00211   */
00212   string int_to_str( short source ) const;
00213 
00214 
00215   //---------------------------------------------
00221   void complementary_char(char * dest,
00222                           const char * source) const{
00223     int_to_char( dest, complementary_char_to_int(source) );
00224   }
00226   /*
00227     \param source source token
00228   */
00229   string complementary_str( const string& source) const{
00230     return int_to_str( complementary_str_to_int( source ) );
00231   }
00232 
00233   //---------------------------------------------  
00235   /*
00236     \param source integer to complementary translate
00237   */
00238   string complementary_int_to_str( short source ) const{ 
00239     return int_to_str( _Ci2i[source] );                                    
00240   }
00241     
00242   //--------------------------------------------- 
00243   //--------------------------------------------- 
00244   //---------------------------------------------
00245   //---------------------------------------------
00247   string complementary_strw( const string& wordsource) const;
00248   
00249   //---------------------------------------------
00256   void vect_to_word( char * worddest,
00257                      const short * vectsource,
00258                      short sizeword ) const;
00260   /*
00261     \param worddest word (must be allocated sizeword*_alphabet_mode + 1 space) corresponding to the sequential translation of source
00262     \param vectsource vector of integer to translate
00263   */
00264   void vect_to_word( char * worddest,
00265                        const vector<short>& vectsource ) const;
00267   /*
00268     \param vectsource vector of integer to translate
00269     \param sizeword size of the vectsource to translate
00270   */
00271   string vect_to_strw(  const short * vectsource,
00272                         short sizeword ) const;
00274   /*
00275     \param vectsource vector of integer to translate   
00276   */
00277   string vect_to_strw(  const vector<short>& vectsource ) const;
00278 
00279 
00280   //---------------------------------------------
00287   void word_to_vect( short * vectdest,
00288                      const char * wordsource,
00289                      short sizeword ) const;
00291   /*
00292     \param vectdest integer vector 
00293     \param wordsource character word to sequentially translate 
00294   */
00295   void word_to_vect( vector<short>& vectdest,
00296                      const char * wordsource ) const;
00297   
00300   /*
00301     \param vectdest integer vector 
00302     \param wordsource string word to sequentially translate 
00303   */
00304   void strw_to_vect( vector<short>& vectdest,
00305                       const string& wordsource ) const;
00306 
00307   //---------------------------------------------
00313   long word_to_coded_int( const char * wordsource, int & l ) const;
00314 
00319   long strw_to_coded_int( const string& wordsource ) const;
00320 
00321   //worddest is a char-word associated to a code 
00322   //int size_word_for_coded_int( long codesource ) const; impossible  
00323   //"worddest" must be allocated in
00324   // (size_word_for_coded_int(codesource)*_alphabet_mode + 1) space
00325   //void coded_int_to_word( char * worddest, long codesource ) const;
00326 
00328   /*
00329     \param codesource code to complementary code (in base alphabet_size) 
00330   */
00331   long complementary_coded_int( long codesource , short sizeword ) const;
00332 
00333   //---------------------------------------------
00335   short isInvalid( const char * source ) const;
00337   short isInvalid( const string& source ) const;
00338 
00339   //---------------------------------------------
00341   /*
00342     \param source corresponding integer value 
00343   */
00344   string int_to_label( short source ) const{
00345     if ( (source<_alphabet_size) && (source>=-_nb_inv) )
00346       return _i2lab[source];
00347     else return "";
00348   }
00349   
00351   /*
00352     \param vectsource vector of integer to ewtract the labels 
00353   */
00354   string vect_to_labelstrw( const vector<short>& vectsource ) const;
00355 
00356  protected:
00357  
00358    map<string, short> _s2i;
00359    string * _i2s;
00360    string * _i2lab;
00361    short * _Ci2i;
00362 
00363    map<string, short> _INVs2i;
00364    map<char, short> _INVc2i;
00365    
00367    short _alphabet_size;
00369    short _alphabet_mode;
00371    short _nb_inv;
00372 
00374    bool _complementary_ok;
00376    bool _label_ok;
00377  
00378   // tools
00379   char * _tmp;
00380   map<string, short>::const_iterator  _iter_si;
00381   map<char, short>::const_iterator _iter_ci;
00382 
00383   short file2nbinv( ifstream & f, short & nbtot );
00384   short line2nbtoken( const string & line2parse );
00385 };
00386 
00387 
00388 #endif //SEQPP_TRANSLATOR_H



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


Generated on Thu Aug 4 20:33:12 2005 for seqpp by doxygen 1.3.9.1