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 #357 from broadinstitute/dr_rev_htslib_nov6
Browse files Browse the repository at this point in the history
Update gamgee to work with revved version of htslib
  • Loading branch information
droazen committed Nov 6, 2014
2 parents 25e3d9f + 3ec5db2 commit e55dbd8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions gamgee/utils/variant_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ void subset_variant_samples(bcf_hdr_t* hdr_ptr, const std::vector<std::string>&
sample_list.erase(sample_list.size() - 1);
bcf_hdr_set_samples(hdr_ptr, sample_list.c_str(), false);
}

// NOTE: must NOT call bcf_hdr_sync() here, since htslib calls it for us in bcf_hdr_set_samples()
}

void merge_variant_headers(const std::shared_ptr<bcf_hdr_t>& dest_hdr_ptr, const std::shared_ptr<bcf_hdr_t>& src_hdr_ptr) {
Expand All @@ -39,6 +41,7 @@ void merge_variant_headers(const std::shared_ptr<bcf_hdr_t>& dest_hdr_ptr, const

// vcf.h "After all samples have been added, NULL must be passed to update internal header structures."
bcf_hdr_add_sample(dest_hdr_ptr.get(), nullptr);
bcf_hdr_sync(dest_hdr_ptr.get());
}

}
4 changes: 2 additions & 2 deletions gamgee/variant.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ class Variant {

bcf_fmt_t* find_individual_field(const std::string& tag) const { return bcf_get_fmt(m_header.m_header.get(), m_body.get(), tag.c_str()); }
bcf_info_t* find_shared_field(const std::string& tag) const { return bcf_get_info(m_header.m_header.get(), m_body.get(), tag.c_str()); }
bcf_fmt_t* find_individual_field(const uint32_t index) const { return bcf_get_fmt_idx(m_body.get(), index); }
bcf_info_t* find_shared_field(const uint32_t index) const { return bcf_get_info_idx(m_body.get(), index); }
bcf_fmt_t* find_individual_field(const uint32_t index) const { return bcf_get_fmt_id(m_body.get(), index); }
bcf_info_t* find_shared_field(const uint32_t index) const { return bcf_get_info_id(m_body.get(), index); }
bool check_field(const int32_t type_field, const int32_t type_value, const int32_t index) const;
inline AlleleType allele_type_from_difference(const int diff) const;

Expand Down
8 changes: 7 additions & 1 deletion gamgee/variant_header_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,20 @@ class VariantHeaderBuilder {
* @brief create a new VariantHeader by copying the contents of this builder into a new object. Allows for reuse.
*/
VariantHeader build() const {
// Need to sync the header before returning it so that changes will be reflected in the final product
bcf_hdr_sync(m_header.get());
return VariantHeader{utils::make_shared_variant_header(utils::variant_header_deep_copy(m_header.get()))};
}

/**
* @brief create a new VariantHeader by moving the contents of this builder into a new object.
* More efficient but does not allow for reuse.
*/
VariantHeader one_time_build() const { return VariantHeader{move(m_header)}; }
VariantHeader one_time_build() const {
// Need to sync the header before returning it so that changes will be reflected in the final product
bcf_hdr_sync(m_header.get());
return VariantHeader{move(m_header)};
}

private:
std::shared_ptr<bcf_hdr_t> m_header;
Expand Down

0 comments on commit e55dbd8

Please sign in to comment.