NVBIO
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Macros | Functions
vcfutils.c File Reference
#include "htslib/vcfutils.h"

Go to the source code of this file.

Macros

#define BRANCH_INT(type_t)
 
#define BRANCH_INT(type_t, missing, vector_end)
 
#define BRANCH_INT(type_t, missing, vector_end)
 
#define BRANCH(type_t, missing, vector_end)
 
#define BRANCH(type_t, is_vector_end)
 
#define BRANCH(type_t, is_vector_end)
 
#define BRANCH(type_t, is_vector_end)
 
#define BRANCH(type_t, is_vector_end)
 

Functions

int bcf_calc_ac (const bcf_hdr_t *header, bcf1_t *line, int *ac, int which)
 
int bcf_gt_type (bcf_fmt_t *fmt_ptr, int isample, int *_ial, int *_jal)
 
int bcf_trim_alleles (const bcf_hdr_t *header, bcf1_t *line)
 
void bcf_remove_alleles (const bcf_hdr_t *header, bcf1_t *line, int rm_mask)
 

Macro Definition Documentation

#define BRANCH (   type_t,
  missing,
  vector_end 
)
Value:
{ \
for (i=0; i<line->n_sample; i++) \
{ \
type_t *p = (type_t*) (gt->p + i*gt->size); \
int ial; \
for (ial=0; ial<gt->size; ial++) \
{ \
if ( p[ial]==vector_end ) break; /* smaller ploidy */ \
if ( !(p[ial]>>1) || p[ial]==missing ) continue; /* missing allele */ \
if ( (p[ial]>>1)-1 >= line->n_allele ) return -1; \
ac[(p[ial]>>1)-1]++; \
} \
} \
}
#define BRANCH (   type_t,
  is_vector_end 
)
Value:
{ \
type_t *ptr = (type_t*) dat; \
int size = sizeof(type_t); \
for (j=0; j<ntop; j++) /* j:ori, k:new */ \
{ \
if ( is_vector_end ) { memcpy(dat+k*size, dat+j*size, size); break; } \
if ( rm_mask & 1<<(j+inc) ) continue; \
if ( j!=k ) memcpy(dat+k*size, dat+j*size, size); \
k++; \
} \
}
#define BRANCH (   type_t,
  is_vector_end 
)
Value:
{ \
type_t *ptr = (type_t*) dat; \
int size = sizeof(type_t); \
for (j=0; j<nR_ori; j++) \
{ \
for (k=0; k<=j; k++) \
{ \
l_ori++; \
if ( is_vector_end ) { memcpy(dat+l_new*size, dat+l_ori*size, size); break; } \
if ( rm_mask & 1<<j || rm_mask & 1<<k ) continue; \
if ( l_ori!=l_new ) memcpy(dat+l_new*size, dat+l_ori*size, size); \
l_new++; \
} \
} \
}
#define BRANCH (   type_t,
  is_vector_end 
)
Value:
{ \
for (j=0; j<line->n_sample; j++) \
{ \
type_t *ptr_src = ((type_t*)dat) + j*nori; \
type_t *ptr_dst = ((type_t*)dat) + j*nA_new; \
int size = sizeof(type_t); \
int k_src, k_dst = 0; \
for (k_src=0; k_src<ntop; k_src++) \
{ \
if ( is_vector_end ) { memcpy(ptr_dst+k_dst, ptr_src+k_src, size); break; } \
if ( rm_mask & 1<<(k_src+inc) ) continue; \
if ( k_src!=k_dst ) memcpy(ptr_dst+k_dst, ptr_src+k_src, size); \
k_dst++; \
} \
} \
}
#define BRANCH (   type_t,
  is_vector_end 
)
#define BRANCH_INT (   type_t)
Value:
{ \
type_t *p = (type_t *) ac_ptr; \
for (i=0; i<ac_len; i++) \
{ \
ac[i+1] = p[i]; \
nac += p[i]; \
} \
}
#define BRANCH_INT (   type_t,
  missing,
  vector_end 
)
Value:
{ \
for (i=0; i<line->n_sample; i++) \
{ \
type_t *p = (type_t*) (fmt_gt->p + i*fmt_gt->size); \
int ial; \
for (ial=0; ial<fmt_gt->n; ial++) \
{ \
if ( p[ial]==vector_end ) break; /* smaller ploidy */ \
if ( !(p[ial]>>1) || p[ial]==missing ) continue; /* missing allele */ \
ac[(p[ial]>>1)-1]++; \
} \
} \
}
#define BRANCH_INT (   type_t,
  missing,
  vector_end 
)
Value:
{ \
type_t *p = (type_t*) (fmt_ptr->p + isample*fmt_ptr->size); \
for (i=0; i<fmt_ptr->n; i++) \
{ \
if ( p[i] == vector_end ) break; /* smaller ploidy */ \
if ( !p[i] || p[i] == missing ) continue; /* missing allele */ \
int tmp = p[i]>>1; \
if ( tmp>1 ) \
{ \
if ( !ial ) { ial = tmp; has_alt = 1; } \
else if ( tmp!=ial ) \
{ \
if ( tmp<ial ) \
{ \
jal = ial; \
ial = tmp; \
} \
else \
{ \
jal = tmp; \
} \
has_alt = 2; \
} \
} \
else has_ref = 1; \
nals++; \
} \
}

Function Documentation

int bcf_calc_ac ( const bcf_hdr_t header,
bcf1_t line,
int *  ac,
int  which 
)

bcf_calc_ac() - calculate the number of REF and ALT alleles : for access to BCF_DT_ID dictionary VCF line obtained from vcf_parse1 : array of length line->n_allele : determine if INFO/AN,AC and indv fields be used

Returns 1 if the call succeeded, or 0 if the value could not be determined.

The value of determines if existing INFO/AC,AN can be used (BCF_UN_INFO) and and if indv fields can be splitted (BCF_UN_FMT).

Definition at line 3 of file vcfutils.c.

int bcf_gt_type ( bcf_fmt_t fmt_ptr,
int  isample,
int *  _ial,
int *  _jal 
)

Definition at line 84 of file vcfutils.c.

void bcf_remove_alleles ( const bcf_hdr_t header,
bcf1_t line,
int  mask 
)

bcf_remove_alleles() - remove ALT alleles according to bitmask : for access to BCF_DT_ID dictionary VCF line obtained from vcf_parse1 : alleles to remove

Definition at line 177 of file vcfutils.c.

int bcf_trim_alleles ( const bcf_hdr_t header,
bcf1_t line 
)

bcf_trim_alleles() - remove ALT alleles unused in genotype fields : for access to BCF_DT_ID dictionary VCF line obtain from vcf_parse1

Returns the number of removed alleles on success or negative on error: -1 .. some allele index is out of bounds

Definition at line 135 of file vcfutils.c.