[med-svn] [htslib] 03/10: Replaced fprintf(stderr, ...) calls with hts_log_<level> calls.

Andreas Tille tille at debian.org
Wed Jul 19 19:54:28 UTC 2017


This is an automated email from the git hooks/post-receive script.

tille pushed a commit to annotated tag 1.5
in repository htslib.

commit 03c4be2b6b8a3a13874e1f3b6552d2331ee6c7f3
Author: Anders Kaplan <anders.kaplan at magasin1.se>
Date:   Sun Jun 4 10:53:00 2017 +0200

    Replaced fprintf(stderr, ...) calls with hts_log_<level> calls.
---
 vcf.c      | 108 ++++++++++++++++++++++++++++++++-----------------------------
 vcfutils.c |  10 +++---
 2 files changed, 62 insertions(+), 56 deletions(-)

diff --git a/vcf.c b/vcf.c
index e1f871e..6a7f16a 100644
--- a/vcf.c
+++ b/vcf.c
@@ -94,7 +94,7 @@ int bcf_hdr_add_sample(bcf_hdr_t *h, const char *s)
     while ( !*ss && isspace_c(*ss) ) ss++;
     if ( !*ss )
     {
-        fprintf(stderr,"[E::%s] Empty sample name: trailing spaces/tabs in the header line?\n", __func__);
+        hts_log_error("Empty sample name: trailing spaces/tabs in the header line?");
         abort();
     }
 
@@ -333,8 +333,8 @@ bcf_hrec_t *bcf_hdr_parse_line(const bcf_hdr_t *h, const char *line, int *len)
         {
             // wrong format
             while ( *q && *q!='\n' ) q++;
-            fprintf(stderr,"Could not parse the header line: \"%.*s\"\n",
-                    (int) (q - line), line);
+            hts_log_error("Could not parse the header line: \"%.*s\"",
+                (int) (q - line), line);
             *len = q - line + (*q ? 1 : 0);
             bcf_hrec_destroy(hrec);
             return NULL;
@@ -382,7 +382,8 @@ static int bcf_hdr_set_idx(bcf_hdr_t *hdr, int dict_type, const char *tag, bcf_i
         idinfo->id = hdr->n[dict_type]++;
     else if ( idinfo->id < hdr->n[dict_type] && hdr->id[dict_type][idinfo->id].key )
     {
-        fprintf(stderr,"[%s:%d %s] Conflicting IDX=%d lines in the header dictionary, the new tag is %s\n", __FILE__,__LINE__,__FUNCTION__, idinfo->id, tag);
+        hts_log_error("Conflicting IDX=%d lines in the header dictionary, the new tag is %s",
+            idinfo->id, tag);
         exit(1);
     }
 
@@ -429,7 +430,7 @@ int bcf_hdr_register_hrec(bcf_hdr_t *hdr, bcf_hrec_t *hrec)
             idx = strtol(hrec->vals[idx], &tmp, 10);
             if ( *tmp || idx < 0 || idx >= INT_MAX - 1)
             {
-                fprintf(stderr,"[%s:%d %s] Error parsing the IDX tag, skipping.\n", __FILE__,__LINE__,__FUNCTION__);
+                hts_log_warning("Error parsing the IDX tag, skipping");
                 return 0;
             }
         }
@@ -463,7 +464,7 @@ int bcf_hdr_register_hrec(bcf_hdr_t *hdr, bcf_hrec_t *hrec)
             idx = strtol(hrec->vals[i], &tmp, 10);
             if ( *tmp || idx < 0 || idx >= INT_MAX - 1)
             {
-                fprintf(stderr,"[%s:%d %s] Error parsing the IDX tag, skipping.\n", __FILE__,__LINE__,__FUNCTION__);
+                hts_log_warning("Error parsing the IDX tag, skipping");
                 return 0;
             }
         }
