64 template <
typename ReadStream>
68 for (
uint32 i = 0; i < exact_len; ++i)
73 for (
uint32 i = exact_len; i < seed_len; ++i)
75 if (seed[i] >= 4 && ++N_count > 1)
84 uint2
match_range(uint2 range,
const FMType index, StreamType query,
87 for (
uint32 i = begin; i < end && range.x <= range.y; ++i)
89 const uint8 c = query[i];
90 if (c > 3)
return make_uint2(1, 0);
92 const uint2 bwt_cnts =
rank(index, make_uint2(range.x-1, range.y), c);
93 range.x = index.L2(c) + bwt_cnts.x + 1;
94 range.y = index.L2(c) + bwt_cnts.y;
109 if (hit_data != NULL)
112 for (
uint32 i = 0; i < n_hits; ++i)
113 hit_data[i] = hitstorage[i];
128 template<
bool find_exact,
132 void map(
const Stream query,
137 HitType& hitheap,
uint32 max_hits,
152 for (
uint32 i = 0; i < len2; ++i)
154 const uint8 c = query[i];
158 if (i < len1 || N_cnt)
return;
165 len1 = N_cnt ? N_pos : len1;
168 uint2 base_range = make_uint2(0, index.length());
169 base_range =
match_range(base_range, index, query, 0, len1);
172 for(
uint32 i = len1; i < len2 && base_range.x <= base_range.y; ++i)
174 const uint8 c = query[i];
177 uint4 occ_lo, occ_hi;
178 rank4(index, make_uint2(base_range.x-1, base_range.y), &occ_lo, &occ_hi);
181 for (
uint8 sub = 0; sub < 4; ++sub)
183 if (sub != c &&
comp(occ_hi, sub) >
comp(occ_lo, sub))
186 uint2 range = make_uint2(index.L2(sub) +
comp(occ_lo, sub) + 1,
187 index.L2(sub) +
comp(occ_hi, sub) );
190 range =
match_range(range, index, query, i+1, len2);
193 if (range.x <= range.y) {
194 if (hitheap.size() == max_hits)
195 hitheap.pop_bottom();
198 range_sum += range.y - range.x + 1u;
206 base_range.x = index.L2(c) +
comp(occ_lo, c) + 1;
207 base_range.y = index.L2(c) +
comp(occ_hi, c);
208 }
else { base_range = make_uint2(1, 0);
break; }
211 if (find_exact && base_range.x <= base_range.y)
213 if (hitheap.size() == max_hits)
214 hitheap.pop_bottom();
217 range_sum += base_range.y - base_range.x + 1u;
223 template <MappingAlgorithm ALG>
232 template<
typename SeedIterator,
typename FMType,
typename rFMType,
typename HitType>
235 const FMType fmi,
const rFMType rfmi,
236 const SeedIterator seed,
237 const uint2 read_range,
257 const fSeedReader f_reader(seed, forward_offset);
263 range = make_uint2(0, fmi.length());
264 range =
match_range(range, fmi, f_reader, 0, seed_len);
265 if (range.x <= range.y)
268 if (hitheap.size() == params.
max_hits)
269 hitheap.pop_bottom();
272 range_sum += range.y - range.x + 1u;
279 #if USE_REVERSE_INDEX
283 range = make_uint2(0, rfmi.length());
284 range =
match_range(range, rfmi, cf_reader, 0, seed_len);
285 if (range.x <= range.y)
288 if (hitheap.size() == params.
max_hits)
289 hitheap.pop_bottom();
294 const rSeedReader r_reader(seed, reverse_offset);
297 range = make_uint2(0, fmi.length());
298 range =
match_range(range, fmi, cr_reader, 0, seed_len);
299 if (range.x <= range.y)
302 if (hitheap.size() == params.
max_hits)
303 hitheap.pop_bottom();
306 range_sum += range.y - range.x + 1u;
321 template<
typename SeedIterator,
typename FMType,
typename rFMType,
typename HitType>
324 const FMType fmi,
const rFMType rfmi,
325 const SeedIterator seed,
326 const uint2 read_range,
345 const fSeedReader f_reader(seed, forward_offset);
352 map<CHECK_EXACT> (f_reader, params.
subseed_len, seed_len, fmi, flags, hitheap, params.
max_hits, range_sum, range_count);
358 const rSeedReader r_reader(seed, reverse_offset);
361 map<IGNORE_EXACT>(cr_reader, params.
subseed_len, seed_len, fmi, flags, hitheap, params.
max_hits, range_sum, range_count);
375 template<
typename SeedIterator,
typename FMType,
typename rFMType,
typename HitType>
378 const FMType fmi,
const rFMType rfmi,
379 const SeedIterator seed,
380 const uint2 read_range,
399 const fSeedReader f_reader(seed, forward_offset);
403 map<CHECK_EXACT> (f_reader, (seed_len )/2, seed_len, fmi, flags, hitheap, params.
max_hits, range_sum, range_count);
406 const rSeedReader r_reader(seed, reverse_offset);
410 map<IGNORE_EXACT>(r_reader, (seed_len+1)/2, seed_len, rfmi, flags, hitheap, params.
max_hits, range_sum, range_count);
418 map<CHECK_EXACT> (cf_reader, (seed_len )/2, seed_len, rfmi, flags, hitheap, params.
max_hits, range_sum, range_count);
426 map<IGNORE_EXACT>(cr_reader, (seed_len+1)/2, seed_len, fmi, flags, hitheap, params.
max_hits, range_sum, range_count);
434 template<
typename BatchType,
typename FMType,
typename rFMType> __global__
436 const BatchType read_batch,
const FMType fmi,
const rFMType rfmi,
445 typename BatchType::sequence_storage_iterator,
446 BatchType::SEQUENCE_BITS,
447 BatchType::SEQUENCE_BIG_ENDIAN,
449 typedef typename packed_loader_type::iterator seed_iterator;
452 packed_loader_type packer_loader;
460 for (
uint32 id = thread_id;
id < queues.
in_size;
id += grid_size)
464 const uint2 read_range = read_batch.get_range( read_id );
475 hit_deque_type hitheap( hit_storage_type( 0, local_hits ),
true );
481 const seed_iterator
read = packer_loader.load( read_batch.sequence_stream() + read_range.x, read_range.y - read_range.x );
489 read_range.y - read_range.x,
498 store_deque( hits, read_id, hitheap.size(), local_hits );
502 reseed[ id ] = (range_count == 0);
511 template<MappingAlgorithm ALGO,
typename BatchType,
typename FMType,
typename rFMType> __global__
513 const BatchType read_batch,
const FMType fmi,
const rFMType rfmi,
523 typename BatchType::sequence_storage_iterator,
524 BatchType::SEQUENCE_BITS,
525 BatchType::SEQUENCE_BIG_ENDIAN,
528 typedef typename packed_loader_type::iterator seed_iterator;
531 packed_loader_type packer_loader;
539 for (
uint32 id = thread_id;
id < queues.
in_size;
id += grid_size)
543 const uint2 read_range = read_batch.get_range( read_id );
544 const uint32 read_len = read_range.y - read_range.x;
559 hit_deque_type hitheap( hit_storage_type( 0, local_hits ),
true );
565 for (
uint32 pos = read_range.x + retry * retry_stride; pos + seed_len <= read_range.y; pos += seed_freq)
567 const seed_iterator seed = packer_loader.load( read_batch.sequence_stream() + pos, seed_len );
584 store_deque( hits, read_id, hitheap.size(), local_hits );
588 reseed[ id ] = (range_count == 0 || range_sum >= params.
rep_seeds * range_count);
599 template<MappingAlgorithm ALGO,
typename BatchType,
typename FMType,
typename rFMType> __global__
601 const BatchType read_batch,
const FMType fmi,
const rFMType rfmi,
603 const uint2 seed_range,
609 typename BatchType::sequence_storage_iterator,
610 BatchType::SEQUENCE_BITS,
611 BatchType::SEQUENCE_BIG_ENDIAN,
614 typedef typename packed_loader_type::iterator seed_iterator;
617 packed_loader_type packer_loader;
625 for (
uint32 read_id = thread_id; read_id < read_batch.size(); read_id += grid_size)
627 const uint2 read_range = read_batch.get_range( read_id );
628 const uint32 read_len = read_range.y - read_range.x;
643 hit_deque_type hitheap( hit_storage_type( 0, local_hits ),
true );
649 for (
uint32 retry = 0; retry <= 0; ++retry)
659 for (
uint32 i = seed_range.x; i < seed_range.y; ++i)
661 const uint32 pos = read_range.x + retry * retry_stride + i * seed_freq;
662 if (pos + seed_len <= read_range.y)
664 const seed_iterator seed = packer_loader.load( read_batch.sequence_stream() + pos, seed_len );
682 if (retry == params.
max_reseed || range_count == 0 && range_sum < params.
rep_seeds * range_count)
688 store_deque( hits, read_id, hitheap.size(), local_hits );
701 template <
typename BatchType,
typename FMType,
typename rFMType>
703 const BatchType& read_batch,
const FMType fmi,
const rFMType rfmi,
713 detail::map_queues_kernel<detail::CASE_PRUNING_MAPPING> <<<blocks,
BLOCKDIM>>>(
714 read_batch, fmi, rfmi, retry, queues, reseed, hits, params, fw, rc );
720 template <
typename BatchType,
typename FMType,
typename rFMType>
722 const BatchType& read_batch,
const FMType fmi,
const rFMType rfmi,
732 detail::map_queues_kernel<detail::APPROX_MAPPING> <<<blocks,
BLOCKDIM>>>(
733 read_batch, fmi, rfmi, retry, queues, reseed, hits, params, fw, rc );
739 template <
typename BatchType,
typename FMType,
typename rFMType>
741 const BatchType& read_batch,
const FMType fmi,
const rFMType rfmi,
743 const uint2 seed_range,
749 detail::map_kernel<detail::APPROX_MAPPING> <<<blocks,
BLOCKDIM>>>(
750 read_batch, fmi, rfmi, hits, seed_range, params, fw, rc );
756 template <
typename BatchType,
typename FMType,
typename rFMType>
758 const BatchType& read_batch,
const FMType fmi,
const rFMType rfmi,
767 detail::map_whole_read_kernel<<<blocks, BLOCKDIM>>> (
768 read_batch, fmi, rfmi, queues, reseed, hits, params, fw, rc );
774 template <
typename BatchType,
typename FMType,
typename rFMType>
776 const BatchType& read_batch,
const FMType fmi,
const rFMType rfmi,
786 detail::map_queues_kernel<detail::EXACT_MAPPING> <<<blocks,
BLOCKDIM>>>(
787 read_batch, fmi, rfmi, retry, queues, reseed, hits, params, fw, rc );
793 template <
typename BatchType,
typename FMType,
typename rFMType>
795 const BatchType& read_batch,
const FMType fmi,
const rFMType rfmi,
797 const uint2 seed_range,
803 detail::map_kernel<detail::EXACT_MAPPING> <<<blocks,
BLOCKDIM>>>(
804 read_batch, fmi, rfmi, hits, seed_range, params, fw, rc );
810 template <
typename BatchType,
typename FMType,
typename rFMType>
812 const BatchType& read_batch,
const FMType fmi,
const rFMType rfmi,
829 read_batch, fmi, rfmi, retry, queues, reseed, hits, params, fw, rc );
835 read_batch, fmi, rfmi, retry, queues, reseed, hits, params, fw, rc );
842 read_batch, fmi, rfmi, retry, queues, reseed, hits, params, fw, rc );