00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CGA_TOOLS_COMMAND_MAP_SAM_UTILS_HPP_
00016 #define CGA_TOOLS_COMMAND_MAP_SAM_UTILS_HPP_ 1
00017
00019
00020 #include "cgatools/core.hpp"
00021 #include "cgatools/util/Exception.hpp"
00022 #include "cgatools/mapping/SamRecord.hpp"
00023 #include "cgatools/cgdata/Dnb.hpp"
00024
00025 #include <vector>
00026 #include <boost/array.hpp>
00027
00028 namespace cgatools { namespace util {
00029 class DelimitedFile;
00030 }};
00031
00032 namespace cgatools { namespace mapping {
00033
00034 class ReadsFlagParser {
00035 public:
00036 ReadsFlagParser():flags_(0) {}
00037 ReadsFlagParser(size_t flags):flags_(flags) {}
00038 bool HalfDnbNoMatches(size_t side) const {return side==0 ? (flags_ & 0x1)!=0:(flags_ & 0x4)!=0;}
00039 bool HalfDnbNoMapOverflow(size_t side) const {return side==0 ? (flags_ & 0x2)!=0:(flags_&0x8)!=0;}
00040 bool NoHalfDnbMappings(size_t side) const {return side==0 ? (flags_ & 0x3)!=0:(flags_ & 0xC)!=0;}
00041 bool NoMappings() const {return (flags_ & 0x3)!=0 && (flags_ & 0xC)!=0;}
00042
00043 size_t flags_;
00044 };
00045
00046 class ReadsRecord {
00047 friend std::ostream& operator<< (std::ostream& out, const ReadsRecord& r);
00048 public:
00049 ReadsRecord():recordIndex_(-1) {}
00050
00051 void initParser(util::DelimitedFile &delimitedFile);
00052
00053 std::string reads_;
00054 std::string scores_;
00055 ReadsFlagParser flags_;
00056
00057
00058 int recordIndex_;
00059 };
00060
00061 class MappingsFlagParser {
00062 public:
00063 MappingsFlagParser():flags_(0) {}
00064 MappingsFlagParser(size_t flags):flags_(flags) {}
00065 bool LastDnbRecord() const {return (flags_ & 0x1) != 0;}
00066 void setLastDnbRecord() {flags_ |= 0x1;}
00067 size_t getSide() const {return (flags_ & 0x2) > 0;}
00068 void setSide(size_t side) {CGA_ASSERT(side<2); flags_ |= side<<1;}
00069 size_t getStrand() const {return (flags_ & 0x4) > 0;}
00070 void setStrand(size_t strand) {CGA_ASSERT(strand<2); flags_ |= strand<<2;}
00071
00072 size_t flags_;
00073 };
00074
00075 class MappingsRecord {
00076 friend std::ostream& operator<< (std::ostream& out, const MappingsRecord& r);
00077 public:
00078 MappingsRecord()
00079 : flags_(0), chr_(""), offsetInChr_(-1), weightChar_(33),
00080 bestMate_(-1), isPrimary_(false), recordIndex_(-1)
00081 {
00082 gaps_.assign(0);
00083 }
00084
00085 void initParser(util::DelimitedFile &delimitedFile);
00086
00087 std::string createCigar(const cgdata::HalfDnbStructure::Reads &readLengths) const;
00088
00089 MappingsFlagParser flags_;
00090 std::string chr_;
00091 int offsetInChr_;
00092 boost::array<int,3> gaps_;
00093 uint8_t weightChar_;
00094 int bestMate_;
00095
00096
00097 bool isPrimary_;
00098 int recordIndex_;
00099 };
00100
00101 typedef std::vector<MappingsRecord> MappingsRecords;
00102
00103 class BaseMappingSamRecord : public SamRecord
00104 {
00105 public:
00106 BaseMappingSamRecord(
00107 const std::string& readName,
00108 const MappingsRecord &mapping,
00109 const cgdata::DnbStructure& dnbStructure,
00110 const std::string& fullReadSequence,
00111 const std::string& fullReadScores,
00112 const UInt16Pair& sequenceStartAndLength,
00113 const reference::CrrFile& reference
00114 );
00115 };
00116
00117
00118 } }
00119
00120 #endif // CGA_TOOLS_COMMAND_MAP_SAM_UTILS_HPP_