36 using namespace nvbio;
65 uint32 mapq(
void)
const {
return (bin_mq_nl & 0xff00) >> 8; }
127 BAM_CRQ_index(): cigar_start(0), cigar_len(0), read_start(0), read_len(0), qual_start(0), qual_len(0) { }
129 : cigar_start(cigar_start), cigar_len(cigar_len), read_start(read_start), read_len(read_len),
130 qual_start(qual_start), qual_len(qual_len) { }
141 : aux_data_start(aux_data_start), aux_data_len(aux_data_len), name_start(name_start) { }
144 #define H_BATCH_SIZE_ALLOC 10000000U
145 #define ALNREC_SIZE_ALLOC 512
198 if(field_mask &
BAM_BIN) bin.resize(size_batch.
bin.size());
199 if(field_mask &
BAM_MAPQ) mapq.resize(size_batch.
mapq.size());
229 next_positions.clear();
256 thrust::gather(shuffle_idx.begin(), shuffle_idx.end(), positions.begin(), batch_out.
positions.begin());
259 thrust::gather(shuffle_idx.begin(), shuffle_idx.end(), refIDs.begin(), batch_out.
refIDs.begin());
262 thrust::gather(shuffle_idx.begin(), shuffle_idx.end(), bin.begin(), batch_out.
bin.begin());
265 thrust::gather(shuffle_idx.begin(), shuffle_idx.end(), mapq.begin(), batch_out.
mapq.begin());
268 thrust::gather(shuffle_idx.begin(), shuffle_idx.end(), flags.begin(), batch_out.
flags.begin());
272 for(
uint64 i = 0; i < num_alns; i++) {
273 uint64 idx = shuffle_idx[i];
274 thrust::copy_n(cigars.begin() + crq_index[idx].cigar_start, crq_index[idx].cigar_len,
275 batch_out.
cigars.begin() + cigar_offset);
276 batch_out.
crq_index[i].cigar_start = cigar_offset;
277 batch_out.
crq_index[i].cigar_len = crq_index[idx].cigar_len;
278 cigar_offset += crq_index[idx].cigar_len;
283 for(
uint64 i = 0; i < num_alns; i++) {
284 uint64 idx = shuffle_idx[i];
285 uint64* data_in = (
uint64 *)reads.addrof(crq_index[idx].read_start);
287 memcpy(data_out, data_in, crq_index[idx].read_len/2);
288 batch_out.
crq_index[i].read_start = read_offset;
289 batch_out.
crq_index[i].read_len = crq_index[idx].read_len;
290 const uint32 padded_read_len_bp = ((crq_index[idx].read_len + 7) / 8) * 8;
291 read_offset += padded_read_len_bp;
294 if(field_mask & BAM_QUALITIES) {
296 for(
uint64 i = 0; i < num_alns; i++) {
297 uint64 idx = shuffle_idx[i];
298 thrust::copy_n(qualities.begin() + crq_index[idx].qual_start, crq_index[idx].qual_len,
299 batch_out.
qualities.begin() + qual_offset);
300 batch_out.
crq_index[i].qual_start = qual_offset;
301 batch_out.
crq_index[i].qual_len = crq_index[idx].qual_len;
302 qual_offset += crq_index[idx].qual_len;
307 for(
uint64 i = 0; i < num_alns; i++) {
308 uint64 idx = shuffle_idx[i];
309 thrust::copy_n(aux_data.begin() + aln_index[idx].aux_data_start, aln_index[idx].aux_data_len, batch_out.
aux_data.begin() + aux_offset);
310 batch_out.
aln_index[i].aux_data_start = aux_offset;
311 batch_out.
aln_index[i].aux_data_len = aln_index[idx].aux_data_len;
312 aux_offset += aln_index[idx].aux_data_len;
317 for(
uint64 i = 0; i < num_alns; i++) {
318 uint64 idx = shuffle_idx[i];
320 if(idx < num_alns-1) {
321 len = aln_index[idx+1].name_start-aln_index[idx].name_start;
323 len = names.size()-aln_index[idx].name_start;
325 thrust::copy_n(names.begin() + aln_index[idx].name_start, len, batch_out.
names.begin() + names_offset);
326 batch_out.
aln_index[i].name_start = names_offset;
331 thrust::gather(shuffle_idx.begin(), shuffle_idx.end(), next_positions.begin(), batch_out.
next_positions.begin());
332 thrust::gather(shuffle_idx.begin(), shuffle_idx.end(), next_refIDs.begin(), batch_out.
next_refIDs.begin());
354 bool read_aln_batch(std::vector<bam1_t*>& batch,
const uint64 batch_size = 1000000);