00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef CGATOOLS_CGDATA_EVIDENCEREADER_HPP_
00016 #define CGATOOLS_CGDATA_EVIDENCEREADER_HPP_ 1
00017
00019
00020 #include "cgatools/core.hpp"
00021 #include "cgatools/util/DelimitedFile.hpp"
00022 #include "cgatools/reference/CrrFile.hpp"
00023 #include "cgatools/cgdata/GenomeMetadata.hpp"
00024 #include "cgatools/variants/Call.hpp"
00025
00026 #include <boost/noncopyable.hpp>
00027 #include <boost/scoped_ptr.hpp>
00028 #include <boost/shared_ptr.hpp>
00029
00030 namespace cgatools { namespace cgdata {
00031
00032 class EvidenceReader : boost::noncopyable
00033 {
00034 public:
00035 struct IntervalRecord
00036 {
00037 IntervalRecord();
00038
00039 int32_t intervalId_;
00040 uint16_t chromosome_;
00041 uint32_t offset_;
00042 uint32_t length_;
00043 uint16_t ploidy_;
00044 int32_t score_;
00045 std::vector<uint16_t> alleleIndexes_;
00046 boost::array<std::string, 3> alleles_;
00047 boost::array<std::string, 2> alleleAlignments_;
00048
00049 reference::Range getRange() const;
00050 bool isCompatible(
00051 uint16_t alleleIndex, const variants::Call& call, const reference::CrrFile& crr) const;
00052 std::string getAlignment(size_t alleleIndex) const;
00053 static std::string cigarToAlignment(const std::string& cigar);
00054 };
00055
00056 struct DnbRecord
00057 {
00058 std::string getId() const;
00059
00060 int32_t intervalId_;
00061 std::string chromosome_;
00062 std::string slide_;
00063 std::string lane_;
00064 uint16_t fileNumInLane_;
00065 uint32_t dnbOffsetInLaneFile_;
00066 int32_t offsetInReference_;
00067 std::string referenceAlignment_;
00068 int32_t mateOffsetInReference_;
00069 std::string mateReferenceAlignment_;
00070 boost::array<int32_t,3> scoreAllele_;
00071 uint8_t mappingQuality_;
00072 };
00073
00074 EvidenceReader(const reference::CrrFile& crr,
00075 const GenomeMetadata& exp);
00076
00077 void seek(const reference::Range& r);
00078
00081 void seekToChr(uint16_t chr);
00082
00085 void nextInChr();
00086
00087 bool inInterval() const
00088 {
00089 return inInterval_;
00090 }
00091
00092 const IntervalRecord& getInterval() const
00093 {
00094 CGA_ASSERT(inInterval_);
00095 return intervalsFile_->rec_;
00096 }
00097
00098 const std::vector<DnbRecord>& getDnbs()
00099 {
00100 seekDnbs();
00101 return dnbs_;
00102 }
00103
00106 uint32_t getScore() const
00107 {
00108 if (!inInterval_)
00109 return 0;
00110 else
00111 return intervalsFile_->rec_.score_;
00112 }
00113
00118 uint32_t countSupportingDnbs(uint16_t alleleIndex, int32_t scoreThreshold);
00119
00120 private:
00121 struct IntervalsFile
00122 {
00123 std::string filename_;
00124 boost::shared_ptr<std::istream> f_;
00125 util::DelimitedFile parser_;
00126 IntervalRecord rec_;
00127
00128
00129
00130
00131 IntervalsFile(const std::string& fn, const reference::CrrFile& crr);
00132 };
00133
00134 struct DnbsFile
00135 {
00136 std::string filename_;
00137 boost::shared_ptr<std::istream> f_;
00138 util::DelimitedFile parser_;
00139 DnbRecord rec_;
00140
00141 DnbsFile(const std::string& fn);
00142 };
00143
00145 void openIntervals(uint16_t chr);
00146
00147 void openDnbs();
00148 void seekDnbs();
00149 bool nextDnbs();
00150
00151 const reference::CrrFile& crr_;
00152 const GenomeMetadata& exp_;
00153
00154
00155 boost::scoped_ptr<IntervalsFile> intervalsFile_;
00156
00157 uint16_t dnbsChromosome_;
00158 int32_t dnbsIntervalId_;
00159 boost::scoped_ptr<DnbsFile> dnbsFile_;
00160 std::vector<DnbRecord> dnbs_;
00161
00162 bool inInterval_;
00163 };
00164
00165 } }
00166
00167 #endif // CGATOOLS_CGDATA_EVIDENCEREADER_HPP_