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
0 commit comments