Changeset 3031 for trunk/yat/omic/BamRead.cc
- Timestamp:
- Apr 27, 2013, 1:24:13 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/yat/omic/BamRead.cc
r3030 r3031 206 206 207 207 208 void BamRead::reserve(int n) 209 { 210 assert(bam_); 211 if (bam_->m_data >= n) 212 return; 213 // at least double capacity 214 bam_->m_data = std::max(bam_->m_data<<1, n); 215 bam_->data = (uint8_t*)realloc(bam_->data, bam_->m_data); 216 if (!bam_->data) { 217 throw utility::runtime_error("BamRead::reserve failed"); 218 } 219 } 220 221 208 222 std::string BamRead::sequence(void) const 209 223 { … … 221 235 222 236 237 void BamRead::sequence(const std::string& seq, 238 const std::vector<uint8_t>& qual) 239 { 240 assert(seq.size()==qual.size()); 241 // data consist of 242 // |-- qname -->-- cigar -->-- seq -->-- qual -->-- aux --> 243 244 uint8_t* new_aux = bam1_seq(bam_) + (seq.size()+1)/2 + qual.size(); 245 246 int len = new_aux + bam_->l_aux - bam_->data; 247 reserve(len); 248 // move aux to its new location 249 memmove(static_cast<void*>(new_aux), 250 static_cast<const void*>(bam1_aux(bam_)), bam_->l_aux); 251 // copy sequence 252 for (size_t i=0; i<seq.size(); ++i) 253 sequence(i, bam_nt16_table[seq[i]]); 254 core().l_qseq = seq.size(); 255 // copy quality 256 if (qual.size()) // FIXME is this needed or does memcpy work with n=0? 257 memcpy(static_cast<void*>(bam1_qual(bam_)), 258 static_cast<const void*>(&qual[0]), qual.size()); 259 } 260 261 223 262 void BamRead::sequence(size_t i, uint8_t seq) 224 263 {
Note: See TracChangeset
for help on using the changeset viewer.