Skip to content

Commit

Permalink
Merge pull request #13 from mourisl/dev
Browse files Browse the repository at this point in the history
Change the compile flags and some macros for better cross-platform performance
  • Loading branch information
mourisl authored Aug 8, 2024
2 parents b8abab2 + 3de22d0 commit 301b086
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 7 deletions.
3 changes: 3 additions & 0 deletions Classifier.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,9 @@ class Classifier

SimpleVector<size_t> taxIds ;
_taxonomy.ReduceTaxIds(bestSeqTaxIds, taxIds, _param.maxResult) ;
// Centrifuge will promote to canonical tax levels here.
// Maybe we will do the same in some future version.
//_taxonomy.PromoteToCanonicalTaxRank(taxIds, /*dedup=*/true) ;

size = taxIds.Size() ;
for (i = 0 ; i < size ; ++i)
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CXX = g++
CXXFLAGS= -Wall -g -O3 -msse4.2 #-pg -g #-Wall #-O3
CXXFLAGS= -Wall -g -O3 -march=native #-pg -g #-Wall #-O3
LINKPATH=
LINKFLAGS = -lpthread -lz
DEBUG=
Expand Down
47 changes: 47 additions & 0 deletions Taxonomy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,16 @@ class Taxonomy
return i ;
return _nodeCnt ;
}

bool IsCanonicalRankNum(uint8_t r) // The taxonomy ranks defined in the TaxonomyPathTable in centrifuge, except for subspecies
{
if (r == RANK_STRAIN //|| r == RANK_SUB_SPECIES
|| r == RANK_SPECIES || r == RANK_GENUS || r == RANK_FAMILY || r == RANK_ORDER
|| r == RANK_CLASS || r == RANK_PHYLUM || r == RANK_KINGDOM || r == RANK_SUPER_KINGDOM
|| r == RANK_DOMAIN)
return true ;
return false ;
}
public:
Taxonomy()
{
Expand Down Expand Up @@ -692,6 +702,43 @@ class Taxonomy
promotedTaxIds.PushBack(_rootCTaxId) ;
}

// Promote the taxIds to the ranks defined in the "IsCanonicalRankNum" function
// dedup: true: remove the duplicated item in the taxIds
void PromoteToCanonicalTaxRank(SimpleVector<size_t> &taxIds, bool dedup)
{
size_t i ;
size_t taxCnt = taxIds.Size() ;
for (i = 0 ; i < taxCnt ; ++i)
{
size_t p = taxIds[i] ;
uint8_t rank = _taxonomyTree[p].rank ;
while ( !IsCanonicalRankNum(rank) )
{
if (p == _taxonomyTree[p].parentTid)
break ;
p = _taxonomyTree[p].parentTid ;
rank = _taxonomyTree[p].rank ;
}
taxIds[i] = p ;
}

if (dedup)
{
std::map<size_t, int> used ;
size_t k = 0 ;
for (i = 0 ; i < taxCnt ; ++i)
{
if (used.find(taxIds[i]) == used.end())
{
taxIds[k] = taxIds[i] ;
++k ;
used[taxIds[i]] = 1 ;
}
}
taxIds.Resize(k) ;
}
}

// @return: Number of children tax ids. childrenTax: compact tax ids below or equal to ctid.
size_t GetChildrenTax(size_t ctid, std::map<size_t, int> &childrenTax)
{
Expand Down
6 changes: 1 addition & 5 deletions compactds/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
#include <math.h>
#include <string.h>

#ifdef __SSE4_2__
#include <xmmintrin.h>
#endif

namespace compactds {
#define WORD_64 // comment this out if word size is 32

Expand Down Expand Up @@ -80,7 +76,7 @@ class Utils
// Count the number of 1's in x.
static int Popcount(WORD x)
{
#ifdef __SSE4_2__
#ifdef __GNUC__
return __builtin_popcountll(x);
#else
#ifdef WORD_64
Expand Down
2 changes: 1 addition & 1 deletion defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

//#define DEBUG

#define CENTRIFUGER_VERSION "1.0.5-r159"
#define CENTRIFUGER_VERSION "1.0.5-r163"

extern char nucToNum[26] ;
extern char numToNuc[26] ;
Expand Down

0 comments on commit 301b086

Please sign in to comment.