Skip to content

Commit

Permalink
Prepare for 64-bit positions
Browse files Browse the repository at this point in the history
This does not add 64-bit position support, it just ensures bcftools
will build without warnings (using gcc/clang -Wall) when built
against both 32-bit and 64-bit position branches of HTSlib.

Makes various printf()s use PRId64 for positions.  The values
are cast to (int64_t) so both 32-bit and 64-bit versions work.
  • Loading branch information
daviesrob committed Sep 9, 2019
1 parent 63f4b93 commit aec5177
Show file tree
Hide file tree
Showing 40 changed files with 273 additions and 249 deletions.
26 changes: 13 additions & 13 deletions consensus.c
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ static void unread_vcf_line(args_t *args, bcf1_t **rec_ptr)
{
bcf1_t *rec = *rec_ptr;
if ( args->vcf_rbuf.n >= args->vcf_rbuf.m )
error("FIXME: too many overlapping records near %s:%d\n", bcf_seqname(args->hdr,rec),rec->pos+1);
error("FIXME: too many overlapping records near %s:%"PRId64"\n", bcf_seqname(args->hdr,rec),(int64_t) rec->pos+1);

// Insert the new record in the buffer. The line would be overwritten in
// the next bcf_sr_next_line call, therefore we need to swap it with an
Expand Down Expand Up @@ -397,7 +397,7 @@ static void apply_variant(args_t *args, bcf1_t *rec)
if ( !fmt ) return;

if ( fmt->type!=BCF_BT_INT8 )
error("Todo: GT field represented with BCF_BT_INT8, too many alleles at %s:%d?\n",bcf_seqname(args->hdr,rec),rec->pos+1);
error("Todo: GT field represented with BCF_BT_INT8, too many alleles at %s:%"PRId64"?\n",bcf_seqname(args->hdr,rec),(int64_t) rec->pos+1);
uint8_t *ptr = fmt->p + fmt->size*args->isample;

enum { use_hap, use_iupac, pick_one } action = use_hap;
Expand All @@ -421,7 +421,7 @@ static void apply_variant(args_t *args, bcf1_t *rec)
{
if ( !warned_haplotype )
{
fprintf(stderr, "Can't apply %d-th haplotype at %s:%d. (This warning is printed only once.)\n", args->haplotype,bcf_seqname(args->hdr,rec),rec->pos+1);
fprintf(stderr, "Can't apply %d-th haplotype at %s:%"PRId64". (This warning is printed only once.)\n", args->haplotype,bcf_seqname(args->hdr,rec),(int64_t) rec->pos+1);
warned_haplotype = 1;
}
return;
Expand Down Expand Up @@ -467,7 +467,7 @@ static void apply_variant(args_t *args, bcf1_t *rec)

if ( ialt>=0 )
{
if ( rec->n_allele <= ialt || rec->n_allele <= jalt ) error("Invalid VCF, too few ALT alleles at %s:%d\n", bcf_seqname(args->hdr,rec),rec->pos+1);
if ( rec->n_allele <= ialt || rec->n_allele <= jalt ) error("Invalid VCF, too few ALT alleles at %s:%"PRId64"\n", bcf_seqname(args->hdr,rec),(int64_t) rec->pos+1);
if ( ialt!=jalt && !rec->d.allele[ialt][1] && !rec->d.allele[jalt][1] ) // is this a het snp?
{
char ial = rec->d.allele[ialt][0];
Expand Down Expand Up @@ -499,7 +499,7 @@ static void apply_variant(args_t *args, bcf1_t *rec)
{
if ( ptr[i]==(uint8_t)bcf_int8_vector_end ) break;
jalt = bcf_gt_allele(ptr[i]);
if ( rec->n_allele <= jalt ) error("Broken VCF, too few alts at %s:%d\n", bcf_seqname(args->hdr,rec),rec->pos+1);
if ( rec->n_allele <= jalt ) error("Broken VCF, too few alts at %s:%"PRId64"\n", bcf_seqname(args->hdr,rec),(int64_t) rec->pos+1);
if ( args->allele & (PICK_LONG|PICK_SHORT) )
{
int len = jalt==0 ? rec->rlen : strlen(rec->d.allele[jalt]);
Expand All @@ -521,7 +521,7 @@ static void apply_variant(args_t *args, bcf1_t *rec)
}
}
if ( !ialt ) return; // ref allele
if ( rec->n_allele <= ialt ) error("Broken VCF, too few alts at %s:%d\n", bcf_seqname(args->hdr,rec),rec->pos+1);
if ( rec->n_allele <= ialt ) error("Broken VCF, too few alts at %s:%"PRId64"\n", bcf_seqname(args->hdr,rec),(int64_t) rec->pos+1);
}
else if ( args->output_iupac && !rec->d.allele[0][1] && !rec->d.allele[1][1] )
{
Expand Down Expand Up @@ -554,7 +554,7 @@ static void apply_variant(args_t *args, bcf1_t *rec)

if ( overlap )
{
fprintf(stderr,"The site %s:%d overlaps with another variant, skipping...\n", bcf_seqname(args->hdr,rec),rec->pos+1);
fprintf(stderr,"The site %s:%"PRId64" overlaps with another variant, skipping...\n", bcf_seqname(args->hdr,rec),(int64_t) rec->pos+1);
return;
}

Expand All @@ -564,7 +564,7 @@ static void apply_variant(args_t *args, bcf1_t *rec)
int idx = rec->pos - args->fa_ori_pos + args->fa_mod_off;
if ( idx<0 )
{
fprintf(stderr,"Warning: ignoring overlapping variant starting at %s:%d\n", bcf_seqname(args->hdr,rec),rec->pos+1);
fprintf(stderr,"Warning: ignoring overlapping variant starting at %s:%"PRId64"\n", bcf_seqname(args->hdr,rec),(int64_t) rec->pos+1);
return;
}
if ( rec->rlen > args->fa_buf.l - idx )
Expand All @@ -574,17 +574,17 @@ static void apply_variant(args_t *args, bcf1_t *rec)
if ( alen > rec->rlen )
{
rec->d.allele[ialt][rec->rlen] = 0;
fprintf(stderr,"Warning: trimming variant starting at %s:%d\n", bcf_seqname(args->hdr,rec),rec->pos+1);
fprintf(stderr,"Warning: trimming variant starting at %s:%"PRId64"\n", bcf_seqname(args->hdr,rec),(int64_t) rec->pos+1);
}
}
if ( idx>=args->fa_buf.l )
error("FIXME: %s:%d .. idx=%d, ori_pos=%d, len=%"PRIu64", off=%d\n",bcf_seqname(args->hdr,rec),rec->pos+1,idx,args->fa_ori_pos,(uint64_t)args->fa_buf.l,args->fa_mod_off);
error("FIXME: %s:%"PRId64" .. idx=%d, ori_pos=%d, len=%"PRIu64", off=%d\n",bcf_seqname(args->hdr,rec),(int64_t) rec->pos+1,idx,args->fa_ori_pos,(uint64_t)args->fa_buf.l,args->fa_mod_off);

// sanity check the reference base
if ( rec->d.allele[ialt][0]=='<' )
{
if ( strcasecmp(rec->d.allele[ialt], "<DEL>") )
error("Symbolic alleles other than <DEL> are currently not supported: %s at %s:%d\n",rec->d.allele[ialt],bcf_seqname(args->hdr,rec),rec->pos+1);
error("Symbolic alleles other than <DEL> are currently not supported: %s at %s:%"PRId64"\n",rec->d.allele[ialt],bcf_seqname(args->hdr,rec),(int64_t) rec->pos+1);
assert( rec->d.allele[0][1]==0 ); // todo: for now expecting strlen(REF) = 1
len_diff = 1-rec->rlen;
rec->d.allele[ialt] = rec->d.allele[0]; // according to VCF spec, REF must precede the event
Expand Down Expand Up @@ -613,11 +613,11 @@ static void apply_variant(args_t *args, bcf1_t *rec)
args->fa_buf.s[idx+rec->rlen] = 0;
}
error(
"The fasta sequence does not match the REF allele at %s:%d:\n"
"The fasta sequence does not match the REF allele at %s:%"PRId64":\n"
" .vcf: [%s] <- (REF)\n"
" .vcf: [%s] <- (ALT)\n"
" .fa: [%s]%c%s\n",
bcf_seqname(args->hdr,rec),rec->pos+1, rec->d.allele[0], rec->d.allele[ialt], args->fa_buf.s+idx,
bcf_seqname(args->hdr,rec),(int64_t) rec->pos+1, rec->d.allele[0], rec->d.allele[ialt], args->fa_buf.s+idx,
tmp?tmp:' ',tmp?args->fa_buf.s+idx+rec->rlen+1:""
);
}
Expand Down
26 changes: 13 additions & 13 deletions convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ static void process_gt_to_prob3(convert_t *convert, bcf1_t *line, fmt_t *fmt, in
// for (i=0; i<convert->nsamples; i++) kputs(" 0.33 0.33 0.33", str);
// return;

error("Error parsing GT tag at %s:%d\n", bcf_seqname(convert->header,line),line->pos+1);
error("Error parsing GT tag at %s:%"PRId64"\n", bcf_seqname(convert->header,line),(int64_t) line->pos+1);
}

n /= convert->nsamples;
Expand Down Expand Up @@ -723,7 +723,7 @@ static void process_pl_to_prob3(convert_t *convert, bcf1_t *line, fmt_t *fmt, in
// for (i=0; i<convert->nsamples; i++) kputs(" 0.33 0.33 0.33", str);
// return;

error("Error parsing PL tag at %s:%d\n", bcf_seqname(convert->header,line),line->pos+1);
error("Error parsing PL tag at %s:%"PRId64"\n", bcf_seqname(convert->header,line),(int64_t) line->pos+1);
}

n /= convert->nsamples;
Expand Down Expand Up @@ -772,7 +772,7 @@ static void process_gp_to_prob3(convert_t *convert, bcf1_t *line, fmt_t *fmt, in
// for (i=0; i<convert->nsamples; i++) kputs(" 0.33 0.33 0.33", str);
// return;

error("Error parsing GP tag at %s:%d\n", bcf_seqname(convert->header,line),line->pos+1);
error("Error parsing GP tag at %s:%"PRId64"\n", bcf_seqname(convert->header,line),(int64_t) line->pos+1);
}

n /= convert->nsamples;
Expand All @@ -784,7 +784,7 @@ static void process_gp_to_prob3(convert_t *convert, bcf1_t *line, fmt_t *fmt, in
{
if ( ptr[j]==bcf_int32_vector_end ) break;
if ( ptr[j]==bcf_int32_missing ) { ptr[j]=0; continue; }
if ( ptr[j]<0 || ptr[j]>1 ) error("[%s:%d:%f] GP value outside range [0,1]; bcftools convert expects the VCF4.3+ spec for the GP field encoding genotype posterior probabilities", bcf_seqname(convert->header,line),line->pos+1,ptr[j]);
if ( ptr[j]<0 || ptr[j]>1 ) error("[%s:%"PRId64":%f] GP value outside range [0,1]; bcftools convert expects the VCF4.3+ spec for the GP field encoding genotype posterior probabilities", bcf_seqname(convert->header,line),(int64_t) line->pos+1,ptr[j]);
sum+=ptr[j];
}
if ( j==line->n_allele )
Expand Down Expand Up @@ -827,24 +827,24 @@ static void process_gt_to_hap(convert_t *convert, bcf1_t *line, fmt_t *fmt, int

int i, gt_id = bcf_hdr_id2int(convert->header, BCF_DT_ID, "GT");
if ( !bcf_hdr_idinfo_exists(convert->header,BCF_HL_FMT,gt_id) )
error("FORMAT/GT tag not present at %s:%d\n", bcf_seqname(convert->header, line), line->pos+1);
error("FORMAT/GT tag not present at %s:%"PRId64"\n", bcf_seqname(convert->header, line),(int64_t) line->pos+1);
if ( !(line->unpacked & BCF_UN_FMT) ) bcf_unpack(line, BCF_UN_FMT);
bcf_fmt_t *fmt_gt = NULL;
for (i=0; i<line->n_fmt; i++)
if ( line->d.fmt[i].id==gt_id ) { fmt_gt = &line->d.fmt[i]; break; }
if ( !fmt_gt )
error("FORMAT/GT tag not present at %s:%d\n", bcf_seqname(convert->header, line), line->pos+1);
error("FORMAT/GT tag not present at %s:%"PRId64"\n", bcf_seqname(convert->header, line),(int64_t) line->pos+1);

// Alloc all memory in advance to avoid kput routines. The biggest allowed allele index is 99
if ( line->n_allele > 100 )
error("Too many alleles (%d) at %s:%d\n", line->n_allele, bcf_seqname(convert->header, line), line->pos+1);
error("Too many alleles (%d) at %s:%"PRId64"\n", line->n_allele, bcf_seqname(convert->header, line),(int64_t) line->pos+1);
if ( ks_resize(str, str->l+convert->nsamples*8) != 0 )
error("Could not alloc %" PRIu64 " bytes\n", (uint64_t)(str->l + convert->nsamples*8));

if ( fmt_gt->type!=BCF_BT_INT8 ) // todo: use BRANCH_INT if the VCF is valid
error("Uh, too many alleles (%d) or redundant BCF representation at %s:%d\n", line->n_allele, bcf_seqname(convert->header, line), line->pos+1);
error("Uh, too many alleles (%d) or redundant BCF representation at %s:%"PRId64"\n", line->n_allele, bcf_seqname(convert->header, line),(int64_t) line->pos+1);
if ( fmt_gt->n!=1 && fmt_gt->n!=2 )
error("Uh, ploidy of %d not supported, see %s:%d\n", fmt_gt->n, bcf_seqname(convert->header, line), line->pos+1);
error("Uh, ploidy of %d not supported, see %s:%"PRId64"\n", fmt_gt->n, bcf_seqname(convert->header, line),(int64_t) line->pos+1);

int8_t *ptr = ((int8_t*) fmt_gt->p) - fmt_gt->n;
for (i=0; i<convert->nsamples; i++)
Expand Down Expand Up @@ -981,22 +981,22 @@ static void process_gt_to_hap2(convert_t *convert, bcf1_t *line, fmt_t *fmt, int

int i, gt_id = bcf_hdr_id2int(convert->header, BCF_DT_ID, "GT");
if ( !bcf_hdr_idinfo_exists(convert->header,BCF_HL_FMT,gt_id) )
error("FORMAT/GT tag not present at %s:%d\n", bcf_seqname(convert->header, line), line->pos+1);
error("FORMAT/GT tag not present at %s:%"PRId64"\n", bcf_seqname(convert->header, line),(int64_t) line->pos+1);
if ( !(line->unpacked & BCF_UN_FMT) ) bcf_unpack(line, BCF_UN_FMT);
bcf_fmt_t *fmt_gt = NULL;
for (i=0; i<line->n_fmt; i++)
if ( line->d.fmt[i].id==gt_id ) { fmt_gt = &line->d.fmt[i]; break; }
if ( !fmt_gt )
error("FORMAT/GT tag not present at %s:%d\n", bcf_seqname(convert->header, line), line->pos+1);
error("FORMAT/GT tag not present at %s:%"PRId64"\n", bcf_seqname(convert->header, line),(int64_t) line->pos+1);

// Alloc all memory in advance to avoid kput routines. The biggest allowed allele index is 99
if ( line->n_allele > 100 )
error("Too many alleles (%d) at %s:%d\n", line->n_allele, bcf_seqname(convert->header, line), line->pos+1);
error("Too many alleles (%d) at %s:%"PRId64"\n", line->n_allele, bcf_seqname(convert->header, line),(int64_t) line->pos+1);
if ( ks_resize(str, str->l+convert->nsamples*8) != 0 )
error("Could not alloc %" PRIu64 " bytes\n", (uint64_t)(str->l + convert->nsamples*8));

if ( fmt_gt->type!=BCF_BT_INT8 ) // todo: use BRANCH_INT if the VCF is valid
error("Uh, too many alleles (%d) or redundant BCF representation at %s:%d\n", line->n_allele, bcf_seqname(convert->header, line), line->pos+1);
error("Uh, too many alleles (%d) or redundant BCF representation at %s:%"PRId64"\n", line->n_allele, bcf_seqname(convert->header, line),(int64_t) line->pos+1);

int8_t *ptr = ((int8_t*) fmt_gt->p) - fmt_gt->n;
for (i=0; i<convert->nsamples; i++)
Expand Down
Loading

0 comments on commit aec5177

Please sign in to comment.