Changeset 3353
- Timestamp:
- Nov 22, 2014, 11:26:14 AM (8 years ago)
- Location:
- trunk/yat/omic
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/omic/BamFile.cc
r3350 r3353 53 53 InBamFile::~InBamFile(void) 54 54 { 55 #if YAT_HAVE_HTSLIB 56 hts_idx_destroy(index_); 57 #else 55 58 bam_index_destroy(index_); 59 #endif 56 60 } 57 61 … … 63 67 64 68 65 const bam_index_t* InBamFile::index(void) const69 const InBamFile::index_type* InBamFile::index(void) const 66 70 { 67 71 if (!index_) { 72 #if YAT_HAVE_HTSLIB 73 index_ = hts_idx_load(filename().c_str(), HTS_FMT_BAI); 74 #else 68 75 index_ = bam_index_load(filename().c_str()); 76 #endif 69 77 if (!index_) { 70 78 std::ostringstream ss; … … 79 87 void InBamFile::open(const std::string& fn) 80 88 { 89 #if YAT_HAVE_HTSLIB 90 assert(0 && "FIXME"); 91 #else 81 92 open_base(fn, "rb", NULL); 82 93 header_.header_ = sf_->header; 94 #endif 83 95 if (header_.header_ == NULL) { 84 96 std::ostringstream ss; … … 91 103 bool InBamFile::read(BamRead& read) 92 104 { 105 #if YAT_HAVE_HTSLIB 106 int result_ = sam_read1(sf_, header_.header_, read.bam_); 107 #else 93 108 int result_ = samread(sf_, read.bam_); 109 #endif 94 110 if (result_<-1) { 95 111 std::ostringstream ss; … … 105 121 106 122 123 #if YAT_HAVE_HTSLIB 124 bool InBamFile::read(BamRead& read, hts_itr_t* iter) 125 { 126 assert(0 && "FIXME"); 127 int result_ = -1; 128 #else 107 129 bool InBamFile::read(BamRead& read, bam_iter_t iter) 108 130 { 109 131 assert(sf_->type & 1); // no random access from sam files 110 132 int result_ = bam_iter_read(sf_->x.bam, iter, read.bam_); 133 #endif 111 134 if (result_<-1) { 112 135 std::ostringstream ss; … … 141 164 void OutBamFile::open(const std::string& fn, const BamHeader& h) 142 165 { 166 #if YAT_HAVE_HTSLIB 167 assert(0 && "FIXME"); 168 #else 143 169 open_base(fn, "wb", h.header_); 170 #endif 144 171 } 145 172 … … 155 182 throw std::invalid_argument(oss.str()); 156 183 } 184 #if YAT_HAVE_HTSLIB 185 assert(0 && "FIXME"); 186 #else 157 187 mode.push_back('0'+compression); 158 188 open_base(fn, mode, h.header_); 189 #endif 159 190 } 160 191 … … 162 193 void OutBamFile::write(const BamRead& read) 163 194 { 195 #if YAT_HAVE_HTSLIB 196 if (bam_write1(sf_->fp.bgzf, read.bam_)) { 197 #else 164 198 if (samwrite(sf_, read.bam_)<=0) { 199 #endif 165 200 throw OutBamFile::error(read); 166 201 } -
trunk/yat/omic/BamFile.h
r3166 r3353 80 80 \see samopen 81 81 */ 82 #ifndef YAT_HAVE_HTSLIB 82 83 void open_base(const std::string& fn, const std::string& mode, 83 84 const void* aux); 85 #endif 86 87 #ifndef YAT_HAVE_HTSLIB 88 /// Old samtools 0.1.xx had a struct samfile_t, which in htslib has 89 /// changed to samFile 90 typedef samfile_t samFile; 91 #endif 92 84 93 /** 85 94 bam file handler 86 95 */ 87 sam file_t* sf_;96 samFile* sf_; 88 97 89 98 /** … … 108 117 public: 109 118 /** 119 Struct describing bam index. 120 121 If compiled against htslib, \c hts_idx_t. If compiled against 122 libbam, \c bam_index_t. 123 124 \see index(void) 125 */ 126 #if YAT_HAVE_HTSLIB 127 typedef hts_idx_t index_type; 128 #else 129 typedef bam_index_t index_type; 130 #endif 131 132 /** 110 133 \brief Default constructor 111 134 */ … … 139 162 reads from stdin, this function throws. 140 163 */ 141 const bam_index_t* index(void) const;164 const index_type* index(void) const; 142 165 143 166 /** … … 162 185 \return true on success 163 186 */ 187 #if YAT_HAVE_HTSLIB 188 bool read(BamRead& read, hts_itr_t* iter); 189 #else 164 190 bool read(BamRead& read, bam_iter_t iter); 191 #endif 165 192 private: 166 193 BamHeader header_; 167 mutable bam_index_t* index_;194 mutable index_type* index_; 168 195 }; 169 196 … … 280 307 void BamFile<Derived>::close(void) 281 308 { 309 #if YAT_HAVE_HTSLIB 310 // FIXME, check that sam_close returns 0 (for success) 311 sam_close(sf_); 312 #else 282 313 samclose(sf_); 314 #endif 283 315 sf_ = NULL; 284 316 } … … 292 324 293 325 326 #ifndef YAT_HAVE_HTSLIB 294 327 template<class Derived> 295 328 void BamFile<Derived>::open_base(const std::string& fn, … … 306 339 } 307 340 } 341 #endif 308 342 309 343 }}} -
trunk/yat/omic/BamReadFilter.h
r3350 r3353 27 27 28 28 #include <functional> 29 30 #ifndef BAM_DEF_MASK 31 #define BAM_DEF_MASK (BAM_FUNMAP | BAM_FSECONDARY | BAM_FQCFAIL | BAM_FDUP) 32 #endif 29 33 30 34 namespace theplu { -
trunk/yat/omic/BamReadIterator.cc
r3056 r3353 112 112 : Actor(&bf) 113 113 { 114 #if YAT_HAVE_HTSLIB 115 hts_itr_t* it = hts_itr_query(bf.index(), tid, begin, end, NULL); 116 #else 114 117 bam_iter_t it = bam_iter_query(bf.index(), tid, begin, end); 118 #endif 115 119 if (!it) { 116 120 std::stringstream ss; … … 120 124 } 121 125 // iter_ takes ownership 126 #if YAT_HAVE_HTSLIB 127 iter_ = boost::shared_ptr<hts_itr_t>(it, IndexDestroyer()); 128 #else 122 129 iter_ = boost::shared_ptr<__bam_iter_t>(it, IndexDestroyer()); 130 #endif 123 131 assert(iter_.get()); 124 132 } -
trunk/yat/omic/BamReadIterator.h
r3018 r3353 132 132 void increment(void); 133 133 private: 134 #if YAT_HAVE_HTSLIB 135 boost::shared_ptr<hts_itr_t> iter_; 136 #else 134 137 boost::shared_ptr<__bam_iter_t> iter_; 138 #endif 135 139 }; 136 140 … … 139 143 struct IndexDestroyer 140 144 { 145 #if YAT_HAVE_HTSLIB 146 void operator()(hts_itr_t* i) const 147 { 148 bam_itr_destroy(i); 149 } 150 #else 141 151 void operator()(bam_iter_t i) const 142 152 { 143 153 bam_iter_destroy(i); 144 154 } 155 #endif 145 156 }; 146 157 };
Note: See TracChangeset
for help on using the changeset viewer.