Skip to content

Commit

Permalink
breaking: fix parameter singleton in subprojects
Browse files Browse the repository at this point in the history
With subprojects who have their own Parameter class it can happen that
the MMseqs2 Parameters object is constructed first (in MMseqsBase.cpp)
and then the subproject singleton is accessed and but is already wrongly initialized 
as the parent.

Here we introduce a function initParameterSingleton that decides who to initialize.
Subprojects need to provide this function that calls the correct Parameters constructor now.
  • Loading branch information
milot-mirdita committed Nov 21, 2023
1 parent af2cc52 commit 5c6e32c
Show file tree
Hide file tree
Showing 23 changed files with 25 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/commons/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ struct MMseqsParameter {
}
};

void initParameterSingleton(void);
#define DEFAULT_PARAMETER_SINGLETON_INIT void initParameterSingleton() { new Parameters; }

class Parameters {
public:
Expand Down Expand Up @@ -712,13 +714,11 @@ class Parameters {
static Parameters& getInstance()
{
if (instance == NULL) {
initInstance();
initParameterSingleton();
}
return *instance;
}
static void initInstance() {
new Parameters;
}
friend void initParameterSingleton(void);

void setDefaults();
void initMatrices();
Expand Down
3 changes: 3 additions & 0 deletions src/mmseqs.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Command.h"
#include "DownloadDatabase.h"
#include "Prefiltering.h"
#include "Parameters.h"

const char* binary_name = "mmseqs";
const char* tool_name = "MMseqs2";
Expand All @@ -19,6 +20,8 @@ void init() {
}
void (*initCommands)(void) = init;

DEFAULT_PARAMETER_SINGLETON_INIT;

std::vector<DatabaseDownload> externalDownloads = {};
std::vector<KmerThreshold> externalThreshold = {};

Expand Down
1 change: 1 addition & 0 deletions src/test/TestAlignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "Matcher.h"

const char* binary_name = "test_alignment";
DEFAULT_PARAMETER_SINGLETON_INIT;

int main (int, const char**) {
const size_t kmer_size=6;
Expand Down
1 change: 1 addition & 0 deletions src/test/TestAlignmentPerformance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "StripedSmithWaterman.h"

const char* binary_name = "test_alignmentperformance";
DEFAULT_PARAMETER_SINGLETON_INIT;

#define MAX_FILENAME_LIST_FILES 4096

Expand Down
1 change: 1 addition & 0 deletions src/test/TestAlignmentTraceback.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "Parameters.h"

const char* binary_name = "test_alignmenttraceback";
DEFAULT_PARAMETER_SINGLETON_INIT;

struct scores{
short H;
Expand Down
1 change: 1 addition & 0 deletions src/test/TestAlp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Contents: pairwise alignment algorithms
#include "sls_alignment_evaluer.hpp"

const char* binary_name = "test_alp";
DEFAULT_PARAMETER_SINGLETON_INIT;

using namespace Sls;
using namespace std;
Expand Down
1 change: 0 additions & 1 deletion src/test/TestBacktraceTranslator.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "BacktraceTranslator.h"
#include "Parameters.h"

const char* binary_name = "test_backtracetranslator";

Expand Down
1 change: 0 additions & 1 deletion src/test/TestBestAlphabet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include "DBReader.h"
#include "Sequence.h"
#include "Indexer.h"
#include "Parameters.h"

const char* binary_name = "test_bestalphabet";

Expand Down
1 change: 1 addition & 0 deletions src/test/TestCompositionBias.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "Parameters.h"

const char* binary_name = "test_compositionbias";
DEFAULT_PARAMETER_SINGLETON_INIT;

void calcLocalAaBiasCorrection(Sequence* seq, SubstitutionMatrix * m){
const int windowSize = 40;
Expand Down
1 change: 1 addition & 0 deletions src/test/TestDiagonalScoring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Parameters.h"

const char* binary_name = "test_diagonalscoring";
DEFAULT_PARAMETER_SINGLETON_INIT;

int main (int, const char**) {
size_t kmer_size = 6;
Expand Down
1 change: 1 addition & 0 deletions src/test/TestDiagonalScoringPerformance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ KSEQ_INIT(int, read)
#include "Parameters.h"

const char* binary_name = "test_diagonalscoringperformance";
DEFAULT_PARAMETER_SINGLETON_INIT;

int main (int, const char**) {
size_t kmer_size = 6;
Expand Down
1 change: 1 addition & 0 deletions src/test/TestKmerGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "Parameters.h"

const char* binary_name = "test_kmergenerator";
DEFAULT_PARAMETER_SINGLETON_INIT;

int main (int, const char**) {
const size_t kmer_size=6;
Expand Down
1 change: 1 addition & 0 deletions src/test/TestKmerNucl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "Orf.h"

const char* binary_name = "test_kmernucl";
DEFAULT_PARAMETER_SINGLETON_INIT;

std::string kmerToSting(size_t idx, int size) {
char output[32];
Expand Down
1 change: 1 addition & 0 deletions src/test/TestKmerScore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Parameters.h"

const char* binary_name = "test_kmerscore";
DEFAULT_PARAMETER_SINGLETON_INIT;

int main (int, const char**) {
const size_t kmer_size = 6;
Expand Down
1 change: 0 additions & 1 deletion src/test/TestKwayMerge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#include "SubstitutionMatrix.h"
#include "Sequence.h"
#include "Parameters.h"

const char* binary_name = "test_kwaymerge";
struct KmerEntry{
Expand Down
1 change: 1 addition & 0 deletions src/test/TestMultipleAlignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "Parameters.h"

const char* binary_name = "test_multiplealignment";
DEFAULT_PARAMETER_SINGLETON_INIT;

int main(int, const char**) {
Parameters& par = Parameters::getInstance();
Expand Down
1 change: 1 addition & 0 deletions src/test/TestPSSM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "MultipleAlignment.h"

const char* binary_name = "test_pssm";
DEFAULT_PARAMETER_SINGLETON_INIT;

int main (int, const char**) {
Parameters& par = Parameters::getInstance();
Expand Down
1 change: 1 addition & 0 deletions src/test/TestPSSMPrune.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <string.h>

const char* binary_name = "test_pssmprune";
DEFAULT_PARAMETER_SINGLETON_INIT;

int main (int, const char**) {
Parameters& par = Parameters::getInstance();
Expand Down
1 change: 1 addition & 0 deletions src/test/TestProfileAlignment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "Parameters.h"

const char* binary_name = "test_profilealignment";
DEFAULT_PARAMETER_SINGLETON_INIT;

int main (int, const char**) {
const size_t kmer_size=6;
Expand Down
1 change: 1 addition & 0 deletions src/test/TestReduceMatrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "Parameters.h"

const char* binary_name = "test_reducematrix";
DEFAULT_PARAMETER_SINGLETON_INIT;

int main (int, const char**) {
const int reductionAlphabetSize = 17;
Expand Down
1 change: 1 addition & 0 deletions src/test/TestScoreMatrixSerialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "Debug.h"

const char* binary_name = "test_scorematrixserialization";
DEFAULT_PARAMETER_SINGLETON_INIT;

int main (int, const char**) {
Parameters& par = Parameters::getInstance();
Expand Down
1 change: 1 addition & 0 deletions src/test/TestSequenceIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Parameters.h"

const char* binary_name = "test_sequenceindex";
DEFAULT_PARAMETER_SINGLETON_INIT;

int main (int, const char**) {
size_t kmer_size = 6;
Expand Down
1 change: 1 addition & 0 deletions src/test/TestTanTan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Parameters.h"

const char* binary_name = "test_tantan";
DEFAULT_PARAMETER_SINGLETON_INIT;

int main (int, const char**) {
const size_t kmer_size = 6;
Expand Down

0 comments on commit 5c6e32c

Please sign in to comment.