This is an automated email from the git hooks/post-receive script. plessy pushed a commit to branch debian/unstable in repository htslib.
commit 5e770b308d2a77aed9d90a74fefb305731c940b0 Author: Petr Danecek <[email protected]> Date: Fri Dec 6 10:16:01 2013 +0000 vcf: bcf_update_format now sets the number of samples in VCF record which previously was responsibility of the user; Fix in bcf_itr_querys macro, non-existent bcf_name2id renamed to bcf_hdr_name2id --- htslib/vcf.h | 18 +++++++++--------- test/test-vcf-api.c | 14 ++++++-------- vcf.c | 19 ++++++++++--------- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/htslib/vcf.h b/htslib/vcf.h index 7be982b..2bebab4 100644 --- a/htslib/vcf.h +++ b/htslib/vcf.h @@ -371,23 +371,23 @@ extern "C" { * @flt_ids: The filter IDs to set, numeric IDs returned by bcf_id2int(hdr, BCF_DT_ID, "PASS") * @n: Number of filters. If n==0, all filters are removed */ - int bcf_update_filter(bcf_hdr_t *hdr, bcf1_t *line, int *flt_ids, int n); + int bcf_update_filter(const bcf_hdr_t *hdr, bcf1_t *line, int *flt_ids, int n); /** * bcf_add_filter() - adds to the FILTER column * @flt_id: 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. */ - int bcf_add_filter(bcf_hdr_t *hdr, bcf1_t *line, int flt_id); + int bcf_add_filter(const bcf_hdr_t *hdr, bcf1_t *line, int flt_id); /** * bcf_update_alleles() and bcf_update_alleles_str() - update REF and ALLT column * @alleles: Array of alleles * @nals: Number of alleles * @alleles_string: Comma-separated alleles, starting with the REF allele */ - int bcf_update_alleles(bcf_hdr_t *hdr, bcf1_t *line, const char **alleles, int nals); - int bcf_update_alleles_str(bcf_hdr_t *hdr, bcf1_t *line, const char *alleles_string); - int bcf_update_id(bcf_hdr_t *hdr, bcf1_t *line, const char *id); + 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); // If n==0, existing tag is removed. Otherwise it is updated or appended. With *_flag, $string is optional. // With *_string, existing tag is removed when $string set to NULL. @@ -395,14 +395,14 @@ extern "C" { #define bcf_update_info_float(hdr,line,key,values,n) bcf_update_info((hdr),(line),(key),(values),(n),BCF_HT_REAL) #define bcf_update_info_flag(hdr,line,key,string,n) bcf_update_info((hdr),(line),(key),(string),(n),BCF_HT_FLAG) #define bcf_update_info_string(hdr,line,key,string) bcf_update_info((hdr),(line),(key),(string),1,BCF_HT_STR) - int bcf_update_info(bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type); + int bcf_update_info(const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type); // If n==0, existing tag is removed. Otherwise it is updated or appended. #define bcf_update_format_int32(hdr,line,key,values,n) bcf_update_format((hdr),(line),(key),(values),(n),BCF_HT_INT) #define bcf_update_format_float(hdr,line,key,values,n) bcf_update_format((hdr),(line),(key),(values),(n),BCF_HT_REAL) #define bcf_update_format_char(hdr,line,key,values,n) bcf_update_format((hdr),(line),(key),(values),(n),BCF_HT_STR) #define bcf_update_genotypes(hdr,line,gts,n) bcf_update_format((hdr),(line),"GT",(gts),(n),BCF_HT_INT) // See bcf_gt_ macros below - int bcf_update_format(bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type); + int bcf_update_format(const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type); // Macros for setting genotypes correctly, for use with bcf_update_genotypes only; idx corresponds // to VCF's GT (1-based index to ALT or 0 for the reference allele) and val is the opposite, obtained @@ -457,7 +457,7 @@ extern "C" { #define bcf_get_format_int(hdr,line,tag,dst,ndst) bcf_get_format_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_INT) #define bcf_get_format_float(hdr,line,tag,dst,ndst) bcf_get_format_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_REAL) #define bcf_get_genotypes(hdr,line,dst,ndst) bcf_get_format_values(hdr,line,"GT",(void**)(dst),ndst,BCF_HT_STR) - int bcf_get_format_values(bcf_hdr_t *hdr, bcf1_t *line, const char *tag, void **dst, int *ndst, int type); + int bcf_get_format_values(const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, void **dst, int *ndst, int type); @@ -521,7 +521,7 @@ extern "C" { #define bcf_itr_destroy(iter) hts_itr_destroy(iter) #define bcf_itr_queryi(idx, tid, beg, end) hts_itr_query((idx), (tid), (beg), (end)) - #define bcf_itr_querys(idx, hdr, s) hts_itr_querys((idx), (s), (hts_name2id_f)(bcf_name2id), (hdr)) + #define bcf_itr_querys(idx, hdr, s) hts_itr_querys((idx), (s), (hts_name2id_f)(bcf_hdr_name2id), (hdr)) #define bcf_itr_next(htsfp, itr, r) hts_itr_next((htsfp)->fp.bgzf, (itr), (r), (hts_readrec_f)(bcf_readrec), 0) #define bcf_index_load(fn) hts_idx_load(fn, HTS_FMT_CSI) diff --git a/test/test-vcf-api.c b/test/test-vcf-api.c index 438cdf8..68feb2a 100644 --- a/test/test-vcf-api.c +++ b/test/test-vcf-api.c @@ -65,30 +65,29 @@ void write_bcf(char *fname) bcf_update_info_flag(hdr, rec, "DB", NULL, 1); bcf_update_info_flag(hdr, rec, "H2", NULL, 1); // .. FORMAT - rec->n_sample = hdr->n[BCF_DT_SAMPLE]; - int *tmpia = (int*)malloc(rec->n_sample*2*sizeof(int)); + int *tmpia = (int*)malloc(bcf_hdr_nsamples(hdr)*2*sizeof(int)); tmpia[0] = bcf_gt_phased(0); tmpia[1] = bcf_gt_phased(0); tmpia[2] = bcf_gt_phased(1); tmpia[3] = bcf_gt_phased(0); tmpia[4] = bcf_gt_unphased(1); tmpia[5] = bcf_gt_unphased(1); - bcf_update_genotypes(hdr, rec, tmpia, rec->n_sample*2); + bcf_update_genotypes(hdr, rec, tmpia, bcf_hdr_nsamples(hdr)*2); tmpia[0] = 48; tmpia[1] = 48; tmpia[2] = 43; - bcf_update_format_int32(hdr, rec, "GQ", tmpia, rec->n_sample); + bcf_update_format_int32(hdr, rec, "GQ", tmpia, bcf_hdr_nsamples(hdr)); tmpia[0] = 1; tmpia[1] = 8; tmpia[2] = 5; - bcf_update_format_int32(hdr, rec, "DP", tmpia, rec->n_sample); + bcf_update_format_int32(hdr, rec, "DP", tmpia, bcf_hdr_nsamples(hdr)); tmpia[0] = 51; tmpia[1] = 51; tmpia[2] = 51; tmpia[3] = 51; tmpia[4] = bcf_int32_missing; tmpia[5] = bcf_int32_missing; - bcf_update_format_int32(hdr, rec, "HQ", tmpia, rec->n_sample*2); + bcf_update_format_int32(hdr, rec, "HQ", tmpia, bcf_hdr_nsamples(hdr)*2); bcf_write1(fp, hdr, rec); // 20 1110696 . A G,T 67 . NS=2;DP=10;AF=0.333,.;AA=T;DB GT 2 1 ./. @@ -107,14 +106,13 @@ void write_bcf(char *fname) bcf_update_info_float(hdr, rec, "AF", tmpfa, 2); bcf_update_info_string(hdr, rec, "AA", "T"); bcf_update_info_flag(hdr, rec, "DB", NULL, 1); - rec->n_sample = hdr->n[BCF_DT_SAMPLE]; tmpia[0] = bcf_gt_phased(2); tmpia[1] = bcf_int32_vector_end; tmpia[2] = bcf_gt_phased(1); tmpia[3] = bcf_int32_vector_end; tmpia[4] = bcf_gt_missing; tmpia[5] = bcf_gt_missing; - bcf_update_genotypes(hdr, rec, tmpia, rec->n_sample*2); + bcf_update_genotypes(hdr, rec, tmpia, bcf_hdr_nsamples(hdr)*2); bcf_write1(fp, hdr, rec); free(tmpia); diff --git a/vcf.c b/vcf.c index 3ec380a..4023930 100644 --- a/vcf.c +++ b/vcf.c @@ -1832,7 +1832,7 @@ int bcf_get_variant_type(bcf1_t *rec, int ith_allele) return rec->d.var[ith_allele].type; } -int bcf_update_info(bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type) +int bcf_update_info(const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type) { // Is the field already present? int i, inf_id = bcf_hdr_id2int(hdr,BCF_DT_ID,key); @@ -1919,7 +1919,7 @@ int bcf_update_info(bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *v } -int bcf_update_format(bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type) +int bcf_update_format(const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type) { // Is the field already present? int i, fmt_id = bcf_hdr_id2int(hdr,BCF_DT_ID,key); @@ -1949,6 +1949,7 @@ int bcf_update_format(bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void return 0; } + line->n_sample = bcf_hdr_nsamples(hdr); int nps = n / line->n_sample; // number of values per sample assert( nps && nps*line->n_sample==n ); // must be divisible by n_sample @@ -2017,7 +2018,7 @@ int bcf_update_format(bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void } -int bcf_update_filter(bcf_hdr_t *hdr, bcf1_t *line, int *flt_ids, int n) +int bcf_update_filter(const bcf_hdr_t *hdr, bcf1_t *line, int *flt_ids, int n) { if ( !(line->unpacked & BCF_UN_FLT) ) bcf_unpack(line, BCF_UN_FLT); line->d.shared_dirty |= BCF1_DIRTY_FLT; @@ -2030,7 +2031,7 @@ int bcf_update_filter(bcf_hdr_t *hdr, bcf1_t *line, int *flt_ids, int n) return 0; } -int bcf_add_filter(bcf_hdr_t *hdr, bcf1_t *line, int flt_id) +int bcf_add_filter(const bcf_hdr_t *hdr, bcf1_t *line, int flt_id) { if ( !(line->unpacked & BCF_UN_FLT) ) bcf_unpack(line, BCF_UN_FLT); int i; @@ -2049,7 +2050,7 @@ int bcf_add_filter(bcf_hdr_t *hdr, bcf1_t *line, int flt_id) return 1; } -static inline int _bcf1_sync_alleles(bcf_hdr_t *hdr, bcf1_t *line, int nals) +static inline int _bcf1_sync_alleles(const bcf_hdr_t *hdr, bcf1_t *line, int nals) { line->n_allele = nals; hts_expand(char*, line->n_allele, line->d.m_allele, line->d.allele); @@ -2067,7 +2068,7 @@ static inline int _bcf1_sync_alleles(bcf_hdr_t *hdr, bcf1_t *line, int nals) line->d.shared_dirty |= BCF1_DIRTY_ALS; return 0; } -int bcf_update_alleles(bcf_hdr_t *hdr, bcf1_t *line, const char **alleles, int nals) +int bcf_update_alleles(const bcf_hdr_t *hdr, bcf1_t *line, const char **alleles, int nals) { kstring_t tmp = {0,0,0}; char *free_old = NULL; @@ -2094,7 +2095,7 @@ int bcf_update_alleles(bcf_hdr_t *hdr, bcf1_t *line, const char **alleles, int n return _bcf1_sync_alleles(hdr,line,nals); } -int bcf_update_alleles_str(bcf_hdr_t *hdr, bcf1_t *line, const char *alleles_string) +int bcf_update_alleles_str(const bcf_hdr_t *hdr, bcf1_t *line, const char *alleles_string) { kstring_t tmp; tmp.l = 0; tmp.s = line->d.als; tmp.m = line->d.m_als; @@ -2111,7 +2112,7 @@ int bcf_update_alleles_str(bcf_hdr_t *hdr, bcf1_t *line, const char *alleles_str return _bcf1_sync_alleles(hdr, line, nals); } -int bcf_update_id(bcf_hdr_t *hdr, bcf1_t *line, const char *id) +int bcf_update_id(const bcf_hdr_t *hdr, bcf1_t *line, const char *id) { kstring_t tmp; tmp.l = 0; tmp.s = line->d.id; tmp.m = line->d.m_id; @@ -2196,7 +2197,7 @@ int bcf_get_info_values(bcf_hdr_t *hdr, bcf1_t *line, const char *tag, void **ds return -4; // this can never happen } -int bcf_get_format_values(bcf_hdr_t *hdr, bcf1_t *line, const char *tag, void **dst, int *ndst, int type) +int bcf_get_format_values(const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, void **dst, int *ndst, int type) { int i,j, tag_id = bcf_hdr_id2int(hdr, BCF_DT_ID, tag); if ( !bcf_hdr_idinfo_exists(hdr,BCF_HL_FMT,tag_id) ) return -1; // no such FORMAT field in the header -- Alioth's /git/debian-med/git-commit-notice on /srv/git.debian.org/git/debian-med/htslib.git _______________________________________________ debian-med-commit mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/debian-med-commit
