Skip to content

Commit b6c7801

Browse files
committed
Add a vcf to compressed vcf index.
1 parent bf11805 commit b6c7801

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

htslib/vcf.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,9 @@ set to one of BCF_ERR* codes and must be checked before calling bcf_write().
516516
*/
517517
HTSLIB_EXPORT
518518
int vcf_write_line(htsFile *fp, kstring_t *line);
519+
520+
HTSLIB_EXPORT
521+
int vcf_write_line_with_index(htsFile *fp, const bcf_hdr_t *h, kstring_t *line, int tid, hts_pos_t pos, hts_pos_t len);
519522

520523
/**************************************************************************
521524
* Header querying and manipulation routines

vcf.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4257,6 +4257,30 @@ int vcf_write(htsFile *fp, const bcf_hdr_t *h, bcf1_t *v)
42574257
return ret==fp->line.l ? 0 : -1;
42584258
}
42594259

4260+
4261+
int vcf_write_line_with_index(htsFile *fp, const bcf_hdr_t *h, kstring_t *line, int tid,
4262+
hts_pos_t pos, hts_pos_t len)
4263+
{
4264+
ssize_t ret;
4265+
4266+
fprintf(stderr, "vcf_write_line_with_index start\n");
4267+
4268+
if (fp->format.compression == no_compression || !fp->idx) { // compressed reads only for indexing
4269+
return -1;
4270+
}
4271+
4272+
ret = bgzf_write(fp->fp.bgzf, line->s, line->l); // error handling?
4273+
4274+
if (bgzf_idx_push(fp->fp.bgzf, fp->idx, tid, pos, pos + len, bgzf_tell(fp->fp.bgzf), 1) < 0) {
4275+
return -1;
4276+
}
4277+
4278+
fprintf(stderr, "vcf_write_line_with_index end\n");
4279+
4280+
return 0; // again, more error handling needed
4281+
}
4282+
4283+
42604284
/************************
42614285
* Data access routines *
42624286
************************/

0 commit comments

Comments
 (0)