Skip to content

Commit 8af52e2

Browse files
committed
review update
1 parent aebd6ee commit 8af52e2

File tree

3 files changed

+18
-29
lines changed

3 files changed

+18
-29
lines changed

htslib/vcf.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,15 +1523,11 @@ int bcf_format_gt_v2(const bcf_hdr_t *hdr, bcf_fmt_t *fmt, int isample,
15231523
* update44phasing - converts GT to/from v4.4 way representation
15241524
* @param h - bcf header, to get version
15251525
* @param v - pointer to bcf data
1526-
* @param setreset - whether to set or reset
1527-
* Returns 0 on success and -1 on failure
1528-
* For data read, to be converted to v44, setreset to be 1. For data write, to
1529-
* be converted to v < v44, setreset to be 0.
1526+
* Returns 0 on success and 1 on failure
15301527
* If the version in header is >= 4.4, no change is made. Otherwise 1st phasing
15311528
* is set if there are no other unphased ones.
15321529
*/
1533-
HTSLIB_EXPORT int update44phasing(bcf_hdr_t *h, bcf1_t *b, int setreset)
1534-
HTS_RESULT_USED;
1530+
HTSLIB_EXPORT int update44phasing(bcf_hdr_t *h, bcf1_t *b) HTS_RESULT_USED;
15351531

15361532
static inline int bcf_format_gt(bcf_fmt_t *fmt, int isample, kstring_t *str)
15371533
{

synced_bcf_reader.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ static int _reader_fill_buffer(bcf_srs_t *files, bcf_sr_t *reader)
709709
if ( ret < -1 ) files->errnum = bcf_read_error;
710710
if ( ret < 0 ) break; // no more lines or an error
711711
//set phasing of 1st value as in vcf v44
712-
if ((ret = update44phasing(reader->header, reader->buffer[reader->nbuffer+1], 1))) {
712+
if ((ret = update44phasing(reader->header, reader->buffer[reader->nbuffer+1]))) {
713713
files->errnum = bcf_read_error;
714714
break;
715715
}

vcf.c

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,15 +1819,14 @@ static void bcf_record_check_err(const bcf_hdr_t *hdr, bcf1_t *rec,
18191819
* @param p - pointer to phase value array
18201820
* @param end - end of array
18211821
* @param q - pointer to consumed data
1822-
* @param set - whether to set (while read) or reset (for write)
18231822
* @param samples - no. of samples in array
18241823
* @param ploidy - no. of phasing values per sample
18251824
* @param type - value type (one of BCF_BT_...)
18261825
* Returns 0 on success and 1 on failure
18271826
*/
1828-
static int updatephasing(uint8_t *p, uint8_t *end, uint8_t **q, int set, int samples, int ploidy, int type)
1827+
static int updatephasing(uint8_t *p, uint8_t *end, uint8_t **q, int samples, int ploidy, int type)
18291828
{
1830-
int j, k, upd = set ? 1 : -1;
1829+
int j, k;
18311830
size_t bytes;
18321831
for (j = 0; j < samples; ++j) { //for each sample
18331832
int anyunphased = 0;
@@ -1839,10 +1838,10 @@ static int updatephasing(uint8_t *p, uint8_t *end, uint8_t **q, int set, int sam
18391838
val = *(uint8_t*)p;
18401839
break;
18411840
case BCF_BT_INT16:
1842-
val = *(uint16_t*)p;
1841+
val = le_to_i16(p);
18431842
break;
18441843
case BCF_BT_INT32:
1845-
val = *(uint32_t*)p;
1844+
val = le_to_i32(p);
18461845
break;
18471846
//wont have anything bigger than 32bit for GT
18481847
default: //invalid
@@ -1854,26 +1853,28 @@ static int updatephasing(uint8_t *p, uint8_t *end, uint8_t **q, int set, int sam
18541853
anyunphased = 1;
18551854
}
18561855
//get to next phasing or skip the rest for this sample
1857-
bytes = (anyunphased ? ploidy - k : 1) << bcf_type_shift[type];
1856+
bytes = ((anyunphased || al1 & 1) ? ploidy - k : 1) << bcf_type_shift[type];
18581857
if (end - p < bytes)
18591858
return 1;
18601859
p += bytes;
1861-
if (anyunphased) {
1860+
if (anyunphased || al1 & 1) {
1861+
//either unphased is found or 1st one itself is set as phased
18621862
break; //no further check required
18631863
}
18641864
}
18651865
if (!anyunphased && al1 > 1) { //no other unphased
18661866
/*set phased on read or make unphased on write as upto 4.3 1st
18671867
phasing is not described explicitly and has to be inferred*/
1868+
al1 |= 1;
18681869
switch(type) {
18691870
case BCF_BT_INT8:
1870-
*(uint8_t*)ptr1 += upd;
1871+
*(uint8_t*)ptr1 = al1;
18711872
break;
18721873
case BCF_BT_INT16:
1873-
*(uint16_t*)ptr1 += upd;
1874+
i16_to_le(le_to_i16((uint8_t*)&al1), ptr1);
18741875
break;
18751876
case BCF_BT_INT32:
1876-
*(uint32_t*)ptr1 += upd;
1877+
i32_to_le(le_to_i32((uint8_t*)&al1), ptr1);
18771878
break;
18781879
}
18791880
}
@@ -1886,14 +1887,11 @@ static int updatephasing(uint8_t *p, uint8_t *end, uint8_t **q, int set, int sam
18861887
* update44phasing - converts GT to/from v4.4 way representation
18871888
* @param h - bcf header, to get version
18881889
* @param v - pointer to bcf data
1889-
* @param setreset - whether to set or reset
1890-
* Returns 0 on success and -1 on failure
1891-
* For data read, to be converted to v44, setreset to be 1. For data write, to
1892-
* be converted to v < v44, setreset to be 0.
1890+
* Returns 0 on success and 1 on failure
18931891
* If the version in header is >= 4.4, no change is made. Otherwise 1st phasing
18941892
* is set if there are no other unphased ones.
18951893
*/
1896-
HTSLIB_EXPORT int update44phasing(bcf_hdr_t *h, bcf1_t *b, int setreset)
1894+
HTSLIB_EXPORT int update44phasing(bcf_hdr_t *h, bcf1_t *b)
18971895
{
18981896
int i, idgt = -1, ver = VCF_DEF, num, type;
18991897
uint8_t *ptr = NULL, *end = NULL;
@@ -1938,7 +1936,7 @@ HTSLIB_EXPORT int update44phasing(bcf_hdr_t *h, bcf1_t *b, int setreset)
19381936
}
19391937
if (ptr) {
19401938
//with GT and v < v44, need phase conversion
1941-
if (updatephasing(ptr, end, &ptr, setreset, b->n_sample, num, type)) return 1;
1939+
if (updatephasing(ptr, end, &ptr, b->n_sample, num, type)) return 1;
19421940
}
19431941
return 0;
19441942
}
@@ -2076,7 +2074,7 @@ static int bcf_record_check(const bcf_hdr_t *hdr, bcf1_t *rec) {
20762074
}
20772075
if (ver < VCF44 && idgt != -1 && idgt == key) {
20782076
//with GT and v < v44, need phase conversion
2079-
if (updatephasing(ptr, end, &ptr, 1, rec->n_sample, num, type)) {
2077+
if (updatephasing(ptr, end, &ptr, rec->n_sample, num, type)) {
20802078
err |= BCF_ERR_TAG_INVALID;
20812079
}
20822080
} else {
@@ -2442,11 +2440,6 @@ int bcf_write(htsFile *hfp, bcf_hdr_t *h, bcf1_t *v)
24422440
return -1;
24432441
}
24442442

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

0 commit comments

Comments
 (0)