Index_AMOS.cc

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 #include "Index_AMOS.hh"
00011 using namespace AMOS;
00012 using namespace std;
00013 
00014 
00015 
00016 
00017 //================================================ Index_t =====================
00018 const NCode_t Index_t::NCODE = M_INDEX;
00019 
00020 
00021 //----------------------------------------------------- buildContigFeature -----
00022 void Index_t::buildContigFeature (const std::string bankname)
00023 {
00024   clear( );
00025   setType (Contig_t::NCODE, Feature_t::NCODE);
00026 
00027   Feature_t fea;
00028   pair<NCode_t, ID_t> src;
00029   BankStream_t fea_bank (Feature_t::NCODE);
00030 
00031   fea_bank . open (bankname, B_READ);
00032 
00033   while ( fea_bank >> fea )
00034     {
00035       src = fea . getSource( );
00036       if ( src . first != NULL_ID  &&  src . second == Contig_t::NCODE )
00037         insert (src . first, fea . getIID( ));
00038     }
00039 
00040   fea_bank . close( );
00041 }
00042 
00043 
00044 //----------------------------------------------------- buildContigScaffold ----
00045 void Index_t::buildContigScaffold (const std::string bankname)
00046 {
00047   clear( );
00048   setType (Contig_t::NCODE, Scaffold_t::NCODE);
00049 
00050   Scaffold_t scf;
00051   vector<Tile_t>::const_iterator cur;
00052   vector<Tile_t>::const_iterator end;
00053   BankStream_t scf_bank (Scaffold_t::NCODE);
00054 
00055   scf_bank . open (bankname, B_READ);
00056 
00057   while ( scf_bank >> scf )
00058     {
00059       end = scf . getContigTiling( ) . end( );
00060       if ( scf . getIID( ) != NULL_ID )
00061         for ( cur = scf . getContigTiling( ) . begin( ); cur != end; ++ cur )
00062           if ( cur -> source != NULL_ID )
00063             insert (cur -> source, scf . getIID( ));
00064     }
00065 
00066   scf_bank . close( );
00067 }
00068 
00069 
00070 //----------------------------------------------------- buildReadContig --------
00071 void Index_t::buildReadContig (const std::string bankname)
00072 {
00073   clear( );
00074   setType (Read_t::NCODE, Contig_t::NCODE);
00075 
00076   Contig_t ctg;
00077   vector<Tile_t>::const_iterator cur;
00078   vector<Tile_t>::const_iterator end;
00079   BankStream_t ctg_bank (Contig_t::NCODE);
00080 
00081   ctg_bank . open (bankname, B_READ);
00082 
00083   while ( ctg_bank >> ctg )
00084     {
00085       end = ctg . getReadTiling( ) . end( );
00086       if ( ctg . getIID( ) != NULL_ID )
00087         for ( cur = ctg . getReadTiling( ) . begin( ); cur != end; ++ cur )
00088           if ( cur -> source != NULL_ID )
00089             insert (cur -> source, ctg . getIID( ));
00090     }
00091 
00092   ctg_bank . close( );
00093 }
00094 
00095 
00096 //----------------------------------------------------- buildReadLibrary -------
00097 void Index_t::buildReadLibrary (const std::string bankname)
00098 {
00099   clear( );
00100   setType (Read_t::NCODE, Library_t::NCODE);
00101 
00102   Read_t red;
00103   Fragment_t frg;
00104   Bank_t frg_bank (Fragment_t::NCODE);
00105   BankStream_t red_bank (Read_t::NCODE);
00106 
00107   frg_bank . open (bankname, B_READ);
00108   red_bank . open (bankname, B_READ);
00109 
00110   while ( red_bank >> red )
00111     {
00112       frg_bank . fetch (red . getFragment( ), frg);
00113       if ( red . getIID( ) != NULL_ID  &&  frg . getLibrary( ) != NULL_ID )
00114         insert (red . getIID( ), frg . getLibrary( ));
00115     }
00116 
00117   frg_bank . close( );
00118   red_bank . close( );
00119 }
00120 
00121 
00122 //----------------------------------------------------- buildReadMate ----------
00123 void Index_t::buildReadMate (const std::string bankname)
00124 {
00125   clear( );
00126   setType (Read_t::NCODE, Read_t::NCODE);
00127 
00128   Fragment_t frg;
00129   pair<ID_t, ID_t> mtp;
00130   BankStream_t frg_bank (Fragment_t::NCODE);
00131 
00132   frg_bank . open (bankname, B_READ);
00133 
00134   while ( frg_bank >> frg )
00135     {
00136       mtp = frg . getMatePair( );
00137       if ( mtp . first != NULL_ID  &&  mtp . second != NULL_ID )
00138         {
00139           insert (mtp . first, mtp . second);
00140           insert (mtp . second, mtp . first);
00141         }
00142     }
00143 
00144   frg_bank . close( );
00145 }
00146 
00147 
00148 //----------------------------------------------------- buildScaffoldFeature ---
00149 void Index_t::buildScaffoldFeature (const std::string bankname)
00150 {
00151   clear( );
00152   setType (Scaffold_t::NCODE, Feature_t::NCODE);
00153 
00154   Feature_t fea;
00155   pair<NCode_t, ID_t> src;
00156   BankStream_t fea_bank (Feature_t::NCODE);
00157 
00158   fea_bank . open (bankname, B_READ);
00159 
00160   while ( fea_bank >> fea )
00161     {
00162       src = fea . getSource( );
00163       if ( src . first != NULL_ID  &&  src . second == Scaffold_t::NCODE )
00164         insert (src . first, fea . getIID( ));
00165     }
00166 
00167   fea_bank . close( );
00168 }
00169 
00170 
00171 //----------------------------------------------------- readMessage ------------
00172 void Index_t::readMessage (const Message_t & msg)
00173 {
00174   Universal_t::readMessage (msg);
00175 
00176   try {
00177     Size_t size = -1;
00178     istringstream ss;
00179 
00180     if ( msg . exists (F_OBJECT) )
00181       {
00182         string str = msg . getField (F_OBJECT);
00183 
00184         if ( str . length( ) != NCODE_SIZE + NCODE_SIZE + 1 )
00185           AMOS_THROW_ARGUMENT ("Invalid object type format");
00186 
00187         type_m . first = Encode (str.substr (0, NCODE_SIZE)); 
00188         type_m . second = Encode (str.substr (NCODE_SIZE + 1));
00189       }
00190 
00191     if ( msg . exists (F_SIZE) )
00192       {
00193         ss . str (msg . getField (F_SIZE));
00194         ss >> size;
00195         if ( !ss )
00196           AMOS_THROW_ARGUMENT ("Invalid size format");
00197         index_m . resize (size);
00198 
00199         ss . clear( );
00200       }
00201 
00202     if ( msg . exists (F_MAP) )
00203       {
00204         pair<ID_t, ID_t> iids;
00205         ss . str (msg . getField (F_MAP));
00206 
00207         while ( ss )
00208           {
00209             ss >> iids . first >> iids . second;
00210             if ( ! ss . fail( ) )
00211               insert (iids);
00212           }
00213 
00214         if ( ! ss . eof( ) )
00215           AMOS_THROW_ARGUMENT ("Invalid map format");
00216 
00217         if ( size >= 0  &&  size != getSize( ) )
00218           AMOS_THROW_ARGUMENT ("map and size fields do not agree");
00219 
00220         ss . clear( );
00221       }
00222   }
00223   catch (ArgumentException_t) {
00224     
00225     clear( );
00226     throw;
00227   }
00228 }
00229 
00230 
00231 //----------------------------------------------------- readRecord -------------
00232 void Index_t::readRecord (istream & fix, istream & var)
00233 {
00234   Universal_t::readRecord (fix, var);
00235 
00236   Size_t size;
00237   readLE (fix, &size);
00238   readLE (fix, &(type_m . first));
00239   readLE (fix, &(type_m . second));
00240 
00241   pair<ID_t, ID_t> iids;
00242   index_m . clear( );
00243   index_m . resize (size);
00244   for ( Pos_t i = 0; i < size; ++ i )
00245     {
00246       readLE (var, &(iids . first));
00247       readLE (var, &(iids . second));
00248       insert (iids);
00249     }
00250 }
00251 
00252 
00253 
00254 //----------------------------------------------------- readRecordFix ----------
00255 void Index_t::readRecordFix (istream & fix)
00256 {
00257   Universal_t::readRecordFix (fix);
00258 
00259   Size_t size;
00260   readLE (fix, &size);
00261   readLE (fix, &(type_m . first));
00262   readLE (fix, &(type_m . second));
00263 
00264   index_m . clear( );
00265 }
00266 
00267 
00268 //----------------------------------------------------- writeMessage -----------
00269 void Index_t::writeMessage (Message_t & msg) const
00270 {
00271   Universal_t::writeMessage (msg);
00272 
00273   try {
00274     Size_t size = getSize( );
00275     ostringstream ss;
00276 
00277     msg . setMessageCode (Index_t::NCODE);
00278 
00279     if ( type_m . first != NULL_NCODE  ||  type_m . second != NULL_NCODE )
00280       {
00281         ss << Decode (type_m . first) << ',' << Decode (type_m . second);
00282         msg . setField (F_OBJECT, ss . str( ));
00283         ss . str (NULL_STRING);
00284       }
00285 
00286     if ( size != 0 )
00287       {
00288         ss << size;
00289         msg . setField (F_SIZE, ss . str( ));
00290         ss . str (NULL_STRING);
00291 
00292         string str;
00293         for ( const_iterator itr = begin( ); itr != end( ); ++ itr )
00294           {
00295             ss << itr -> first << '\t' << itr -> second;
00296             str . append (ss . str( ));
00297             str . push_back (NL_CHAR);
00298             ss . str (NULL_STRING);
00299           }
00300 
00301         msg . setField (F_MAP, str);
00302       }
00303   }
00304   catch (ArgumentException_t) {
00305 
00306     msg . clear( );
00307     throw;
00308   }
00309 }
00310 
00311 
00312 //----------------------------------------------------- writeRecord ------------
00313 void Index_t::writeRecord (ostream & fix, ostream & var) const
00314 {
00315   Universal_t::writeRecord (fix, var);
00316 
00317   Size_t size = getSize( );
00318   writeLE (fix, &size);
00319   writeLE (fix, &(type_m . first));
00320   writeLE (fix, &(type_m . second));
00321 
00322   for ( const_iterator itr = begin( ); itr != end( ); ++ itr )
00323     {
00324       writeLE (var, &(itr -> first));
00325       writeLE (var, &(itr -> second));
00326     }
00327 }

Generated on Mon Feb 22 17:36:27 2010 for libAMOS by  doxygen 1.4.7