-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9635be5
commit f5288e0
Showing
4 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/*************************************************************************\ | ||
* AdapterRemoval - cleaning next-generation sequencing reads * | ||
* * | ||
* Copyright (C) 2022 by Mikkel Schubert - [email protected] * | ||
* * | ||
* This program is free software: you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation, either version 3 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
* This program is distributed in the hope that it will be useful, * | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | ||
* GNU General Public License for more details. * | ||
* * | ||
* You should have received a copy of the GNU General Public License * | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. * | ||
\*************************************************************************/ | ||
// #include "simd.hpp" // declarations | ||
#include <algorithm> // for min | ||
#include <arm_neon.h> // for vdupq_n_u8, vld1q_u8, vorrq_u8, ... | ||
#include <cstddef> // for size_t | ||
|
||
namespace adapterremoval { | ||
|
||
namespace simd { | ||
|
||
namespace { | ||
|
||
/** Counts the number of masked bytes **/ | ||
inline auto | ||
count_masked_neon(uint8x16_t value) | ||
{ | ||
// Extract one bit per uint8_t and sum across vector | ||
return vaddvq_u8(vandq_u8(vdupq_n_u8(0x01), value)); | ||
} | ||
|
||
} // namespace | ||
|
||
bool | ||
compare_subsequences_neon(size_t& n_mismatches, | ||
size_t& n_ambiguous, | ||
const char* seq_1, | ||
const char* seq_2, | ||
size_t length, | ||
size_t max_penalty) | ||
{ | ||
//! Mask of all Ns | ||
const auto n_mask = vdupq_n_u8('N'); | ||
|
||
// The sequence is assumed to be padded with 15 'N's not included in `length`. | ||
while (length) { | ||
auto s1 = vld1q_u8(reinterpret_cast<const uint8_t*>(seq_1)); | ||
auto s2 = vld1q_u8(reinterpret_cast<const uint8_t*>(seq_2)); | ||
|
||
// Sets 0xFF for every byte where one or both nts is N | ||
const auto ns_mask = vorrq_u8(vceqq_u8(s1, n_mask), vceqq_u8(s2, n_mask)); | ||
|
||
// Sets 0xFF for every byte where bytes are equal or N | ||
const auto eq_mask = vorrq_u8(vceqq_u8(s1, s2), ns_mask); | ||
|
||
n_mismatches += 16 - count_masked_neon(eq_mask); | ||
if (2 * n_mismatches + n_ambiguous > max_penalty) { | ||
return false; | ||
} | ||
|
||
// Fragment length without 'N' padding | ||
size_t unpadded_length = std::min<size_t>(16, length); | ||
|
||
// Early termination is almost always due to mismatches, so updating the | ||
// number of Ns after the above check saves time in the common case. | ||
n_ambiguous += count_masked_neon(ns_mask) - (16 - unpadded_length); | ||
|
||
seq_1 += 16; | ||
seq_2 += 16; | ||
length -= unpadded_length; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
} // namespace simd | ||
|
||
} // namespace adapterremoval |