Skip to content

Commit

Permalink
bcf_hdr_combine replaced by bcf_hdr_merge, fixes samtools/bcftools#208
Browse files Browse the repository at this point in the history
  • Loading branch information
pd3 committed Apr 29, 2015
1 parent d492214 commit db18b8a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
20 changes: 15 additions & 5 deletions htslib/vcf.h
Expand Up @@ -376,13 +376,23 @@ typedef struct {

/** Create a new header using the supplied template */
bcf_hdr_t *bcf_hdr_dup(const bcf_hdr_t *hdr);

/**
* Copy header lines from src to dst if not already present in dst. See also bcf_translate().
* Returns 0 on success or sets a bit on error:
* 1 .. conflicting definitions of tag length
* // todo
* bcf_hdr_merge() - copy header lines from src to dst, see also bcf_translate()
* @param dst: the destination header to be merged into, NULL on the first pass
* @param src: the source header
*
* Notes:
* - use as:
* bcf_hdr_t *dst = NULL;
* for (i=0; i<nsrc; i++) dst = bcf_hdr_merge(dst,src[i]);
*
* - bcf_hdr_merge() replaces bcf_hdr_combine() which had a problem when
* combining multiple BCF headers. The current bcf_hdr_combine() is
* does not have this problem, but became slow when used for many files.
*/
int bcf_hdr_combine(bcf_hdr_t *dst, const bcf_hdr_t *src);
int bcf_hdr_combine(bcf_hdr_t *dst, const bcf_hdr_t *src); // deprecated, do not use!
bcf_hdr_t *bcf_hdr_merge(bcf_hdr_t *dst, const bcf_hdr_t *src);

/**
* bcf_hdr_add_sample() - add a new sample.
Expand Down
18 changes: 17 additions & 1 deletion vcf.c
Expand Up @@ -2209,6 +2209,22 @@ int bcf_index_build(const char *fn, int min_shift)

int bcf_hdr_combine(bcf_hdr_t *dst, const bcf_hdr_t *src)
{
fprintf(stderr,"Please use bcf_hdr_merge instead, bcf_hdr_combine will be deprecated\n");
assert(0); // todo
}

bcf_hdr_t *bcf_hdr_merge(bcf_hdr_t *dst, const bcf_hdr_t *src)
{
if ( !dst )
{
// this will effectively strip existing IDX attributes from src to become dst
dst = bcf_hdr_init("r");
char *htxt = bcf_hdr_fmt_text(src, 0, NULL);
bcf_hdr_parse(dst, htxt);
free(htxt);
return dst;
}

int i, ndst_ori = dst->nhrec, need_sync = 0, ret = 0;
for (i=0; i<src->nhrec; i++)
{
Expand Down Expand Up @@ -2268,7 +2284,7 @@ int bcf_hdr_combine(bcf_hdr_t *dst, const bcf_hdr_t *src)
}
}
if ( need_sync ) bcf_hdr_sync(dst);
return ret;
return dst;
}
int bcf_translate(const bcf_hdr_t *dst_hdr, bcf_hdr_t *src_hdr, bcf1_t *line)
{
Expand Down

0 comments on commit db18b8a

Please sign in to comment.