@@ -643,7 +644,7 @@ int bcf_hdr_parse(bcf_hdr_t *hdr, char *htxt)
     // Check sanity: "fileformat" string must come as first
     bcf_hrec_t *hrec = bcf_hdr_parse_line(hdr,p,&len);
     if ( !hrec || !hrec->key || strcasecmp(hrec->key,"fileformat") )
-        fprintf(stderr, "[W::%s] The first line should be ##fileformat; is the VCF/BCF header broken?\n", __func__);
+        hts_log_warning("The first line should be ##fileformat; is the VCF/BCF header broken?");
     needs_sync += bcf_hdr_add_hrec(hdr, hrec);
 
     // The filter PASS must appear first in the dictionary
@@ -800,7 +801,7 @@ const char *bcf_hdr_get_version(const bcf_hdr_t *hdr)
     bcf_hrec_t *hrec = bcf_hdr_get_hrec(hdr, BCF_HL_GEN, "fileformat", NULL, NULL);
     if ( !hrec )
     {
-        fprintf(stderr,"No version string found, assuming VCFv4.2\n");
+        hts_log_warning("No version string found, assuming VCFv4.2");
         return "VCFv4.2";
     }
     return hrec->value;
@@ -876,8 +877,7 @@ bcf_hdr_t *bcf_hdr_read(htsFile *hfp)
     if (hfp->format.format == vcf)
         return vcf_hdr_read(hfp);
     if (hfp->format.format != bcf) {
-        fprintf(stderr, "[E::%s] Input is not detected as bcf or vcf format\n",
-                __func__);
+        hts_log_error("Input is not detected as bcf or vcf format");
         return NULL;
     }
 
@@ -888,12 +888,12 @@ bcf_hdr_t *bcf_hdr_read(htsFile *hfp)
     bcf_hdr_t *h;
     h = bcf_hdr_init("r");
     if (!h) {
-        fprintf(stderr, "[E::%s] failed to allocate bcf header\n", __func__);
+        hts_log_error("Failed to allocate bcf header");
         return NULL;
     }
     if (bgzf_read(fp, magic, 5) != 5)
     {
-        fprintf(stderr,"[%s:%d %s] Failed to read the header (reading BCF in text mode?)\n", __FILE__,__LINE__,__FUNCTION__);
+        hts_log_error("Failed to read the header (reading BCF in text mode?)");
         bcf_hdr_destroy(h);
         return NULL;
     }
@@ -1495,8 +1495,8 @@ int bcf_write(htsFile *hfp, bcf_hdr_t *h, bcf1_t *v)
     if ( h->dirty ) bcf_hdr_sync(h);
     if ( bcf_hdr_nsamples(h)!=v->n_sample )
     {
-        fprintf(stderr,"[%s:%d %s] Broken VCF record, the number of columns at %s:%d does not match the number of samples (%d vs %d).\n",
-                __FILE__,__LINE__,__FUNCTION__,bcf_seqname(h,v),v->pos+1, v->n_sample,bcf_hdr_nsamples(h));
+        hts_log_error("Broken VCF record, the number of columns at %s:%d does not match the number of samples (%d vs %d)",
+            bcf_seqname(h,v), v->pos+1, v->n_sample, bcf_hdr_nsamples(h));
         return -1;
     }
 
@@ -1509,7 +1509,7 @@ int bcf_write(htsFile *hfp, bcf_hdr_t *h, bcf1_t *v)
         // header.  At this point, the header must have been printed,
         // proceeding would lead to a broken BCF file. Errors must be checked
         // and cleared by the caller before we can proceed.
-        fprintf(stderr,"[%s:%d %s] Unchecked error (%d), exiting.\n", __FILE__,__LINE__,__FUNCTION__,v->errcode);
+        hts_log_error("Unchecked error (%d), exiting", v->errcode);
         exit(1);
     }
     bcf1_sync(v);   // check if the BCF record was modified
