src/metaspades/ext/src/easel/esl_dsqdata.c
/* Unpack 2-bit (+ mixed 5-bit for noncanonicals) encoding.
 * Important: dsq[0] is already initialized to eslDSQ_SENTINEL
 *
 * This will work for protein sequences just fine; just a little
 * slower than calling dsqdata_unpack5(), because here we have
 * to check the 5-bit encoding bit on every packet.
 */
Unpack 2-bit (+ mixed 5-bit for noncanonicals) encoding.
Important: dsq[0] is already initialized to eslDSQ_SENTINEL

This will work for protein sequences just fine; just a little
slower than calling dsqdata_unpack5(), because here we have
to check the 5-bit encoding bit on every packet.
Unpack 2 - bit ( + mixed 5 - bit for noncanonicals ) encoding . Important : dsq [ 0 ] is already initialized to eslDSQ_SENTINEL This will work for protein sequences just fine ; just a little slower than calling dsqdata_unpack5 () because here we have to check the 5 - bit encoding bit on every packet .
static int
dsqdata_unpack2(uint32_t *psq, ESL_DSQ *dsq, int *ret_L, int *ret_P)
{
  int      pos = 0;
  int      r   = 1;
  uint32_t v   = psq[pos++];
  int      b;                  
  while (! ESL_DSQDATA_EOD(v))
    {
      if ( ESL_DSQDATA_5BIT(v))  
	{
	  dsq[r++] = (v >> 25) & 31; dsq[r++] = (v >> 20) & 31; dsq[r++] = (v >> 15) & 31;
	  dsq[r++] = (v >> 10) & 31; dsq[r++] = (v >>  5) & 31; dsq[r++] = (v >>  0) & 31;
	}
      else                      
	{ 
	  dsq[r++] = (v >> 28) & 3;  dsq[r++] = (v >> 26) & 3;  dsq[r++] = (v >> 24) & 3;
	  dsq[r++] = (v >> 22) & 3;  dsq[r++] = (v >> 20) & 3;  dsq[r++] = (v >> 18) & 3;
	  dsq[r++] = (v >> 16) & 3;  dsq[r++] = (v >> 14) & 3;  dsq[r++] = (v >> 12) & 3;
	  dsq[r++] = (v >> 10) & 3;  dsq[r++] = (v >>  8) & 3;  dsq[r++] = (v >>  6) & 3;
	  dsq[r++] = (v >>  4) & 3;  dsq[r++] = (v >>  2) & 3;  dsq[r++] = (v >>  0) & 3;
	}
      v = psq[pos++];
    }
  if ( ESL_DSQDATA_5BIT(v)) 
    {
      for (b = 25; b >= 0 && ((v >> b) & 31) != 31; b -= 5)
	dsq[r++] = (v >> b) & 31;
    }
  else
    {
      dsq[r++] = (v >> 28) & 3;  dsq[r++] = (v >> 26) & 3;  dsq[r++] = (v >> 24) & 3;
      dsq[r++] = (v >> 22) & 3;  dsq[r++] = (v >> 20) & 3;  dsq[r++] = (v >> 18) & 3;
      dsq[r++] = (v >> 16) & 3;  dsq[r++] = (v >> 14) & 3;  dsq[r++] = (v >> 12) & 3;
      dsq[r++] = (v >> 10) & 3;  dsq[r++] = (v >>  8) & 3;  dsq[r++] = (v >>  6) & 3;
      dsq[r++] = (v >>  4) & 3;  dsq[r++] = (v >>  2) & 3;  dsq[r++] = (v >>  0) & 3;
    }
  dsq[r++] = eslDSQ_SENTINEL;
  *ret_L = r-2;
  *ret_P = pos;
  return eslOK;
}
static int dsqdata_unpack2 ( uint32_t * psq , ESL_DSQ * dsq , int * ret_L , int * ret_P ) { int pos = 0 ; int r = 1 ; uint32_t v = psq [ pos ++ ] ; int b ; while ( ! ESL_DSQDATA_EOD ( v ) ) { if ( ESL_DSQDATA_5BIT ( v ) ) { dsq [ r ++ ] = ( v >> 25 ) & 31 ; dsq [ r ++ ] = ( v >> 20 ) & 31 ; dsq [ r ++ ] = ( v >> 15 ) & 31 ; dsq [ r ++ ] = ( v >> 10 ) & 31 ; dsq [ r ++ ] = ( v >> 5 ) & 31 ; dsq [ r ++ ] = ( v >> 0 ) & 31 ; } else { dsq [ r ++ ] = ( v >> 28 ) & 3 ; dsq [ r ++ ] = ( v >> 26 ) & 3 ; dsq [ r ++ ] = ( v >> 24 ) & 3 ; dsq [ r ++ ] = ( v >> 22 ) & 3 ; dsq [ r ++ ] = ( v >> 20 ) & 3 ; dsq [ r ++ ] = ( v >> 18 ) & 3 ; dsq [ r ++ ] = ( v >> 16 ) & 3 ; dsq [ r ++ ] = ( v >> 14 ) & 3 ; dsq [ r ++ ] = ( v >> 12 ) & 3 ; dsq [ r ++ ] = ( v >> 10 ) & 3 ; dsq [ r ++ ] = ( v >> 8 ) & 3 ; dsq [ r ++ ] = ( v >> 6 ) & 3 ; dsq [ r ++ ] = ( v >> 4 ) & 3 ; dsq [ r ++ ] = ( v >> 2 ) & 3 ; dsq [ r ++ ] = ( v >> 0 ) & 3 ; } v = psq [ pos ++ ] ; } if ( ESL_DSQDATA_5BIT ( v ) ) { for ( b = 25 ; b >= 0 && ( ( v >> b ) & 31 ) != 31 ; b -= 5 ) dsq [ r ++ ] = ( v >> b ) & 31 ; } else { dsq [ r ++ ] = ( v >> 28 ) & 3 ; dsq [ r ++ ] = ( v >> 26 ) & 3 ; dsq [ r ++ ] = ( v >> 24 ) & 3 ; dsq [ r ++ ] = ( v >> 22 ) & 3 ; dsq [ r ++ ] = ( v >> 20 ) & 3 ; dsq [ r ++ ] = ( v >> 18 ) & 3 ; dsq [ r ++ ] = ( v >> 16 ) & 3 ; dsq [ r ++ ] = ( v >> 14 ) & 3 ; dsq [ r ++ ] = ( v >> 12 ) & 3 ; dsq [ r ++ ] = ( v >> 10 ) & 3 ; dsq [ r ++ ] = ( v >> 8 ) & 3 ; dsq [ r ++ ] = ( v >> 6 ) & 3 ; dsq [ r ++ ] = ( v >> 4 ) & 3 ; dsq [ r ++ ] = ( v >> 2 ) & 3 ; dsq [ r ++ ] = ( v >> 0 ) & 3 ; } dsq [ r ++ ] = eslDSQ_SENTINEL ; * ret_L = r - 2 ; * ret_P = pos ; return eslOK ; }
Unpack 2-bit (+ mixed 5-bit for noncanonicals) encoding.
Unpack 2 - bit ( + mixed 5 - bit for noncanonicals ) encoding .
// bit shift counter // 5-bit encoded, full. Don't need mask on bit 31 because we know it's down. // 2-bit encoded, full /* Sentinel packet. 
   * If 2-bit, it's full. If 5-bit, it's usually partial, and may even be 0-len.
   */ // 5-bit, partial