|
21 | 21 | y += @inline body(data[i]) |
22 | 22 | end |
23 | 23 | y |
24 | | - y |
25 | 24 | end |
26 | 25 |
|
27 | 26 | """ |
@@ -356,44 +355,22 @@ function count_symbol(seq::BioSequence, sym::BioSymbol) |
356 | 355 | n |
357 | 356 | end |
358 | 357 |
|
359 | | -function Base.count( |
360 | | - pred::Base.Fix2{<:Union{typeof(==), typeof(isequal)}, <: BioSymbol}, |
361 | | - s::BioSequence |
362 | | -) |
363 | | - count_symbol(s, pred.x) |
364 | | -end |
365 | | - |
366 | | -function count_symbol(seq::FourBit, s::Union{RNA, DNA}) |
367 | | - pattern = encode(Alphabet(seq), s)::UInt64 * 0x1111111111111111 |
| 358 | +function count_symbol(seq::Union{LongSubSeq, LongSequence}, sym::BioSymbol) |
| 359 | + enc = encode(Alphabet(seq), sym) |
368 | 360 | tail = (chunk, rm) -> begin |
369 | 361 | mask = UInt64(1) << (rm & 63) - 1 |
370 | | - masked = iszero(pattern) ? chunk | ~mask : mask & chunk |
371 | | - count_0000_nibbles(masked ⊻ pattern) |
| 362 | + masked = iszero(enc) ? chunk | ~mask : mask & chunk |
| 363 | + count_encoding(masked, enc, BitsPerSymbol(seq)) |
372 | 364 | end |
373 | | - body = i -> count_0000_nibbles(i ⊻ pattern) |
| 365 | + body = i -> count_encoding(i, enc, BitsPerSymbol(seq)) |
374 | 366 | counter_1seq(tail, body, seq) |
375 | 367 | end |
376 | 368 |
|
377 | | -function count_symbol(seq::TwoBit, s::Union{RNA, DNA}) |
378 | | - pattern = encode(Alphabet(seq), s)::UInt64 * 0x5555555555555555 |
379 | | - tail = (chunk, rm) -> begin |
380 | | - mask = UInt64(1) << (rm & 63) - 1 |
381 | | - masked = iszero(pattern) ? chunk | ~mask : mask & chunk |
382 | | - count_00_bitpairs(masked ⊻ pattern) |
383 | | - end |
384 | | - body = i -> count_00_bitpairs(i ⊻ pattern) |
385 | | - counter_1seq(tail, body, seq) |
386 | | -end |
387 | | - |
388 | | -function count_symbol(seq::SeqOrView{AminoAcidAlphabet}, s::AminoAcid) |
389 | | - byte = encode(Alphabet(seq), s) % UInt8 |
390 | | - tail = (chunk, rm) -> begin |
391 | | - mask = UInt64(1) << (rm & 63) - 1 |
392 | | - masked = iszero(byte) ? chunk | ~mask : mask & chunk |
393 | | - count_compared_bytes(==(byte), masked) |
394 | | - end |
395 | | - body = i -> count_compared_bytes(==(byte), i) |
396 | | - counter_1seq(tail, body, seq) |
| 369 | +function Base.count( |
| 370 | + pred::Base.Fix2{<:Union{typeof(==), typeof(isequal)}, <: BioSymbol}, |
| 371 | + s::BioSequence |
| 372 | +) |
| 373 | + count_symbol(s, pred.x) |
397 | 374 | end |
398 | 375 |
|
399 | 376 | ## Deprecate weird two-arg methods |
|
0 commit comments