Skip to content

Commit

Permalink
Added --version option
Browse files Browse the repository at this point in the history
  • Loading branch information
agudys authored Oct 22, 2024
1 parent d80c26a commit 7b109d4
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ jobs:
steps:
- name: help
run: ./clusty
- name: version
run: ./clusty --version

########################################################################################
upload:
Expand Down
11 changes: 8 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/self-hosted.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 21 additions & 12 deletions src/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

// *******************************************************************************************
Expand Down
87 changes: 46 additions & 41 deletions src/params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "distances.h"
#include "log.h"
#include "leiden.h"
#include "version.h"

#include <vector>
#include <fstream>
Expand Down Expand Up @@ -41,7 +42,8 @@ void Params::printUsage() const {
<< " " + PARAM_MAX + " <column-name> <real-threshold> - 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
Expand All @@ -53,65 +55,68 @@ void Params::printUsage() const {
}


bool Params::parse(int argc, char** argv) {
Params::Status Params::parse(int argc, char** argv) {

vector<string> 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;
}

10 changes: 9 additions & 1 deletion src/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum class DistanceSpecification {
PercentSimilarity
};


class Params {
const std::string PARAM_ALGO{ "--algo" };

Expand All @@ -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; }
Expand Down Expand Up @@ -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<std::string>& params, const std::string& name) {
auto it = find(params.begin(), params.end(), name); // verbose mode
Expand Down
9 changes: 6 additions & 3 deletions src/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down

0 comments on commit 7b109d4

Please sign in to comment.