Skip to content

Commit f84bba1

Browse files
committed
Add bcf_get_info_int64; make bcf_update_info_int64 a static inline
As bcf_get_info_int64() and bcf_update_info_int64() are new interfaces, they can be made static inlines instead of macros so that the compiler can check the data type of the values / dst parameter. The old macros probably have to stay as they are as we don't know how they are being used in third-party code. The documentation around the bcf_get_info_ and bcf_update_info_ macros is made a bit more doxygen-like.
1 parent 995069d commit f84bba1

File tree

1 file changed

+76
-24
lines changed

1 file changed

+76
-24
lines changed

htslib/vcf.h

Lines changed: 76 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -669,26 +669,48 @@ set to one of BCF_ERR* codes and must be checked before calling bcf_write().
669669
int bcf_update_id(const bcf_hdr_t *hdr, bcf1_t *line, const char *id);
670670
int bcf_add_id(const bcf_hdr_t *hdr, bcf1_t *line, const char *id);
671671

672-
/*
672+
/**
673673
* bcf_update_info_*() - functions for updating INFO fields
674-
* @hdr: the BCF header
675-
* @line: VCF line to be edited
676-
* @key: the INFO tag to be updated
677-
* @values: pointer to the array of values. Pass NULL to remove the tag.
678-
* @n: number of values in the array. When set to 0, the INFO tag is removed
674+
* @param hdr: the BCF header
675+
* @param line: VCF line to be edited
676+
* @param key: the INFO tag to be updated
677+
* @param values: pointer to the array of values. Pass NULL to remove the tag.
678+
* @param n: number of values in the array. When set to 0, the INFO tag is removed
679+
* @return 0 on success or negative value on error.
679680
*
680-
* The @string in bcf_update_info_flag() is optional, @n indicates whether
681-
* the flag is set or removed.
681+
* The @p string in bcf_update_info_flag() is optional,
682+
* @p n indicates whether the flag is set or removed.
682683
*
683-
* Returns 0 on success or negative value on error.
684684
*/
685685
#define bcf_update_info_int32(hdr,line,key,values,n) bcf_update_info((hdr),(line),(key),(values),(n),BCF_HT_INT)
686-
#define bcf_update_info_int64(hdr,line,key,values,n) bcf_update_info((hdr),(line),(key),(values),(n),BCF_HT_LONG)
687686
#define bcf_update_info_float(hdr,line,key,values,n) bcf_update_info((hdr),(line),(key),(values),(n),BCF_HT_REAL)
688687
#define bcf_update_info_flag(hdr,line,key,string,n) bcf_update_info((hdr),(line),(key),(string),(n),BCF_HT_FLAG)
689688
#define bcf_update_info_string(hdr,line,key,string) bcf_update_info((hdr),(line),(key),(string),1,BCF_HT_STR)
690689
int bcf_update_info(const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type);
691690

