hmmer-3.3/easel/esl_sqio_ncbi.c
/* Function:  sqncbi_Open()
 * Synopsis:  Open an ncbi database.
 * Incept:    MSF, Mon Dec 10, 2009 [Janelia]
 *
 * Purpose:   Open an ncbi database making sure all the necessry
 *            files are present.  Parse the index file for database 
 *            information filling in the ncbi data structure.
 * 
 * Returns:   <eslOK> on success, and the ncbi data structre is filled
 *            in with the database information.
 *            
 *            Returns <eslENOTFOUND> if <filename> can't be found or
 *            opened.  Returns <eslEFORMAT> if the index file is an
 *            upsupported version.
 *             
 * Throws:    <eslEMEM> on allocation failure.
 */
sqncbi_Open()
Synopsis:  Open an ncbi database.
Incept:    MSF, Mon Dec 10, 2009 [Janelia]

Open an ncbi database making sure all the necessry
files are present.  Parse the index file for database
information filling in the ncbi data structure.

 on success, and the ncbi data structre is filled
in with the database information.

Returns  if  can't be found or
opened.  Returns  if the index file is an
upsupported version.

 on allocation failure.
sqncbi_Open () Synopsis : Open an ncbi database . Incept : MSF Mon Dec 10 2009 [ Janelia ] Open an ncbi database making sure all the necessry files are present . Parse the index file for database information filling in the ncbi data structure . on success and the ncbi data structre is filled in with the database information . Returns if can ' t be found or opened . Returns if the index file is an upsupported version . on allocation failure .
static int
sqncbi_Open(ESL_SQNCBI_DATA *ncbi, char *filename)
{
  int    status  = eslOK;	
  char  *name    = NULL;
  status = sqncbi_DbOpen(ncbi, filename, NCBI_AMINO_DB);
  if (status == eslENOTFOUND) {
    status = sqncbi_AliasOpen(ncbi, filename, NCBI_AMINO_DB);
  }
  if (status == eslENOTFOUND) {
    status = sqncbi_DbOpen(ncbi, filename, NCBI_DNA_DB);
  }
  if (status == eslENOTFOUND) {
    status = sqncbi_AliasOpen(ncbi, filename, NCBI_DNA_DB);
  }
  if (status != eslOK) goto ERROR;
  ESL_ALLOC(ncbi->hdr_indexes, sizeof(uint32_t) * INDEX_TABLE_SIZE);
  ESL_ALLOC(ncbi->seq_indexes, sizeof(uint32_t) * INDEX_TABLE_SIZE);
  if (ncbi->alphatype == eslDNA) {
    ncbi->amb_off = ncbi->seq_off + sizeof(uint32_t) * (ncbi->num_seq + 1);
    ESL_ALLOC(ncbi->amb_indexes, sizeof(uint32_t) * INDEX_TABLE_SIZE);
  }
  ncbi->hdr_alloced = INIT_HDR_BUFFER_SIZE;
  ESL_ALLOC(ncbi->hdr_buf, sizeof(unsigned char) * INIT_HDR_BUFFER_SIZE);
  fgetc(ncbi->fppsq);
  if (name != NULL) free(name);
  return eslOK;
 ERROR:
  if (name != NULL) free(name);
  return status;
}
static int sqncbi_Open ( ESL_SQNCBI_DATA * ncbi , char * filename ) { int status = eslOK ; char * name = NULL ; status = sqncbi_DbOpen ( ncbi , filename , NCBI_AMINO_DB ) ; if ( status == eslENOTFOUND ) { status = sqncbi_AliasOpen ( ncbi , filename , NCBI_AMINO_DB ) ; } if ( status == eslENOTFOUND ) { status = sqncbi_DbOpen ( ncbi , filename , NCBI_DNA_DB ) ; } if ( status == eslENOTFOUND ) { status = sqncbi_AliasOpen ( ncbi , filename , NCBI_DNA_DB ) ; } if ( status != eslOK ) goto ERROR ; ESL_ALLOC ( ncbi -> hdr_indexes , sizeof ( uint32_t ) * INDEX_TABLE_SIZE ) ; ESL_ALLOC ( ncbi -> seq_indexes , sizeof ( uint32_t ) * INDEX_TABLE_SIZE ) ; if ( ncbi -> alphatype == eslDNA ) { ncbi -> amb_off = ncbi -> seq_off + sizeof ( uint32_t ) * ( ncbi -> num_seq + 1 ) ; ESL_ALLOC ( ncbi -> amb_indexes , sizeof ( uint32_t ) * INDEX_TABLE_SIZE ) ; } ncbi -> hdr_alloced = INIT_HDR_BUFFER_SIZE ; ESL_ALLOC ( ncbi -> hdr_buf , sizeof ( unsigned char ) * INIT_HDR_BUFFER_SIZE ) ; fgetc ( ncbi -> fppsq ) ; if ( name != NULL ) free ( name ) ; return eslOK ; ERROR : if ( name != NULL ) free ( name ) ; return status ; }
Function:  sqncbi_Open()
 Synopsis:  Open an ncbi database.
Function : sqncbi_Open () Synopsis : Open an ncbi database .
/* return status from an ESL call */ /* first try to open a single protein database */ /* if the database was not found, look for protein volume */ /* if nothing so far, try a dna database */ /* still nothing, look for dna volume */ /* allocate buffers used in parsing the database files */ /* if this is a dna database we need to allocate space for the
   * ambiguity offsets.
   */ /* skip the first sentinal byte in the .psq file */