Skip to content

Commit

Permalink
use aa_uint_kmer_t
Browse files Browse the repository at this point in the history
  • Loading branch information
hmusta committed May 30, 2024
1 parent fee1bfd commit 04e21f1
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 27 deletions.
24 changes: 0 additions & 24 deletions metagraph/src/graph/representation/hash/dbg_sshash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ void DBGSSHash::map_to_nodes_sequentially(std::string_view sequence,
for (size_t i = k_ - 1; i < sequence.size() && !terminate(); ++i) {
uint_kmer.drop_char();
uint_kmer.kth_char_or(k_ - 1, kmer_t::char_to_uint(sequence[i]));
#if _PROTEIN_GRAPH
callback(sshash_to_graph_index(dict_.lookup_uint(uint_kmer)));
#else
callback(sshash_to_graph_index(dict_.lookup_uint(uint_kmer, false)));
#endif
}
}

Expand All @@ -133,12 +129,8 @@ void DBGSSHash::map_to_nodes_with_rc(std::string_view sequence,
for (size_t i = k_ - 1; i < sequence.size() && !terminate(); ++i) {
uint_kmer.drop_char();
uint_kmer.kth_char_or(k_ - 1, kmer_t::char_to_uint(sequence[i]));
#if _PROTEIN_GRAPH
callback(sshash_to_graph_index(dict_.lookup_uint(uint_kmer)), false);
#else
auto res = dict_.lookup_advanced_uint(uint_kmer, true);
callback(sshash_to_graph_index(res.kmer_id), res.kmer_orientation);
#endif
}
}

Expand All @@ -147,27 +139,19 @@ DBGSSHash::node_index DBGSSHash::traverse(node_index node, char next_char) const
kmer_t new_kmer = sshash::util::string_to_uint_kmer<kmer_t>(string_kmer.c_str(), k_);
new_kmer.drop_char();
new_kmer.kth_char_or(k_ - 1, kmer_t::char_to_uint(next_char));
#if _PROTEIN_GRAPH
return sshash_to_graph_index(dict_.lookup_uint(new_kmer));
#else
auto res = dict_.lookup_advanced_uint(new_kmer, mode_ == CANONICAL);
node_index next = sshash_to_graph_index(res.kmer_id);
return res.kmer_orientation ? reverse_complement(next) : next;
#endif
}

DBGSSHash::node_index DBGSSHash::traverse_back(node_index node, char prev_char) const {
std::string string_kmer = get_node_sequence(node);
kmer_t new_kmer = sshash::util::string_to_uint_kmer<kmer_t>(string_kmer.c_str(), k_);
new_kmer.append_char(kmer_t::char_to_uint(prev_char));
new_kmer.take_chars(k_);
#if _PROTEIN_GRAPH
return sshash_to_graph_index(dict_.lookup_uint(new_kmer));
#else
auto res = dict_.lookup_advanced_uint(new_kmer, mode_ == CANONICAL);
node_index prev = sshash_to_graph_index(res.kmer_id);
return res.kmer_orientation ? reverse_complement(prev) : prev;
#endif
}

void DBGSSHash::adjacent_outgoing_nodes(node_index node,
Expand Down Expand Up @@ -269,26 +253,18 @@ DBGSSHash::node_index DBGSSHash::kmer_to_node(std::string_view kmer) const {
if (!num_nodes())
return npos;

#if _PROTEIN_GRAPH
return sshash_to_graph_index(dict_.lookup(kmer.data()));
#else
auto res = dict_.lookup_advanced(kmer.data(), mode_ == CANONICAL);
node_index node = sshash_to_graph_index(res.kmer_id);
return res.kmer_orientation ? reverse_complement(node) : node;
#endif
}

std::pair<DBGSSHash::node_index, bool>
DBGSSHash::kmer_to_node_with_rc(std::string_view kmer) const {
if (!num_nodes())
return std::make_pair(npos, false);

#if _PROTEIN_GRAPH
return std::make_pair(sshash_to_graph_index(dict_.lookup(kmer.data())), false);
#else
auto res = dict_.lookup_advanced(kmer.data(), true);
return std::make_pair(sshash_to_graph_index(res.kmer_id), res.kmer_orientation);
#endif
}

std::string DBGSSHash::get_node_sequence(node_index node) const {
Expand Down
4 changes: 1 addition & 3 deletions metagraph/src/graph/representation/hash/dbg_sshash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ namespace mtg::graph {

class DBGSSHash : public DeBruijnGraph {
#if _PROTEIN_GRAPH
using kmer_t = sshash::alpha_kmer_t<uint64_t,
kmer::KmerExtractor2Bit::bits_per_char,
kmer::alphabets::kAlphabetProtein>;
using kmer_t = sshash::aa_uint_kmer_t<uint64_t>;
#else
using kmer_t = sshash::dna_uint_kmer_t<uint64_t>;
#endif
Expand Down

0 comments on commit 04e21f1

Please sign in to comment.