Gamgee
You miserable little maggot. I'll stove your head in!
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
sam_builder.h
Go to the documentation of this file.
1 #ifndef gamgee__sam_builder__guard
2 #define gamgee__sam_builder__guard
3 
4 #include "sam.h"
6 
7 #include <string>
8 #include <vector>
9 #include <memory>
10 
11 namespace gamgee {
12 
58 class SamBuilder {
59  public:
60  explicit SamBuilder(const SamHeader& header, const bool validate_on_build = true);
61  explicit SamBuilder(const Sam& starting_read, const bool validate_on_build = true);
62  explicit SamBuilder(const SamHeader& header, const Sam& starting_read, const bool validate_on_build = true);
63 
64  // SamBuilders are moveable but not copyable, and use default destruction
65  SamBuilder(SamBuilder&& other) = default;
66  SamBuilder& operator=(SamBuilder&& other) = default;
67  SamBuilder(const SamBuilder& other) = delete;
68  SamBuilder& operator=(const SamBuilder& other) = delete;
69  ~SamBuilder() = default;
70 
71  // Setters for data fields
72  SamBuilder& set_name(const std::string& new_name);
73 
74  SamBuilder& set_cigar(const Cigar& new_cigar);
75  SamBuilder& set_cigar(const std::vector<CigarElement>& new_cigar);
76  SamBuilder& set_cigar(const std::initializer_list<CigarElement> new_cigar);
77  SamBuilder& set_cigar(const std::string& new_cigar);
78 
79  SamBuilder& set_bases(const ReadBases& new_bases);
80  SamBuilder& set_bases(const std::vector<Base>& new_bases);
81  SamBuilder& set_bases(const std::initializer_list<Base> new_bases);
82  SamBuilder& set_bases(const std::string& new_bases);
83 
84  SamBuilder& set_base_quals(const BaseQuals& new_base_quals);
85  SamBuilder& set_base_quals(const std::vector<uint8_t>& new_base_quals);
86  SamBuilder& set_base_quals(const std::initializer_list<uint8_t> new_base_quals);
87  SamBuilder& set_base_quals(const std::initializer_list<int> new_base_quals);
88 
89  // Setters for core fields: these pass through to the implementations in Sam
90  SamBuilder& set_chromosome(const uint32_t chr) { m_core_read.set_chromosome(chr); return *this; }
91  SamBuilder& set_alignment_start(const uint32_t start) { m_core_read.set_alignment_start(start); return *this; }
92  SamBuilder& set_mate_chromosome(const uint32_t mchr) { m_core_read.set_mate_chromosome(mchr); return *this; }
93  SamBuilder& set_mate_alignment_start(const uint32_t mstart) { m_core_read.set_mate_alignment_start(mstart); return *this; }
94  SamBuilder& set_paired() { m_core_read.set_paired(); return *this; }
95  SamBuilder& set_not_paired() { m_core_read.set_not_paired(); return *this; }
96  SamBuilder& set_unmapped() { m_core_read.set_unmapped(); return *this; }
97  SamBuilder& set_not_unmapped() { m_core_read.set_not_unmapped(); return *this; }
98  SamBuilder& set_mate_unmapped() { m_core_read.set_mate_unmapped(); return *this; }
99  SamBuilder& set_not_mate_unmapped() { m_core_read.set_not_mate_unmapped(); return *this; }
100  SamBuilder& set_reverse() { m_core_read.set_reverse(); return *this; }
101  SamBuilder& set_not_reverse() { m_core_read.set_not_reverse(); return *this; }
102  SamBuilder& set_mate_reverse() { m_core_read.set_mate_reverse(); return *this; }
103  SamBuilder& set_not_mate_reverse() { m_core_read.set_not_mate_reverse(); return *this; }
104  SamBuilder& set_first() { m_core_read.set_first(); return *this; }
105  SamBuilder& set_not_first() { m_core_read.set_not_first(); return *this; }
106  SamBuilder& set_last() { m_core_read.set_last(); return *this; }
107  SamBuilder& set_not_last() { m_core_read.set_not_last(); return *this; }
108  SamBuilder& set_secondary() { m_core_read.set_secondary(); return *this; }
109  SamBuilder& set_not_secondary() { m_core_read.set_not_secondary(); return *this; }
110  SamBuilder& set_fail() { m_core_read.set_fail(); return *this; }
111  SamBuilder& set_not_fail() { m_core_read.set_not_fail(); return *this; }
112  SamBuilder& set_duplicate() { m_core_read.set_duplicate(); return *this; }
113  SamBuilder& set_not_duplicate() { m_core_read.set_not_duplicate(); return *this; }
114  SamBuilder& set_supplementary() { m_core_read.set_supplementary(); return *this; }
115  SamBuilder& set_not_supplementary() { m_core_read.set_not_supplementary(); return *this; }
116 
117  Sam build() const;
118  Sam one_time_build();
119 
120  private:
121  Sam m_core_read;
122  SamBuilderDataField m_name;
123  SamBuilderDataField m_cigar;
124  SamBuilderDataField m_bases;
125  SamBuilderDataField m_base_quals;
126  SamBuilderDataField m_tags;
127  bool m_validate_on_build;
128 
129  void validate() const;
130  void build_data_array(bam1_t* sam) const;
131 };
132 
133 }
134 
135 
136 #endif /* gamgee__sam_builder__guard */
Sam one_time_build()
build a Sam more efficiently by moving the builder's data out of it and invalidating future builds ...
Definition: sam_builder.cpp:283
void set_first()
Definition: sam.h:303
void set_not_paired()
Definition: sam.h:294
Utility class to hold the header of a sam file.
Definition: sam_header.h:16
~SamBuilder()=default
class to hold encoded byte arrays for individual data fields (cigar, bases, etc.) during building of ...
Definition: sam_builder_data_field.h:19
SamBuilder & set_chromosome(const uint32_t chr)
simple setter for the chromosome index. Index is 0-based.
Definition: sam_builder.h:90
void set_not_first()
Definition: sam.h:304
void set_duplicate()
Definition: sam.h:311
SamBuilder & set_last()
Definition: sam_builder.h:106
SamBuilder & set_unmapped()
Definition: sam_builder.h:96
Sam build() const
build a Sam (can be called repeatedly)
Definition: sam_builder.cpp:256
class to build Sam objects from existing data or from scratch
Definition: sam_builder.h:58
SamBuilder & set_not_last()
Definition: sam_builder.h:107
SamBuilder & set_first()
Definition: sam_builder.h:104
void set_reverse()
Definition: sam.h:299
void set_not_last()
Definition: sam.h:306
SamBuilder & set_not_unmapped()
Definition: sam_builder.h:97
SamBuilder & set_paired()
Definition: sam_builder.h:94
SamBuilder & set_not_reverse()
Definition: sam_builder.h:101
void set_not_duplicate()
Definition: sam.h:312
SamBuilder & set_cigar(const Cigar &new_cigar)
set the read's cigar to the cigar of an existing read
Definition: sam_builder.cpp:76
SamBuilder & set_secondary()
Definition: sam_builder.h:108
Definition: hts.h:87
SamBuilder & set_not_supplementary()
Definition: sam_builder.h:115
void set_fail()
Definition: sam.h:309
Utility class to handle the memory management of the sam record object for a read base qualities...
Definition: base_quals.h:13
Definition: sam.h:170
SamBuilder & set_mate_chromosome(const uint32_t mchr)
simple setter for the mate's chromosome index. Index is 0-based.
Definition: sam_builder.h:92
SamBuilder & set_not_duplicate()
Definition: sam_builder.h:113
void set_mate_alignment_start(const uint32_t mstart)
simple setter for the mate's alignment start.
Definition: sam.h:262
SamBuilder & set_name(const std::string &new_name)
set the read's QNAME to the specified value
Definition: sam_builder.cpp:66
SamBuilder & set_not_first()
Definition: sam_builder.h:105
SamBuilder & set_fail()
Definition: sam_builder.h:110
SamBuilder & operator=(SamBuilder &&other)=default
void set_mate_unmapped()
Definition: sam.h:297
SamBuilder & set_supplementary()
Definition: sam_builder.h:114
SamBuilder(const SamHeader &header, const bool validate_on_build=true)
create a Sam from scratch, starting only with a header
Definition: sam_builder.cpp:21
SamBuilder & set_base_quals(const BaseQuals &new_base_quals)
set the read's base qualities to the base qualities of an existing read
Definition: sam_builder.cpp:200
SamBuilder & set_not_mate_unmapped()
Definition: sam_builder.h:99
void set_not_secondary()
Definition: sam.h:308
Definition: exceptions.h:9
void set_mate_reverse()
Definition: sam.h:301
void set_mate_chromosome(const uint32_t mchr)
simple setter for the mate's chromosome index. Index is 0-based.
Definition: sam.h:261
SamBuilder & set_not_mate_reverse()
Definition: sam_builder.h:103
SamBuilder & set_alignment_start(const uint32_t start)
simple setter for the alignment start.
Definition: sam_builder.h:91
void set_not_unmapped()
Definition: sam.h:296
void set_alignment_start(const uint32_t start)
simple setter for the alignment start.
Definition: sam.h:260
void set_last()
Definition: sam.h:305
void set_supplementary()
Definition: sam.h:313
void set_not_reverse()
Definition: sam.h:300
SamBuilder & set_not_fail()
Definition: sam_builder.h:111
Utility class to manipulate a Sam record.
Definition: sam.h:20
SamBuilder & set_not_paired()
Definition: sam_builder.h:95
void set_not_supplementary()
Definition: sam.h:314
Utility class to handle the memory management of the sam record object for read bases.
Definition: read_bases.h:26
void set_paired()
Definition: sam.h:293
SamBuilder & set_reverse()
Definition: sam_builder.h:100
SamBuilder & set_duplicate()
Definition: sam_builder.h:112
void set_chromosome(const uint32_t chr)
simple setter for the chromosome index. Index is 0-based.
Definition: sam.h:259
SamBuilder & set_bases(const ReadBases &new_bases)
set the read's bases to the bases of an existing read
Definition: sam_builder.cpp:138
Utility class to manage the memory of the cigar structure.
Definition: cigar.h:24
SamBuilder & set_mate_alignment_start(const uint32_t mstart)
simple setter for the mate's alignment start.
Definition: sam_builder.h:93
void set_not_fail()
Definition: sam.h:310
void set_not_mate_reverse()
Definition: sam.h:302
SamBuilder & set_mate_unmapped()
Definition: sam_builder.h:98
SamBuilder & set_not_secondary()
Definition: sam_builder.h:109
void set_secondary()
Definition: sam.h:307
SamBuilder & set_mate_reverse()
Definition: sam_builder.h:102
void set_unmapped()
Definition: sam.h:295
void set_not_mate_unmapped()
Definition: sam.h:298