Skip to content

Commit

Permalink
Renamed some of the internal functions for clarity. (#12)
Browse files Browse the repository at this point in the history
Mostly to clear up the which functions operate on bases, and which ones operate
on bitsets. Also, we don't reverse-complement individual bases.
  • Loading branch information
LTLA authored Aug 12, 2023
1 parent 78bcefa commit 811debe
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion include/kaori/BarcodeSearch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void fill_library(
} else {
current.reserve(len);
for (size_t j = 0; j < len; ++j) {
current += reverse_complement<true, true>(ptr[len - j - 1]);
current += complement_base<true, true>(ptr[len - j - 1]);
}
}

Expand Down
42 changes: 21 additions & 21 deletions include/kaori/ScanTemplate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ class ScanTemplate {
for (size_t i = 0; i < length; ++i) {
char b = template_seq[i];
if (b != '-') {
add_base(forward_ref, b);
add_mask(forward_mask);
add_base_to_hash(forward_ref, b);
add_mask_to_hash(forward_mask);
} else {
shift(forward_ref);
shift(forward_mask);
shift_hash(forward_ref);
shift_hash(forward_mask);
add_variable_base(forward_variables, i);
}
}
Expand All @@ -84,11 +84,11 @@ class ScanTemplate {
for (size_t i = 0; i < length; ++i) {
char b = template_seq[length - i - 1];
if (b != '-') {
add_base(reverse_ref, reverse_complement(b));
add_mask(reverse_mask);
add_base_to_hash(reverse_ref, complement_base(b));
add_mask_to_hash(reverse_mask);
} else {
shift(reverse_ref);
shift(reverse_mask);
shift_hash(reverse_ref);
shift_hash(reverse_mask);
add_variable_base(reverse_variables, i);
}
}
Expand Down Expand Up @@ -155,14 +155,14 @@ class ScanTemplate {
for (size_t i = 0; i < length - 1; ++i) {
char base = read_seq[i];

if (is_good(base)) {
add_base(out.state, base);
if (is_standard_base(base)) {
add_base_to_hash(out.state, base);
if (!out.bad.empty()) {
shift(out.ambiguous);
shift_hash(out.ambiguous);
}
} else {
add_other(out.state);
add_other(out.ambiguous);
add_other_to_hash(out.state);
add_other_to_hash(out.ambiguous);
out.bad.push_back(i);
}
}
Expand Down Expand Up @@ -190,20 +190,20 @@ class ScanTemplate {
// us to skip its shifting if there are no more ambiguous
// bases. We do it here because we won't get an opportunity to
// do it later; as 'bad' is empty, the shift below is skipped.
shift(state.ambiguous);
shift_hash(state.ambiguous);
}
}

size_t right = state.position + length;
char base = state.seq[right];
if (is_good(base)) {
add_base(state.state, base); // no need to trim off the end, the mask will handle that.
if (is_standard_base(base)) {
add_base_to_hash(state.state, base); // no need to trim off the end, the mask will handle that.
if (!state.bad.empty()) {
shift(state.ambiguous);
shift_hash(state.ambiguous);
}
} else {
add_other(state.state);
add_other(state.ambiguous);
add_other_to_hash(state.state);
add_other_to_hash(state.ambiguous);
state.bad.push_back(right);
}

Expand All @@ -223,8 +223,8 @@ class ScanTemplate {
int mismatches;
bool forward, reverse;

static void add_mask(std::bitset<N>& current) {
shift(current);
static void add_mask_to_hash(std::bitset<N>& current) {
shift_hash(current);
current.set(0);
current.set(1);
current.set(2);
Expand Down
4 changes: 2 additions & 2 deletions include/kaori/handlers/DualBarcodes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class DualBarcodes {
auto ptr1 = barcode_pool1[i];
if (search_reverse1) {
for (size_t j = 0; j < len1; ++j) {
current += reverse_complement<true, true>(ptr1[len1 - j - 1]);
current += complement_base<true, true>(ptr1[len1 - j - 1]);
}
} else {
current.insert(current.end(), ptr1, ptr1 + len1);
Expand All @@ -112,7 +112,7 @@ class DualBarcodes {
auto ptr2 = barcode_pool2[i];
if (search_reverse2) {
for (size_t j = 0; j < len2; ++j) {
current += reverse_complement<true, true>(ptr2[len2 - j - 1]);
current += complement_base<true, true>(ptr2[len2 - j - 1]);
}
} else {
current.insert(current.end(), ptr2, ptr2 + len2);
Expand Down
2 changes: 1 addition & 1 deletion include/kaori/handlers/RandomBarcodeSingleEnd.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class RandomBarcodeSingleEnd {
auto start = seq + position + range.first;
size_t len = state.buffer.size();
for (size_t j = 0; j < len; ++j) {
state.buffer[j] = reverse_complement<true>(start[len - j - 1]);
state.buffer[j] = complement_base<true>(start[len - j - 1]);
}

auto it = state.counts.find(state.buffer);
Expand Down
22 changes: 11 additions & 11 deletions include/kaori/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace {

template<bool allow_n_ = false, bool allow_iupac_ = false>
char reverse_complement(char b) {
char complement_base(char b) {
char output;
switch (b) {
case 'A': case 'a':
Expand Down Expand Up @@ -88,12 +88,7 @@ char reverse_complement(char b) {
return output;
}

template<size_t N>
void shift(std::bitset<N>& x) {
x <<= 4;
}

inline bool is_good(char b) {
inline bool is_standard_base(char b) {
bool okay = false;
switch (b) {
case 'A': case 'a':
Expand All @@ -107,8 +102,13 @@ inline bool is_good(char b) {
}

template<size_t N>
void add_base(std::bitset<N>& x, char b) {
shift(x);
void shift_hash(std::bitset<N>& x) {
x <<= 4;
}

template<size_t N>
void add_base_to_hash(std::bitset<N>& x, char b) {
shift_hash(x);
switch (b) {
case 'A': case 'a':
x.set(0);
Expand All @@ -130,8 +130,8 @@ void add_base(std::bitset<N>& x, char b) {
}

template<size_t N>
void add_other(std::bitset<N>& x) {
shift(x);
void add_other_to_hash(std::bitset<N>& x) {
shift_hash(x);
x.set(0);
x.set(1);
x.set(2);
Expand Down

0 comments on commit 811debe

Please sign in to comment.