691+
/// Set or update 64-bit integer INFO values
692+
/**
693+
* @param hdr: the BCF header
694+
* @param line: VCF line to be edited
695+
* @param key: the INFO tag to be updated
696+
* @param values: pointer to the array of values. Pass NULL to remove the tag.
697+
* @param n: number of values in the array. When set to 0, the INFO tag is removed
698+
* @return 0 on success or negative value on error.
699+
*
700+
* This function takes an int64_t values array as input. The data
701+
* actually stored will be shrunk to the minimum size that can
702+
* accept all of the values.
703+
*
704+
* INFO values outside of the range BCF_MIN_BT_INT32 to BCF_MAX_BT_INT32
705+
* can only be written to VCF files.
706+
*/
707+
static inline int bcf_update_info_int64(const bcf_hdr_t *hdr, bcf1_t *line,
708+
const char *key,
709+
const int64_t *values, int n)
710+
{
711+
return bcf_update_info(hdr, line, key, values, n, BCF_HT_LONG);
712+
}
713+
692714
/*
693715
* bcf_update_format_*() - functions for updating FORMAT fields
694716
* @values: pointer to the array of values, the same number of elements
@@ -756,29 +778,59 @@ set to one of BCF_ERR* codes and must be checked before calling bcf_write().
756778

757779
/**
758780
* bcf_get_info_*() - get INFO values, integers or floats
759-
* @hdr: BCF header
760-
* @line: BCF record
761-
* @tag: INFO tag to retrieve
762-
* @dst: *dst is pointer to a memory location, can point to NULL
763-
* @ndst: pointer to the size of allocated memory
781+
* @param hdr: BCF header
782+
* @param line: BCF record
783+
* @param tag: INFO tag to retrieve
784+
* @param dst: *dst is pointer to a memory location, can point to NULL
785+
* @param ndst: pointer to the size of allocated memory
786+
* @return >=0 on success
787+
* -1 .. no such INFO tag defined in the header
788+
* -2 .. clash between types defined in the header and encountered in the VCF record
789+
* -3 .. tag is not present in the VCF record
790+
* -4 .. the operation could not be completed (e.g. out of memory)
764791
*
765-
* Returns negative value on error or the number of written values
766-
* (including missing values) on success. bcf_get_info_string() returns
767-
* on success the number of characters written excluding the null-
768-
* terminating byte. bcf_get_info_flag() returns 1 when flag is set or 0
769-
* if not.
792+
* Returns negative value on error or the number of values (including
793+
* missing values) put in *dst on success. bcf_get_info_string() returns
794+
* on success the number of characters stored excluding the nul-
795+
* terminating byte. bcf_get_info_flag() does not store anything in *dst
796+
* but returns 1 if the flag is set or 0 if not.
770797
*
771-
* List of return codes:
772-
* -1 .. no such INFO tag defined in the header
773-
* -2 .. clash between types defined in the header and encountered in the VCF record
774-
* -3 .. tag is not present in the VCF record
798+
* *dst will be reallocated if it is not big enough (i.e. *ndst is too
799+
* small) or NULL on entry. The new size will be stored in *ndst.
775800
*/
776801
#define bcf_get_info_int32(hdr,line,tag,dst,ndst) bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_INT)
777802
#define bcf_get_info_float(hdr,line,tag,dst,ndst) bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_REAL)
778803
#define bcf_get_info_string(hdr,line,tag,dst,ndst) bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_STR)
779804
#define bcf_get_info_flag(hdr,line,tag,dst,ndst) bcf_get_info_values(hdr,line,tag,(void**)(dst),ndst,BCF_HT_FLAG)
780805
int bcf_get_info_values(const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, void **dst, int *ndst, int type);
781806

807+
/// Put integer INFO values into an int64_t array
808+
/**
809+
* @param hdr: BCF header
810+
* @param line: BCF record
811+
* @param tag: INFO tag to retrieve
812+
* @param dst: *dst is pointer to a memory location, can point to NULL
813+
* @param ndst: pointer to the size of allocated memory
814+
* @return >=0 on success
815+
* -1 .. no such INFO tag defined in the header
816+
* -2 .. clash between types defined in the header and encountered in the VCF record
817+
* -3 .. tag is not present in the VCF record
818+
* -4 .. the operation could not be completed (e.g. out of memory)
819+
*
820+
* Returns negative value on error or the number of values (including
821+
* missing values) put in *dst on success.
822+
*
823+
* *dst will be reallocated if it is not big enough (i.e. *ndst is too
824+
* small) or NULL on entry. The new size will be stored in *ndst.
825+
*/
826+
static inline int bcf_get_info_int64(const bcf_hdr_t *hdr, bcf1_t *line,
827+
const char *tag, int64_t **dst,
828+
int *ndst)
829+
{
830+
return bcf_get_info_values(hdr, line, tag,
831+
(void **) dst, ndst, BCF_HT_LONG);
832+
}
833+
782834
/**
783835
* bcf_get_format_*() - same as bcf_get_info*() above
784836
*

0 commit comments

Comments
 (0)