From 8be5ca74606889751ddc9784e78430bb09ffbfe5 Mon Sep 17 00:00:00 2001 From: Rob Davies Date: Tue, 5 Aug 2025 16:50:41 +0100 Subject: [PATCH] Ignore first phasing bit in process_gt_to_hap / process_gt_to_hap2 HTSlib version 1.22 introduced prefixed phasing support for VCF files with version 4.4 or later. Prior to this the first GT phase (when reading VCF) was always zero; after it is set either explicitly or when all other alleles are phased. This updates process_gt_to_hap() and process_gt_to_hap2() to ignore the first phase bit, removing an assumption it is always zero. Fixes incorrect reporting of phase when using HTSlib 1.22 to read VCF files with version 4.4 or 4.5. --- convert.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/convert.c b/convert.c index 9faaded6e..6a36bc708 100644 --- a/convert.c +++ b/convert.c @@ -878,7 +878,7 @@ static void process_gt_to_hap(convert_t *convert, bcf1_t *line, fmt_t *fmt, int ptr += fmt_gt->n; if ( fmt_gt->n==1 ) // haploid genotypes { - if ( ptr[0]==2 ) /* 0 */ + if ( ( ptr[0] >> 1 )==1 ) /* 0 */ { str->s[str->l++] = '0'; str->s[str->l++] = ' '; str->s[str->l++] = '-'; str->s[str->l++] = ' '; } @@ -886,7 +886,7 @@ static void process_gt_to_hap(convert_t *convert, bcf1_t *line, fmt_t *fmt, int { str->s[str->l++] = '?'; str->s[str->l++] = ' '; str->s[str->l++] = '?'; str->s[str->l++] = ' '; } - else if ( ptr[0]==4 ) /* 1 */ + else if ( ( ptr[0] >> 1 )==2 ) /* 1 */ { str->s[str->l++] = '1'; str->s[str->l++] = ' '; str->s[str->l++] = '-'; str->s[str->l++] = ' '; } @@ -895,7 +895,7 @@ static void process_gt_to_hap(convert_t *convert, bcf1_t *line, fmt_t *fmt, int kputw(bcf_gt_allele(ptr[0]),str); str->s[str->l++] = ' '; str->s[str->l++] = '-'; str->s[str->l++] = ' '; } } - else if ( ptr[0]==2 ) + else if ( ( ptr[0] >> 1 )==1 ) { if ( ptr[1]==3 ) /* 0|0 */ { @@ -934,7 +934,7 @@ static void process_gt_to_hap(convert_t *convert, bcf1_t *line, fmt_t *fmt, int str->s[str->l++] = '*'; str->s[str->l++] = ' '; } } - else if ( ptr[0]==4 ) + else if ( ( ptr[0] >> 1 )==2 ) { if ( ptr[1]==3 ) /* 1|0 */ { @@ -1028,7 +1028,7 @@ static void process_gt_to_hap2(convert_t *convert, bcf1_t *line, fmt_t *fmt, int for (i=0; insamples; i++) { ptr += fmt_gt->n; - if ( ptr[0]==2 ) + if ( ( ptr[0] >> 1 )==1 ) { if ( ptr[1]==3 ) /* 0|0 */ { @@ -1067,7 +1067,7 @@ static void process_gt_to_hap2(convert_t *convert, bcf1_t *line, fmt_t *fmt, int str->s[str->l++] = '*'; str->s[str->l++] = ' '; } } - else if ( ptr[0]==4 ) + else if ( ( ptr[0] >> 1 )==2 ) { if ( ptr[1]==3 ) /* 1|0 */ {