bcf_get_format_string

bcf_get_format_*() - same as bcf_get_info*() above

The function bcf_get_format_string() is a higher-level (slower) variant of bcf_get_format_char(). see the description of bcf_update_format_string() and bcf_update_format_char() above. Unlike other bcf_get_format__*() functions, bcf_get_format_string() allocates two arrays: a single block of \0-terminated strings collapsed into a single array and an array of pointers to these strings. Both arrays must be cleaned by the user.

Returns negative value on error or the number of written values on success.

Use the returned number of written values for accessing valid entries of dst, as ndst is only a watermark that can be higher than the returned value, i.e. the end of dst can contain carry-over values from previous calls to bcf_get_format_*() on lines with more values per sample.

  1. int bcf_get_format_string(const(bcf_hdr_t)* hdr, bcf1_t* line, const(char)* tag, char*** dst, int* ndst)
    extern (C)
    int
    bcf_get_format_string
    (
    const(bcf_hdr_t)* hdr
    ,,
    const(char)* tag
    ,
    char*** dst
    ,
    int* ndst
    )
  2. int bcf_get_format_values(const(bcf_hdr_t)* hdr, bcf1_t* line, const(char)* tag, void** dst, int* ndst, int type)

Examples

int ndst = 0; char **dst = NULL; if ( bcf_get_format_string(hdr, line, "XX", &dst, &ndst) > 0 ) for (i=0; i<bcf_hdr_nsamples(hdr); i++) printf("%s\n", dsti); free(dst[0]); free(dst);

int i, j, ngt, nsmpl = bcf_hdr_nsamples(hdr); int32_t *gt_arr = NULL, ngt_arr = 0;

ngt = bcf_get_genotypes(hdr, line, &gt_arr, &ngt_arr); if ( ngt<=0 ) return; // GT not present

int max_ploidy = ngt/nsmpl; for (i=0; i<nsmpl; i++) { int32_t *ptr = gt + i*max_ploidy; for (j=0; j<max_ploidy; j++) { // if true, the sample has smaller ploidy if ( ptrj==bcf_int32_vector_end ) break;

// missing allele if ( bcf_gt_is_missing(ptrj) ) continue;

// the VCF 0-based allele index int allele_index = bcf_gt_allele(ptrj);

// is phased? int is_phased = bcf_gt_is_phased(ptrj);

// .. do something .. } } free(gt_arr);

Meta