00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CGA_TOOLS_CIGAR_HPP_
00016 #define CGA_TOOLS_CIGAR_HPP_ 1
00017
00019
00020 #include "cgatools/core.hpp"
00021
00022 #include <vector>
00023 #include <string>
00024 #include <map>
00025 #include <boost/shared_ptr.hpp>
00026
00027 namespace cgatools { namespace mapping {
00028
00030 class Cigar {
00031 friend std::ostream& operator<< (std::ostream& out, const Cigar& cigar);
00032 public:
00033 class CigarElement {
00034 public:
00035 CigarElement(char type, size_t length)
00036 : type_(type), length_(length) {}
00037 int getSequenceLength() const;
00038 bool operator== (const CigarElement& e) const {return type_==e.type_ && length_==e.length_;}
00039
00040 char type_;
00041 size_t length_;
00042 };
00043 typedef std::vector<CigarElement> ParsedCigar;
00044
00045 Cigar(bool mergeNeighbours = false, bool removeZeros = false)
00046 :mergeNeighbours_(mergeNeighbours), removeZeros_(removeZeros)
00047 {}
00048
00049 Cigar(const std::string &cigar, bool mergeNeighbours = false, bool removeZeros = false)
00050 :mergeNeighbours_(mergeNeighbours), removeZeros_(removeZeros)
00051 {
00052 parse(cigar);
00053 }
00054
00055 void parse(const std::string &cigar);
00056
00058 size_t getSequenceLength() const;
00060 size_t getReferenceLength() const;
00061
00062 const ParsedCigar& getParsedCigar() const {return parsedCigar_;}
00063
00064
00065 void add(const CigarElement &e);
00066
00068 void push_back(const CigarElement &e) {parsedCigar_.push_back(e);}
00070 void merge_back(const CigarElement &e);
00071
00072 CigarElement &operator[](size_t i) {return parsedCigar_[i];}
00073 CigarElement &back() {return parsedCigar_.back();}
00074
00075 size_t size() const {return parsedCigar_.size();}
00076
00077 void trancatePaddings();
00078
00080 Cigar pack() const;
00081
00082 bool operator== (const Cigar& c) const {return parsedCigar_==c.parsedCigar_;}
00083 protected:
00084
00085 bool mergeNeighbours_;
00086 bool removeZeros_;
00087 ParsedCigar parsedCigar_;
00088 };
00089
00090 } }
00091
00092 #endif // CGA_TOOLS_CIGAR_HPP_