Gamgee
You miserable little maggot. I'll stove your head in!
|
#include <zlib.h>
#include <stdio.h>
#include <ctype.h>
#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <limits.h>
#include "htslib/kstring.h"
#include "htslib/bgzf.h"
#include "htslib/vcf.h"
#include "htslib/tbx.h"
#include "htslib/hfile.h"
#include "htslib/khash.h"
#include "htslib/kseq.h"
Classes | |
struct | fmt_aux_t |
Macros | |
#define | bit_array_size(n) ((n)/8+1) |
#define | bit_array_set(a, i) ((a)[(i)/8] |= 1 << ((i)%8)) |
#define | bit_array_clear(a, i) ((a)[(i)/8] &= ~(1 << ((i)%8))) |
#define | bit_array_test(a, i) ((a)[(i)/8] & (1 << ((i)%8))) |
#define | BRANCH(type_t, is_missing, is_vector_end, kprint) |
#define | BRANCH(type_t, missing) |
#define | BRANCH(type_t, is_missing, is_vector_end, set_missing, out_type_t) |
#define | BRANCH(type_t, is_missing, is_vector_end, set_missing, set_vector_end, out_type_t) |
Functions | |
typedef | khash_t (vdict) |
int | bcf_hdr_sync (bcf_hdr_t *h) |
int | bcf_hdr_add_sample (bcf_hdr_t *h, const char *s) |
void | bcf_hdr_parse_sample_line (bcf_hdr_t *h, const char *str) |
void | bcf_hrec_destroy (bcf_hrec_t *hrec) |
bcf_hrec_t * | bcf_hrec_dup (bcf_hrec_t *hrec) |
void | bcf_hrec_debug (FILE *fp, bcf_hrec_t *hrec) |
void | bcf_header_debug (bcf_hdr_t *hdr) |
void | bcf_hrec_add_key (bcf_hrec_t *hrec, const char *str, int len) |
void | bcf_hrec_set_val (bcf_hrec_t *hrec, int i, const char *str, int len, int is_quoted) |
void | hrec_add_idx (bcf_hrec_t *hrec, int idx) |
int | bcf_hrec_find_key (bcf_hrec_t *hrec, const char *key) |
bcf_hrec_t * | bcf_hdr_parse_line (const bcf_hdr_t *h, const char *line, int *len) |
int | bcf_hdr_register_hrec (bcf_hdr_t *hdr, bcf_hrec_t *hrec) |
int | bcf_hdr_add_hrec (bcf_hdr_t *hdr, bcf_hrec_t *hrec) |
bcf_hrec_t * | bcf_hdr_get_hrec (const bcf_hdr_t *hdr, int type, const char *key, const char *value, const char *str_class) |
void | bcf_hdr_check_sanity (bcf_hdr_t *hdr) |
int | bcf_hdr_parse (bcf_hdr_t *hdr, char *htxt) |
int | bcf_hdr_append (bcf_hdr_t *hdr, const char *line) |
void | bcf_hdr_remove (bcf_hdr_t *hdr, int type, const char *key) |
int | bcf_hdr_printf (bcf_hdr_t *hdr, const char *fmt,...) |
const char * | bcf_hdr_get_version (const bcf_hdr_t *hdr) |
void | bcf_hdr_set_version (bcf_hdr_t *hdr, const char *version) |
bcf_hdr_t * | bcf_hdr_init (const char *mode) |
void | bcf_hdr_destroy (bcf_hdr_t *h) |
bcf_hdr_t * | bcf_hdr_read (htsFile *hfp) |
int | bcf_hdr_write (htsFile *hfp, bcf_hdr_t *h) |
bcf1_t * | bcf_init1 () |
void | bcf_clear (bcf1_t *v) |
void | bcf_empty1 (bcf1_t *v) |
void | bcf_destroy1 (bcf1_t *v) |
int | bcf_subset_format (const bcf_hdr_t *hdr, bcf1_t *rec) |
int | bcf_read (htsFile *fp, const bcf_hdr_t *h, bcf1_t *v) |
int | bcf_readrec (BGZF *fp, void *null, void *vv, int *tid, int *beg, int *end) |
bcf1_t * | bcf_copy (bcf1_t *dst, bcf1_t *src) |
bcf1_t * | bcf_dup (bcf1_t *src) |
int | bcf_write (htsFile *hfp, const bcf_hdr_t *h, bcf1_t *v) |
bcf_hdr_t * | vcf_hdr_read (htsFile *fp) |
int | bcf_hdr_set (bcf_hdr_t *hdr, const char *fname) |
void | bcf_hrec_format (const bcf_hrec_t *hrec, kstring_t *str) |
char * | bcf_hdr_fmt_text (const bcf_hdr_t *hdr, int is_bcf, int *len) |
const char ** | bcf_hdr_seqnames (const bcf_hdr_t *h, int *n) |
int | vcf_hdr_write (htsFile *fp, const bcf_hdr_t *h) |
void | bcf_enc_vint (kstring_t *s, int n, int32_t *a, int wsize) |
void | bcf_enc_vfloat (kstring_t *s, int n, float *a) |
void | bcf_enc_vchar (kstring_t *s, int l, const char *a) |
void | bcf_fmt_array (kstring_t *s, int n, int type, void *data) |
uint8_t * | bcf_fmt_sized_array (kstring_t *s, uint8_t *ptr) |
int | _vcf_parse_format (kstring_t *s, const bcf_hdr_t *h, bcf1_t *v, char *p, char *q) |
int | vcf_parse (kstring_t *s, const bcf_hdr_t *h, bcf1_t *v) |
int | vcf_read (htsFile *fp, const bcf_hdr_t *h, bcf1_t *v) |
int | bcf_unpack (bcf1_t *b, int which) |
int | vcf_format (const bcf_hdr_t *h, const bcf1_t *v, kstring_t *s) |
int | vcf_write_line (htsFile *fp, kstring_t *line) |
int | vcf_write (htsFile *fp, const bcf_hdr_t *h, bcf1_t *v) |
int | bcf_hdr_id2int (const bcf_hdr_t *h, int which, const char *id) |
hts_idx_t * | bcf_index (htsFile *fp, int min_shift) |
int | bcf_index_build (const char *fn, int min_shift) |
int | bcf_hdr_combine (bcf_hdr_t *dst, const bcf_hdr_t *src) |
int | bcf_translate (const bcf_hdr_t *dst_hdr, bcf_hdr_t *src_hdr, bcf1_t *line) |
bcf_hdr_t * | bcf_hdr_dup (const bcf_hdr_t *hdr) |
bcf_hdr_t * | bcf_hdr_subset (const bcf_hdr_t *h0, int n, char *const *samples, int *imap) |
int | bcf_hdr_set_samples (bcf_hdr_t *hdr, const char *samples, int is_file) |
int | bcf_subset (const bcf_hdr_t *h, bcf1_t *v, int n, int *imap) |
int | bcf_is_snp (bcf1_t *v) |
int | bcf_get_variant_types (bcf1_t *rec) |
int | bcf_get_variant_type (bcf1_t *rec, int ith_allele) |
int | bcf_update_info (const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type) |
int | bcf_update_format_string (const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const char **values, int n) |
int | bcf_update_format (const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type) |
int | bcf_update_filter (const bcf_hdr_t *hdr, bcf1_t *line, int *flt_ids, int n) |
int | bcf_add_filter (const bcf_hdr_t *hdr, bcf1_t *line, int flt_id) |
int | bcf_remove_filter (const bcf_hdr_t *hdr, bcf1_t *line, int flt_id, int pass) |
int | bcf_has_filter (const bcf_hdr_t *hdr, bcf1_t *line, char *filter) |
int | bcf_update_alleles (const bcf_hdr_t *hdr, bcf1_t *line, const char **alleles, int nals) |
int | bcf_update_alleles_str (const bcf_hdr_t *hdr, bcf1_t *line, const char *alleles_string) |
int | bcf_update_id (const bcf_hdr_t *hdr, bcf1_t *line, const char *id) |
bcf_fmt_t * | bcf_get_fmt (const bcf_hdr_t *hdr, bcf1_t *line, const char *key) |
bcf_info_t * | bcf_get_info (const bcf_hdr_t *hdr, bcf1_t *line, const char *key) |
bcf_fmt_t * | bcf_get_fmt_id (bcf1_t *line, const int id) |
bcf_info_t * | bcf_get_info_id (bcf1_t *line, const int id) |
int | bcf_get_info_values (const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, void **dst, int *ndst, int type) |
int | bcf_get_format_string (const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, char ***dst, int *ndst) |
int | bcf_get_format_values (const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, void **dst, int *ndst, int type) |
#define bit_array_clear | ( | a, | |
i | |||
) | ((a)[(i)/8] &= ~(1 << ((i)%8))) |
#define bit_array_set | ( | a, | |
i | |||
) | ((a)[(i)/8] |= 1 << ((i)%8)) |
#define bit_array_size | ( | n | ) | ((n)/8+1) |
#define bit_array_test | ( | a, | |
i | |||
) | ((a)[(i)/8] & (1 << ((i)%8))) |
#define BRANCH | ( | type_t, | |
is_missing, | |||
is_vector_end, | |||
kprint | |||
) |
#define BRANCH | ( | type_t, | |
missing | |||
) |
#define BRANCH | ( | type_t, | |
is_missing, | |||
is_vector_end, | |||
set_missing, | |||
out_type_t | |||
) |
#define BRANCH | ( | type_t, | |
is_missing, | |||
is_vector_end, | |||
set_missing, | |||
set_vector_end, | |||
out_type_t | |||
) |
bcf_add_filter() - adds to the FILTER column : filter ID to add, numeric ID returned by bcf_id2int(hdr, BCF_DT_ID, "PASS")
If flt_id is PASS, all existing filters are removed first. If other than PASS, existing PASS is removed.
void bcf_clear | ( | bcf1_t * | v | ) |
Make the bcf1_t object ready for next read. Intended mostly for internal use, the user should rarely need to call this function directly.
void bcf_destroy1 | ( | bcf1_t * | v | ) |
void bcf_empty1 | ( | bcf1_t * | v | ) |
void bcf_enc_vchar | ( | kstring_t * | s, |
int | l, | ||
const char * | a | ||
) |
void bcf_enc_vfloat | ( | kstring_t * | s, |
int | n, | ||
float * | a | ||
) |
void bcf_enc_vint | ( | kstring_t * | s, |
int | n, | ||
int32_t * | a, | ||
int | wsize | ||
) |
void bcf_fmt_array | ( | kstring_t * | s, |
int | n, | ||
int | type, | ||
void * | data | ||
) |
uint8_t* bcf_fmt_sized_array | ( | kstring_t * | s, |
uint8_t * | ptr | ||
) |
bcf_get_fmt() - returns pointer to FORMAT's field data : for access to BCF_DT_ID dictionary VCF line obtained from vcf_parse1 : one of GT,PL,...
Returns bcf_fmt_t* if the call succeeded, or returns NULL when the field is not available.
bcf_get_*_id() - returns pointer to FORMAT/INFO field data given the header index instead of the string ID VCF line obtained from vcf_parse1 : The header index for the tag, obtained from bcf_hdr_id2int()
Returns bcf_fmt_t* / bcf_info_t*. These functions do not check if the index is valid as their goal is to avoid the header lookup.
int bcf_get_format_string | ( | const bcf_hdr_t * | hdr, |
bcf1_t * | line, | ||
const char * | tag, | ||
char *** | dst, | ||
int * | ndst | ||
) |
int bcf_get_format_values | ( | const bcf_hdr_t * | hdr, |
bcf1_t * | line, | ||
const char * | tag, | ||
void ** | dst, | ||
int * | ndst, | ||
int | type | ||
) |
bcf_info_t* bcf_get_info | ( | const bcf_hdr_t * | hdr, |
bcf1_t * | line, | ||
const char * | key | ||
) |
bcf_info_t* bcf_get_info_id | ( | bcf1_t * | line, |
const int | id | ||
) |
int bcf_get_info_values | ( | const bcf_hdr_t * | hdr, |
bcf1_t * | line, | ||
const char * | tag, | ||
void ** | dst, | ||
int * | ndst, | ||
int | type | ||
) |
int bcf_get_variant_type | ( | bcf1_t * | rec, |
int | ith_allele | ||
) |
int bcf_get_variant_types | ( | bcf1_t * | rec | ) |
bcf_get_variant_type[s]() - returns one of VCF_REF, VCF_SNP, etc
Returns 1 if present, 0 if absent, or -1 if filter does not exist. "PASS" and "." can be used interchangeably.
int bcf_hdr_add_hrec | ( | bcf_hdr_t * | hdr, |
bcf_hrec_t * | hrec | ||
) |
int bcf_hdr_add_sample | ( | bcf_hdr_t * | hdr, |
const char * | sample | ||
) |
bcf_hdr_add_sample() - add a new sample.
sample | sample name to be added |
int bcf_hdr_append | ( | bcf_hdr_t * | h, |
const char * | line | ||
) |
Append new VCF header line, returns 0 on success
void bcf_hdr_check_sanity | ( | bcf_hdr_t * | hdr | ) |
Copy header lines from src to dst if not already present in dst. See also bcf_translate(). Returns 0 on success or sets a bit on error: 1 .. conflicting definitions of tag length // todo
void bcf_hdr_destroy | ( | bcf_hdr_t * | h | ) |
Destroy a BCF header struct
char* bcf_hdr_fmt_text | ( | const bcf_hdr_t * | hdr, |
int | is_bcf, | ||
int * | len | ||
) |
Returns formatted header (newly allocated string) and its length, excluding the terminating \0. If is_bcf parameter is unset, IDX fields are discarded.
bcf_hrec_t* bcf_hdr_get_hrec | ( | const bcf_hdr_t * | hdr, |
int | type, | ||
const char * | key, | ||
const char * | value, | ||
const char * | str_class | ||
) |
bcf_hdr_get_hrec() - get header line info
type | one of the BCF_HL_* types: FLT,INFO,FMT,CTG,STR,GEN |
key | the header key for generic lines (e.g. "fileformat"), any field for structured lines, typically "ID". |
value | the value which pairs with key. Can be be NULL for BCF_HL_GEN |
str_class | the class of BCF_HL_STR line (e.g. "ALT" or "SAMPLE"), otherwise NULL |
const char* bcf_hdr_get_version | ( | const bcf_hdr_t * | hdr | ) |
int bcf_hdr_id2int | ( | const bcf_hdr_t * | hdr, |
int | type, | ||
const char * | id | ||
) |
bcf_hdr_id2int() - Translates string into numeric ID bcf_hdr_int2id() - Translates numeric ID into string : one of BCF_DT_ID, BCF_DT_CTG, BCF_DT_SAMPLE : tag name, such as: PL, DP, GT, etc.
Returns -1 if string is not in dictionary, otherwise numeric ID which identifies fields in BCF records.
bcf_hdr_t* bcf_hdr_init | ( | const char * | mode | ) |
bcf_hdr_init() - create an empty BCF header.
mode | "r" or "w" |
When opened for writing, the mandatory fileFormat and FILTER=PASS lines are added automatically.
int bcf_hdr_parse | ( | bcf_hdr_t * | hdr, |
char * | htxt | ||
) |
The following functions are for internal use and should rarely be called directly
bcf_hrec_t* bcf_hdr_parse_line | ( | const bcf_hdr_t * | h, |
const char * | line, | ||
int * | len | ||
) |
void bcf_hdr_parse_sample_line | ( | bcf_hdr_t * | h, |
const char * | str | ||
) |
int bcf_hdr_printf | ( | bcf_hdr_t * | hdr, |
const char * | fmt, | ||
... | |||
) |
int bcf_hdr_register_hrec | ( | bcf_hdr_t * | hdr, |
bcf_hrec_t * | hrec | ||
) |
void bcf_hdr_remove | ( | bcf_hdr_t * | h, |
int | type, | ||
const char * | key | ||
) |
bcf_hdr_remove() - remove VCF header tag
type | one of BCF_HL_* |
key | tag name |
const char** bcf_hdr_seqnames | ( | const bcf_hdr_t * | h, |
int * | nseqs | ||
) |
Creates a list of sequence names. It is up to the caller to free the list (but not the sequence names)
int bcf_hdr_set | ( | bcf_hdr_t * | hdr, |
const char * | fname | ||
) |
Read VCF header from a file and update the header
int bcf_hdr_set_samples | ( | bcf_hdr_t * | hdr, |
const char * | samples, | ||
int | is_file | ||
) |
bcf_hdr_set_samples() - for more efficient VCF parsing when only one/few samples are needed : samples to include or exclude from file or as a comma-separated string. LIST|FILE .. select samples in list/file ^LIST|FILE .. exclude samples from list/file
The bottleneck of VCF reading is parsing of genotype fields. If the reader knows in advance that only subset of samples is needed (possibly no samples at all), the performance of bcf_read() can be significantly improved by calling bcf_hdr_set_samples after bcf_hdr_read(). The function bcf_read() will subset the VCF/BCF records automatically with the notable exception when reading records via bcf_itr_next(). In this case, bcf_subset_format() must be called explicitly, because bcf_readrec() does not see the header.
Returns 0 on success, -1 on error or a positive integer if the list contains samples not present in the VCF header. In such a case, the return value is the index of the offending sample.
void bcf_hdr_set_version | ( | bcf_hdr_t * | hdr, |
const char * | version | ||
) |
bcf_hdr_subset() - creates a new copy of the header removing unwanted samples
n | number of samples to keep |
samples | names of the samples to keep |
imap | mapping from index in to the sample index in the original file |
Sample names not present in h0 are ignored. The number of unmatched samples can be checked by comparing n and bcf_hdr_nsamples(out_hdr). This function can be used to reorder samples. See also bcf_subset() which subsets individual records.
int bcf_hdr_sync | ( | bcf_hdr_t * | h | ) |
void bcf_header_debug | ( | bcf_hdr_t * | hdr | ) |
void bcf_hrec_add_key | ( | bcf_hrec_t * | hrec, |
const char * | str, | ||
int | len | ||
) |
void bcf_hrec_debug | ( | FILE * | fp, |
bcf_hrec_t * | hrec | ||
) |
void bcf_hrec_destroy | ( | bcf_hrec_t * | hrec | ) |
bcf_hrec_t* bcf_hrec_dup | ( | bcf_hrec_t * | hrec | ) |
int bcf_hrec_find_key | ( | bcf_hrec_t * | hrec, |
const char * | key | ||
) |
void bcf_hrec_format | ( | const bcf_hrec_t * | hrec, |
kstring_t * | str | ||
) |
void bcf_hrec_set_val | ( | bcf_hrec_t * | hrec, |
int | i, | ||
const char * | str, | ||
int | len, | ||
int | is_quoted | ||
) |
int bcf_index_build | ( | const char * | fn, |
int | min_shift | ||
) |
bcf1_t* bcf_init1 | ( | ) |
int bcf_is_snp | ( | bcf1_t * | v | ) |
bcf_read() - read next VCF or BCF record
Returns -1 on critical errors, 0 otherwise. On errors which are not critical for reading, such as missing header definitions, v->errcode is set to one of BCF_ERR* code and must be checked before calling vcf_write().
int bcf_readrec | ( | BGZF * | fp, |
void * | null, | ||
void * | v, | ||
int * | tid, | ||
int * | beg, | ||
int * | end | ||
) |
Helper function for the bcf_itr_next() macro; internal use, ignore it
bcf_remove_filter() - removes from the FILTER column : filter ID to remove, numeric ID returned by bcf_id2int(hdr, BCF_DT_ID, "PASS") : when set to 1 and no filters are present, set to PASS
See the description of bcf_hdr_subset()
bcf_translate() - translate tags ids to be consistent with different header. This function is useful when lines from multiple VCF need to be combined. : the destination header, to be used in bcf_write(), see also bcf_hdr_combine() : the source header, used in bcf_read() : line obtained by bcf_read()
int bcf_unpack | ( | bcf1_t * | b, |
int | which | ||
) |
bcf_update_alleles() and bcf_update_alleles_str() - update REF and ALLT column : Array of alleles : Number of alleles : Comma-separated alleles, starting with the REF allele
Not that in order for indexing to work correctly in presence of INFO/END tag, the length of reference allele (line->rlen) must be set explicitly by the caller, or otherwise, if rlen is zero, strlen(line->d.allele[0]) is used to set the length on bcf_write().
bcf_update_filter() - sets the FILTER column : The filter IDs to set, numeric IDs returned by bcf_id2int(hdr, BCF_DT_ID, "PASS")
: Number of filters. If n==0, all filters are removed
int bcf_update_format | ( | const bcf_hdr_t * | hdr, |
bcf1_t * | line, | ||
const char * | key, | ||
const void * | values, | ||
int | n, | ||
int | type | ||
) |
int bcf_update_format_string | ( | const bcf_hdr_t * | hdr, |
bcf1_t * | line, | ||
const char * | key, | ||
const char ** | values, | ||
int | n | ||
) |
int bcf_update_info | ( | const bcf_hdr_t * | hdr, |
bcf1_t * | line, | ||
const char * | key, | ||
const void * | values, | ||
int | n, | ||
int | type | ||
) |
bcf_write() - write one VCF or BCF record. The type is determined at the open() call.
void hrec_add_idx | ( | bcf_hrec_t * | hrec, |
int | idx | ||
) |
typedef khash_t | ( | vdict | ) |
The opposite of vcf_parse. It should rarely be called directly, see vcf_write
bcf_hdr_idinfo_exists(h,BCF_HL_FMT,fmt[i].id) )
The following functions work only with VCFs and should rarely be called directly. Usually one wants to use their bcf_* alternatives, which work transparently with both VCFs and BCFs.
Parse VCF line contained in kstring and populate the bcf1_t struct