Gamgee
You miserable little maggot. I'll stove your head in!
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
variant_header_builder.h
Go to the documentation of this file.
1 #ifndef gamgee__variant_header_builder__guard
2 #define gamgee__variant_header_builder__guard
3 
4 #include "variant_header.h"
5 #include "variant_reader.h"
6 
7 #include "../utils/utils.h"
8 #include "../utils/hts_memory.h"
9 
10 #include "htslib/vcf.h"
11 
12 #include <memory>
13 
14 namespace gamgee {
15 
20  public:
21 
27  VariantHeaderBuilder() noexcept;
33  VariantHeaderBuilder(const VariantHeader& header);
34  // TODO: version with move semantics
35 
36  VariantHeaderBuilder(const VariantHeaderBuilder& other) = delete;
37  VariantHeaderBuilder& operator=(const VariantHeaderBuilder& other) = delete;
38 
39  VariantHeaderBuilder(VariantHeaderBuilder&& other) = default;
41 
42  VariantHeaderBuilder& add_chromosome(const std::string& id, const std::string& length = "", const std::string& url = "", const std::string& extra = "");
43  VariantHeaderBuilder& add_filter(const std::string& id, const std::string& description = "", const std::string& extra = "");
44  VariantHeaderBuilder& add_shared_field(const std::string& id, const std::string& number, const std::string& type, const std::string& description = "", const std::string& source = "", const std::string& version = "", const std::string& extra = "");
45  VariantHeaderBuilder& add_individual_field(const std::string& id, const std::string& number, const std::string& type, const std::string& description = "", const std::string& extra = "");
46  VariantHeaderBuilder& add_sample(const std::string& sample);
47  VariantHeaderBuilder& add_source(const std::string& source);
48 
49  VariantHeaderBuilder& advanced_add_arbitrary_line(const std::string& line);
50 
55  VariantHeaderBuilder& merge(const VariantHeader& other_header);
56 
60  VariantHeader build() const {
61  // Need to sync the header before returning it so that changes will be reflected in the final product
62  bcf_hdr_sync(m_header.get());
64  }
65 
71  // Need to sync the header before returning it so that changes will be reflected in the final product
72  bcf_hdr_sync(m_header.get());
73  return VariantHeader{move(m_header)};
74  }
75 
76  private:
77  std::shared_ptr<bcf_hdr_t> m_header;
78 
79 };
80 
81 }
82 
83 #endif // gamgee__variant_header_builder__guard
VariantHeaderBuilder & add_filter(const std::string &id, const std::string &description="", const std::string &extra="")
Definition: variant_header_builder.cpp:41
int bcf_hdr_sync(bcf_hdr_t *h)
Definition: vcf.c:110
shared_ptr< bcf_hdr_t > make_shared_variant_header(bcf_hdr_t *bcf_hdr_ptr)
wraps a pre-allocated bcf_hdr_t in a shared_ptr with correct deleter
Definition: hts_memory.cpp:63
VariantHeaderBuilder & add_shared_field(const std::string &id, const std::string &number, const std::string &type, const std::string &description="", const std::string &source="", const std::string &version="", const std::string &extra="")
Definition: variant_header_builder.cpp:50
VariantHeaderBuilder & operator=(const VariantHeaderBuilder &other)=delete
VariantHeader one_time_build() const
create a new VariantHeader by moving the contents of this builder into a new object. More efficient but does not allow for reuse.
Definition: variant_header_builder.h:70
VariantHeaderBuilder & add_sample(const std::string &sample)
Definition: variant_header_builder.cpp:80
Utility class to build VariantHeader objects from scratch.
Definition: variant_header_builder.h:19
VariantHeaderBuilder & merge(const VariantHeader &other_header)
merges a variant header into this builder, using bcf_hdr_combine() from htslib
Definition: variant_header_builder.cpp:90
VariantHeaderBuilder & add_individual_field(const std::string &id, const std::string &number, const std::string &type, const std::string &description="", const std::string &extra="")
Definition: variant_header_builder.cpp:63
VariantHeaderBuilder & add_source(const std::string &source)
Definition: variant_header_builder.cpp:74
bcf_hdr_t * variant_header_deep_copy(bcf_hdr_t *original)
creates a deep copy of an existing bcf_hdr_t
Definition: hts_memory.cpp:119
VariantHeader build() const
create a new VariantHeader by copying the contents of this builder into a new object. Allows for reuse.
Definition: variant_header_builder.h:60
Definition: exceptions.h:9
VariantHeaderBuilder & advanced_add_arbitrary_line(const std::string &line)
Definition: variant_header_builder.cpp:85
Utility class to hold a variant header.
Definition: variant_header.h:52
VariantHeaderBuilder() noexcept
initializes a variant header builder
Definition: variant_header_builder.cpp:23
VariantHeaderBuilder & add_chromosome(const std::string &id, const std::string &length="", const std::string &url="", const std::string &extra="")
Definition: variant_header_builder.cpp:31