vcf.c
/***************************************************************************
 *  Library:
 *      #include <biolibc/vcf.h>
 *      -lbiolibc -lxtend
 *
 *  Description:
 *      Extract sample IDs from a VCF input header line.  This is typically
 *      done following bl_vcf_skip_meta_data(3), which will leave the FILE
 *      pointer pointing to the beginning of the header line, if one is
 *      present.
 *
 *      The arguments first_col and last_col represent the first and
 *      last sample columns, both inclusive, from which sample IDs should
 *      be extracted.  A value of 1 represents the first sample column.
 *      This feature allows a VCF file with many columns to be processed
 *      in multiple stages.  For example, the vcf-split tool, based on
 *      biolibc, cannot efficiently process more than abou1 10,000 samples
 *      at once, since each sample requires an open output file.  A VCF
 *      with 150,000 samples can be processed in 15 separate passes.
 *
 *  Arguments:
 *      vcf_stream  FILE pointer to the VCF input stream
 *      sample_ids  Array if character pointers to receive sample IDs
 *      first_col   First column from which a sample ID should be saved
 *      last_col    Last column from which a sample ID should be saved
 *
 *  See also:
 *      bl_vcf_skip_meta_data(3)
 *
 *  History: 
 *  Date        Name        Modification
 *  2019-12-06  Jason Bacon Begin
 ***************************************************************************/
#include 
-lbiolibc -lxtend

Extract sample IDs from a VCF input header line.  This is typically
done following bl_vcf_skip_meta_data(3), which will leave the FILE
pointer pointing to the beginning of the header line, if one is
present.

The arguments first_col and last_col represent the first and
last sample columns, both inclusive, from which sample IDs should
be extracted.  A value of 1 represents the first sample column.
This feature allows a VCF file with many columns to be processed
in multiple stages.  For example, the vcf-split tool, based on
biolibc, cannot efficiently process more than abou1 10,000 samples
at once, since each sample requires an open output file.  A VCF
with 150,000 samples can be processed in 15 separate passes.

vcf_stream  FILE pointer to the VCF input stream
sample_ids  Array if character pointers to receive sample IDs
first_col   First column from which a sample ID should be saved
last_col    Last column from which a sample ID should be saved



Date        Name        Modification
2019-12-06  Jason Bacon Begin
#include - lbiolibc - lxtend Extract sample IDs from a VCF input header line . This is typically done following bl_vcf_skip_meta_data ( 3 ) which will leave the FILE pointer pointing to the beginning of the header line if one is present . The arguments first_col and last_col represent the first and last sample columns both inclusive from which sample IDs should be extracted . A value of 1 represents the first sample column . This feature allows a VCF file with many columns to be processed in multiple stages . For example the vcf - split tool based on biolibc cannot efficiently process more than abou1 10 000 samples at once since each sample requires an open output file . A VCF with 150 000 samples can be processed in 15 separate passes . vcf_stream FILE pointer to the VCF input stream sample_ids Array if character pointers to receive sample IDs first_col First column from which a sample ID should be saved last_col Last column from which a sample ID should be saved Date Name Modification 2019 - 12 - 06 Jason Bacon Begin
void    bl_vcf_get_sample_ids(FILE *vcf_stream, char *sample_ids[],
			   size_t first_col, size_t last_col)
{
    size_t  c,
	    len;
    char    temp_sample_id[BL_VCF_ID_MAX_CHARS + 1];
    int     delimiter = 0;
    for (c = 0; c < 9; ++c)
	tsv_skip_field(vcf_stream, &len);
    for (c = 1; c < first_col; ++c)
	tsv_skip_field(vcf_stream, &len);
    for (; (c <= last_col) &&
	   (delimiter = tsv_read_field(vcf_stream, temp_sample_id,
				     BL_VCF_ID_MAX_CHARS, &len)) != EOF; ++c)
    {
	sample_ids[c - first_col] = strdup(temp_sample_id);
    }
    if ( delimiter == 0 )
    {
	fprintf(stderr, "Reached last_col before reading any sample IDs.\n");
	fprintf(stderr, "Check your first_col and last_col values.\n");
	exit(EX_DATAERR);
    }
    if ( delimiter != '\n' )
	tsv_skip_rest_of_line(vcf_stream);
}
void bl_vcf_get_sample_ids ( FILE * vcf_stream , char * sample_ids [ ] , size_t first_col , size_t last_col ) { size_t c , len ; char temp_sample_id [ BL_VCF_ID_MAX_CHARS + 1 ] ; int delimiter = 0 ; for ( c = 0 ; c < 9 ; ++ c ) tsv_skip_field ( vcf_stream , & len ) ; for ( c = 1 ; c < first_col ; ++ c ) tsv_skip_field ( vcf_stream , & len ) ; for ( ; ( c <= last_col ) && ( delimiter = tsv_read_field ( vcf_stream , temp_sample_id , BL_VCF_ID_MAX_CHARS , & len ) ) != EOF ; ++ c ) { sample_ids [ c - first_col ] = strdup ( temp_sample_id ) ; } if ( delimiter == 0 ) { fprintf ( stderr , " \n " ) ; fprintf ( stderr , " \n " ) ; exit ( EX_DATAERR ) ; } if ( delimiter != ' \n ' ) tsv_skip_rest_of_line ( vcf_stream ) ; }
Library:
      #include <biolibc/vcf.h>
      -lbiolibc -lxtend
Library : #include <biolibc / vcf . h > - lbiolibc - lxtend
// Skip standard header tags to get to sample IDs // Skip sample IDs before first_col // fprintf(stderr, "'%s'\n", temp_sample_id); // Skip any remaining fields after last_col