Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Merge pull request #402 from broadinstitute/intel_header_field_length
Browse files Browse the repository at this point in the history
Added functions in VariantHeader to query field length descriptors and field lengths.
  • Loading branch information
jmthibault79 committed Dec 2, 2014
2 parents 816bca0 + 3a79ceb commit d923b53
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
25 changes: 24 additions & 1 deletion gamgee/variant/variant_header.h
Expand Up @@ -123,7 +123,30 @@ class VariantHeader {
* @note must check whether the field exists before calling this function, as it doesn't check for you
*/
uint8_t field_type(const int32_t index, const int32_t field_category) const { return bcf_hdr_id2type(m_header.get(), field_category, index); }

/*
* returns one of BCF_VL_* values for field with the specified name and category (one of BCF_HL_FMT, BCF_HL_INFO, or BCF_HL_FLT)
*
* @note must check whether the field exists before calling this function, as it doesn't check for you
*/
uint32_t field_length_descriptor(const std::string& tag, const int32_t field_category) const { return field_length_descriptor(field_index(tag), field_category); }
/**
* returns one of BCF_VL_* values for the field with the specified index and category (one of BCF_HL_FMT, BCF_HL_INFO, or BCF_HL_FLT)
*
* @note must check whether the field exists before calling this function, as it doesn't check for you
*/
uint32_t field_length_descriptor(const int32_t index, const int32_t field_category) const { return bcf_hdr_id2length(m_header.get(), field_category, index); }
/**
* returns number of values for the field with the specified name and category (one of BCF_HL_FMT, BCF_HL_INFO, or BCF_HL_FLT), 0xfffff for variable length fields
*
* @note must check whether the field exists before calling this function, as it doesn't check for you
*/
uint32_t field_length(const std::string& tag, const int32_t field_category) const { return field_length(field_index(tag), field_category); }
/**
* returns number of values for the field with the specified index and category (one of BCF_HL_FMT, BCF_HL_INFO, or BCF_HL_FLT), 0xfffff for variable length fields
*
* @note must check whether the field exists before calling this function, as it doesn't check for you
*/
uint32_t field_length(const int32_t index, const int32_t field_category) const { return bcf_hdr_id2number(m_header.get(), field_category, index); }
/**
* @brief checks whether the given filter is present given the filter name
*/
Expand Down
16 changes: 16 additions & 0 deletions test/variant_test.cpp
Expand Up @@ -112,3 +112,19 @@ BOOST_AUTO_TEST_CASE( test_missing_string_individual_field_values ) {
BOOST_CHECK(missing(variant.string_individual_field("AS")[1]));
BOOST_CHECK(! missing(variant.string_individual_field("AS")[2]));
}

BOOST_AUTO_TEST_CASE( test_field_lengths ) {
auto header = SingleVariantReader{"testdata/test_variants.vcf"}.header();
BOOST_CHECK_EQUAL(header.field_length_descriptor("AF", BCF_HL_INFO), static_cast<uint32_t>(BCF_VL_A));
BOOST_CHECK_EQUAL(header.field_length_descriptor("AF", BCF_HL_FMT), static_cast<uint32_t>(BCF_VL_FIXED));
BOOST_CHECK_EQUAL(header.field_length_descriptor("PL", BCF_HL_FMT), static_cast<uint32_t>(BCF_VL_G));
BOOST_CHECK_EQUAL(header.field_length_descriptor("AS", BCF_HL_FMT), static_cast<uint32_t>(BCF_VL_FIXED));
BOOST_CHECK_EQUAL(header.field_length_descriptor("VLINT", BCF_HL_FMT), static_cast<uint32_t>(BCF_VL_VAR));

BOOST_CHECK_EQUAL(header.field_length("AF", BCF_HL_INFO), 0xfffffu);
BOOST_CHECK_EQUAL(header.field_length("AF", BCF_HL_FMT), 2u);
BOOST_CHECK_EQUAL(header.field_length("PL", BCF_HL_FMT), 0xfffffu);
BOOST_CHECK_EQUAL(header.field_length("AS", BCF_HL_FMT), 1u);
BOOST_CHECK_EQUAL(header.field_length("VLINT", BCF_HL_FMT), 0xfffffu);
}

0 comments on commit d923b53

Please sign in to comment.