vcf.c
/***************************************************************************
 *  Library:
 *      #include <biolibc/vcf.h>
 *      -lbiolibc -lxtend
 *
 *  Description:
 *      Skip over meta-data lines in VCF input stream, leaving the FILE
 *      structure pointing to the first character in the first line of data
 *      or the first character of the header line starting with #CHROM if
 *      one is present.  The header line is typically read using
 *      bl_vcf_get_sample_ids(3). The skipped meta-data is copied to a
 *      temporary file whose FILE pointer is returned.
 *
 *  Arguments:
 *      vcf_stream  FILE pointer of VCF stream to be read
 *
 *  Returns:
 *      BL_READ_OK upon success, BL_READ_TRUNCATED if read fails
 *
 *  See also:
 *      bl_vcf_get_sample_ids(3), bl_vcf_read_static_fields(3), bl_vcf_read_ss_call(3)
 *
 *  History: 
 *  Date        Name        Modification
 *  2019-12-06  Jason Bacon Begin
 ***************************************************************************/
#include 
-lbiolibc -lxtend

Skip over meta-data lines in VCF input stream, leaving the FILE
structure pointing to the first character in the first line of data
or the first character of the header line starting with #CHROM if
one is present.  The header line is typically read using
bl_vcf_get_sample_ids(3). The skipped meta-data is copied to a
temporary file whose FILE pointer is returned.

vcf_stream  FILE pointer of VCF stream to be read

BL_READ_OK upon success, BL_READ_TRUNCATED if read fails



Date        Name        Modification
2019-12-06  Jason Bacon Begin
#include - lbiolibc - lxtend Skip over meta - data lines in VCF input stream leaving the FILE structure pointing to the first character in the first line of data or the first character of the header line starting with #CHROM if one is present . The header line is typically read using bl_vcf_get_sample_ids ( 3 ) . The skipped meta - data is copied to a temporary file whose FILE pointer is returned . vcf_stream FILE pointer of VCF stream to be read BL_READ_OK upon success BL_READ_TRUNCATED if read fails Date Name Modification 2019 - 12 - 06 Jason Bacon Begin
FILE    *bl_vcf_skip_meta_data(FILE *vcf_stream)
{
    int     ch,
	    c,
	    count;
    char    start[6];
    FILE    *meta_stream;
    meta_stream = tmpfile();
    while ( (ch = getc(vcf_stream)) == '#' )
    {
	count = fread(start, 1, 5, vcf_stream);
	for (c = count - 1; c >= 0; --c)
	    ungetc(start[c], vcf_stream);
	if ( count != 5 )
	{
	    fclose(meta_stream);
	    return NULL;
	}
	if ( memcmp(start, "CHROM", 5) == 0 )
	{
	    ungetc(ch, vcf_stream);
	    rewind(meta_stream);
	    return meta_stream;
	}
	else
	{
	    putc('#', meta_stream);
	    do
	    {
		ch = getc(vcf_stream);
		putc(ch, meta_stream);
	    }   while ( (ch != '\n') && (ch != EOF) );
	    if ( ch == EOF )
	    {
		fprintf(stderr,
		    "bl_vcf_skip_meta_data(): EOF reached reading meta-data.\n");
		fclose(meta_stream);
		return NULL;
	    }
	}
    }
    fprintf(stderr, "bl_vcf_skip_meta_data(): Warning: No #CHROM found in header.\n");
    rewind(meta_stream);
    return meta_stream;
}
FILE * bl_vcf_skip_meta_data ( FILE * vcf_stream ) { int ch , c , count ; char start [ 6 ] ; FILE * meta_stream ; meta_stream = tmpfile ( ) ; while ( ( ch = getc ( vcf_stream ) ) == ' ' ) { count = fread ( start , 1 , 5 , vcf_stream ) ; for ( c = count - 1 ; c >= 0 ; -- c ) ungetc ( start [ c ] , vcf_stream ) ; if ( count != 5 ) { fclose ( meta_stream ) ; return NULL ; } if ( memcmp ( start , " " , 5 ) == 0 ) { ungetc ( ch , vcf_stream ) ; rewind ( meta_stream ) ; return meta_stream ; } else { putc ( ' ' , meta_stream ) ; do { ch = getc ( vcf_stream ) ; putc ( ch , meta_stream ) ; } while ( ( ch != ' \n ' ) && ( ch != EOF ) ) ; if ( ch == EOF ) { fprintf ( stderr , " \n " ) ; fclose ( meta_stream ) ; return NULL ; } } } fprintf ( stderr , " \n " ) ; rewind ( meta_stream ) ; return meta_stream ; }
Library:
      #include <biolibc/vcf.h>
      -lbiolibc -lxtend
Library : #include <biolibc / vcf . h > - lbiolibc - lxtend
/*
     *  Copy header to a nameless temp file and return the FILE *.
     *  This can be used by tools like vcf-split to replicate the
     *  header in output files.
     */ // Put back "CHROM" or whatever was read regardless // Something is seriously wrong if we don't find at least 5 chars // After return, read should start with #CHROM // No #CHROM, transfer entire line to temp file