Skip to content
Snippets Groups Projects
Commit 8219b6d9 authored by nkindlon's avatar nkindlon
Browse files

Improved help and error msgs in Context

parent ca4265ec
No related branches found
No related tags found
No related merge requests found
......@@ -23,8 +23,8 @@ void intersect_help(void);
int intersect_main(int argc, char* argv[]) {
Context *context = new Context();
context->parseCmdArgs(argc, argv, 1);
if (context->getShowHelp() || !context->isValidState()) {
if (!context->parseCmdArgs(argc, argv, 1) || context->getShowHelp() || !context->isValidState()) {
if (!context->getErrorMsg().empty()) {
cerr << context->getErrorMsg() << endl;
}
......
......@@ -44,6 +44,8 @@ Context::Context()
_reportNames(false),
_reportScores(false)
{
_programNames["intersect"] = INTERSECT;
_validScoreOps.insert("sum");
_validScoreOps.insert("max");
_validScoreOps.insert("min");
......@@ -90,15 +92,17 @@ void Context::openGenomeFile(const BamTools::RefVector &refVector)
_genomeFile = new NewGenomeFile(refVector);
}
void Context::parseCmdArgs(int argc, char **argv, int skipFirstArgs) {
bool Context::parseCmdArgs(int argc, char **argv, int skipFirstArgs) {
_argc = argc;
_argv = argv;
_skipFirstArgs = skipFirstArgs;
if (argc < 2) {
setShowHelp(true);
return;
return false;
}
setProgram(_programNames[argv[0]]);
_argsProcessed.resize(argc - skipFirstArgs, false);
for (int i=skipFirstArgs; i < argc; i++) {
......@@ -112,6 +116,10 @@ void Context::parseCmdArgs(int argc, char **argv, int skipFirstArgs) {
i++;
markUsed(i - skipFirstArgs);
} else if (strcmp(argv[i], "-g") == 0) {
if (argc <= i+1) {
_errorMsg = "Error: -g option given, but no genome file specified.";
return false;
}
openGenomeFile(argv[i+1]);
markUsed(i - skipFirstArgs);
i++;
......@@ -128,6 +136,11 @@ void Context::parseCmdArgs(int argc, char **argv, int skipFirstArgs) {
markUsed(i - skipFirstArgs);
}
if (strcmp(argv[i], "-a") == 0) {
if (argc <= i+1) {
_errorMsg = "Error: -a option given, but no query file specified.";
return false;
}
addInputFile(argv[i+1]);
_queryFileIdx = getNumInputFiles() -1;
markUsed(i - skipFirstArgs);
......@@ -135,6 +148,10 @@ void Context::parseCmdArgs(int argc, char **argv, int skipFirstArgs) {
markUsed(i - skipFirstArgs);
}
else if(strcmp(argv[i], "-abam") == 0) {
if (argc <= i+1) {
_errorMsg = "Error: -abam option given, but no query BAM file specified.";
return false;
}
addInputFile(argv[i+1]);
_queryFileIdx = getNumInputFiles() -1;
markUsed(i - skipFirstArgs);
......@@ -143,6 +160,10 @@ void Context::parseCmdArgs(int argc, char **argv, int skipFirstArgs) {
setInputFileType(_queryFileIdx, FileRecordTypeChecker::BAM_FILE_TYPE);
}
else if (strcmp(argv[i], "-b") == 0) {
if (argc <= i+1) {
_errorMsg = "Error: -b option given, but no database file specified.";
return false;
}
addInputFile(argv[i+1]);
_databaseFileIdx = getNumInputFiles() -1;
markUsed(i - skipFirstArgs);
......@@ -218,13 +239,20 @@ void Context::parseCmdArgs(int argc, char **argv, int skipFirstArgs) {
markUsed(i - skipFirstArgs);
}
}
return true;
}
bool Context::isValidState()
{
if (!Context::cmdArgsValid()) {
if (!cmdArgsValid()) {
return false;
}
if (getProgram() == INTERSECT && (_queryFileIdx == -1 || _databaseFileIdx == -1)) {
_errorMsg = "Error: Intersect program was not given a query and database file.";
return false;
}
if (getAnyHit() && getNoHit()) {
_errorMsg = "Error: request either -u for anyHit OR -v for noHit, not both.";
return false;
......
......@@ -74,7 +74,7 @@ public:
void setOutputFileType(ContextFileType fileType) { _outputFileType = fileType; }
ContextFileType getOutputFileType() const { return _outputFileType; }
void parseCmdArgs(int argc, char **argv, int skipFirstArgs);
bool parseCmdArgs(int argc, char **argv, int skipFirstArgs);
//isValidState checks that parameters to context are in an acceptable state.
// If not, the error msg string will be set with a reason why it failed.
......@@ -193,6 +193,7 @@ protected:
ContextRecordType _recordType;
};
vector<FileEntryType> _inputFiles;
map<QuickString, PROGRAM_TYPE> _programNames;
bool _useMergedIntervals;
NewGenomeFile *_genomeFile;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment