Skip to content

Commit db48877

Browse files
Merge pull request #25 from jeromekelleher/refactor-genotype-write
Refactor genotype write code path
2 parents dd9ccbc + 4c22afc commit db48877

File tree

1 file changed

+4
-29
lines changed

1 file changed

+4
-29
lines changed

lib/vcf_encoder.c

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ bool_field_write_entry(const vcz_field_t *VCZ_UNUSED(self), const void *VCZ_UNUS
243243

244244
static int64_t
245245
int32_field_write_entry(const vcz_field_t *self, const void *restrict data, char *buf,
246-
int64_t buflen, int64_t offset)
246+
int64_t buflen, int64_t offset, char separator)
247247
{
248248
const int32_t *restrict source = (const int32_t *) data;
249249
size_t column;
@@ -253,7 +253,7 @@ int32_field_write_entry(const vcz_field_t *self, const void *restrict data, char
253253
break;
254254
}
255255
if (column > 0) {
256-
offset = append_char(buf, ',', offset, buflen);
256+
offset = append_char(buf, separator, offset, buflen);
257257
if (offset < 0) {
258258
goto out;
259259
}
@@ -302,7 +302,7 @@ vcz_field_write_entry(
302302
{
303303
if (self->type == VCZ_TYPE_INT) {
304304
if (self->item_size == 4) {
305-
return int32_field_write_entry(self, data, buf, buflen, offset);
305+
return int32_field_write_entry(self, data, buf, buflen, offset, ',');
306306
}
307307
} else if (self->type == VCZ_TYPE_FLOAT) {
308308
assert(self->item_size == 4);
@@ -409,33 +409,9 @@ vcz_variant_encoder_write_sample_gt(const vcz_variant_encoder_t *self, size_t va
409409
size_t source_offset = variant * self->num_samples * ploidy + sample * ploidy;
410410
const int32_t *source = ((const int32_t *) self->gt.data) + source_offset;
411411
const bool phased = self->gt_phased_data[variant * self->num_samples + sample];
412-
int32_t value;
413-
size_t ploid;
414412
char sep = phased ? '|' : '/';
415413

416-
if (self->gt.item_size != 4) {
417-
offset = VCZ_ERR_FIELD_UNSUPPORTED_TYPE;
418-
goto out;
419-
}
420-
421-
for (ploid = 0; ploid < ploidy; ploid++) {
422-
value = source[ploid];
423-
if (value == VCZ_INT_FILL) {
424-
break;
425-
}
426-
if (ploid > 0) {
427-
offset = append_char(buf, sep, offset, buflen);
428-
if (offset < 0) {
429-
goto out;
430-
}
431-
}
432-
offset = append_int(buf, value, offset, buflen);
433-
if (offset < 0) {
434-
goto out;
435-
}
436-
}
437-
out:
438-
return offset;
414+
return int32_field_write_entry(&self->gt, source, buf, buflen, offset, sep);
439415
}
440416

441417
static int64_t
@@ -656,7 +632,6 @@ vcz_variant_encoder_write_row(
656632
size_t j;
657633

658634
for (j = 0; j < VCZ_NUM_FIXED_FIELDS; j++) {
659-
// FIXME do we really need to do this check?
660635
if (vcz_info_field_is_missing(&self->fixed_fields[j], variant)) {
661636
offset = append_char(buf, '.', offset, (int64_t) buflen);
662637
if (offset < 0) {

0 commit comments

Comments
 (0)