Skip to content

Commit

Permalink
Support finding taxonomy db paths from other prefilter databases
Browse files Browse the repository at this point in the history
  • Loading branch information
milot-mirdita committed Aug 5, 2022
1 parent 8ff7279 commit 8ff26f2
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/prefiltering/QueryMatcherTaxonomyHook.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@
#include "NcbiTaxonomy.h"
#include "MappingReader.h"
#include "DBReader.h"
#include "PrefilteringIndexReader.h"
#include "TaxonomyExpression.h"

class QueryMatcherTaxonomyHook : public QueryMatcherHook {
public:
QueryMatcherTaxonomyHook(std::string targetPath, DBReader<unsigned int>* targetReader, const std::string& expressionString)
: targetReader(targetReader), dbFrom(0) {
std::string targetName = PrefilteringIndexReader::dbPathWithoutIndex(targetPath);
std::string targetName = dbPathWithoutIndex(targetPath);
taxonomy = NcbiTaxonomy::openTaxonomy(targetName);
taxonomyMapping = new MappingReader(targetName);
expression = new TaxonomyExpression(expressionString, *taxonomy);
Expand Down Expand Up @@ -44,6 +43,23 @@ class QueryMatcherTaxonomyHook : public QueryMatcherHook {
return writePos;
}

static std::string dbPathWithoutIndex(const std::string& dbname) {
static const std::vector<std::string> suffices = {
"_ss.idx",
"_ss.linidx",
"_ss",
".idx",
".linidx"
};
for (size_t i = 0; i < suffices.size(); ++i) {
size_t lastpos = dbname.rfind(suffices[i]);
if (lastpos != std::string::npos && dbname.size() - lastpos == suffices[i].length()){
return dbname.substr(0, lastpos);
}
}
return dbname;
}

NcbiTaxonomy* taxonomy;
MappingReader* taxonomyMapping;
DBReader<unsigned int>* targetReader;
Expand Down

0 comments on commit 8ff26f2

Please sign in to comment.