Skip to content

Commit 6d69141

Browse files
committed
Fix a bug which causes consensus --absent miss some absent positions
This was caused by fasta buffer being on occassions flushed too early. It is surprisingly hard to narrow this down to a small test case therefore, alas, no test is added with this commit
1 parent c5a978f commit 6d69141

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ Changes affecting specific commands:
2323

2424
- Fix a bug which prevented reading fasta files containing empty lines in their entirety (#2424)
2525

26+
- Fix a bug which causes `--absent` miss some absent positions
27+
2628
* bcftools csq
2729

2830
- Add support for complex substitutions, such as AC>TAA

consensus.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ static void flush_fa_buffer(args_t *args, int len)
430430
{
431431
if ( !args->fa_buf.l ) return;
432432
int nwr = 0;
433-
while ( nwr + 60 <= args->fa_buf.l )
433+
while ( nwr + 60 <= args->fa_buf.l && args->fa_ori_pos + nwr + 60 < args->fa_frz_pos )
434434
{
435435
if ( fwrite(args->fa_buf.s+nwr,1,60,args->fp_out) != 60 ) error("Could not write: %s\n", args->output_fname);
436436
if ( fwrite("\n",1,1,args->fp_out) != 1 ) error("Could not write: %s\n", args->output_fname);
@@ -462,7 +462,9 @@ static void flush_fa_buffer(args_t *args, int len)
462462
}
463463
static void apply_absent(args_t *args, hts_pos_t pos)
464464
{
465-
if ( !args->fa_buf.l || pos <= args->fa_frz_pos + 1 || pos <= args->fa_ori_pos ) return;
465+
if ( !args->fa_buf.l ) return;
466+
if ( pos <= args->fa_frz_pos + 1 ) return; // if pos==frz+1, then there is no gap, ie=ib, nothing to fill
467+
if ( pos <= args->fa_ori_pos ) return;
466468

467469
int ie = pos && pos - args->fa_ori_pos + args->fa_mod_off < args->fa_buf.l ? pos - args->fa_ori_pos + args->fa_mod_off : args->fa_buf.l;
468470
int ib = args->fa_frz_mod < 0 ? 0 : args->fa_frz_mod;
@@ -585,7 +587,6 @@ static int iupac_set_allele(args_t *args, bcf1_t *rec)
585587
static void apply_variant(args_t *args, bcf1_t *rec)
586588
{
587589
static int warned_haplotype = 0;
588-
589590
if ( args->absent_allele ) apply_absent(args, rec->pos);
590591
if ( rec->n_allele==1 && !args->missing_allele && !args->absent_allele ) { return; }
591592

0 commit comments

Comments
 (0)