@@ -1538,7 +1538,7 @@ bcf_hdr_t *vcf_hdr_read(htsFile *fp)
     bcf_hdr_t *h;
     h = bcf_hdr_init("r");
     if (!h) {
-        fprintf(stderr, "[E::%s] failed to allocate bcf header\n", __func__);
+        hts_log_error("Failed to allocate bcf header");
         return NULL;
     }
     txt.l = txt.m = 0; txt.s = 0;
@@ -1552,7 +1552,7 @@ bcf_hdr_t *vcf_hdr_read(htsFile *fp)
             kstring_t tmp = { 0, 0, NULL };
             hFILE *f = hopen(fp->fn_aux, "r");
             if (f == NULL) {
-                fprintf(stderr, "[E::%s] couldn't open \"%s\"\n", __func__, fp->fn_aux);
+                hts_log_error("Couldn't open \"%s\"", fp->fn_aux);
                 goto error;
             }
             while (tmp.l = 0, kgetline(&tmp, (kgets_func *) hgets, f) >= 0) {
@@ -1574,7 +1574,7 @@ bcf_hdr_t *vcf_hdr_read(htsFile *fp)
     if ( ret < -1 ) goto error;
     if ( !txt.s )
     {
-        fprintf(stderr,"[%s:%d %s] Could not read the header\n", __FILE__,__LINE__,__FUNCTION__);
+        hts_log_error("Could not read the header");
         goto error;
     }
     if ( bcf_hdr_parse(h, txt.s) < 0 ) goto error;
@@ -1831,7 +1831,7 @@ void bcf_fmt_array(kstring_t *s, int n, int type, void *data)
             case BCF_BT_INT16: BRANCH(int16_t, le_to_i16, v==bcf_int16_missing, v==bcf_int16_vector_end, kputw(v, s)); break;
             case BCF_BT_INT32: BRANCH(int32_t, le_to_i32, v==bcf_int32_missing, v==bcf_int32_vector_end, kputw(v, s)); break;
             case BCF_BT_FLOAT: BRANCH(uint32_t, le_to_u32, v==bcf_float_missing, v==bcf_float_vector_end, kputd(le_to_float(p), s)); break;
-            default: fprintf(stderr,"todo: type %d\n", type); exit(1); break;
+            default: hts_log_error("Unexpected type %d", type); exit(1); break;
         }
         #undef BRANCH
     }
