From 3b9cf88179737563acfdb83b516c0b5219cc531e Mon Sep 17 00:00:00 2001 From: Milot Mirdita Date: Fri, 29 Jul 2022 13:20:28 +0900 Subject: [PATCH] Add URIs as allowed parameter inputs --- src/commons/Command.cpp | 1 + src/commons/Command.h | 1 + src/commons/Parameters.cpp | 18 +++++++++++++++--- src/commons/Parameters.h | 2 ++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/commons/Command.cpp b/src/commons/Command.cpp index 68596e88a..677f46a03 100644 --- a/src/commons/Command.cpp +++ b/src/commons/Command.cpp @@ -52,6 +52,7 @@ std::vector DbValidator::directory = {Parameters::DBTYPE_DIRECTORY}; std::vector DbValidator::flatfile = {Parameters::DBTYPE_FLATFILE}; std::vector DbValidator::flatfileAndStdin = {Parameters::DBTYPE_FLATFILE, Parameters::DBTYPE_STDIN}; std::vector DbValidator::flatfileStdinAndGeneric = {Parameters::DBTYPE_FLATFILE, Parameters::DBTYPE_STDIN, Parameters::DBTYPE_GENERIC_DB}; +std::vector DbValidator::flatfileStdinGenericUri = {Parameters::DBTYPE_FLATFILE, Parameters::DBTYPE_STDIN, Parameters::DBTYPE_GENERIC_DB, Parameters::DBTYPE_URI}; std::vector DbValidator::resultDb = {Parameters::DBTYPE_ALIGNMENT_RES, Parameters::DBTYPE_PREFILTER_RES, Parameters::DBTYPE_PREFILTER_REV_RES, Parameters::DBTYPE_CLUSTER_RES}; std::vector 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 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}; diff --git a/src/commons/Command.h b/src/commons/Command.h index a291f96bc..5c5fd1ae4 100644 --- a/src/commons/Command.h +++ b/src/commons/Command.h @@ -68,6 +68,7 @@ struct DbValidator { static std::vector flatfile; static std::vector flatfileAndStdin; static std::vector flatfileStdinAndGeneric; + static std::vector flatfileStdinGenericUri; static std::vector empty; }; diff --git a/src/commons/Parameters.cpp b/src/commons/Parameters.cpp index 67c3e4949..4208b272b 100644 --- a/src/commons/Parameters.cpp +++ b/src/commons/Parameters.cpp @@ -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(®ex, "[a-zA-Z][a-zA-Z0-9+-.]*:\\/\\/"); + int nomatch = regexec(®ex, filenames[fileIdx].c_str(), 0, NULL, 0); + regfree(®ex); + 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) { @@ -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(®ex, "[a-zA-Z][a-zA-Z0-9+-.]*:\\/\\/"); + int nomatch = regexec(®ex, filenames[fileIdx].c_str(), 0, NULL, 0); + regfree(®ex); + dbtypeFound = nomatch == false; } else if (validatorDbtype == Parameters::DBTYPE_FLATFILE) { dbtypeFound = (FileUtil::fileExists(filenames[fileIdx].c_str()) == true && FileUtil::directoryExists(filenames[fileIdx].c_str()) == false); diff --git a/src/commons/Parameters.h b/src/commons/Parameters.h index fe5eb480e..74aeedd0c 100644 --- a/src/commons/Parameters.h +++ b/src/commons/Parameters.h @@ -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; @@ -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"; }