Skip to content

Commit 7b109d4

Browse files
authored
Added --version option
1 parent d80c26a commit 7b109d4

File tree

7 files changed

+96
-60
lines changed

7 files changed

+96
-60
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ jobs:
6767
steps:
6868
- name: help
6969
run: ./clusty
70+
- name: version
71+
run: ./clusty --version
7072

7173
########################################################################################
7274
upload:

.github/workflows/main.yml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,15 @@ jobs:
6464
with:
6565
name: executable-artifact-${{ matrix.machine }}
6666
path: ./
67-
67+
6868
- name: untar artifacts
69-
run: |
70-
tar -xf clusty.tar
69+
run: tar -xf clusty.tar
70+
71+
- name: help
72+
run: ./clusty-${{matrix.compiler}}
73+
74+
- name: version
75+
run: ./clusty-${{matrix.compiler}} --version
7176

7277
- name: ${{matrix.algo}}, ${{matrix.threshold}} (with representatives, reordered columns)
7378
run: |

.github/workflows/self-hosted.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ jobs:
7474
runs-on: [self-hosted, clusty, '${{ matrix.machine }}']
7575

7676
steps:
77+
- name: help
78+
run: ./clusty-${{matrix.compiler}}
79+
- name: version
80+
run: ./clusty-${{matrix.compiler}} --version
7781
- name: ${{matrix.algo}} (no representatives, numeric ids, singletons in object file)
7882
run: |
7983
./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

