Gamgee
You miserable little maggot. I'll stove your head in!
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sam_header.h
Go to the documentation of this file.
1 #ifndef gamgee__sam_header__guard
2 #define gamgee__sam_header__guard
3 
4 #include "htslib/sam.h"
5 #include "read_group.h"
6 
7 #include <memory>
8 #include <string>
9 #include <vector>
10 
11 namespace gamgee {
12 
16 class SamHeader {
17  public:
18  explicit SamHeader() = default;
19  explicit SamHeader(const std::shared_ptr<bam_hdr_t>& header);
20  SamHeader(const SamHeader& other);
21  SamHeader& operator=(const SamHeader& other);
22  SamHeader(SamHeader&& other) = default;
23  SamHeader& operator=(SamHeader&& other) = default;
24  uint32_t n_sequences() const {return m_header->n_targets;}
25  uint32_t sequence_length(const std::string& sequence_name) const;
26  uint32_t sequence_length(const uint32_t sequence_index) const { return m_header->target_len[sequence_index]; }
27  std::string sequence_name(const uint32_t sequence_index) const { return std::string(m_header->target_name[sequence_index]); }
28  std::vector<ReadGroup> read_groups() const;
29 
30  private:
31  std::string header_text() const { return std::string(m_header->text, m_header->l_text); }
32  std::shared_ptr<bam_hdr_t> m_header;
33 
34  friend class SamWriter;
35  friend class SamBuilder;
36 };
37 
38 }
39 #endif // gamgee__sam_header__guard
Utility class to hold the header of a sam file.
Definition: sam_header.h:16
class to build Sam objects from existing data or from scratch
Definition: sam_builder.h:58
uint32_t sequence_length(const std::string &sequence_name) const
Returns the length of the given reference sequence as stored in the @SQ tag in the BAM header...
Definition: sam_header.cpp:44
utility class to write out a SAM/BAM/CRAM file to any stream
Definition: sam_writer.h:20
SamHeader & operator=(const SamHeader &other)
deep copy assignment of a SamHeader. Shared pointers maintain state to all other associated objects c...
Definition: sam_header.cpp:33
SamHeader()=default
initializes a null SamHeader
uint32_t sequence_length(const uint32_t sequence_index) const
Returns the length of the given reference sequence as stored in the @SQ tag in the BAM header...
Definition: sam_header.h:26
std::vector< ReadGroup > read_groups() const
extracts read group objects from a SAM header
Definition: sam_header.cpp:57
Definition: exceptions.h:9
std::string sequence_name(const uint32_t sequence_index) const
Returns the sequence name for the sequence with the given zero-based index.
Definition: sam_header.h:27
uint32_t n_sequences() const
Returns the number of reference sequences in the header.
Definition: sam_header.h:24