hmmer-3.3/easel/esl_sqio_ncbi.c
/* Function:  parse_header()
 * Synopsis:  Parse the ncbi db header
 * Incept:    MSF, Mon Dec 10, 2009 [Janelia]
 *
 * Purpose:   Parse a ncbi database header.  This routine implements
 *            a recursive descent parser for the ASN.1 definition of
 *            a blast database header filling in <sq>.
 *
 *            The blast db header can have multiple definitions defined
 *            within it.  Only the information from the first usable
 *            defition will be used.
 *
 * Returns:   <eslOK> on success; the new sequence is stored in <s>.
 * 
 *            Returns <eslEFORMAT> if there's a problem with the format,
 *            such as an illegal character.
 */
parse_header()
Synopsis:  Parse the ncbi db header
Incept:    MSF, Mon Dec 10, 2009 [Janelia]

Parse a ncbi database header.  This routine implements
a recursive descent parser for the ASN.1 definition of
a blast database header filling in .

The blast db header can have multiple definitions defined
within it.  Only the information from the first usable
defition will be used.

 on success; the new sequence is stored in .

Returns  if there's a problem with the format,
such as an illegal character.
parse_header () Synopsis : Parse the ncbi db header Incept : MSF Mon Dec 10 2009 [ Janelia ] Parse a ncbi database header . This routine implements a recursive descent parser for the ASN . 1 definition of a blast database header filling in . The blast db header can have multiple definitions defined within it . Only the information from the first usable defition will be used . on success ; the new sequence is stored in . Returns if there ' s a problem with the format such as an illegal character .
static int
parse_header(ESL_SQNCBI_DATA *ncbi, ESL_SQ *sq)
{
  int   size;
  int   status;
  void *tmp;
  unsigned char c;
  reset_header_values(ncbi);
  size  = ncbi->hoff - ncbi->roff;
  if (ncbi->hdr_alloced < size) {
    while (ncbi->hdr_alloced < size) ncbi->hdr_alloced += ncbi->hdr_alloced;
    ESL_RALLOC(ncbi->hdr_buf, tmp, sizeof(char) * ncbi->hdr_alloced);
  }
  if (fread(ncbi->hdr_buf, sizeof(char), size, ncbi->fpphr) != size) return eslEFORMAT;
  ncbi->hdr_ptr = ncbi->hdr_buf;
  if (parse_expect(ncbi, "\x30\x80", 2) != eslOK)             return eslEFORMAT;
  if (parse_peek(ncbi, &c) != eslOK)                          return eslEFORMAT;
  while (c != 0x00) {
    if ((status = parse_def_line(ncbi, sq)) != eslOK)         return status;
    if (parse_peek(ncbi, &c) != eslOK)                        return eslEFORMAT;
  }
  if (parse_expect(ncbi, "\x00\x00", 2) != eslOK)             return eslEFORMAT;
  return eslOK;
 ERROR:
  return eslEMEM;
}
static int parse_header ( ESL_SQNCBI_DATA * ncbi , ESL_SQ * sq ) { int size ; int status ; void * tmp ; unsigned char c ; reset_header_values ( ncbi ) ; size = ncbi -> hoff - ncbi -> roff ; if ( ncbi -> hdr_alloced < size ) { while ( ncbi -> hdr_alloced < size ) ncbi -> hdr_alloced += ncbi -> hdr_alloced ; ESL_RALLOC ( ncbi -> hdr_buf , tmp , sizeof ( char ) * ncbi -> hdr_alloced ) ; } if ( fread ( ncbi -> hdr_buf , sizeof ( char ) , size , ncbi -> fpphr ) != size ) return eslEFORMAT ; ncbi -> hdr_ptr = ncbi -> hdr_buf ; if ( parse_expect ( ncbi , " \x30 \x80 " , 2 ) != eslOK ) return eslEFORMAT ; if ( parse_peek ( ncbi , & c ) != eslOK ) return eslEFORMAT ; while ( c != 0x00 ) { if ( ( status = parse_def_line ( ncbi , sq ) ) != eslOK ) return status ; if ( parse_peek ( ncbi , & c ) != eslOK ) return eslEFORMAT ; } if ( parse_expect ( ncbi , " \x00 \x00 " , 2 ) != eslOK ) return eslEFORMAT ; return eslOK ; ERROR : return eslEMEM ; }
Function:  parse_header()
 Synopsis:  Parse the ncbi db header
 Incept:    MSF, Mon Dec 10, 2009 [Janelia]
Function : parse_header () Synopsis : Parse the ncbi db header Incept : MSF Mon Dec 10 2009 [ Janelia ]
/* read in the header data */ /* verify we are at the beginning of a structure */ /* parse the different seq id structures */ /* verify we are at the end of the structure */