@@ -1827,7 +1827,7 @@ static void bcf_record_check_err(const bcf_hdr_t *hdr, bcf1_t *rec,
1827
1827
*/
1828
1828
static int updatephasing (uint8_t * p , uint8_t * end , uint8_t * * q , int set , int samples , int ploidy , int type )
1829
1829
{
1830
- int j , k , upd = set ? 1 : -1 ;
1830
+ int j , k ;
1831
1831
size_t bytes ;
1832
1832
for (j = 0 ; j < samples ; ++ j ) { //for each sample
1833
1833
int anyunphased = 0 ;
@@ -1839,10 +1839,10 @@ static int updatephasing(uint8_t *p, uint8_t *end, uint8_t **q, int set, int sam
1839
1839
val = * (uint8_t * )p ;
1840
1840
break ;
1841
1841
case BCF_BT_INT16 :
1842
- val = * ( uint16_t * ) p ;
1842
+ val = le_to_i16 ( p ) ;
1843
1843
break ;
1844
1844
case BCF_BT_INT32 :
1845
- val = * ( uint32_t * ) p ;
1845
+ val = le_to_i32 ( p ) ;
1846
1846
break ;
1847
1847
//wont have anything bigger than 32bit for GT
1848
1848
default : //invalid
@@ -1854,26 +1854,28 @@ static int updatephasing(uint8_t *p, uint8_t *end, uint8_t **q, int set, int sam
1854
1854
anyunphased = 1 ;
1855
1855
}
1856
1856
//get to next phasing or skip the rest for this sample
1857
- bytes = (anyunphased ? ploidy - k : 1 ) << bcf_type_shift [type ];
1857
+ bytes = (( anyunphased || al1 & 1 ) ? ploidy - k : 1 ) << bcf_type_shift [type ];
1858
1858
if (end - p < bytes )
1859
1859
return 1 ;
1860
1860
p += bytes ;
1861
- if (anyunphased ) {
1861
+ if (anyunphased || al1 & 1 ) {
1862
+ //either unphased is found or 1st one itself is set as phased
1862
1863
break ; //no further check required
1863
1864
}
1864
1865
}
1865
1866
if (!anyunphased && al1 > 1 ) { //no other unphased
1866
1867
/*set phased on read or make unphased on write as upto 4.3 1st
1867
1868
phasing is not described explicitly and has to be inferred*/
1869
+ al1 = set ? al1 | 1 : al1 & 0xFFFFFFFE ;
1868
1870
switch (type ) {
1869
1871
case BCF_BT_INT8 :
1870
- * (uint8_t * )ptr1 += upd ;
1872
+ * (uint8_t * )ptr1 = al1 ;
1871
1873
break ;
1872
1874
case BCF_BT_INT16 :
1873
- * ( uint16_t * ) ptr1 += upd ;
1875
+ i16_to_le ( le_to_i16 (( uint8_t * ) & al1 ), ptr1 ) ;
1874
1876
break ;
1875
1877
case BCF_BT_INT32 :
1876
- * ( uint32_t * ) ptr1 += upd ;
1878
+ i32_to_le ( le_to_i32 (( uint8_t * ) & al1 ), ptr1 ) ;
1877
1879
break ;
1878
1880
}
1879
1881
}
@@ -2442,11 +2444,6 @@ int bcf_write(htsFile *hfp, bcf_hdr_t *h, bcf1_t *v)
2442
2444
return -1 ;
2443
2445
}
2444
2446
2445
- if (update44phasing (h , v , 0 )) { //reset phasing update made after read
2446
- hts_log_error ("Failed to set prorper phasing at %s:%" PRIhts_pos "" , bcf_seqname_safe (h ,v ), v -> pos + 1 );
2447
- return -1 ;
2448
- }
2449
-
2450
2447
BGZF * fp = hfp -> fp .bgzf ;
2451
2448
uint8_t x [32 ];
2452
2449
u32_to_le (v -> shared .l + 24 , x ); // to include six 32-bit integers
0 commit comments