Sleipnir
tools/Data2Bnt/Data2Bnt.cpp
00001 /*****************************************************************************
00002 * This file is provided under the Creative Commons Attribution 3.0 license.
00003 *
00004 * You are free to share, copy, distribute, transmit, or adapt this work
00005 * PROVIDED THAT you attribute the work to the authors listed below.
00006 * For more information, please see the following web page:
00007 * http://creativecommons.org/licenses/by/3.0/
00008 *
00009 * This file is a component of the Sleipnir library for functional genomics,
00010 * authored by:
00011 * Curtis Huttenhower (chuttenh@princeton.edu)
00012 * Mark Schroeder
00013 * Maria D. Chikina
00014 * Olga G. Troyanskaya (ogt@princeton.edu, primary contact)
00015 *
00016 * If you use this library, the included executable tools, or any related
00017 * code in your work, please cite the following publication:
00018 * Curtis Huttenhower, Mark Schroeder, Maria D. Chikina, and
00019 * Olga G. Troyanskaya.
00020 * "The Sleipnir library for computational functional genomics"
00021 *****************************************************************************/
00022 #include "stdafx.h"
00023 #include "cmdline.h"
00024 
00025 static const char   c_szERROR[]     = "ERROR";
00026 static const char   c_szAnnotated[] = "annotated";
00027 static const char   c_szValue[]     = "value";
00028 static const char   c_cComment      = '#';
00029 static const char   c_cDot          = '.';
00030 static const size_t c_iBuf          = 1024;
00031 
00032 struct SFeature {
00033     string          m_strName;
00034     vector<string>  m_vecstrValues;
00035     size_t          m_iDefault;
00036 
00037     SFeature( const string& strName ) : m_strName(strName), m_iDefault(-1) { }
00038 
00039     size_t quantize( const string& strValue ) const {
00040         size_t  i;
00041 
00042         for( i = 0; i < m_vecstrValues.size( ); ++i )
00043             if( strValue == m_vecstrValues[ i ] )
00044                 return i;
00045 
00046         return -1; }
00047 };
00048 
00049 struct SDatum {
00050     string              m_strName;
00051     map<size_t,size_t>  m_mapiiFeatures;
00052 };
00053 
00054 void output_row( const string&, const CGenes&, size_t, const SDatum&, const vector<SFeature>&,
00055     const map<size_t,size_t>&, bool, bool, bool );
00056 void vectorize_row( const string&, const CGenes&, size_t, const SDatum&, const vector<SFeature>&,
00057     const map<size_t,size_t>&, vector<unsigned char>& );
00058 size_t get_feature( const string&, const vector<SFeature>& );
00059 int main_bnt( const gengetopt_args_info&, const vector<SFeature>&, map<string,SDatum>&, const vector<float>&,
00060     const CGenes&, const CGenome& );
00061 int main_xrff( const gengetopt_args_info&, const vector<SFeature>&, map<string,SDatum>&, const vector<float>&,
00062     const CGenes&, const CGenome& );
00063 
00064 int main( int iArgs, char** aszArgs ) {
00065     gengetopt_args_info sArgs;
00066     size_t              i, j, k;
00067     CPCL                DataOut;
00068     vector<SFeature>    vecsFeatures;
00069     vector<string>      vecstrLine, vecstrToken;
00070     ifstream            ifsm;
00071     char                szBuf[ c_iBuf ];
00072     map<string,SDatum>  mapValues;
00073     CGenome             Genome;
00074     CGenes              Genes( Genome );
00075     vector<float>       vecdQuants;
00076     int                 iRet;
00077 
00078     if( cmdline_parser( iArgs, aszArgs, &sArgs ) ) {
00079         cmdline_parser_print_help( );
00080         return 1; }
00081     CMeta Meta( sArgs.verbosity_arg );
00082 
00083     ifsm.open( sArgs.features_arg );
00084     if( !ifsm.is_open( ) ) {
00085         cerr << "Could not open: " << sArgs.features_arg << endl;
00086         return 1; }
00087     while( ifsm.peek( ) != EOF ) {
00088         ifsm.getline( szBuf, c_iBuf - 1 );
00089         vecstrLine.clear( );
00090         CMeta::Tokenize( szBuf, vecstrLine );
00091         if( ( vecstrLine.size( ) != 0 ) && ( vecstrLine[ 0 ][ 0 ] != c_cComment ) ) {
00092             vecsFeatures.push_back( SFeature( vecstrLine[ 0 ] ) );
00093             {
00094                 SFeature&   sFeature    = vecsFeatures[ vecsFeatures.size( ) - 1 ];
00095 
00096                 vecstrToken.clear( );
00097                 CMeta::Tokenize( vecstrLine[ 1 ].c_str( ), vecstrToken, "|" );
00098                 sFeature.m_vecstrValues.resize( vecstrToken.size( ) );
00099                 copy( vecstrToken.begin( ), vecstrToken.end( ), sFeature.m_vecstrValues.begin( ) );
00100 
00101                 if( vecstrLine.size( ) > 2 )
00102                     sFeature.m_iDefault = sFeature.quantize( vecstrLine[ 2 ] );
00103             } } }
00104     ifsm.close( );
00105 
00106     ifsm.clear( );
00107     ifsm.open( sArgs.data_arg );
00108     if( !ifsm.is_open( ) ) {
00109         cerr << "Could not open: " << sArgs.data_arg << endl;
00110         return 1; }
00111     while( ifsm.peek( ) != EOF ) {
00112         ifsm.getline( szBuf, c_iBuf - 1 );
00113         vecstrLine.clear( );
00114         CMeta::Tokenize( szBuf, vecstrLine );
00115         if( vecstrLine.size( ) == 0 )
00116             continue;
00117         {
00118             SDatum& sCur    = mapValues[ vecstrLine[ 0 ] ];
00119             char*   pc;
00120 
00121             sCur.m_strName = vecstrLine[ 0 ];
00122             for( i = 1; i < vecstrLine.size( ); ++i ) {
00123                 vecstrToken.clear( );
00124                 CMeta::Tokenize( vecstrLine[ i ].c_str( ), vecstrToken, "|" );
00125                 if( vecstrToken.size( ) != 2 ) {
00126                     cerr << "Illegal token in " << sArgs.data_arg << ": " << szBuf << endl;
00127                     return 1; }
00128                 for( j = 0; j < vecsFeatures.size( ); ++j )
00129                     if( vecstrToken[ 0 ] == vecsFeatures[ j ].m_strName )
00130                         break;
00131                 if( j >= vecsFeatures.size( ) ) {
00132                     cerr << "Unknown feature: " << vecstrLine[ i ] << endl;
00133                     return 1; }
00134                 k = strtol( vecstrToken[ 1 ].c_str( ), &pc, 10 );
00135                 sCur.m_mapiiFeatures[ j ] = ( pc != vecstrToken[ 1 ].c_str( )) ? k :
00136                     vecsFeatures[ j ].quantize( vecstrToken[ 1 ] ); }
00137         } }
00138     ifsm.close( );
00139 
00140     ifsm.clear( );
00141     ifsm.open( sArgs.quants_arg );
00142     if( !ifsm.is_open( ) ) {
00143         cerr << "Could not open: " << sArgs.quants_arg << endl;
00144         return 1; }
00145     ifsm.getline( szBuf, c_iBuf - 1 );
00146     vecstrLine.clear( );
00147     CMeta::Tokenize( szBuf, vecstrLine );
00148     vecdQuants.resize( vecstrLine.size( ) );
00149     for( i = 0; i < vecdQuants.size( ); ++i )
00150         vecdQuants[ i ] = (float)atof( vecstrLine[ i ].c_str( ) );
00151     ifsm.close( );
00152 
00153     if( sArgs.genome_arg ) {
00154         ifsm.clear( );
00155         ifsm.open( sArgs.genome_arg );
00156         if( !Genome.Open( ifsm ) ) {
00157             cerr << "Could not open: " << sArgs.genome_arg << endl;
00158             return 1; }
00159         ifsm.close( ); }
00160 
00161     if( sArgs.input_arg ) {
00162         ifsm.clear( );
00163         ifsm.open( sArgs.input_arg ); }
00164     if( !Genes.Open( sArgs.input_arg ? ifsm : cin ) ) {
00165         cerr << "Could not open: " << ( sArgs.input_arg ? sArgs.input_arg : "input genes" ) << endl;
00166         return 1; }
00167     if( sArgs.input_arg )
00168         ifsm.close( );
00169 
00170     iRet = sArgs.xrff_flag ? main_xrff( sArgs, vecsFeatures, mapValues, vecdQuants, Genes, Genome ) :
00171         main_bnt( sArgs, vecsFeatures, mapValues, vecdQuants, Genes, Genome );
00172 
00173     return iRet; }
00174 
00175 void output_row( const string& strGene, const CGenes& Genes, size_t iValue, const SDatum& sDatum,
00176     const vector<SFeature>& vecsFeatures, const map<size_t,size_t>& mapiiCur, bool fComments,
00177     bool fSparse, bool fDefault ) {
00178     size_t  i;
00179 
00180     if( fSparse ) {
00181         if( Genes.IsGene( strGene ) )
00182             cout << get_feature( c_szAnnotated, vecsFeatures ) << "|1   ";
00183         if( iValue )
00184             cout << get_feature( c_szValue, vecsFeatures ) << '|' << iValue << '\t'; }
00185     else
00186         cout << ( Genes.IsGene( strGene ) ? 2 : 1 ) << '\t' << ( 1 + iValue );
00187     for( i = 2; i < vecsFeatures.size( ); ++i ) {
00188         const SFeature&                     sFeature    = vecsFeatures[ i ];
00189         map<size_t,size_t>::const_iterator  iterCur;
00190         size_t                              iCur;
00191 
00192         if( ( iterCur = mapiiCur.find( i ) ) != mapiiCur.end( ) )
00193             iCur = iterCur->second;
00194         else if( ( iterCur = sDatum.m_mapiiFeatures.find( i ) ) != sDatum.m_mapiiFeatures.end( ) )
00195             iCur = iterCur->second;
00196         else
00197             iCur = sFeature.m_iDefault;
00198         if( fSparse ) {
00199             if( ( iCur != -1 ) && ( iCur > 0 ) )
00200                 cout << i << '|' << iCur << '\t'; }
00201         else {
00202             cout << '\t';
00203             if( iCur != -1 )
00204                 cout << ( iCur + 1 ); } }
00205     if( fComments ) {
00206         cout << "   #   " << strGene << '\t' << sDatum.m_strName;
00207         if( fDefault )
00208             cout << "   default"; }
00209     cout << endl; }
00210 
00211 size_t get_feature( const string& strName, const vector<SFeature>& vecsFeatures ) {
00212     size_t  i;
00213 
00214     for( i = 0; i < vecsFeatures.size( ); ++i )
00215         if( vecsFeatures[ i ].m_strName == strName )
00216             return i;
00217 
00218     return -1; }
00219 
00220 int main_bnt( const gengetopt_args_info& sArgs, const vector<SFeature>& vecsFeatures,
00221     map<string,SDatum>& mapValues, const vector<float>& vecdQuants, const CGenes& Genes,
00222     const CGenome& Genome ) {
00223     size_t              i, j, k, iFeature;
00224     float               d;
00225     string              strName;
00226     map<size_t,size_t>  mapiiCur;
00227     ifstream            ifsm;
00228     char                szBuf[ c_iBuf ];
00229     vector<string>      vecstrLine, vecstrToken;
00230 
00231     if( sArgs.comments_flag ) {
00232         cout << '#';
00233         for( i = 1; i < vecsFeatures.size( ); ++i )
00234             cout << '\t' << vecsFeatures[ i ].m_strName;
00235         cout << endl; }
00236     for( i = 0; i < sArgs.inputs_num; ++i ) {
00237         CDat    Dat;
00238 
00239         cerr << "Processing: " << sArgs.inputs[ i ] << endl;
00240         strName = CMeta::Basename( sArgs.inputs[ i ] );
00241         if( ( j = strName.rfind( c_cDot ) ) != string::npos )
00242             strName = strName.substr( 0, j );
00243         const SDatum&   sDatum  = mapValues[ strName ];
00244 
00245         if( Dat.Open( sArgs.inputs[ i ] ) ) {
00246             size_t                              iValue, iDefault, iJ;
00247             map<size_t,size_t>::const_iterator  iterDefault;
00248 
00249             Dat.Normalize( CDat::ENormalizeZScore );
00250             for( j = 0; j < Dat.GetGenes( ); ++j ) {
00251                 iJ = get_feature( Dat.GetGene( j ), vecsFeatures );
00252                 for( k = ( j + 1 ); k < Dat.GetGenes( ); ++k ) {
00253                     if( CMeta::IsNaN( d = Dat.Get( j, k ) ) )
00254                         continue;
00255                     iValue = CMeta::Quantize( d, vecdQuants );
00256                     mapiiCur.clear( );
00257                     mapiiCur[ get_feature( Dat.GetGene( k ), vecsFeatures ) ] = 1;
00258                     output_row( Dat.GetGene( j ), Genes, iValue, sDatum, vecsFeatures, mapiiCur,
00259                         !!sArgs.comments_flag, !!sArgs.sparse_flag, false );
00260                     mapiiCur.clear( );
00261                     mapiiCur[ iJ ] = 1;
00262                     output_row( Dat.GetGene( k ), Genes, iValue, sDatum, vecsFeatures, mapiiCur,
00263                         !!sArgs.comments_flag, !!sArgs.sparse_flag, false ); } }
00264             for( iDefault = -1,j = 0; j < vecsFeatures.size( ); ++j )
00265                 if( vecsFeatures[ j ].m_strName == c_szValue ) {
00266                     iDefault = ( ( iterDefault = sDatum.m_mapiiFeatures.find( j ) ) ==
00267                         sDatum.m_mapiiFeatures.end( ) ) ? vecsFeatures[ j ].m_iDefault : iterDefault->second;
00268                     break; }
00269             if( iDefault != -1 ) {
00270                 vector<size_t>  veciGenes;
00271                 size_t          iOne, iTwo;
00272 
00273                 veciGenes.resize( sArgs.genome_arg ? Genome.GetGenes( ) : Dat.GetGenes( ) );
00274                 for( j = 0; j < veciGenes.size( ); ++j )
00275                     veciGenes[ j ] = sArgs.genome_arg ? Dat.GetGene( Genome.GetGene( j ).GetName( ) ) : j;
00276                 for( j = 0; j < veciGenes.size( ); ++j ) {
00277                     if( ( iOne = veciGenes[ j ] ) == -1 )
00278                         continue;
00279                     iJ = get_feature( Dat.GetGene( iOne ), vecsFeatures );
00280                     for( k = ( j + 1 ); k < veciGenes.size( ); ++k ) {
00281                         if( ( ( iTwo = veciGenes[ k ] ) == -1 ) || !CMeta::IsNaN( Dat.Get( iOne, iTwo ) ) ||
00282                             ( ( (float)rand( ) / RAND_MAX ) > sArgs.fraction_arg ) )
00283                             continue;
00284                         mapiiCur.clear( );
00285                         mapiiCur[ get_feature( Dat.GetGene( iTwo ), vecsFeatures ) ] = 1;
00286                         output_row( Dat.GetGene( iOne ), Genes, iDefault, sDatum, vecsFeatures, mapiiCur,
00287                             !!sArgs.comments_flag, !!sArgs.sparse_flag, true );
00288                         mapiiCur.clear( );
00289                         mapiiCur[ iJ ] = 1;
00290                         output_row( Dat.GetGene( iTwo ), Genes, iDefault, sDatum, vecsFeatures, mapiiCur,
00291                             !!sArgs.comments_flag, !!sArgs.sparse_flag, true ); } } } }
00292         else {
00293             ifsm.clear( );
00294             ifsm.open( sArgs.inputs[ i ] );
00295             if( !ifsm.is_open( ) ) {
00296                 cerr << "Could not open: " << sArgs.inputs[ i ] << endl;
00297                 return 1; }
00298             while( ifsm.peek( ) != EOF ) {
00299                 mapiiCur.clear( );
00300                 ifsm.getline( szBuf, c_iBuf - 1 );
00301                 vecstrLine.clear( );
00302                 CMeta::Tokenize( szBuf, vecstrLine );
00303                 if( ( vecstrLine.size( ) == 0 ) || ( vecstrLine[ 0 ].find( c_szERROR ) == 0 ) )
00304                     continue;
00305                 if( vecstrLine.size( ) < 2 ) {
00306                     cerr << "Illegal line in " << sArgs.inputs[ i ] << ": " << szBuf << endl;
00307                     return 1; }
00308 
00309                 for( j = 2; j < vecstrLine.size( ); ++j ) {
00310                     vecstrToken.clear( );
00311                     CMeta::Tokenize( vecstrLine[ j ].c_str( ), vecstrToken, "|" );
00312                     if( vecstrToken.size( ) != 2 ) {
00313                         cerr << "Illegal token in " << sArgs.data_arg << ": " << szBuf << endl;
00314                         return 1; }
00315                     for( iFeature = 0; iFeature < vecsFeatures.size( ); ++iFeature )
00316                         if( vecstrToken[ 0 ] == vecsFeatures[ iFeature ].m_strName )
00317                             break;
00318                     if( iFeature >= vecsFeatures.size( ) ) {
00319                         cerr << "Unknown feature: " << vecstrLine[ j ] << endl;
00320                         return 1; }
00321                     mapiiCur[ iFeature ] = vecsFeatures[ iFeature ].quantize( vecstrToken[ 1 ] ); }
00322 
00323                 if( !CMeta::IsNaN( d = (float)atof( vecstrLine[ 1 ].c_str( ) ) ) )
00324                     output_row( vecstrLine[ 0 ], Genes, CMeta::Quantize( d, vecdQuants ),
00325                         sDatum, vecsFeatures, mapiiCur, !!sArgs.comments_flag, !!sArgs.sparse_flag,
00326                         false ); }
00327             ifsm.close( ); } }
00328 
00329     return 0; }
00330 
00331 int main_xrff( const gengetopt_args_info& sArgs, const vector<SFeature>& vecsFeatures,
00332     map<string,SDatum>& mapValues, const vector<float>& vecdQuants, const CGenes& Genes,
00333     const CGenome& Genome ) {
00334     size_t                                          i, j, iTotal, iFeature;
00335     float                                           d;
00336     string                                          strName;
00337     ifstream                                        ifsm;
00338     map<size_t,size_t>                              mapiiCur;
00339     char                                            szBuf[ c_iBuf ];
00340     vector<string>                                  vecstrLine, vecstrToken;
00341     map<vector<unsigned char>, size_t>              mapvecbiCounts;
00342     vector<size_t>                                  veciCounts;
00343     map<vector<unsigned char>, size_t>::iterator    iterCount;
00344 
00345     cout << "<?xml version='1.0' encoding='utf-8'?>" << endl;
00346     cout << "<dataset name='" << sArgs.input_arg << "'>" << endl;
00347     cout << "  <header>" << endl;
00348     cout << "    <attributes>" << endl;
00349     for( i = 0; i < vecsFeatures.size( ); ++i ) {
00350         cout << "      <attribute name='" << vecsFeatures[ i ].m_strName << "' type='nominal'>" << endl;
00351         cout << "        <labels>" << endl;
00352         for( j = 0; j < vecsFeatures[ i ].m_vecstrValues.size( ); ++j )
00353             cout << "          <label>" << ( j + 1 ) << "</label>" << endl;
00354         cout << "        </labels>" << endl;
00355         cout << "      </attribute>" << endl; }
00356     cout << "    </attributes>" << endl;
00357     cout << "  </header>" << endl;
00358 
00359     for( i = 0; i < sArgs.inputs_num; ++i ) {
00360         cerr << "Processing: " << sArgs.inputs[ i ] << endl;
00361         strName = CMeta::Basename( sArgs.inputs[ i ] );
00362         if( ( j = strName.rfind( c_cDot ) ) != string::npos )
00363             strName = strName.substr( 0, j );
00364         const SDatum&   sDatum  = mapValues[ strName ];
00365 
00366         ifsm.clear( );
00367         ifsm.open( sArgs.inputs[ i ] );
00368         if( !ifsm.is_open( ) ) {
00369             cerr << "Could not open: " << sArgs.inputs[ i ] << endl;
00370             return 1; }
00371         while( ifsm.peek( ) != EOF ) {
00372             mapiiCur.clear( );
00373             ifsm.getline( szBuf, c_iBuf - 1 );
00374             vecstrLine.clear( );
00375             CMeta::Tokenize( szBuf, vecstrLine );
00376             if( ( vecstrLine.size( ) == 0 ) || ( vecstrLine[ 0 ].find( c_szERROR ) == 0 ) )
00377                 continue;
00378             if( vecstrLine.size( ) < 2 ) {
00379                 cerr << "Illegal line in " << sArgs.inputs[ i ] << ": " << szBuf << endl;
00380                 return 1; }
00381 
00382             for( j = 2; j < vecstrLine.size( ); ++j ) {
00383                 vecstrToken.clear( );
00384                 CMeta::Tokenize( vecstrLine[ j ].c_str( ), vecstrToken, "|" );
00385                 if( vecstrToken.size( ) != 2 ) {
00386                     cerr << "Illegal token in " << sArgs.data_arg << ": " << szBuf << endl;
00387                     return 1; }
00388                 for( iFeature = 0; iFeature < vecsFeatures.size( ); ++iFeature )
00389                     if( vecstrToken[ 0 ] == vecsFeatures[ iFeature ].m_strName )
00390                         break;
00391                 if( iFeature >= vecsFeatures.size( ) ) {
00392                     cerr << "Unknown feature: " << vecstrLine[ j ] << endl;
00393                     return 1; }
00394                 mapiiCur[ iFeature ] = vecsFeatures[ iFeature ].quantize( vecstrToken[ 1 ] ); }
00395 
00396             if( !CMeta::IsNaN( d = (float)atof( vecstrLine[ 1 ].c_str( ) ) ) ) {
00397                 vector<unsigned char>   vecbRow;
00398 
00399                 vectorize_row( vecstrLine[ 0 ], Genes, CMeta::Quantize( d, vecdQuants ),
00400                     sDatum, vecsFeatures, mapiiCur, vecbRow );
00401                 if( veciCounts.size( ) < vecbRow[ 0 ] )
00402                     veciCounts.resize( vecbRow[ 0 ] );
00403                 veciCounts[ vecbRow[ 0 ] - 1 ]++;
00404                 if( ( iterCount = mapvecbiCounts.find( vecbRow ) ) == mapvecbiCounts.end( ) )
00405                     mapvecbiCounts[ vecbRow ] = 1;
00406                 else
00407                     iterCount->second++; } }
00408         ifsm.close( ); }
00409     for( iTotal = i = 0; i < veciCounts.size( ); ++i )
00410         iTotal += veciCounts[ i ];
00411 
00412     cout << "  <body>" << endl;
00413     cout << "    <instances>" << endl;
00414     for( iFeature = 0,iterCount = mapvecbiCounts.begin( ); iterCount != mapvecbiCounts.end( );
00415         ++iterCount,++iFeature ) {
00416         float   dWeight;
00417 
00418         cerr << iFeature << '/' << mapvecbiCounts.size( ) << endl;
00419         if( sArgs.weights_flag ) {
00420             dWeight = (float)( ( iTotal - veciCounts[ iterCount->first[ 0 ] - 1 ] ) * iterCount->second ) /
00421                 iTotal;
00422             cout << "      <instance weight='" << dWeight << "'>" << endl;
00423             for( i = 0; i < iterCount->first.size( ); ++i )
00424                 cout << "        <value>" << (size_t)iterCount->first[ i ] << "</value>" << endl;
00425             cout << "      </instance>" << endl; }
00426         else {
00427             dWeight = (float)( iTotal - veciCounts[ iterCount->first[ 0 ] - 1 ] ) / iTotal;
00428             for( i = 0; i < iterCount->second; ++i ) {
00429                 if( ( (float)rand( ) / RAND_MAX ) > sArgs.fraction_arg )
00430                     continue;
00431                 cout << "      <instance weight='" << dWeight << "'>" << endl;
00432                 for( j = 0; j < iterCount->first.size( ); ++j )
00433                     cout << "        <value>" << (size_t)iterCount->first[ j ] << "</value>" << endl;
00434                 cout << "      </instance>" << endl; } } }
00435     cout << "    </instances>" << endl;
00436     cout << "  </body>" << endl;
00437     cout << "</dataset>" << endl;
00438 
00439     return 0; }
00440 
00441 void vectorize_row( const string& strGene, const CGenes& Genes, size_t iValue, const SDatum& sDatum,
00442     const vector<SFeature>& vecsFeatures, const map<size_t,size_t>& mapiiCur,
00443     vector<unsigned char>& vecbRow ) {
00444     size_t  i;
00445 
00446     vecbRow.resize( vecsFeatures.size( ) );
00447     vecbRow[ 0 ] = Genes.IsGene( strGene ) ? 2 : 1;
00448     vecbRow[ 1 ] = (unsigned char)iValue + 1;
00449     for( i = 2; i < vecsFeatures.size( ); ++i ) {
00450         const SFeature&                     sFeature    = vecsFeatures[ i ];
00451         map<size_t,size_t>::const_iterator  iterCur;
00452         size_t                              iCur;
00453 
00454         if( ( iterCur = mapiiCur.find( i ) ) != mapiiCur.end( ) )
00455             iCur = iterCur->second;
00456         else if( ( iterCur = sDatum.m_mapiiFeatures.find( i ) ) != sDatum.m_mapiiFeatures.end( ) )
00457             iCur = iterCur->second;
00458         else
00459             iCur = sFeature.m_iDefault;
00460         if( iCur != -1 )
00461             vecbRow[ i ] = (unsigned char)iCur + 1; } }