@@ -1883,7 +1883,7 @@ static int vcf_parse_format(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v, char *p
     char *end = s->s + s->l;
     if ( q>=end )
     {
-        fprintf(stderr,"[%s:%d %s] Error: FORMAT column with no sample columns starting at %s:%d\n", __FILE__,__LINE__,__FUNCTION__,s->s,v->pos+1);
+        hts_log_error("FORMAT column with no sample columns starting at %s:%d", s->s, v->pos+1);
         return -1;
     }
 
@@ -1898,7 +1898,8 @@ static int vcf_parse_format(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v, char *p
     for (j = 0, t = kstrtok(p, ":", &aux1); t; t = kstrtok(0, 0, &aux1), ++j) {
         if (j >= MAX_N_FMT) {
             v->errcode |= BCF_ERR_LIMITS;
-            fprintf(stderr,"[E::%s] Error: FORMAT column at %s:%d lists more identifiers than htslib can handle.\n", __func__, bcf_seqname(h,v), v->pos+1);
+            hts_log_error("FORMAT column at %s:%d lists more identifiers than htslib can handle",
+                bcf_seqname(h,v), v->pos+1);
             return -1;
         }
 
@@ -1907,7 +1908,7 @@ static int vcf_parse_format(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v, char *p
         if (k == kh_end(d) || kh_val(d, k).info[BCF_HL_FMT] == 15) {
             if ( t[0]=='.' && t[1]==0 )
             {
-                fprintf(stderr, "[E::%s] Invalid FORMAT tag name '.'\n", __func__);
+                hts_log_error("Invalid FORMAT tag name '.'");
                 v->errcode |= BCF_ERR_TAG_INVALID;
                 return -1;
             }
@@ -1921,7 +1922,7 @@ static int vcf_parse_format(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v, char *p
             k = kh_get(vdict, d, t);
             v->errcode = BCF_ERR_TAG_UNDEF;
             if (k == kh_end(d)) {
-                fprintf(stderr, "[E::%s] Could not add dummy header for FORMAT '%s'\n", __func__, t);
+                hts_log_error("Could not add dummy header for FORMAT '%s'", t);
                 v->errcode |= BCF_ERR_TAG_INVALID;
                 return -1;
             }
@@ -1965,8 +1966,9 @@ static int vcf_parse_format(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v, char *p
                 {
                     j++;
                     if ( j>=v->n_fmt ) 
-                    { 
-                        fprintf(stderr,"Incorrect number of FORMAT fields at %s:%d\n", h->id[BCF_DT_CTG][v->rid].key,v->pos+1);
+                    {
+                        hts_log_error("Incorrect number of FORMAT fields at %s:%d",
+                            h->id[BCF_DT_CTG][v->rid].key, v->pos+1);
                         exit(1); 
                     }
                 }
@@ -1992,7 +1994,7 @@ static int vcf_parse_format(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v, char *p
             f->size = f->max_m << 2;
         } else
         {
-            fprintf(stderr, "[E::%s] the format type %d currently not supported\n", __func__, f->y>>4&0xf);
+            hts_log_error("The format type %d is currently not supported", f->y>>4&0xf);
             abort(); // I do not know how to do with Flag in the genotype fields
         }
         align_mem(mem);
@@ -2071,7 +2073,8 @@ static int vcf_parse_format(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v, char *p
             }
             else {
                 char buffer[8];
-                fprintf(stderr,"[E::%s] Invalid character '%s' in '%s' FORMAT field at %s:%d\n", __FUNCTION__, dump_char(buffer, *t), h->id[BCF_DT_ID][z->key].key, bcf_seqname(h,v), v->pos+1);
+                hts_log_error("Invalid character '%s' in '%s' FORMAT field at %s:%d",
+                    dump_char(buffer, *t), h->id[BCF_DT_ID][z->key].key, bcf_seqname(h,v), v->pos+1);
                 v->errcode |= BCF_ERR_CHAR;
                 return -1;
             }
@@ -2129,15 +2132,14 @@ static int vcf_parse_format(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v, char *p
 
     if ( v->n_sample!=bcf_hdr_nsamples(h) )
     {
-        fprintf(stderr,"[%s:%d %s] Number of columns at %s:%d does not match the number of samples (%d vs %d).\n",
-                __FILE__,__LINE__,__FUNCTION__,bcf_seqname(h,v),v->pos+1, v->n_sample,bcf_hdr_nsamples(h));
+        hts_log_error("Number of columns at %s:%d does not match the number of samples (%d vs %d)",
+            bcf_seqname(h,v), v->pos+1, v->n_sample, bcf_hdr_nsamples(h));
         v->errcode |= BCF_ERR_NCOLS;
         return -1;
     }
     if ( v->indiv.l > 0xffffffff )
     {
-        fprintf(stderr,"[%s:%d %s] The FORMAT at %s:%d is too long...\n",
-                __FILE__,__LINE__,__FUNCTION__,bcf_seqname(h,v),v->pos+1);
+        hts_log_error("The FORMAT at %s:%d is too long", bcf_seqname(h,v), v->pos+1);
         v->errcode |= BCF_ERR_LIMITS;
 
         // Error recovery: return -1 if this is a critical error or 0 if we want to ignore the FORMAT and proceed
@@ -2185,7 +2187,7 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v)
                 k = kh_get(vdict, d, p);
                 v->errcode = BCF_ERR_CTG_UNDEF;
                 if (k == kh_end(d)) {
-                    fprintf(stderr, "[E::%s] Could not add dummy header for contig '%s'\n", __func__, p);
+                    hts_log_error("Could not add dummy header for contig '%s'", p);
                     v->errcode |= BCF_ERR_CTG_INVALID;
                     goto err;
                 }
@@ -2226,7 +2228,7 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v)
                 if (n_flt > max_n_flt) {
                     int32_t *a = realloc(flt_a, n_flt * sizeof(int32_t));
                     if (!a) {
-                        fprintf(stderr, "[E::%s] Could not allocate memory\n", __func__);
+                        hts_log_error("Could not allocate memory");
                         v->errcode |= BCF_ERR_LIMITS; // No appropriate code?
                         goto err;
                     }
@@ -2251,7 +2253,7 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v)
                         k = kh_get(vdict, d, t);
                         v->errcode = BCF_ERR_TAG_UNDEF;
                         if (k == kh_end(d)) {
-                            fprintf(stderr, "[E::%s] Could not add dummy header for FILTER '%s'\n", __func__, t);
+                            hts_log_error("Could not add dummy header for FILTER '%s'", t);
                             v->errcode |= BCF_ERR_TAG_INVALID;
                             goto err;
                         }
@@ -2293,7 +2295,7 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v)
                         k = kh_get(vdict, d, key);
                         v->errcode = BCF_ERR_TAG_UNDEF;
                         if (k == kh_end(d)) {
-                            fprintf(stderr, "[E::%s] Could not add dummy header for INFO '%s'\n", __func__, key);
+                            hts_log_error("Could not add dummy header for INFO '%s'", key);
                             v->errcode |= BCF_ERR_TAG_INVALID;
                             goto err;
                         }
@@ -2315,7 +2317,7 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v)
                             int32_t *z;
                             z = (int32_t *)realloc((void *)val_a, n_val * sizeof(*z));
                             if (!z) {
-                                fprintf(stderr, "[E::%s] Could not allocate memory\n", __func__);
+                                hts_log_error("Could not allocate memory");
                                 v->errcode |= BCF_ERR_LIMITS; // No appropriate code?
                                 goto err;
                             }
@@ -2519,7 +2521,7 @@ int vcf_format(const bcf_hdr_t *h, const bcf1_t *v, kstring_t *s)
             if ( !first ) kputc(';', s);
             first = 0;
             if (z->key >= h->n[BCF_DT_ID]) {
-                fprintf(stderr, "[E::%s] invalid BCF, the INFO index is too large.\n", __func__);
+                hts_log_error("Invalid BCF, the INFO index is too large");
                 errno = EINVAL;
                 return -1;
             }
@@ -2535,7 +2537,7 @@ int vcf_format(const bcf_hdr_t *h, const bcf1_t *v, kstring_t *s)
                     case BCF_BT_INT32: if ( z->v1.i==bcf_int32_missing ) kputc('.', s); else kputw(z->v1.i, s); break;
                     case BCF_BT_FLOAT: if ( bcf_float_is_missing(z->v1.f) ) kputc('.', s); else kputd(z->v1.f, s); break;
                     case BCF_BT_CHAR:  kputc(z->v1.i, s); break;
-                    default: fprintf(stderr,"todo: type %d\n", z->type); exit(1); break;
+                    default: hts_log_error("Unexpected type %d", z->type); exit(1); break;
                 }
             }
             else bcf_fmt_array(s, z->len, z->type, z->vptr);
@@ -2556,7 +2558,7 @@ int vcf_format(const bcf_hdr_t *h, const bcf1_t *v, kstring_t *s)
                 kputc(!first ? ':' : '\t', s); first = 0;
                 if ( fmt[i].id<0 ) //!bcf_hdr_idinfo_exists(h,BCF_HL_FMT,fmt[i].id) )
                 {
-                    fprintf(stderr, "[E::%s] invalid BCF, the FORMAT tag id=%d not present in the header.\n", __func__, fmt[i].id);
+                    hts_log_error("Invalid BCF, the FORMAT tag id=%d not present in the header", fmt[i].id);
                     abort();
                 }
                 kputs(h->id[BCF_DT_ID][fmt[i].id].key, s);
@@ -2777,12 +2779,14 @@ int bcf_hdr_combine(bcf_hdr_t *dst, const bcf_hdr_t *src)
                 khint_t k_dst  = kh_get(vdict, d_dst, src->hrec[i]->vals[0]);
                 if ( (kh_val(d_src,k_src).info[rec->type]>>8 & 0xf) != (kh_val(d_dst,k_dst).info[rec->type]>>8 & 0xf) )
                 {
-                    fprintf(stderr,"Warning: trying to combine \"%s\" tag definitions of different lengths\n", src->hrec[i]->vals[0]);
+                    hts_log_warning("Trying to combine \"%s\" tag definitions of different lengths",
+                        src->hrec[i]->vals[0]);
                     ret |= 1;
                 }
                 if ( (kh_val(d_src,k_src).info[rec->type]>>4 & 0xf) != (kh_val(d_dst,k_dst).info[rec->type]>>4 & 0xf) )
                 {
-                    fprintf(stderr,"Warning: trying to combine \"%s\" tag definitions of different types\n", src->hrec[i]->vals[0]);
+                    hts_log_warning("Trying to combine \"%s\" tag definitions of different types",
+                        src->hrec[i]->vals[0]);
                     ret |= 1;
                 }
             }
@@ -2855,12 +2859,14 @@ bcf_hdr_t *bcf_hdr_merge(bcf_hdr_t *dst, const bcf_hdr_t *src)
                 khint_t k_dst  = kh_get(vdict, d_dst, src->hrec[i]->vals[0]);
                 if ( (kh_val(d_src,k_src).info[rec->type]>>8 & 0xf) != (kh_val(d_dst,k_dst).info[rec->type]>>8 & 0xf) )
                 {
-                    fprintf(stderr,"Warning: trying to combine \"%s\" tag definitions of different lengths\n", src->hrec[i]->vals[0]);
+                    hts_log_warning("Trying to combine \"%s\" tag definitions of different lengths",
+                        src->hrec[i]->vals[0]);
                     ret |= 1;
                 }
                 if ( (kh_val(d_src,k_src).info[rec->type]>>4 & 0xf) != (kh_val(d_dst,k_dst).info[rec->type]>>4 & 0xf) )
                 {
-                    fprintf(stderr,"Warning: trying to combine \"%s\" tag definitions of different types\n", src->hrec[i]->vals[0]);
+                    hts_log_warning("Trying to combine \"%s\" tag definitions of different types",
+                        src->hrec[i]->vals[0]);
                     ret |= 1;
                 }
             }
@@ -2874,7 +2880,7 @@ int bcf_translate(const bcf_hdr_t *dst_hdr, bcf_hdr_t *src_hdr, bcf1_t *line)
     int i;
     if ( line->errcode )
     {
-        fprintf(stderr,"[%s:%d %s] Unchecked error (%d), exiting.\n", __FILE__,__LINE__,__FUNCTION__,line->errcode);
+        hts_log_error("Unchecked error (%d), exiting", line->errcode);
         exit(1);
     }
     if ( src_hdr->ntransl==-1 ) return 0;    // no need to translate, all tags have the same id
@@ -2987,7 +2993,7 @@ bcf_hdr_t *bcf_hdr_dup(const bcf_hdr_t *hdr)
 {
     bcf_hdr_t *hout = bcf_hdr_init("r");
     if (!hout) {
-        fprintf(stderr, "[E::%s] failed to allocate bcf header\n", __func__);
+        hts_log_error("Failed to allocate bcf header");
         return NULL;
     }
     kstring_t htxt = {0,0,0};
@@ -3007,7 +3013,7 @@ bcf_hdr_t *bcf_hdr_subset(const bcf_hdr_t *h0, int n, char *const* samples, int
     kstring_t str = {0,0,0};
     bcf_hdr_t *h = bcf_hdr_init("w");
     if (!h) {
-        fprintf(stderr, "[E::%s] failed to allocate bcf header\n", __func__);
+        hts_log_error("Failed to allocate bcf header");
         return NULL;
     }
     bcf_hdr_format(h0, 1, &htxt);
@@ -3026,7 +3032,7 @@ bcf_hdr_t *bcf_hdr_subset(const bcf_hdr_t *h0, int n, char *const* samples, int
         for (i = 0; i < n; ++i) {
             if ( khash_str2int_has_key(names_hash,samples[i]) )
             {
-                fprintf(stderr,"[E::bcf_hdr_subset] Duplicate sample name \"%s\".\n", samples[i]);
+                hts_log_error("Duplicate sample name \"%s\"", samples[i]);
                 free(str.s);
                 free(htxt.s);
                 khash_str2int_destroy(names_hash);
@@ -3300,7 +3306,7 @@ int bcf_update_info(const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const v
     }
     else
     {
-        fprintf(stderr, "[E::%s] the type %d not implemented yet\n", __func__, type);
+        hts_log_error("The type %d not implemented yet", type);
         abort();
     }
 
@@ -3421,7 +3427,7 @@ int bcf_update_format(const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const
     }
     else
     {
-        fprintf(stderr, "[E::%s] the type %d not implemented yet\n", __func__, type);
+        hts_log_error("The type %d not implemented yet", type);
         abort();
     }
 
@@ -3728,7 +3734,7 @@ int bcf_get_info_values(const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, voi
         case BCF_BT_INT16: BRANCH(int16_t, le_to_i16, p==bcf_int16_missing, p==bcf_int16_vector_end, *tmp=bcf_int32_missing, *tmp=p, int32_t); break;
         case BCF_BT_INT32: BRANCH(int32_t, le_to_i32, p==bcf_int32_missing, p==bcf_int32_vector_end, *tmp=bcf_int32_missing, *tmp=p, int32_t); break;
         case BCF_BT_FLOAT: BRANCH(uint32_t, le_to_u32, p==bcf_float_missing, p==bcf_float_vector_end, bcf_float_set_missing(*tmp), bcf_float_set(tmp, p), float); break;
-        default: fprintf(stderr,"TODO: %s:%d .. info->type=%d\n", __FILE__,__LINE__, info->type); exit(1);
+        default: hts_log_error("Unexpected type %d", info->type); exit(1);
     }
     #undef BRANCH
     return -4;  // this can never happen
@@ -3837,7 +3843,7 @@ int bcf_get_format_values(const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, v
         case BCF_BT_INT16: BRANCH(int16_t, le_to_i16, p==bcf_int16_missing, p==bcf_int16_vector_end, *tmp=bcf_int32_missing, *tmp=bcf_int32_vector_end, *tmp=p, int32_t); break;
         case BCF_BT_INT32: BRANCH(int32_t, le_to_i32, p==bcf_int32_missing, p==bcf_int32_vector_end, *tmp=bcf_int32_missing, *tmp=bcf_int32_vector_end, *tmp=p, int32_t); break;
         case BCF_BT_FLOAT: BRANCH(uint32_t, le_to_u32, p==bcf_float_missing, p==bcf_float_vector_end, bcf_float_set_missing(*tmp), bcf_float_set_vector_end(*tmp), bcf_float_set(tmp, p), float); break;
-        default: fprintf(stderr,"TODO: %s:%d .. fmt->type=%d\n", __FILE__,__LINE__, fmt->type); exit(1);
+        default: hts_log_error("Unexpected type %d", fmt->type); exit(1);
     }
     #undef BRANCH
     return nsmpl*fmt->n;
diff --git a/vcfutils.c b/vcfutils.c
index d1526fa..4e1a6c9 100644
--- a/vcfutils.c
+++ b/vcfutils.c
@@ -64,12 +64,12 @@ int bcf_calc_ac(const bcf_hdr_t *header, bcf1_t *line, int *ac, int which)
                 case BCF_BT_INT8:  BRANCH_INT(int8_t); break;
                 case BCF_BT_INT16: BRANCH_INT(int16_t); break;
                 case BCF_BT_INT32: BRANCH_INT(int32_t); break;
-                default: fprintf(stderr, "[E::%s] todo: %d at %s:%d\n", __func__, ac_type, header->id[BCF_DT_CTG][line->rid].key, line->pos+1); exit(1); break;
+                default: hts_log_error("Unexpected type %d at %s:%d", ac_type, header->id[BCF_DT_CTG][line->rid].key, line->pos+1); exit(1); break;
             }
             #undef BRANCH_INT
             if ( an<nac )
             {
-                fprintf(stderr,"[E::%s] Incorrect AN/AC counts at %s:%d\n", __func__,header->id[BCF_DT_CTG][line->rid].key, line->pos+1); 
+                hts_log_error("Incorrect AN/AC counts at %s:%d", header->id[BCF_DT_CTG][line->rid].key, line->pos+1);
                 exit(1); 
             }
             ac[0] = an - nac;
@@ -98,7 +98,7 @@ int bcf_calc_ac(const bcf_hdr_t *header, bcf1_t *line, int *ac, int which)
                     if ( bcf_gt_is_missing(p[ial]) ) continue; /* missing allele */ \
                     if ( p[ial]>>1 > line->n_allele ) \
                     { \
-                        fprintf(stderr,"[E::%s] Incorrect allele (\"%d\") in %s at %s:%d\n", __func__,(p[ial]>>1)-1, header->samples[i],header->id[BCF_DT_CTG][line->rid].key, line->pos+1); \
+                        hts_log_error("Incorrect allele (\"%d\") in %s at %s:%d", (p[ial]>>1)-1, header->samples[i], header->id[BCF_DT_CTG][line->rid].key, line->pos+1); \
                         exit(1); \
                     } \
                     ac[(p[ial]>>1)-1]++; \
@@ -109,7 +109,7 @@ int bcf_calc_ac(const bcf_hdr_t *header, bcf1_t *line, int *ac, int which)
             case BCF_BT_INT8:  BRANCH_INT(int8_t,  bcf_int8_vector_end); break;
             case BCF_BT_INT16: BRANCH_INT(int16_t, bcf_int16_vector_end); break;
             case BCF_BT_INT32: BRANCH_INT(int32_t, bcf_int32_vector_end); break;
-            default: fprintf(stderr, "[E::%s] todo: %d at %s:%d\n", __func__, fmt_gt->type, header->id[BCF_DT_CTG][line->rid].key, line->pos+1); exit(1); break;
+            default: hts_log_error("Unexpected type %d at %s:%d", fmt_gt->type, header->id[BCF_DT_CTG][line->rid].key, line->pos+1); exit(1); break;
         }
         #undef BRANCH_INT
         return 1;
@@ -152,7 +152,7 @@ int bcf_gt_type(bcf_fmt_t *fmt_ptr, int isample, int *_ial, int *_jal)
         case BCF_BT_INT8:  BRANCH_INT(int8_t,  bcf_int8_vector_end); break;
         case BCF_BT_INT16: BRANCH_INT(int16_t, bcf_int16_vector_end); break;
         case BCF_BT_INT32: BRANCH_INT(int32_t, bcf_int32_vector_end); break;
-        default: fprintf(stderr, "[E::%s] todo: fmt_type %d\n", __func__, fmt_ptr->type); exit(1); break;
+        default: hts_log_error("Unexpected type %d", fmt_ptr->type); exit(1); break;
     }
     #undef BRANCH_INT
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-med/htslib.git



More information about the debian-med-commit mailing list