Skip to content

Commit

Permalink
Add a vcf to compressed vcf index.
Browse files Browse the repository at this point in the history
  • Loading branch information
whitwham committed Sep 12, 2024
1 parent bf11805 commit b6c7801
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
3 changes: 3 additions & 0 deletions htslib/vcf.h
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,9 @@ set to one of BCF_ERR* codes and must be checked before calling bcf_write().
*/
HTSLIB_EXPORT
int vcf_write_line(htsFile *fp, kstring_t *line);

HTSLIB_EXPORT
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);

/**************************************************************************
* Header querying and manipulation routines
Expand Down
24 changes: 24 additions & 0 deletions vcf.c
Original file line number Diff line number Diff line change
Expand Up @@ -4257,6 +4257,30 @@ int vcf_write(htsFile *fp, const bcf_hdr_t *h, bcf1_t *v)
return ret==fp->line.l ? 0 : -1;
}


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)
{
ssize_t ret;

fprintf(stderr, "vcf_write_line_with_index start\n");

if (fp->format.compression == no_compression || !fp->idx) { // compressed reads only for indexing
return -1;
}

ret = bgzf_write(fp->fp.bgzf, line->s, line->l); // error handling?

if (bgzf_idx_push(fp->fp.bgzf, fp->idx, tid, pos, pos + len, bgzf_tell(fp->fp.bgzf), 1) < 0) {
return -1;
}

fprintf(stderr, "vcf_write_line_with_index end\n");

return 0; // again, more error handling needed
}


/************************
* Data access routines *
************************/
Expand Down

0 comments on commit b6c7801

Please sign in to comment.