Link_AMOS.cc

Go to the documentation of this file.
00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 #include "Link_AMOS.hh"
00011 using namespace AMOS;
00012 using namespace std;
00013 
00014 
00015 
00016 
00017 //====================================================== Link_t ================
00018 const NCode_t Link_t::NCODE = M_LINK;
00019 
00020 
00021 //----------------------------------------------------- clear ------------------
00022 void Link_t::clear ( )
00023 {
00024   Universal_t::clear( );
00025   nods_m . first = nods_m . second = source_m . first = NULL_ID;
00026   source_m . second = NULL_NCODE;
00027   nodtype_m = NULL_NCODE;
00028   sd_m = size_m = 0;
00029   type_m = NULL_LINK;
00030 }
00031 
00032 
00033 //----------------------------------------------------- flip -------------------
00034 void Link_t::flip ( )
00035 {
00036   LinkAdjacency_t la = getAdjacency( );
00037   if ( la == NORMAL )
00038     setAdjacency (ANTINORMAL);
00039   else if ( la == ANTINORMAL )
00040     setAdjacency (NORMAL);
00041 
00042   nods_m = std::make_pair (nods_m . second, nods_m . first);
00043 }
00044 
00045 
00046 //----------------------------------------------------- getAdjacency -----------
00047 LinkAdjacency_t Link_t::getAdjacency ( ) const
00048 {
00049   if ( flags_m . nibble & ADJACENCY_BIT )
00050     {
00051       switch (flags_m . nibble & ADJACENCY_BITS)
00052         {
00053         case NORMAL_BITS     : return NORMAL;
00054         case ANTINORMAL_BITS : return ANTINORMAL;
00055         case INNIE_BITS      : return INNIE;
00056         case OUTIE_BITS      : return OUTIE;
00057         }
00058     }
00059   return NULL_ADJACENCY;
00060 }
00061 
00062 
00063 //----------------------------------------------------- readMessage ------------
00064 void Link_t::readMessage (const Message_t & msg)
00065 {
00066   Universal_t::readMessage (msg);
00067 
00068   try {
00069 
00070     istringstream ss;
00071 
00072     if ( msg . exists (F_NODES) )
00073       {
00074         ss . str (msg . getField (F_NODES));
00075         ss >> nods_m . first;
00076         ss . ignore( );
00077         ss >> nods_m . second;
00078         if ( !ss )
00079           AMOS_THROW_ARGUMENT ("Invalid nodes format");
00080         ss . clear( );
00081       }
00082 
00083     if ( msg . exists (F_OBJECT) )
00084       {
00085         string str;
00086 
00087         ss . str (msg . getField (F_OBJECT));
00088         ss >> str;
00089         if ( !ss || str . length( ) != NCODE_SIZE )
00090           AMOS_THROW_ARGUMENT ("Invalid object type format");
00091         ss . clear( );
00092         nodtype_m = Encode (str);
00093       }
00094 
00095     if ( msg . exists (F_ADJACENCY) )
00096       {
00097         ss . str (msg . getField (F_ADJACENCY));
00098         setAdjacency (ss . get( ));
00099         ss . clear( );
00100       }
00101 
00102     if ( msg . exists (F_SD) )
00103       {
00104         ss . str (msg . getField (F_SD));
00105         ss >> sd_m;
00106         if ( !ss )
00107           AMOS_THROW_ARGUMENT ("Invalid standard deviation format");
00108         ss . clear( );
00109       }
00110 
00111     if ( msg . exists (F_SIZE) )
00112       {
00113         ss . str (msg . getField (F_SIZE));
00114         ss >> size_m;
00115         if ( !ss )
00116           AMOS_THROW_ARGUMENT ("Invalid size format");
00117         ss . clear( );
00118       }
00119 
00120     if ( msg . exists (F_TYPE) )
00121       {
00122         ss . str (msg . getField (F_TYPE));
00123         setType (ss . get( ));
00124         ss . clear( );
00125       }
00126 
00127     if ( msg . exists (F_SOURCE) )
00128       {
00129         string str;
00130 
00131         ss . str (msg . getField (F_SOURCE));
00132         ss >> source_m . first;
00133         ss . ignore( );
00134         ss >> str;
00135         if ( !ss  ||  str . length( ) != NCODE_SIZE )
00136           AMOS_THROW_ARGUMENT ("Invalid source format");
00137         ss . clear( );
00138         source_m . second = Encode (str);
00139       }
00140   }
00141   catch (ArgumentException_t) {
00142     
00143     clear( );
00144     throw;
00145   }
00146 }
00147 
00148 
00149 //----------------------------------------------------- readRecord -------------
00150 void Link_t::readRecord (istream & fix, istream & var)
00151 {
00152   Universal_t::readRecord (fix, var);
00153 
00154   readLE (fix, &(nods_m . first));
00155   readLE (fix, &(nods_m . second));
00156   readLE (fix, &nodtype_m);
00157   readLE (fix, &sd_m);
00158   readLE (fix, &size_m);
00159   readLE (fix, &(source_m . first));
00160   readLE (fix, &(source_m . second));
00161   fix . get (type_m);
00162 }
00163 
00164 
00165 //----------------------------------------------------- readRecordFix ----------
00166 void Link_t::readRecordFix (istream & fix)
00167 {
00168   Universal_t::readRecordFix (fix);
00169 
00170   readLE (fix, &(nods_m . first));
00171   readLE (fix, &(nods_m . second));
00172   readLE (fix, &nodtype_m);
00173   readLE (fix, &sd_m);
00174   readLE (fix, &size_m);
00175   readLE (fix, &(source_m . first));
00176   readLE (fix, &(source_m . second));
00177   fix . get (type_m);
00178 }
00179 
00180 
00181 //----------------------------------------------------- setAdjacency -----------
00182 void Link_t::setAdjacency (LinkAdjacency_t adj)
00183 {
00184   uint8_t bits = flags_m . nibble;
00185   flags_m . nibble &= ~ADJACENCY_BITS;
00186   flags_m . nibble |=  ADJACENCY_BIT;
00187 
00188   switch (adj)
00189     {
00190     case NORMAL     : flags_m . nibble |= NORMAL_BITS;     break;
00191     case ANTINORMAL : flags_m . nibble |= ANTINORMAL_BITS; break;
00192     case INNIE      : flags_m . nibble |= INNIE_BITS;      break;
00193     case OUTIE      : flags_m . nibble |= OUTIE_BITS;      break;
00194     case NULL_ADJACENCY:
00195       flags_m . nibble &= ~ADJACENCY_BIT;
00196       break;
00197     default:
00198       flags_m . nibble = bits;
00199       AMOS_THROW_ARGUMENT ((string)"Invalid adjacency " + adj);
00200     }
00201 }
00202 
00203 
00204 //----------------------------------------------------- setType ----------------
00205 void Link_t::setType (LinkType_t type)
00206 {
00207   switch (type)
00208     {
00209     case NULL_LINK:
00210     case OTHER:
00211     case MATEPAIR:
00212     case OVERLAP:
00213     case PHYSICAL:
00214     case ALIGNMENT:
00215     case SYNTENY:
00216       type_m = type;
00217       break;
00218     default:
00219       AMOS_THROW_ARGUMENT ((string)"Invalid contig link type " + type);
00220     }
00221   type_m = type;
00222 }
00223 
00224 
00225 //----------------------------------------------------- writeMessage -----------
00226 void Link_t::writeMessage (Message_t & msg) const
00227 {
00228   Universal_t::writeMessage (msg);
00229 
00230   try {
00231     ostringstream ss;
00232 
00233     msg . setMessageCode (Link_t::NCODE);
00234 
00235     if ( nods_m . first != NULL_ID  ||  nods_m . second != NULL_ID )
00236       {
00237         ss << nods_m . first << ',' << nods_m . second;
00238         msg . setField (F_NODES, ss . str( ));
00239         ss . str (NULL_STRING);
00240       }
00241 
00242     if ( nodtype_m != NULL_NCODE )
00243       {
00244         msg . setField (F_OBJECT, Decode (nodtype_m));
00245         ss . str (NULL_STRING);
00246       }
00247 
00248     if ( getAdjacency( ) != NULL_ADJACENCY )
00249       {
00250         ss << getAdjacency( );
00251         msg . setField (F_ADJACENCY, ss . str( ));
00252         ss . str (NULL_STRING);
00253       }
00254 
00255     ss << sd_m;
00256     msg . setField (F_SD, ss . str( ));
00257     ss . str (NULL_STRING);
00258 
00259     ss << size_m;
00260     msg . setField (F_SIZE, ss . str( ));
00261     ss . str (NULL_STRING);
00262 
00263     if ( type_m != NULL_LINK )
00264       {
00265         ss << type_m;
00266         msg . setField (F_TYPE, ss . str( ));
00267         ss . str (NULL_STRING);
00268       }
00269 
00270     if ( source_m . first != NULL_ID  ||  source_m . second != NULL_NCODE )
00271       {
00272         ss << source_m . first << ',' << Decode (source_m . second);
00273         msg . setField (F_SOURCE, ss . str( ));
00274         ss . str (NULL_STRING);
00275       }
00276   }
00277   catch (ArgumentException_t) {
00278 
00279     msg . clear( );
00280     throw;
00281   }
00282 }
00283 
00284 
00285 //----------------------------------------------------- writeRecord ------------
00286 void Link_t::writeRecord (ostream & fix, ostream & var) const
00287 {
00288   Universal_t::writeRecord (fix, var);
00289 
00290   writeLE (fix, &(nods_m . first));
00291   writeLE (fix, &(nods_m . second));
00292   writeLE (fix, &nodtype_m);
00293   writeLE (fix, &sd_m);
00294   writeLE (fix, &size_m);
00295   writeLE (fix, &(source_m . first));
00296   writeLE (fix, &(source_m . second));
00297   fix . put (type_m);
00298 }

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