Skip to content

Commit

Permalink
Add URIs as allowed parameter inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
milot-mirdita committed Jul 29, 2022
1 parent 1c739ae commit 3b9cf88
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/commons/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ std::vector<int> DbValidator::directory = {Parameters::DBTYPE_DIRECTORY};
std::vector<int> DbValidator::flatfile = {Parameters::DBTYPE_FLATFILE};
std::vector<int> DbValidator::flatfileAndStdin = {Parameters::DBTYPE_FLATFILE, Parameters::DBTYPE_STDIN};
std::vector<int> DbValidator::flatfileStdinAndGeneric = {Parameters::DBTYPE_FLATFILE, Parameters::DBTYPE_STDIN, Parameters::DBTYPE_GENERIC_DB};
std::vector<int> DbValidator::flatfileStdinGenericUri = {Parameters::DBTYPE_FLATFILE, Parameters::DBTYPE_STDIN, Parameters::DBTYPE_GENERIC_DB, Parameters::DBTYPE_URI};
std::vector<int> DbValidator::resultDb = {Parameters::DBTYPE_ALIGNMENT_RES, Parameters::DBTYPE_PREFILTER_RES, Parameters::DBTYPE_PREFILTER_REV_RES, Parameters::DBTYPE_CLUSTER_RES};
std::vector<int> DbValidator::ppResultDb = {Parameters::DBTYPE_ALIGNMENT_RES, Parameters::DBTYPE_PREFILTER_RES, Parameters::DBTYPE_PREFILTER_REV_RES, Parameters::DBTYPE_CLUSTER_RES, Parameters::DBTYPE_INDEX_DB};
std::vector<int> DbValidator::taxonomyReportInput = {Parameters::DBTYPE_ALIGNMENT_RES, Parameters::DBTYPE_PREFILTER_RES, Parameters::DBTYPE_PREFILTER_REV_RES, Parameters::DBTYPE_CLUSTER_RES, Parameters::DBTYPE_TAXONOMICAL_RESULT, Parameters::DBTYPE_NUCLEOTIDES, Parameters::DBTYPE_HMM_PROFILE, Parameters::DBTYPE_AMINO_ACIDS};
Expand Down
1 change: 1 addition & 0 deletions src/commons/Command.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ struct DbValidator {
static std::vector<int> flatfile;
static std::vector<int> flatfileAndStdin;
static std::vector<int> flatfileStdinAndGeneric;
static std::vector<int> flatfileStdinGenericUri;
static std::vector<int> empty;
};

Expand Down
18 changes: 15 additions & 3 deletions src/commons/Parameters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2007,9 +2007,15 @@ void Parameters::checkIfDatabaseIsValid(const Command& command, int argc, const
}

if (filenames[fileIdx] != "stdin" && FileUtil::fileExists((filenames[fileIdx]).c_str()) == false && FileUtil::fileExists((filenames[fileIdx] + ".dbtype").c_str()) == false) {
printParameters(command.cmd, argc, argv, *command.params);
Debug(Debug::ERROR) << "Input " << filenames[fileIdx] << " does not exist\n";
EXIT(EXIT_FAILURE);
regex_t regex;
compileRegex(&regex, "[a-zA-Z][a-zA-Z0-9+-.]*:\\/\\/");
int nomatch = regexec(&regex, filenames[fileIdx].c_str(), 0, NULL, 0);
regfree(&regex);
if (nomatch) {
printParameters(command.cmd, argc, argv, *command.params);
Debug(Debug::ERROR) << "Input " << filenames[fileIdx] << " does not exist\n";
EXIT(EXIT_FAILURE);
}
}
int dbtype = FileUtil::parseDbType(filenames[fileIdx].c_str());
if (db.specialType & DbType::NEED_HEADER && FileUtil::fileExists((filenames[fileIdx] + "_h.dbtype").c_str()) == false && Parameters::isEqualDbtype(dbtype, Parameters::DBTYPE_INDEX_DB) == false) {
Expand All @@ -2035,6 +2041,12 @@ void Parameters::checkIfDatabaseIsValid(const Command& command, int argc, const
int validatorDbtype = db.validator->at(i);
if (validatorDbtype == Parameters::DBTYPE_STDIN) {
dbtypeFound = (filenames[fileIdx] == "stdin");
} else if (validatorDbtype == Parameters::DBTYPE_URI) {
regex_t regex;
compileRegex(&regex, "[a-zA-Z][a-zA-Z0-9+-.]*:\\/\\/");
int nomatch = regexec(&regex, filenames[fileIdx].c_str(), 0, NULL, 0);
regfree(&regex);
dbtypeFound = nomatch == false;
} else if (validatorDbtype == Parameters::DBTYPE_FLATFILE) {
dbtypeFound = (FileUtil::fileExists(filenames[fileIdx].c_str()) == true &&
FileUtil::directoryExists(filenames[fileIdx].c_str()) == false);
Expand Down
2 changes: 2 additions & 0 deletions src/commons/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ class Parameters {
static const int DBTYPE_FLATFILE = 17; // needed for verification
static const int DBTYPE_SEQTAXDB = 18; // needed for verification
static const int DBTYPE_STDIN = 19; // needed for verification
static const int DBTYPE_URI = 20; // needed for verification

static const unsigned int DBTYPE_EXTENDED_COMPRESSED = 1;
static const unsigned int DBTYPE_EXTENDED_INDEX_NEED_SRC = 2;
Expand Down Expand Up @@ -1152,6 +1153,7 @@ class Parameters {
case DBTYPE_DIRECTORY: return "Directory";
case DBTYPE_FLATFILE: return "Flatfile";
case DBTYPE_STDIN: return "stdin";
case DBTYPE_URI: return "uri";

default: return "Unknown";
}
Expand Down

0 comments on commit 3b9cf88

Please sign in to comment.