hmmer-3.3/easel/esl_dsqdata.c
/* dsqdata_unpack_chunk()
 * 
 * <do_pack5> is a hint: if caller knows that all the packets in the
 * chunk are 5-bit encoded (i.e. amino acid sequence), it can pass
 * <TRUE>, enabling a small optimization. Otherwise the packed
 * sequences will be treated as mixed 2- and 5-bit encoding, as is
 * needed for DNA/RNA sequences; protein sequences also unpack fine
 * that way, but the 5-bit flag on every packet needs to be checked.
 *
 * Throws:    <eslEFORMAT> if a problem is seen in the binary format 
 */


 is a hint: if caller knows that all the packets in the
chunk are 5-bit encoded , it can pass
, enabling a small optimization. Otherwise the packed
sequences will be treated as mixed 2- and 5-bit encoding, as is
needed for DNA/RNA sequences; protein sequences also unpack fine
that way, but the 5-bit flag on every packet needs to be checked.

 if a problem is seen in the binary format
is a hint : if caller knows that all the packets in the chunk are 5 - bit encoded it can pass enabling a small optimization . Otherwise the packed sequences will be treated as mixed 2 - and 5 - bit encoding as is needed for DNA / RNA sequences ; protein sequences also unpack fine that way but the 5 - bit flag on every packet needs to be checked . if a problem is seen in the binary format
static int
dsqdata_unpack_chunk(ESL_DSQDATA_CHUNK *chu, int do_pack5)
{
  char     *ptr = chu->metadata;           
  int       r;                             
  int       i;                             
  int       pos;                           
  int       L;                             
  int       P;                             
  for (i = 0; i < chu->N; i++)
    {
      if ( ptr >= chu->metadata + chu->mdalloc) ESL_EXCEPTION(eslEFORMAT, "metadata format error");
      chu->name[i] = ptr;                           ptr = 1 + strchr(ptr, '\0');   if ( ptr >= chu->metadata + chu->mdalloc) ESL_EXCEPTION(eslEFORMAT, "metadata format error");
      chu->acc[i]  = ptr;                           ptr = 1 + strchr(ptr, '\0');   if ( ptr >= chu->metadata + chu->mdalloc) ESL_EXCEPTION(eslEFORMAT, "metadata format error");
      chu->desc[i] = ptr;                           ptr = 1 + strchr(ptr, '\0');   if ( ptr >= chu->metadata + chu->mdalloc) ESL_EXCEPTION(eslEFORMAT, "metadata format error");
      chu->taxid[i] = (int32_t) *((int32_t *) ptr); ptr += sizeof(int32_t);     
    }
  i            = 0;
  r            = 0;
  pos          = 0;
  chu->smem[0] = eslDSQ_SENTINEL;  
  while (pos < chu->pn)
    {
      chu->dsq[i] = (ESL_DSQ *) chu->smem + r;
      if (do_pack5) dsqdata_unpack5(chu->psq + pos, chu->dsq[i], &L, &P);
      else          dsqdata_unpack2(chu->psq + pos, chu->dsq[i], &L, &P);
      r   += L+1;     
      pos += P;
      chu->L[i] = L;
      i++;
    }
  ESL_DASSERT1(( pos == chu->pn ));  
  ESL_DASSERT1((   i == chu->N ));   
  return eslOK;
}
static int dsqdata_unpack_chunk ( ESL_DSQDATA_CHUNK * chu , int do_pack5 ) { char * ptr = chu -> metadata ; int r ; int i ; int pos ; int L ; int P ; for ( i = 0 ; i < chu -> N ; i ++ ) { if ( ptr >= chu -> metadata + chu -> mdalloc ) ESL_EXCEPTION ( eslEFORMAT , " " ) ; chu -> name [ i ] = ptr ; ptr = 1 + strchr ( ptr , ' \0 ' ) ; if ( ptr >= chu -> metadata + chu -> mdalloc ) ESL_EXCEPTION ( eslEFORMAT , " " ) ; chu -> acc [ i ] = ptr ; ptr = 1 + strchr ( ptr , ' \0 ' ) ; if ( ptr >= chu -> metadata + chu -> mdalloc ) ESL_EXCEPTION ( eslEFORMAT , " " ) ; chu -> desc [ i ] = ptr ; ptr = 1 + strchr ( ptr , ' \0 ' ) ; if ( ptr >= chu -> metadata + chu -> mdalloc ) ESL_EXCEPTION ( eslEFORMAT , " " ) ; chu -> taxid [ i ] = ( int32_t ) * ( ( int32_t * ) ptr ) ; ptr += sizeof ( int32_t ) ; } i = 0 ; r = 0 ; pos = 0 ; chu -> smem [ 0 ] = eslDSQ_SENTINEL ; while ( pos < chu -> pn ) { chu -> dsq [ i ] = ( ESL_DSQ * ) chu -> smem + r ; if ( do_pack5 ) dsqdata_unpack5 ( chu -> psq + pos , chu -> dsq [ i ] , & L , & P ) ; else dsqdata_unpack2 ( chu -> psq + pos , chu -> dsq [ i ] , & L , & P ) ; r += L + 1 ; pos += P ; chu -> L [ i ] = L ; i ++ ; } ESL_DASSERT1 ( ( pos == chu -> pn ) ) ; ESL_DASSERT1 ( ( i == chu -> N ) ) ; return eslOK ; }
dsqdata_unpack_chunk()
dsqdata_unpack_chunk ()
// ptr will walk through metadata // position in unpacked dsq array // sequence index: 0..chu->N-1 // position in packet array // an unpacked sequence length // number of packets unpacked /* "Unpack" the metadata */ /* The data are user input, so we cannot trust that it has \0's where we expect them.  */ /* Unpack the sequence data */ // This initialization is why <smem> needs to be unsigned. // L+1, not L+2, because we overlap start/end sentinels // we should've unpacked exactly pn packets, //  .. and exactly N sequences.