hmmer-3.3/easel/esl_dsqdata.c
/*****************************************************************
 * 3. ESL_DSQDATA_CHUNK: a chunk of input sequence data
 *****************************************************************/
3. ESL_DSQDATA_CHUNK: a chunk of input sequence data
3 . ESL_DSQDATA_CHUNK : a chunk of input sequence data
static ESL_DSQDATA_CHUNK *
dsqdata_chunk_Create(ESL_DSQDATA *dd)
{
  ESL_DSQDATA_CHUNK *chu = NULL;
  int                U;               
  int                status;
  ESL_ALLOC(chu, sizeof(ESL_DSQDATA_CHUNK));
  chu->i0       = 0;
  chu->N        = 0;
  chu->pn       = 0;
  chu->dsq      = NULL;
  chu->name     = NULL;
  chu->acc      = NULL;
  chu->desc     = NULL;
  chu->taxid    = NULL;
  chu->L        = NULL;
  chu->metadata = NULL;
  chu->smem     = NULL;
  chu->nxt      = NULL;
  ESL_ALLOC(chu->dsq,   dd->chunk_maxseq * sizeof(ESL_DSQ *));   
  ESL_ALLOC(chu->name,  dd->chunk_maxseq * sizeof(char *));
  ESL_ALLOC(chu->acc,   dd->chunk_maxseq * sizeof(char *));
  ESL_ALLOC(chu->desc,  dd->chunk_maxseq * sizeof(char *));
  ESL_ALLOC(chu->taxid, dd->chunk_maxseq * sizeof(int));
  ESL_ALLOC(chu->L,     dd->chunk_maxseq * sizeof(int64_t));
  U  = (dd->pack5 ? 6 * dd->chunk_maxpacket : 15 * dd->chunk_maxpacket);
  U += dd->chunk_maxseq + 1;
  ESL_ALLOC(chu->smem, sizeof(ESL_DSQ) * U);
  chu->psq = (uint32_t *) (chu->smem + U - 4*dd->chunk_maxpacket);
  chu->mdalloc = 20 * dd->chunk_maxseq;
  ESL_ALLOC(chu->metadata, sizeof(char) * chu->mdalloc);
  return chu;
 ERROR:
  dsqdata_chunk_Destroy(chu);
  return NULL;
}
static ESL_DSQDATA_CHUNK * dsqdata_chunk_Create ( ESL_DSQDATA * dd ) { ESL_DSQDATA_CHUNK * chu = NULL ; int U ; int status ; ESL_ALLOC ( chu , sizeof ( ESL_DSQDATA_CHUNK ) ) ; chu -> i0 = 0 ; chu -> N = 0 ; chu -> pn = 0 ; chu -> dsq = NULL ; chu -> name = NULL ; chu -> acc = NULL ; chu -> desc = NULL ; chu -> taxid = NULL ; chu -> L = NULL ; chu -> metadata = NULL ; chu -> smem = NULL ; chu -> nxt = NULL ; ESL_ALLOC ( chu -> dsq , dd -> chunk_maxseq * sizeof ( ESL_DSQ * ) ) ; ESL_ALLOC ( chu -> name , dd -> chunk_maxseq * sizeof ( char * ) ) ; ESL_ALLOC ( chu -> acc , dd -> chunk_maxseq * sizeof ( char * ) ) ; ESL_ALLOC ( chu -> desc , dd -> chunk_maxseq * sizeof ( char * ) ) ; ESL_ALLOC ( chu -> taxid , dd -> chunk_maxseq * sizeof ( int ) ) ; ESL_ALLOC ( chu -> L , dd -> chunk_maxseq * sizeof ( int64_t ) ) ; U = ( dd -> pack5 ? 6 * dd -> chunk_maxpacket : 15 * dd -> chunk_maxpacket ) ; U += dd -> chunk_maxseq + 1 ; ESL_ALLOC ( chu -> smem , sizeof ( ESL_DSQ ) * U ) ; chu -> psq = ( uint32_t * ) ( chu -> smem + U - 4 * dd -> chunk_maxpacket ) ; chu -> mdalloc = 20 * dd -> chunk_maxseq ; ESL_ALLOC ( chu -> metadata , sizeof ( char ) * chu -> mdalloc ) ; return chu ; ERROR : dsqdata_chunk_Destroy ( chu ) ; return NULL ; }
3.
3 .
// max size of unpacked seq data, in bytes (smem allocation) /* dsq, name, acc, desc are arrays of pointers into smem, metadata.
   * taxid is cast to int, from the metadata.
   * L is figured out by the unpacker.
   * All of these are set by the unpacker.
   */ /* On the <smem> allocation, and the <dsq> and <psq> pointers into it:
   *
   * <maxpacket> (in uint32's) sets the maximum single fread() size:
   * one load of a new chunk of packed sequence, up to maxpacket*4
   * bytes. <smem> needs to be able to hold both that and the fully
   * unpacked sequence, because we unpack in place.  Each packet
   * unpacks to at most 6 or 15 residues (5-bit or 2-bit packing) We
   * don't pack sentinels, so the maximum unpacked size includes
   * <maxseq>+1 sentinels... because we concat the digital seqs so
   * that the trailing sentinel of seq i is the leading sentinel of
   * seq i+1.
   *
   * The packed seq (max of P bytes) loads overlap with the unpacked
   * data (max of U bytes):
   *                   psq
   *                   v[    P bytes    ]
   * smem: 0........0........0..........0
   *       ^[         U bytes           ]
   *       ^dsq[0]  ^dsq[1]  ^dsq[2]
   *
   * and as long as we unpack psq left to right -- and as long as we
   * read the last packet before we write the last unpacked residues
   * to smem - we're guaranteed that the unpacking works without
   * overwriting any unpacked data.
   */ /* We don't have any guarantees about the amount of metadata
   * associated with the N sequences, so <metadata> has to be a
   * reallocatable space. We make a lowball guess for the initial
   * alloc, on the off chance that the metadata size is small (names
   * only, no acc/desc): minimally, say 12 bytes of name, 3 \0's, and
   * 4 bytes for the taxid integer: call it 20.
   */