hmmer-3.3/easel/esl_sqio_ncbi.c
/* volume_open()
 *
 * Open up the index, head and sequence files for a particular
 * volume.  Parse the first three fields in the index file,
 * one more time, just to make sure nothing funny is going on.
 */
volume_open()
Open up the index, head and sequence files for a particular
volume.  Parse the first three fields in the index file,
one more time, just to make sure nothing funny is going on.
volume_open () Open up the index head and sequence files for a particular volume . Parse the first three fields in the index file one more time just to make sure nothing funny is going on .
static int
volume_open(ESL_SQNCBI_DATA *ncbi, int volume)
{
  int       len;
  uint32_t  info[4];
  int       dbtype;
  int       status = eslOK;	
  char     *name;
  if (volume < 0 || volume > ncbi->volumes) return eslEINVAL;
  if (ncbi->volumes == 0) return eslOK;
  if (ncbi->fppin != NULL) fclose(ncbi->fppin);
  if (ncbi->fpphr != NULL) fclose(ncbi->fpphr);
  if (ncbi->fppsq != NULL) fclose(ncbi->fppsq);
  name = ncbi->vols[volume].name;
  len  = strlen(name);
  dbtype = (ncbi->alphatype == eslDNA) ? NCBI_DNA_DB : NCBI_AMINO_DB;
  strcpy(name+len, ".Xin");
  name[len+1] = (dbtype == NCBI_DNA_DB) ? 'n' : 'p';
  if ((ncbi->fppin = fopen(name, "rb")) == NULL) {
    status = eslFAIL; 
    goto ERROR;
  }
  strcpy(name+len, ".Xhr");
  name[len+1] = (dbtype == NCBI_DNA_DB) ? 'n' : 'p';
  if ((ncbi->fpphr = fopen(name, "rb")) == NULL) {
    status = eslFAIL; 
    goto ERROR;
  }
  strcpy(name+len, ".Xsq");
  name[len+1] = (dbtype == NCBI_DNA_DB) ? 'n' : 'p';
  if ((ncbi->fppsq = fopen(name, "rb")) == NULL) {
    status = eslFAIL; 
    goto ERROR;
  }
  if (fread(&info[0], sizeof(uint32_t), 3, ncbi->fppin) != 3) status = eslFAIL;
  if (htobe32(info[0]) != NCBI_VERSION_4)                     status = eslEFORMAT;
  if (htobe32(info[1]) != dbtype)                             status = eslEFORMAT;
  if (status != eslOK) goto ERROR;
  ncbi->hdr_off = ncbi->vols[volume].hdr_off;
  ncbi->seq_off = ncbi->vols[volume].seq_off;
  if (dbtype == NCBI_DNA_DB) {
    ncbi->amb_off = ncbi->vols[volume].amb_off;
  }
  ncbi->vol_index   = volume;
  ncbi->index_start = -1;
  ncbi->index_end   = -1;
  fgetc(ncbi->fppsq);
  name[len] = '\0';
  return eslOK;
 ERROR:
  reset_db(ncbi);
  return status;
}
static int volume_open ( ESL_SQNCBI_DATA * ncbi , int volume ) { int len ; uint32_t info [ 4 ] ; int dbtype ; int status = eslOK ; char * name ; if ( volume < 0 || volume > ncbi -> volumes ) return eslEINVAL ; if ( ncbi -> volumes == 0 ) return eslOK ; if ( ncbi -> fppin != NULL ) fclose ( ncbi -> fppin ) ; if ( ncbi -> fpphr != NULL ) fclose ( ncbi -> fpphr ) ; if ( ncbi -> fppsq != NULL ) fclose ( ncbi -> fppsq ) ; name = ncbi -> vols [ volume ] . name ; len = strlen ( name ) ; dbtype = ( ncbi -> alphatype == eslDNA ) ? NCBI_DNA_DB : NCBI_AMINO_DB ; strcpy ( name + len , " " ) ; name [ len + 1 ] = ( dbtype == NCBI_DNA_DB ) ? ' ' : ' ' ; if ( ( ncbi -> fppin = fopen ( name , " " ) ) == NULL ) { status = eslFAIL ; goto ERROR ; } strcpy ( name + len , " " ) ; name [ len + 1 ] = ( dbtype == NCBI_DNA_DB ) ? ' ' : ' ' ; if ( ( ncbi -> fpphr = fopen ( name , " " ) ) == NULL ) { status = eslFAIL ; goto ERROR ; } strcpy ( name + len , " " ) ; name [ len + 1 ] = ( dbtype == NCBI_DNA_DB ) ? ' ' : ' ' ; if ( ( ncbi -> fppsq = fopen ( name , " " ) ) == NULL ) { status = eslFAIL ; goto ERROR ; } if ( fread ( & info [ 0 ] , sizeof ( uint32_t ) , 3 , ncbi -> fppin ) != 3 ) status = eslFAIL ; if ( htobe32 ( info [ 0 ] ) != NCBI_VERSION_4 ) status = eslEFORMAT ; if ( htobe32 ( info [ 1 ] ) != dbtype ) status = eslEFORMAT ; if ( status != eslOK ) goto ERROR ; ncbi -> hdr_off = ncbi -> vols [ volume ] . hdr_off ; ncbi -> seq_off = ncbi -> vols [ volume ] . seq_off ; if ( dbtype == NCBI_DNA_DB ) { ncbi -> amb_off = ncbi -> vols [ volume ] . amb_off ; } ncbi -> vol_index = volume ; ncbi -> index_start = -1 ; ncbi -> index_end = -1 ; fgetc ( ncbi -> fppsq ) ; name [ len ] = ' \0 ' ; return eslOK ; ERROR : reset_db ( ncbi ) ; return status ; }
volume_open()
 Open up the index, head and sequence files for a particular
 volume.
volume_open () Open up the index head and sequence files for a particular volume .
/* return status from an ESL call */ /* if the db has no volumes return */ /* Check for basic database first */ /* quickly parse the header make sure we are sane. */ /* save the offsets to the index tables */ /* skip the first sentinal byte in the .psq file */ /* zero terminate the name other functions can just
   * tack on any extension without a lot of testing.
   */