Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
asl committed Dec 4, 2024
1 parent 5e9367a commit 67748a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 33 deletions.
16 changes: 9 additions & 7 deletions src/common/alignment/kmer_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,15 @@ class KMerMap {
KMerMap(unsigned k)
: k_(k) {
rawcnt_ = (unsigned)Seq::GetDataSize(k_);
key_size_ = rawcnt_ * sizeof(RawSeqData);
}

~KMerMap() {
clear();
}

void erase(const Kmer &key) {
auto res = mapping_.find_ks((const char*)key.data(), rawcnt_ * sizeof(RawSeqData));
auto res = mapping_.find_ks((const char*)key.data(), key_size_);
if (res == mapping_.end())
return;

Expand All @@ -86,30 +87,30 @@ class KMerMap {

void set(const Kmer &key, const Seq &value) {
RawSeqData *rawvalue = nullptr;
auto res = mapping_.find_ks((const char*)key.data(), rawcnt_ * sizeof(RawSeqData));
auto res = mapping_.find_ks((const char*)key.data(), key_size_);
if (res == mapping_.end()) {
rawvalue = new RawSeqData[rawcnt_];
mapping_.insert_ks((const char*)key.data(), rawcnt_ * sizeof(RawSeqData), rawvalue);
mapping_.insert_ks((const char*)key.data(), key_size_, rawvalue);
} else {
rawvalue = res.value();
}
memcpy(rawvalue, value.data(), rawcnt_ * sizeof(RawSeqData));
memcpy(rawvalue, value.data(), key_size_);
}

bool count(const Kmer &key) const {
return mapping_.count_ks((const char*)key.data(), rawcnt_ * sizeof(RawSeqData));
return mapping_.count_ks((const char*)key.data(), key_size_);
}

const RawSeqData *find(const Kmer &key) const {
auto res = mapping_.find_ks((const char*)key.data(), rawcnt_ * sizeof(RawSeqData));
auto res = mapping_.find_ks((const char*)key.data(), key_size_);
if (res == mapping_.end())
return nullptr;

return res.value();
}

const RawSeqData *find(const RawSeqData *key) const {
auto res = mapping_.find_ks((const char*)key, rawcnt_ * sizeof(RawSeqData));
auto res = mapping_.find_ks((const char*)key, key_size_);
if (res == mapping_.end())
return nullptr;

Expand Down Expand Up @@ -143,6 +144,7 @@ class KMerMap {
private:
unsigned k_;
unsigned rawcnt_;
unsigned key_size_;
HTMap mapping_;
};

Expand Down
36 changes: 10 additions & 26 deletions src/common/alignment/kmer_mapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,17 @@ class KmerMapper : public omnigraph::GraphActionHandler<Graph> {
KMerMap mapping_;
bool normalized_;

bool CheckAllDifferent(const Sequence &old_s, const Sequence &new_s) const {
std::set<Kmer> kmers;
Kmer kmer = old_s.start<Kmer>(k_) >> 0;
for (size_t i = k_ - 1; i < old_s.size(); ++i) {
kmer <<= old_s[i];
kmers.insert(kmer);
}
kmer = new_s.start<Kmer>(k_) >> 0;
for (size_t i = k_ - 1; i < new_s.size(); ++i) {
kmer <<= new_s[i];
kmers.insert(kmer);
const RawSeqData* GetRoot(const Kmer &kmer) const {
const RawSeqData *answer = nullptr;
const RawSeqData *rawval = mapping_.find(kmer);

while (rawval != nullptr) {
Seq val(k_, rawval);

answer = rawval;
rawval = mapping_.find(val);
}
return kmers.size() == old_s.size() - k_ + 1 + new_s.size() - k_ + 1;
return answer;
}

public:
Expand Down Expand Up @@ -150,20 +148,6 @@ class KmerMapper : public omnigraph::GraphActionHandler<Graph> {
RemapKmers(this->g().EdgeNucls(edge1), this->g().EdgeNucls(edge2));
}

const RawSeqData* GetRoot(const Kmer &kmer) const {
const RawSeqData *answer = nullptr;
const RawSeqData *rawval = mapping_.find(kmer);

while (rawval != nullptr) {
Seq val(k_, rawval);

answer = rawval;
rawval = mapping_.find(val);
}
return answer;
}


Kmer Substitute(const Kmer &kmer) const {
VERIFY(this->IsAttached());
const auto *rawval = mapping_.find(kmer);
Expand Down

0 comments on commit 67748a3

Please sign in to comment.