diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 1f1dbff..2ef2c13 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -67,6 +67,8 @@ jobs: steps: - name: help run: ./clusty + - name: version + run: ./clusty --version ######################################################################################## upload: diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 2a6ebe8..676a2a0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -64,10 +64,15 @@ jobs: with: name: executable-artifact-${{ matrix.machine }} path: ./ - + - name: untar artifacts - run: | - tar -xf clusty.tar + run: tar -xf clusty.tar + + - name: help + run: ./clusty-${{matrix.compiler}} + + - name: version + run: ./clusty-${{matrix.compiler}} --version - name: ${{matrix.algo}}, ${{matrix.threshold}} (with representatives, reordered columns) run: | diff --git a/.github/workflows/self-hosted.yml b/.github/workflows/self-hosted.yml index 9c2c2cd..3a760d8 100644 --- a/.github/workflows/self-hosted.yml +++ b/.github/workflows/self-hosted.yml @@ -74,6 +74,10 @@ jobs: runs-on: [self-hosted, clusty, '${{ matrix.machine }}'] steps: + - name: help + run: ./clusty-${{matrix.compiler}} + - name: version + run: ./clusty-${{matrix.compiler}} --version - name: ${{matrix.algo}} (no representatives, numeric ids, singletons in object file) run: | ./clusty-${{matrix.compiler}} --objects-file ./test/toy.ids.tsv --algo ${{matrix.algo}} --id-cols idx1 idx2 --distance-col tani --similarity --numeric-ids --min tani 0.95 ./test/toy.ani.tsv toy.${{matrix.algo}}.tsv diff --git a/src/console.cpp b/src/console.cpp index 3dc03cf..e09f0bd 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -29,23 +29,32 @@ using namespace std; bool Console::init(int argc, char** argv, Params& params) { Log::getInstance(Log::LEVEL_NORMAL).enable(); - LOG_NORMAL << "Clusty" << endl - << " version " << VERSION -#ifdef GIT_COMMIT - << "-" << TOSTRING(GIT_COMMIT) -#endif - << " (" << DATE << ")" << endl << endl; + Params::Status status = params.parse(argc, argv); - if (!params.parse(argc, argv)) { - params.printUsage(); + if (status == Params::Status::ShowVersion) { + LOG_NORMAL << VERSION; return false; } + else { - if (params.verbose) { - Log::getInstance(Log::LEVEL_VERBOSE).enable(); - } + LOG_NORMAL << "Clusty" << endl + << " version " << VERSION +#ifdef GIT_COMMIT + << "-" << TOSTRING(GIT_COMMIT) +#endif + << " (" << DATE << ")" << endl << endl; - return true; + if (status == Params::Status::Incorrect) { + params.printUsage(); + return false; + } + + if (params.verbose) { + Log::getInstance(Log::LEVEL_VERBOSE).enable(); + } + + return true; + } } // ******************************************************************************************* diff --git a/src/params.cpp b/src/params.cpp index 0e413f0..b811683 100644 --- a/src/params.cpp +++ b/src/params.cpp @@ -10,6 +10,7 @@ #include "distances.h" #include "log.h" #include "leiden.h" +#include "version.h" #include #include @@ -41,7 +42,8 @@ void Params::printUsage() const { << " " + PARAM_MAX + " - accept pairwise connections with values lower or equal given threshold in a specified column" << endl << " " + FLAG_NUMERIC_IDS + " - use when sequences in the distances file are represented by numbers (can be mapped to string ids by the object file)" << endl << " " + FLAG_OUT_REPRESENTATIVES + " - output a representative object for each cluster instead of a cluster numerical identifier (default: " << std::boolalpha << outputRepresentatives << ")" << endl - << " " + FLAG_OUT_CSV + " - output a CSV table instead of a default TSV (default: " << std::boolalpha << outputCSV << ")" + << " " + FLAG_OUT_CSV + " - output a CSV table instead of a default TSV (default: " << std::boolalpha << outputCSV << ")" << endl + << " " + FLAG_VERSION + " - show Clusty version" #ifndef NO_LEIDEN << endl << endl @@ -53,65 +55,68 @@ void Params::printUsage() const { } -bool Params::parse(int argc, char** argv) { +Params::Status Params::parse(int argc, char** argv) { vector args; for (int i = 1; i < argc; ++i) { args.emplace_back(argv[i]); } - if (args.size() < 2) { - return false; + if (findSwitch(args, FLAG_VERSION)) { + return Status::ShowVersion; } - std::string tmp; - findOption(args, PARAM_ALGO, tmp); - if (tmp.length()) { - algo = str2algo(tmp); - } + if (args.size() >= 2) { - findOption(args, PARAM_FILE_OBJECTS, objectsFile); + std::string tmp; + findOption(args, PARAM_ALGO, tmp); + if (tmp.length()) { + algo = str2algo(tmp); + } - findOption(args, PARAM_ID_COLUMNS, idColumns.first, idColumns.second); - numericIds = findSwitch(args, FLAG_NUMERIC_IDS); + findOption(args, PARAM_FILE_OBJECTS, objectsFile); - findOption(args, PARAM_DISTANCE_COLUMN, distanceColumn); + findOption(args, PARAM_ID_COLUMNS, idColumns.first, idColumns.second); + numericIds = findSwitch(args, FLAG_NUMERIC_IDS); - bool use_similarity = findSwitch(args, FLAG_SIMILARITY); - bool use_percent_similarity = findSwitch(args, FLAG_PERCENT_SIMILARITY); + findOption(args, PARAM_DISTANCE_COLUMN, distanceColumn); - if (use_percent_similarity) { - distanceSpecification = DistanceSpecification::PercentSimilarity; - } - else if (use_similarity) { - distanceSpecification = DistanceSpecification::Similarity; - } + bool use_similarity = findSwitch(args, FLAG_SIMILARITY); + bool use_percent_similarity = findSwitch(args, FLAG_PERCENT_SIMILARITY); - string column; - double value; - while (findOption(args, PARAM_MIN, column, value)) { - columns2filters[column].min = std::max(value, columns2filters[column].min); - } - while (findOption(args, PARAM_MAX, column, value)) { - columns2filters[column].max = std::min(value, columns2filters[column].max); - } + if (use_percent_similarity) { + distanceSpecification = DistanceSpecification::PercentSimilarity; + } + else if (use_similarity) { + distanceSpecification = DistanceSpecification::Similarity; + } + + string column; + double value; + while (findOption(args, PARAM_MIN, column, value)) { + columns2filters[column].min = std::max(value, columns2filters[column].min); + } + while (findOption(args, PARAM_MAX, column, value)) { + columns2filters[column].max = std::min(value, columns2filters[column].max); + } - outputRepresentatives = findSwitch(args, FLAG_OUT_REPRESENTATIVES); - outputCSV = findSwitch(args, FLAG_OUT_CSV); + outputRepresentatives = findSwitch(args, FLAG_OUT_REPRESENTATIVES); + outputCSV = findSwitch(args, FLAG_OUT_CSV); - // leiden parameters - findOption(args, PARAM_LEIDEN_RESOLUTION, leidenParams.resolution); - findOption(args, PARAM_LEIDEN_BETA, leidenParams.beta); - findOption(args, PARAM_LEIDEN_ITERATIONS, leidenParams.numIterations); + // leiden parameters + findOption(args, PARAM_LEIDEN_RESOLUTION, leidenParams.resolution); + findOption(args, PARAM_LEIDEN_BETA, leidenParams.beta); + findOption(args, PARAM_LEIDEN_ITERATIONS, leidenParams.numIterations); - verbose = findSwitch(args, FLAG_VERBOSE); + verbose = findSwitch(args, FLAG_VERBOSE); - if (args.size() == 2) { - distancesFile = args[0]; - output = args[1]; - return true; + if (args.size() == 2) { + distancesFile = args[0]; + output = args[1]; + return Status::Correct; + } } - return false; + return Status::Incorrect; } diff --git a/src/params.h b/src/params.h index e862112..9560940 100644 --- a/src/params.h +++ b/src/params.h @@ -29,6 +29,7 @@ enum class DistanceSpecification { PercentSimilarity }; + class Params { const std::string PARAM_ALGO{ "--algo" }; @@ -51,8 +52,15 @@ class Params { const std::string PARAM_LEIDEN_ITERATIONS{ "--leiden-iterations" }; const std::string FLAG_VERBOSE{ "-v" }; + const std::string FLAG_VERSION{ "--version" }; public: + enum Status { + Correct, + Incorrect, + ShowVersion + }; + static Algo str2algo(const std::string& str) { if (str == "single") { return Algo::SingleLinkage; } @@ -101,7 +109,7 @@ class Params { bool verbose{ false }; void printUsage() const; - bool parse(int argc, char** argv); + Status parse(int argc, char** argv); bool findSwitch(std::vector& params, const std::string& name) { auto it = find(params.begin(), params.end(), name); // verbose mode diff --git a/src/version.h b/src/version.h index 3a8f095..b9f31c8 100644 --- a/src/version.h +++ b/src/version.h @@ -8,13 +8,16 @@ // // ******************************************************************************************* -#define VERSION "1.1.2" -#define DATE "2024-10-13" +#define VERSION "1.1.3" +#define DATE "2024-10-21" /********* Version history ********* -1.1.2 +1.1.3 (2024-10-21) +* Added `--version` switch. + +1.1.2 (2024-10-13) * Precompiled binaries for macOS include Leiden algorithm. * Fixed small bug with `--leiden-iterations` param being displayed in help as `--leiden-resolution`.