Skip to content

Commit

Permalink
Fix memory issue
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-steinegger committed Dec 8, 2024
1 parent b80ce10 commit 7f5c000
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
12 changes: 8 additions & 4 deletions src/linclust/kmermatcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ std::pair<size_t, size_t> fillKmerPositionArray(KmerPosition<T> * kmerArray, siz
size_t offset = 0;
int querySeqType = seqDbr.getDbtype();
size_t longestKmer = par.kmerSize;
Masker *masker = NULL;
if (par.maskMode == 1) {
masker = new Masker(*subMat);
}


ScoreMatrix two;
ScoreMatrix three;
Expand All @@ -85,6 +82,10 @@ std::pair<size_t, size_t> fillKmerPositionArray(KmerPosition<T> * kmerArray, siz
unsigned short * scoreDist= new unsigned short[65536];
unsigned int * hierarchicalScoreDist= new unsigned int[128];

Masker *masker = NULL;
if (par.maskMode == 1) {
masker = new Masker(*subMat);
}
const int adjustedKmerSize = (par.adjustKmerLength) ? std::min( par.kmerSize+5, 23) : par.kmerSize;
Sequence seq(par.maxSeqLen, querySeqType, subMat, adjustedKmerSize, par.spacedKmer, false, true, par.spacedKmerPattern);
KmerGenerator* generator;
Expand Down Expand Up @@ -336,6 +337,9 @@ std::pair<size_t, size_t> fillKmerPositionArray(KmerPosition<T> * kmerArray, siz
if (thread_idx == 0) {
seqDbr.remapData();
}
if (masker != NULL) {
delete masker;
}
#pragma omp barrier
}

Expand Down
18 changes: 10 additions & 8 deletions src/prefiltering/IndexBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ void IndexBuilder::fillDatabase(IndexTable *indexTable, SequenceLookup **maskedL
EXIT(EXIT_FAILURE);
}

// need to prune low scoring k-mers through masking
Masker *masker = NULL;
if (maskedLookup != NULL) {
masker = new Masker(subMat);
}

// identical scores for memory reduction code
char *idScoreLookup = getScoreLookup(subMat);
Expand All @@ -99,6 +94,12 @@ void IndexBuilder::fillDatabase(IndexTable *indexTable, SequenceLookup **maskedL
#ifdef OPENMP
thread_idx = static_cast<unsigned int>(omp_get_thread_num());
#endif
// need to prune low scoring k-mers through masking
Masker *masker = NULL;
if (maskedLookup != NULL) {
masker = new Masker(subMat);
}


Indexer idxer(static_cast<unsigned int>(indexTable->getAlphabetSize()), seq->getKmerSize());
Sequence s(seq->getMaxLen(), seq->getSeqType(), &subMat, seq->getKmerSize(), seq->isSpaced(), false, true, seq->getUserSpacedKmerPattern());
Expand Down Expand Up @@ -159,11 +160,12 @@ void IndexBuilder::fillDatabase(IndexTable *indexTable, SequenceLookup **maskedL
if (generator != NULL) {
delete generator;
}
if(masker != NULL) {
delete masker;
}
}

if(masker != NULL) {
delete masker;
}


Debug(Debug::INFO) << "Index table: Masked residues: " << maskedResidues << "\n";
if(totalKmerCount == 0) {
Expand Down
3 changes: 1 addition & 2 deletions src/util/makepaddedseqdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ int makepaddedseqdb(int argc, const char **argv, const Command &command) {
dbhw.open();

// need to prune low scoring k-mers through masking
Masker masker(subMat);

Debug::Progress progress(dbr.getSize());
#pragma omp parallel
Expand All @@ -40,7 +39,7 @@ int makepaddedseqdb(int argc, const char **argv, const Command &command) {
#ifdef OPENMP
thread_idx = static_cast<unsigned int>(omp_get_thread_num());
#endif

Masker masker(subMat);
std::string result;
result.reserve(par.maxSeqLen);

Expand Down
2 changes: 1 addition & 1 deletion src/util/masksequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ int masksequence(int argc, const char **argv, const Command& command) {
}

// need to prune low scoring k-mers through masking
Masker masker(*subMat);

DBWriter writer(par.db2.c_str(), par.db2Index.c_str(), par.threads, par.compressed, reader.getDbtype());
writer.open();
Expand All @@ -40,6 +39,7 @@ int masksequence(int argc, const char **argv, const Command& command) {
#ifdef OPENMP
thread_idx = (unsigned int) omp_get_thread_num();
#endif
Masker masker(*subMat);
unsigned char *charSequence = new unsigned char[reader.getMaxSeqLen() + 1];
Sequence seq(reader.getMaxSeqLen(), reader.getDbtype(), subMat, 0, false, false);
#pragma omp for schedule(dynamic, 1)
Expand Down

0 comments on commit 7f5c000

Please sign in to comment.