src/console.cpp

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,32 @@ using namespace std;
2929
bool Console::init(int argc, char** argv, Params& params) {
3030
Log::getInstance(Log::LEVEL_NORMAL).enable();
3131

32-
LOG_NORMAL << "Clusty" << endl
33-
<< " version " << VERSION
34-
#ifdef GIT_COMMIT
35-
<< "-" << TOSTRING(GIT_COMMIT)
36-
#endif
37-
<< " (" << DATE << ")" << endl << endl;
32+
Params::Status status = params.parse(argc, argv);
3833

39-
if (!params.parse(argc, argv)) {
40-
params.printUsage();
34+
if (status == Params::Status::ShowVersion) {
35+
LOG_NORMAL << VERSION;
4136
return false;
4237
}
38+
else {
4339

44-
if (params.verbose) {
45-
Log::getInstance(Log::LEVEL_VERBOSE).enable();
46-
}
40+
LOG_NORMAL << "Clusty" << endl
41+
<< " version " << VERSION
42+
#ifdef GIT_COMMIT
43+
<< "-" << TOSTRING(GIT_COMMIT)
44+
#endif
45+
<< " (" << DATE << ")" << endl << endl;
4746

48-
return true;
47+
if (status == Params::Status::Incorrect) {
48+
params.printUsage();
49+
return false;
50+
}
51+
52+
if (params.verbose) {
53+
Log::getInstance(Log::LEVEL_VERBOSE).enable();
54+
}
55+
56+
return true;
57+
}
4958
}
5059

5160
// *******************************************************************************************

src/params.cpp

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "distances.h"
1111
#include "log.h"
1212
#include "leiden.h"
13+
#include "version.h"
1314

1415
#include <vector>
1516
#include <fstream>
@@ -41,7 +42,8 @@ void Params::printUsage() const {
4142
<< " " + PARAM_MAX + " <column-name> <real-threshold> - accept pairwise connections with values lower or equal given threshold in a specified column" << endl
4243
<< " " + 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
4344
<< " " + FLAG_OUT_REPRESENTATIVES + " - output a representative object for each cluster instead of a cluster numerical identifier (default: " << std::boolalpha << outputRepresentatives << ")" << endl
44-
<< " " + FLAG_OUT_CSV + " - output a CSV table instead of a default TSV (default: " << std::boolalpha << outputCSV << ")"
45+
<< " " + FLAG_OUT_CSV + " - output a CSV table instead of a default TSV (default: " << std::boolalpha << outputCSV << ")" << endl
46+
<< " " + FLAG_VERSION + " - show Clusty version"
4547

4648
#ifndef NO_LEIDEN
4749
<< endl << endl
@@ -53,65 +55,68 @@ void Params::printUsage() const {
5355
}
5456

5557

56-
bool Params::parse(int argc, char** argv) {
58+
Params::Status Params::parse(int argc, char** argv) {
5759

5860
vector<string> args;
5961
for (int i = 1; i < argc; ++i) {
6062
args.emplace_back(argv[i]);
6163
}
6264

63-
if (args.size() < 2) {
64-
return false;
65+
if (findSwitch(args, FLAG_VERSION)) {
66+
return Status::ShowVersion;
6567
}
6668

67-
std::string tmp;
68-
findOption(args, PARAM_ALGO, tmp);
69-
if (tmp.length()) {
70-
algo = str2algo(tmp);
71-
}
69+
if (args.size() >= 2) {
7270

73-
findOption(args, PARAM_FILE_OBJECTS, objectsFile);
71+
std::string tmp;
72+
findOption(args, PARAM_ALGO, tmp);
73+
if (tmp.length()) {
74+
algo = str2algo(tmp);
75+
}
7476

75-
findOption(args, PARAM_ID_COLUMNS, idColumns.first, idColumns.second);
76-
numericIds = findSwitch(args, FLAG_NUMERIC_IDS);
77+
findOption(args, PARAM_FILE_OBJECTS, objectsFile);
7778

78-
findOption(args, PARAM_DISTANCE_COLUMN, distanceColumn);
79+
findOption(args, PARAM_ID_COLUMNS, idColumns.first, idColumns.second);
80+
numericIds = findSwitch(args, FLAG_NUMERIC_IDS);
7981

80-
bool use_similarity = findSwitch(args, FLAG_SIMILARITY);
81-
bool use_percent_similarity = findSwitch(args, FLAG_PERCENT_SIMILARITY);
82+
findOption(args, PARAM_DISTANCE_COLUMN, distanceColumn);
8283

83-
if (use_percent_similarity) {
84-
distanceSpecification = DistanceSpecification::PercentSimilarity;
85-
}
86-
else if (use_similarity) {
87-
distanceSpecification = DistanceSpecification::Similarity;
88-
}
84+
bool use_similarity = findSwitch(args, FLAG_SIMILARITY);
85+
bool use_percent_similarity = findSwitch(args, FLAG_PERCENT_SIMILARITY);
8986

90-
string column;
91-
double value;
92-
while (findOption(args, PARAM_MIN, column, value)) {
93-
columns2filters[column].min = std::max(value, columns2filters[column].min);
94-
}
95-
while (findOption(args, PARAM_MAX, column, value)) {
96-
columns2filters[column].max = std::min(value, columns2filters[column].max);
97-
}
87+
if (use_percent_similarity) {
88+
distanceSpecification = DistanceSpecification::PercentSimilarity;
89+
}
90+
else if (use_similarity) {
91+
distanceSpecification = DistanceSpecification::Similarity;
92+
}
93+
94+
string column;
95+
double value;
96+
while (findOption(args, PARAM_MIN, column, value)) {
97+
columns2filters[column].min = std::max(value, columns2filters[column].min);
98+
}
99+
while (findOption(args, PARAM_MAX, column, value)) {
100+
columns2filters[column].max = std::min(value, columns2filters[column].max);
101+
}
98102

99-
outputRepresentatives = findSwitch(args, FLAG_OUT_REPRESENTATIVES);
100-
outputCSV = findSwitch(args, FLAG_OUT_CSV);
103+
outputRepresentatives = findSwitch(args, FLAG_OUT_REPRESENTATIVES);
104+
outputCSV = findSwitch(args, FLAG_OUT_CSV);
101105

102-
// leiden parameters
103-
findOption(args, PARAM_LEIDEN_RESOLUTION, leidenParams.resolution);
104-
findOption(args, PARAM_LEIDEN_BETA, leidenParams.beta);
105-
findOption(args, PARAM_LEIDEN_ITERATIONS, leidenParams.numIterations);
106+
// leiden parameters
107+
findOption(args, PARAM_LEIDEN_RESOLUTION, leidenParams.resolution);
108+
findOption(args, PARAM_LEIDEN_BETA, leidenParams.beta);
109+
findOption(args, PARAM_LEIDEN_ITERATIONS, leidenParams.numIterations);
106110

107-
verbose = findSwitch(args, FLAG_VERBOSE);
111+
verbose = findSwitch(args, FLAG_VERBOSE);
108112

109-
if (args.size() == 2) {
110-
distancesFile = args[0];
111-
output = args[1];
112-
return true;
113+
if (args.size() == 2) {
114+
distancesFile = args[0];
115+
output = args[1];
116+
return Status::Correct;
117+
}
113118
}
114119

115-
return false;
120+
return Status::Incorrect;
116121
}
117122

src/params.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ enum class DistanceSpecification {
2929
PercentSimilarity
3030
};
3131

32+
3233
class Params {
3334
const std::string PARAM_ALGO{ "--algo" };
3435

@@ -51,8 +52,15 @@ class Params {
5152
const std::string PARAM_LEIDEN_ITERATIONS{ "--leiden-iterations" };
5253

5354
const std::string FLAG_VERBOSE{ "-v" };
55+
const std::string FLAG_VERSION{ "--version" };
5456

5557
public:
58+
enum Status {
59+
Correct,
60+
Incorrect,
61+
ShowVersion
62+
};
63+
5664
static Algo str2algo(const std::string& str)
5765
{
5866
if (str == "single") { return Algo::SingleLinkage; }
@@ -101,7 +109,7 @@ class Params {
101109
bool verbose{ false };
102110

103111
void printUsage() const;
104-
bool parse(int argc, char** argv);
112+
Status parse(int argc, char** argv);
105113

106114
bool findSwitch(std::vector<std::string>& params, const std::string& name) {
107115
auto it = find(params.begin(), params.end(), name); // verbose mode

src/version.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,16 @@
88
//
99
// *******************************************************************************************
1010

11-
#define VERSION "1.1.2"
12-
#define DATE "2024-10-13"
11+
#define VERSION "1.1.3"
12+
#define DATE "2024-10-21"
1313

1414

1515
/********* Version history *********
1616
17-
1.1.2
17+
1.1.3 (2024-10-21)
18+
* Added `--version` switch.
19+
20+
1.1.2 (2024-10-13)
1821
* Precompiled binaries for macOS include Leiden algorithm.
1922
* Fixed small bug with `--leiden-iterations` param being displayed in help as `--leiden-resolution`.
2023

0 commit comments

Comments
 (0)