Gamgee
You miserable little maggot. I'll stove your head in!
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
interval.h
Go to the documentation of this file.
1 #ifndef gamgee__interval__guard
2 #define gamgee__interval__guard
3 
4 #include <vector>
5 #include <string>
6 
7 namespace gamgee {
8 
19 class Interval {
20  public:
21 
23  enum class IntervalType {
24  GATK,
25  PICARD,
26  BED
27  };
28 
35  m_chr {0},
36  m_start {0},
37  m_stop {0},
38  m_output_type {IntervalType::GATK}
39  {}
40 
49  explicit Interval(const std::string& chr, const uint32_t start, const uint32_t stop, const IntervalType output_type = IntervalType::GATK) :
50  m_chr{chr},
51  m_start{start},
52  m_stop{stop},
53  m_output_type{output_type}
54  {}
55 
56  // it is good to be explicit about these defaults.
57  Interval(const Interval&) = default;
58  Interval(Interval&&) = default;
59  Interval& operator=(const Interval&) = default;
60  Interval& operator=(Interval&&) = default;
61 
70  bool operator==(const Interval& rhs) const;
71 
79  bool operator!=(const Interval& rhs) const { return !(*this == rhs); }
80 
86  inline uint32_t size() const { return m_stop - m_start + 1; }
87 
98  std::vector<Interval> tile_left(const uint32_t tile_size,
99  const uint32_t spacing
100  ) const;
101 
112  std::vector<Interval> tile_right(const uint32_t tile_size,
113  const uint32_t spacing
114  ) const;
115 
127  std::vector<Interval> tsca_tiling(const uint32_t spacing,
128  const uint32_t insert_size,
129  const uint32_t flanking
130  ) const;
131 
132  std::string str() const;
133 
134  std::string chr() const { return m_chr; }
135  uint32_t start() const { return m_start; }
136  uint32_t stop() const { return m_stop; }
137  IntervalType output_type() const { return m_output_type; }
138  void set_chr(const std::string& chr) { m_chr = chr; }
139  void set_start(const uint32_t start) { m_start = start; }
140  void set_stop(const uint32_t stop) { m_stop = stop; }
141  void set_output_type(const IntervalType output_type) { m_output_type = output_type; }
142 
143  private:
144  std::string m_chr;
145  uint32_t m_start;
146  uint32_t m_stop;
147  IntervalType m_output_type;
148 
149 };
150 
158 std::vector<Interval> read_intervals(const std::string& intervals_file);
159 
167 std::vector<Interval> read_intervals(std::istream& input);
168 
169 } // end of namespace
170 
174 std::ostream& operator<<(std::ostream&, const gamgee::Interval&);
175 
176 #endif /* gamgee__interval__guard */
177 
IntervalType output_type() const
Definition: interval.h:137
Utility class to store an genomic location (Interval).
Definition: interval.h:19
std::vector< Interval > tile_left(const uint32_t tile_size, const uint32_t spacing) const
Tiles an Interval with smaller Intervals anchoring (starting) on the left side (start) of the Interva...
Definition: interval.cpp:65
std::string chr() const
Definition: interval.h:134
bool operator==(const Interval &rhs) const
Checks two Intervals for equality.
Definition: interval.cpp:81
std::ostream & operator<<(std::ostream &, const gamgee::Interval &)
outputs the interval in the outputtype format
Definition: interval.cpp:94
void set_stop(const uint32_t stop)
Definition: interval.h:140
IntervalType
supported output formats for an Interval
Definition: interval.h:23
Interval()
creates an interval with standard values
Definition: interval.h:34
bool operator!=(const Interval &rhs) const
Checks two intervals for inequality.
Definition: interval.h:79
void set_output_type(const IntervalType output_type)
Definition: interval.h:141
Interval & operator=(const Interval &)=default
PICARD format – chr [tab] start [tab] stop [tab] strand [tab] comments.
void set_start(const uint32_t start)
Definition: interval.h:139
std::string str() const
returns a string representation of the interval
Definition: interval.cpp:85
GATK format – chr:start-stop.
std::vector< Interval > tile_right(const uint32_t tile_size, const uint32_t spacing) const
Tiles an Interval with smaller Intervals anchoring (starting) on the right side (stop) of the Interva...
Definition: interval.cpp:73
vector< Interval > read_intervals(const string &intervals_file)
Definition: interval.cpp:39
Definition: exceptions.h:9
BED format – chr [tab] start [tab] stop.
uint32_t size() const
calculates the number of loci in the Intervals
Definition: interval.h:86
uint32_t start() const
Definition: interval.h:135
void set_chr(const std::string &chr)
Definition: interval.h:138
std::vector< Interval > tsca_tiling(const uint32_t spacing, const uint32_t insert_size, const uint32_t flanking) const
creates tiling TSCA baits (small intervals with an insert in between) that tile across the entire Int...
Definition: interval.cpp:53
Interval(const std::string &chr, const uint32_t start, const uint32_t stop, const IntervalType output_type=IntervalType::GATK)
creates an interval with all parameters
Definition: interval.h:49
uint32_t stop() const
Definition: interval.h:136