Skip to content

Commit fce7ac9

Browse files
committed
review update
1 parent aebd6ee commit fce7ac9

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

vcf.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,7 +1827,7 @@ static void bcf_record_check_err(const bcf_hdr_t *hdr, bcf1_t *rec,
18271827
*/
18281828
static int updatephasing(uint8_t *p, uint8_t *end, uint8_t **q, int set, int samples, int ploidy, int type)
18291829
{
1830-
int j, k, upd = set ? 1 : -1;
1830+
int j, k;
18311831
size_t bytes;
18321832
for (j = 0; j < samples; ++j) { //for each sample
18331833
int anyunphased = 0;
@@ -1839,10 +1839,10 @@ static int updatephasing(uint8_t *p, uint8_t *end, uint8_t **q, int set, int sam
18391839
val = *(uint8_t*)p;
18401840
break;
18411841
case BCF_BT_INT16:
1842-
val = *(uint16_t*)p;
1842+
val = le_to_i16(p);
18431843
break;
18441844
case BCF_BT_INT32:
1845-
val = *(uint32_t*)p;
1845+
val = le_to_i32(p);
18461846
break;
18471847
//wont have anything bigger than 32bit for GT
18481848
default: //invalid
@@ -1854,26 +1854,28 @@ static int updatephasing(uint8_t *p, uint8_t *end, uint8_t **q, int set, int sam
18541854
anyunphased = 1;
18551855
}
18561856
//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];
18581858
if (end - p < bytes)
18591859
return 1;
18601860
p += bytes;
1861-
if (anyunphased) {
1861+
if (anyunphased || al1 & 1) {
1862+
//either unphased is found or 1st one itself is set as phased
18621863
break; //no further check required
18631864
}
18641865
}
18651866
if (!anyunphased && al1 > 1) { //no other unphased
18661867
/*set phased on read or make unphased on write as upto 4.3 1st
18671868
phasing is not described explicitly and has to be inferred*/
1869+
al1 = set ? al1 | 1 : al1 & 0xFFFFFFFE;
18681870
switch(type) {
18691871
case BCF_BT_INT8:
1870-
*(uint8_t*)ptr1 += upd;
1872+
*(uint8_t*)ptr1 = al1;
18711873
break;
18721874
case BCF_BT_INT16:
1873-
*(uint16_t*)ptr1 += upd;
1875+
i16_to_le(le_to_i16((uint8_t*)&al1), ptr1);
18741876
break;
18751877
case BCF_BT_INT32:
1876-
*(uint32_t*)ptr1 += upd;
1878+
i32_to_le(le_to_i32((uint8_t*)&al1), ptr1);
18771879
break;
18781880
}
18791881
}
@@ -2442,11 +2444,6 @@ int bcf_write(htsFile *hfp, bcf_hdr_t *h, bcf1_t *v)
24422444
return -1;
24432445
}
24442446

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-
24502447
BGZF *fp = hfp->fp.bgzf;
24512448
uint8_t x[32];
24522449
u32_to_le(v->shared.l + 24, x); // to include six 32-bit integers

0 commit comments

Comments
 (0)