hmmer-3.3/easel/esl_sqio_ncbi.c
/* sqncbi_AliasOpen()
 *
 * Opens an alias file parsing the DBLIST directive building
 * a list of all the volumes makeing up this database.  As each
 * volume is successfully parsed, the name of the volume, number
 * of sequences and offsets are kept for quick reference.
 */
sqncbi_AliasOpen()
Opens an alias file parsing the DBLIST directive building
a list of all the volumes makeing up this database.  As each
volume is successfully parsed, the name of the volume, number
of sequences and offsets are kept for quick reference.
sqncbi_AliasOpen () Opens an alias file parsing the DBLIST directive building a list of all the volumes makeing up this database . As each volume is successfully parsed the name of the volume number of sequences and offsets are kept for quick reference .
static int
sqncbi_AliasOpen(ESL_SQNCBI_DATA *ncbi, char *filename, int dbtype)
{
  int         status    = eslOK;	
  int         newline   = 1;
  int         seqcnt    = 0;
  int         rescnt    = 0;
  int         done      = 0;
  int         vol;
  int         len;
  char       *ptr       = NULL;
  char       *name      = NULL;
  char        buffer[80];
  char       *dbptr     = NULL;
  char       *dbname    = NULL;
  int         dbsize    = 512;
  int         dblen     = 0;
  FILE       *fp        = NULL;
  len = strlen(filename);
  ESL_ALLOC(name, sizeof(char) * (len+5));
  strcpy(name, filename);
  strcpy(name+len, ".Xal");
  name[len+1] = (dbtype == NCBI_DNA_DB) ? 'n' : 'p';
  if ((fp = fopen(name, "r")) == NULL) {
    status = eslENOTFOUND; 
    goto ERROR;
  }
  dbsize = (dbsize > len) ? dbsize : len * 2;
  ESL_ALLOC(dbname, sizeof(char) * dbsize);
  strcpy(dbname, filename);
  while (len > 0 && dbname[len-1] != eslDIRSLASH) {
    dbname[len-1] = '\0';
    --len;
  }
  while (!done) {
    ptr = buffer;
    if (fgets(buffer, sizeof(buffer), fp) == NULL) {
      status = eslEFORMAT;
      goto ERROR;
    }
    if (newline) {
      if (strncmp(buffer, "DBLIST", 6) == 0 && isspace(buffer[6])) {
	done = 1;
	ptr = buffer + 6;
      }
    }
    if (!done) {
      newline = 0;
      while (*ptr != '\0') {
	if (*ptr == '\n') newline = 1;
	++ptr;
      }
    }
  }
  done = 0;
  dblen = len;
  while (!done) {
    if (*ptr == '\0') {
      ptr = buffer;
      if (fgets(buffer, sizeof(buffer), fp) == NULL) {
	status = eslEFORMAT;
	goto ERROR;
      }
    }
    if (isspace(*ptr)) {
      if (dblen > len) {
	dbname[dblen++] = '\0';
	if (dbname[len] == eslDIRSLASH) {
	  dbptr = dbname + len;
	} else {
	  dbptr = dbname;
	}
	status = sqncbi_DbOpen(ncbi, dbptr, dbtype);
	if (status != eslOK) goto ERROR;
	reset_db(ncbi);
	vol = ncbi->volumes++;
	ncbi->vols[vol].name = NULL;
	ESL_ALLOC(ncbi->vols[vol].name, sizeof(char) * strlen(dbptr) + 5);
	strcpy(ncbi->vols[vol].name, dbptr);
	ncbi->vols[vol].start_seq = seqcnt;
	ncbi->vols[vol].end_seq   = seqcnt + ncbi->num_seq - 1;
	ncbi->vols[vol].hdr_off = ncbi->hdr_off;
	ncbi->vols[vol].seq_off = ncbi->seq_off;
	ncbi->vols[vol].amb_off = ncbi->amb_off;
	seqcnt += ncbi->num_seq;
	rescnt += ncbi->total_res;
	dblen = len;
      }
      done = *ptr == '\n' || *ptr == '\r';
      ptr++;
    } else {
      dbname[dblen++] = *ptr++;
      if (dblen >= dbsize - 1) {
	char *t;
	dbsize += dbsize;
	ESL_RALLOC(dbname, t, dbsize);
      }
    }
  }
  if ((status = volume_open(ncbi, 0)) != eslOK) goto ERROR;
  ncbi->num_seq = seqcnt;
  ncbi->total_res = rescnt;
  if (name   != NULL) free(name);
  if (dbname != NULL) free(dbname);
  if (fp != NULL) fclose(fp);
  return eslOK;
 ERROR:
  reset_db(ncbi);
  if (fp != NULL) fclose(fp);
  if (dbname != NULL) free(dbname);
  if (name   != NULL) free(name);
  return status;
}
static int sqncbi_AliasOpen ( ESL_SQNCBI_DATA * ncbi , char * filename , int dbtype ) { int status = eslOK ; int newline = 1 ; int seqcnt = 0 ; int rescnt = 0 ; int done = 0 ; int vol ; int len ; char * ptr = NULL ; char * name = NULL ; char buffer [ 80 ] ; char * dbptr = NULL ; char * dbname = NULL ; int dbsize = 512 ; int dblen = 0 ; FILE * fp = NULL ; len = strlen ( filename ) ; ESL_ALLOC ( name , sizeof ( char ) * ( len + 5 ) ) ; strcpy ( name , filename ) ; strcpy ( name + len , " " ) ; name [ len + 1 ] = ( dbtype == NCBI_DNA_DB ) ? ' ' : ' ' ; if ( ( fp = fopen ( name , " " ) ) == NULL ) { status = eslENOTFOUND ; goto ERROR ; } dbsize = ( dbsize > len ) ? dbsize : len * 2 ; ESL_ALLOC ( dbname , sizeof ( char ) * dbsize ) ; strcpy ( dbname , filename ) ; while ( len > 0 && dbname [ len - 1 ] != eslDIRSLASH ) { dbname [ len - 1 ] = ' \0 ' ; -- len ; } while ( ! done ) { ptr = buffer ; if ( fgets ( buffer , sizeof ( buffer ) , fp ) == NULL ) { status = eslEFORMAT ; goto ERROR ; } if ( newline ) { if ( strncmp ( buffer , " " , 6 ) == 0 && isspace ( buffer [ 6 ] ) ) { done = 1 ; ptr = buffer + 6 ; } } if ( ! done ) { newline = 0 ; while ( * ptr != ' \0 ' ) { if ( * ptr == ' \n ' ) newline = 1 ; ++ ptr ; } } } done = 0 ; dblen = len ; while ( ! done ) { if ( * ptr == ' \0 ' ) { ptr = buffer ; if ( fgets ( buffer , sizeof ( buffer ) , fp ) == NULL ) { status = eslEFORMAT ; goto ERROR ; } } if ( isspace ( * ptr ) ) { if ( dblen > len ) { dbname [ dblen ++ ] = ' \0 ' ; if ( dbname [ len ] == eslDIRSLASH ) { dbptr = dbname + len ; } else { dbptr = dbname ; } status = sqncbi_DbOpen ( ncbi , dbptr , dbtype ) ; if ( status != eslOK ) goto ERROR ; reset_db ( ncbi ) ; vol = ncbi -> volumes ++ ; ncbi -> vols [ vol ] . name = NULL ; ESL_ALLOC ( ncbi -> vols [ vol ] . name , sizeof ( char ) * strlen ( dbptr ) + 5 ) ; strcpy ( ncbi -> vols [ vol ] . name , dbptr ) ; ncbi -> vols [ vol ] . start_seq = seqcnt ; ncbi -> vols [ vol ] . end_seq = seqcnt + ncbi -> num_seq - 1 ; ncbi -> vols [ vol ] . hdr_off = ncbi -> hdr_off ; ncbi -> vols [ vol ] . seq_off = ncbi -> seq_off ; ncbi -> vols [ vol ] . amb_off = ncbi -> amb_off ; seqcnt += ncbi -> num_seq ; rescnt += ncbi -> total_res ; dblen = len ; } done = * ptr == ' \n ' || * ptr == ' \r ' ; ptr ++ ; } else { dbname [ dblen ++ ] = * ptr ++ ; if ( dblen >= dbsize - 1 ) { char * t ; dbsize += dbsize ; ESL_RALLOC ( dbname , t , dbsize ) ; } } } if ( ( status = volume_open ( ncbi , 0 ) ) != eslOK ) goto ERROR ; ncbi -> num_seq = seqcnt ; ncbi -> total_res = rescnt ; if ( name != NULL ) free ( name ) ; if ( dbname != NULL ) free ( dbname ) ; if ( fp != NULL ) fclose ( fp ) ; return eslOK ; ERROR : reset_db ( ncbi ) ; if ( fp != NULL ) fclose ( fp ) ; if ( dbname != NULL ) free ( dbname ) ; if ( name != NULL ) free ( name ) ; return status ; }
sqncbi_AliasOpen()
 Opens an alias file parsing the DBLIST directive building
 a list of all the volumes makeing up this database.
sqncbi_AliasOpen () Opens an alias file parsing the DBLIST directive building a list of all the volumes makeing up this database .
/* return status from an ESL call */ /* Check for alias file */ /* copy the filename */ /* remove the filename keeping the path */ /* find the DBLIST directive */ /* skip to the end of the line */ /* parse the DBLIST line */ /* check if we hit the end of the buffer */ /* skip spaces */ /* if the name in the DBLIST directive was ablsolute, do not
	 * use the working directory as a prefix.
	 */ /* close any open files and free up allocations */ /* if successful, copy the db information */ /* allocate the name of the string big enought so the buffer can
	 * handle an extension, i.e. ".pin" or ".nsq" tacked on to the end
	 * of it without reallocating.
	 */ /* reopen the first volume for processing */