Gamgee
You miserable little maggot. I'll stove your head in!
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
utils.h
Go to the documentation of this file.
1 #ifndef gamgee__utils__guard
2 #define gamgee__utils__guard
3 
4 #include <string>
5 #include <memory>
6 #include <vector>
7 #include <sstream>
8 #include "htslib/vcf.h"
9 
10 namespace gamgee {
11 
18 namespace utils {
19 
25 std::string reverse_complement(const std::string& sequence);
26 
32 std::string complement(const std::string& sequence);
33 
39 std::string complement(std::string& sequence);
40 
46 char complement (const char base);
47 
54 std::vector<std::string> hts_string_array_to_vector(const char * const * const string_array, const uint32_t array_size);
55 
63 inline void check_max_boundary(const uint32_t index, const uint32_t size, const std::string& prefix_msg) {
64  if (index >= size) {
65  std::stringstream error_message {};
66  error_message << prefix_msg << "Index: " << index << " must be less than " << size << std::endl;
67  throw std::out_of_range(error_message.str());
68  }
69 }
70 
77 inline void check_max_boundary(const uint32_t index, const uint32_t size) {
78  check_max_boundary(index, size, "");
79 }
84 template<class TYPE>
85 inline bool bcf_check_equal_element(const TYPE& x, const TYPE& y) {
86  return (x == y);
87 }
93 template<>
94 inline bool bcf_check_equal_element<float>(const float& x, const float& y) {
95  return ((x == y) || (bcf_float_is_missing(x) && bcf_float_is_missing(y))
96  || (bcf_float_is_vector_end(x) && bcf_float_is_vector_end(y)));
97 }
98 
99 /*
100  * @brief: returns true if value is the vector end for current TYPE
101  * @note: for non numeric types returns false, as vector end is undefined
102  */
103 template<class TYPE> inline
104 bool bcf_is_vector_end_value(const TYPE& value) {
105  return false;
106 }
107 
108 /*
109  * @brief specialization of the bcf_is_vector_end_value function for int32_t
110  */
111 template<> inline
112 bool bcf_is_vector_end_value<int32_t>(const int32_t& value) {
113  return (value == bcf_int32_vector_end);
114 }
115 
116 /*
117  * @brief specialization of the bcf_is_vector_end_value function for float
118  */
119 template<> inline
120 bool bcf_is_vector_end_value<float>(const float& value) {
121  return bcf_float_is_vector_end(value);
122 }
123 
124 
125 
129 template<class ITER> inline
130 const uint8_t* cache_and_advance_to_end_if_necessary(const uint8_t* current_ptr, const uint8_t* end_ptr, ITER& it) {
131  if(end_ptr != nullptr && current_ptr < end_ptr
132  && utils::bcf_is_vector_end_value(it.read_and_cache_current_pointee()))
133  return end_ptr;
134  return current_ptr;
135 }
136 
137 
138 } // end utils namespace
139 } // end gamgee namespace
140 
141 #endif // gamgee__utils__guard
std::string reverse_complement(const std::string &sequence)
calculates the reverse complement of a sequence
Definition: utils.cpp:46
void check_max_boundary(const uint32_t index, const uint32_t size, const std::string &prefix_msg)
checks that an index is greater than or equal to size
Definition: utils.h:63
bool bcf_is_vector_end_value< int32_t >(const int32_t &value)
Definition: utils.h:112
std::string complement(std::string &sequence)
calculates the complement of a sequence in-place
Definition: utils.cpp:34
std::vector< std::string > hts_string_array_to_vector(const char *const *const string_array, const uint32_t array_size)
converts an array of c-strings into a vector
Definition: utils.cpp:53
#define bcf_int32_vector_end
Definition: vcf.h:752
bool bcf_is_vector_end_value(const TYPE &value)
Definition: utils.h:104
const uint8_t * cache_and_advance_to_end_if_necessary(const uint8_t *current_ptr, const uint8_t *end_ptr, ITER &it)
advances current ptr to end of the vector if the current element is bcf_*_vector_end ...
Definition: utils.h:130
bool bcf_check_equal_element< float >(const float &x, const float &y)
: Check whether two float values from VCF fields are equal
Definition: utils.h:94
bool bcf_check_equal_element(const TYPE &x, const TYPE &y)
Check whether two values from VCF fields of primitive types (for which the == operator is defined) * ...
Definition: utils.h:85
Definition: exceptions.h:9
bool bcf_is_vector_end_value< float >(const float &value)
Definition: utils.h:120