Skip to content

Commit

Permalink
Fix --taxon-list being broken multi-threaded in prefilter and ungappe…
Browse files Browse the repository at this point in the history
…dprefilter
  • Loading branch information
milot-mirdita committed Apr 2, 2024
1 parent f6c9880 commit 804bb2a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/prefiltering/Prefiltering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Prefiltering::Prefiltering(const std::string &queryDB,


if (par.taxonList.length() > 0) {
taxonomyHook = new QueryMatcherTaxonomyHook(targetDB, tdbr, par.taxonList);
taxonomyHook = new QueryMatcherTaxonomyHook(targetDB, tdbr, par.taxonList, par.threads);
} else {
taxonomyHook = NULL;
}
Expand Down
27 changes: 21 additions & 6 deletions src/prefiltering/QueryMatcherTaxonomyHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,47 @@
#include "DBReader.h"
#include "TaxonomyExpression.h"

#ifdef OPENMP
#include <omp.h>
#endif

class QueryMatcherTaxonomyHook : public QueryMatcherHook {
public:
QueryMatcherTaxonomyHook(std::string targetPath, DBReader<unsigned int>* targetReader, const std::string& expressionString)
: targetReader(targetReader), dbFrom(0) {
QueryMatcherTaxonomyHook(std::string targetPath, DBReader<unsigned int>* targetReader, const std::string& expressionString, unsigned int threads)
: targetReader(targetReader), dbFrom(0), threads(threads) {
std::string targetName = dbPathWithoutIndex(targetPath);
taxonomy = NcbiTaxonomy::openTaxonomy(targetName);
taxonomyMapping = new MappingReader(targetName);
expression = new TaxonomyExpression(expressionString, *taxonomy);
expression = new TaxonomyExpression*[threads];
for (unsigned int i = 0; i < threads; i++) {
expression[i] = new TaxonomyExpression(expressionString, *taxonomy);
}
}

~QueryMatcherTaxonomyHook() {
delete taxonomy;
delete taxonomyMapping;
delete expression;
for (unsigned int i = 0; i < threads; i++) {
delete expression[i];
}
delete[] expression;
}

void setDbFrom(unsigned int from) {
dbFrom = from;
}

size_t afterDiagonalMatchingHook(QueryMatcher& matcher, size_t resultSize) {
unsigned int thread_idx = 0;
#ifdef OPENMP
thread_idx = (unsigned int) omp_get_thread_num();
#endif
size_t writePos = 0;
for (size_t i = 0; i < resultSize; i++) {
unsigned int currId = matcher.foundDiagonals[i].id;
unsigned int key = targetReader->getDbKey(dbFrom + currId);
TaxID currTax = taxonomyMapping->lookup(key);
if (expression->isAncestor(currTax)) {
if (expression[thread_idx]->isAncestor(currTax)) {
if (i != writePos) {
matcher.foundDiagonals[writePos] = matcher.foundDiagonals[i];
}
Expand Down Expand Up @@ -63,9 +77,10 @@ class QueryMatcherTaxonomyHook : public QueryMatcherHook {
NcbiTaxonomy* taxonomy;
MappingReader* taxonomyMapping;
DBReader<unsigned int>* targetReader;
TaxonomyExpression* expression;
TaxonomyExpression** expression;

unsigned int dbFrom;
unsigned int threads;
};

#endif
6 changes: 3 additions & 3 deletions src/prefiltering/ungappedprefilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ int prefilterInternal(int argc, const char **argv, const Command &command, int m


QueryMatcherTaxonomyHook * taxonomyHook = NULL;
if(par.PARAM_TAXON_LIST.wasSet){
taxonomyHook = new QueryMatcherTaxonomyHook(par.db2, tdbr, par.taxonList);
if (par.PARAM_TAXON_LIST.wasSet) {
taxonomyHook = new QueryMatcherTaxonomyHook(par.db2, tdbr, par.taxonList, par.threads);
}

Debug::Progress progress(qdbr->getSize());
Expand Down Expand Up @@ -121,7 +121,7 @@ int prefilterInternal(int argc, const char **argv, const Command &command, int m
unsigned int targetKey = tdbr->getDbKey(tId);
if(taxonomyHook != NULL){
TaxID currTax = taxonomyHook->taxonomyMapping->lookup(targetKey);
if (taxonomyHook->expression->isAncestor(currTax) == false) {
if (taxonomyHook->expression[thread_idx]->isAncestor(currTax) == false) {
continue;
}
}
Expand Down

0 comments on commit 804bb2a

Please sign in to comment.