hmmer-3.3/easel/miniapps/esl-sfetch.c
/* Create an SSI index file for open sequence file <sqfp>.
 * Both name and accession of sequences are stored as keys.
 */
Create an SSI index file for open sequence file .
Both name and accession of sequences are stored as keys.
Create an SSI index file for open sequence file . Both name and accession of sequences are stored as keys .
static void
create_ssi_index(ESL_GETOPTS *go, ESL_SQFILE *sqfp)
{
  ESL_NEWSSI *ns      = NULL;
  ESL_SQ     *sq      = esl_sq_Create();
  int         nseq    = 0;
  char       *ssifile = NULL;
  uint16_t    fh;
  int         status;
  esl_strdup(sqfp->filename, -1, &ssifile);
  esl_strcat(&ssifile, -1, ".ssi", 4);
  status = esl_newssi_Open(ssifile, TRUE, &ns); 
  if      (status == eslENOTFOUND)   esl_fatal("failed to open SSI index %s", ssifile);
  else if (status == eslEOVERWRITE)  esl_fatal("SSI index %s already exists; delete or rename it", ssifile); 
  else if (status != eslOK)          esl_fatal("failed to create a new SSI index");
  if (esl_newssi_AddFile(ns, sqfp->filename, sqfp->format, &fh) != eslOK)
    esl_fatal("Failed to add sequence file %s to new SSI index\n", sqfp->filename);
  printf("Creating SSI index for %s...    ", sqfp->filename); 
  fflush(stdout);
  while ((status = esl_sqio_ReadInfo(sqfp, sq)) == eslOK)
    {
      nseq++;
      if (sq->name == NULL) esl_fatal("Every sequence must have a name to be indexed. Failed to find name of seq #%d\n", nseq);
      if (esl_newssi_AddKey(ns, sq->name, fh, sq->roff, sq->doff, sq->L) != eslOK)
	esl_fatal("Failed to add key %s to SSI index", sq->name);
      if (sq->acc[0] != '\0') {
	if (esl_newssi_AddAlias(ns, sq->acc, sq->name) != eslOK)
	  esl_fatal("Failed to add secondary key %s to SSI index", sq->acc);
      }
      esl_sq_Reuse(sq);
    }
  if      (status == eslEFORMAT) esl_fatal("Parse failed (sequence file %s):\n%s\n",
					   sqfp->filename, esl_sqfile_GetErrorBuf(sqfp));
  else if (status != eslEOF)     esl_fatal("Unexpected error %d reading sequence file %s",
					    status, sqfp->filename);
  if (sqfp->data.ascii.bpl > 0 && sqfp->data.ascii.rpl > 0) {
    if ((status = esl_newssi_SetSubseq(ns, fh, sqfp->data.ascii.bpl, sqfp->data.ascii.rpl)) != eslOK) 
      esl_fatal("Failed to set %s for fast subseq lookup.");
  }
  if (esl_newssi_Write(ns) != eslOK)  
    esl_fatal("\nFailed to write keys to ssi file %s:\n  %s", ssifile, ns->errbuf);
  printf("done.\n");
  if (ns->nsecondary > 0) 
    printf("Indexed %d sequences (%ld names and %ld accessions).\n", nseq, (long) ns->nprimary, (long) ns->nsecondary);
  else 
    printf("Indexed %d sequences (%ld names).\n", nseq, (long) ns->nprimary);
  printf("SSI index written to file %s\n", ssifile);
  free(ssifile);
  esl_sq_Destroy(sq);
  esl_newssi_Close(ns);
  return;
}
static void create_ssi_index ( ESL_GETOPTS * go , ESL_SQFILE * sqfp ) { ESL_NEWSSI * ns = NULL ; ESL_SQ * sq = esl_sq_Create ( ) ; int nseq = 0 ; char * ssifile = NULL ; uint16_t fh ; int status ; esl_strdup ( sqfp -> filename , -1 , & ssifile ) ; esl_strcat ( & ssifile , -1 , " " , 4 ) ; status = esl_newssi_Open ( ssifile , TRUE , & ns ) ; if ( status == eslENOTFOUND ) esl_fatal ( " " , ssifile ) ; else if ( status == eslEOVERWRITE ) esl_fatal ( " " , ssifile ) ; else if ( status != eslOK ) esl_fatal ( " " ) ; if ( esl_newssi_AddFile ( ns , sqfp -> filename , sqfp -> format , & fh ) != eslOK ) esl_fatal ( " \n " , sqfp -> filename ) ; printf ( " " , sqfp -> filename ) ; fflush ( stdout ) ; while ( ( status = esl_sqio_ReadInfo ( sqfp , sq ) ) == eslOK ) { nseq ++ ; if ( sq -> name == NULL ) esl_fatal ( " \n " , nseq ) ; if ( esl_newssi_AddKey ( ns , sq -> name , fh , sq -> roff , sq -> doff , sq -> L ) != eslOK ) esl_fatal ( " " , sq -> name ) ; if ( sq -> acc [ 0 ] != ' \0 ' ) { if ( esl_newssi_AddAlias ( ns , sq -> acc , sq -> name ) != eslOK ) esl_fatal ( " " , sq -> acc ) ; } esl_sq_Reuse ( sq ) ; } if ( status == eslEFORMAT ) esl_fatal ( " \n \n " , sqfp -> filename , esl_sqfile_GetErrorBuf ( sqfp ) ) ; else if ( status != eslEOF ) esl_fatal ( " " , status , sqfp -> filename ) ; if ( sqfp -> data . ascii . bpl > 0 && sqfp -> data . ascii . rpl > 0 ) { if ( ( status = esl_newssi_SetSubseq ( ns , fh , sqfp -> data . ascii . bpl , sqfp -> data . ascii . rpl ) ) != eslOK ) esl_fatal ( " " ) ; } if ( esl_newssi_Write ( ns ) != eslOK ) esl_fatal ( " \n \n " , ssifile , ns -> errbuf ) ; printf ( " \n " ) ; if ( ns -> nsecondary > 0 ) printf ( " \n " , nseq , ( long ) ns -> nprimary , ( long ) ns -> nsecondary ) ; else printf ( " \n " , nseq , ( long ) ns -> nprimary ) ; printf ( " \n " , ssifile ) ; free ( ssifile ) ; esl_sq_Destroy ( sq ) ; esl_newssi_Close ( ns ) ; return ; }
Create an SSI index file for open sequence file <sqfp>.
Create an SSI index file for open sequence file <sqfp > .
/* TRUE is for allowing overwrite. */ /* won't happen, see TRUE above... */ /* Determine if the file was suitable for fast subseq lookup. */ /* Save the SSI file to disk */ /* Done - output and exit. */