X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=errorchecking.cpp;h=caf7f73dc31cf02bd48ac7352f339e41b4f6cb96;hb=74c78f9abd9e733f0c2f812efec97a76632fcbf8;hp=54465729f5e04c36c6a0e2bed16064a5ea32b9a2;hpb=ec43347d04dbb2a7d9d9ecfb5fc556e21ad8c2bc;p=mothur.git diff --git a/errorchecking.cpp b/errorchecking.cpp index 5446572..caf7f73 100644 --- a/errorchecking.cpp +++ b/errorchecking.cpp @@ -8,7 +8,6 @@ */ #include "errorchecking.h" -#include /*******************************************************/ @@ -24,149 +23,33 @@ ErrorCheck::ErrorCheck() { /******************************************************/ void ErrorCheck::refresh() { - columnfile = globaldata->getColumnFile(); - phylipfile = globaldata->getPhylipFile(); - listfile = globaldata->getListFile(); - rabundfile = globaldata->getRabundFile(); - sabundfile = globaldata->getSabundFile(); - namefile = globaldata->getNameFile(); - groupfile = globaldata->getGroupFile(); - orderfile = globaldata->getOrderFile(); - fastafile = globaldata->getFastaFile(); - treefile = globaldata->getTreeFile(); - cutoff = globaldata->getCutOff(); - format = globaldata->getFormat(); - method = globaldata->getMethod(); - - string p[] = { - "phylip", //0 - "column", //1 - "list", //2 - "rabund", //3 - "sabund", //4 - "name", //5 - "order", //6 - "group", //7 - "fasta", //8 - "treefile", //9 - "cutoff", //10 - "precision", //11 - "iters", //12 - "jumble", //13 - "freq", //14 - "method", //15 - "fileroot", //16 - "line", //17 - "label", //18 - "single", //19 - "rarefaction", //20 - "shared", //21 - "summary", //22 - "sharedrarefaction", //23 - "sharedsummary", //24 - "comparegroups", //25 - "abund", //26 - }; - - string c0[] = {p[0],p[5],p[10],p[11]}; - string c1[] = {p[2],p[6],p[7]}; - string c2[] = {p[10],p[11],p[15]}; - string c3[] = {p[8]}; - string c4[] = {p[14],p[17],p[18],p[19],p[26]}; - string c5[] = {p[13],p[14],p[17],p[18],p[21],p[25]}; - string c6[] = {""}; - string c7[] = {""}; - string c8[] = {""}; - string c9[] = {p[12],p[14],p[17],p[18],p[20],p[26]}; - string c10[] = {p[12],p[13],p[17],p[18],p[23]}; - string c11[] = {p[17],p[18],p[22],p[26]}; - string c12[] = {p[13],p[17],p[18],p[24]}; - string c13[] = {""}; - - vector v0 (c0, c0+sizeof(c0)/sizeof(string)); - vector v1 (c1, c1+sizeof(c1)/sizeof(string)); - vector v2 (c2, c2+sizeof(c2)/sizeof(string)); - vector v3 (c3, c3+sizeof(c3)/sizeof(string)); - vector v4 (c4, c4+sizeof(c4)/sizeof(string)); - vector v5 (c5, c5+sizeof(c5)/sizeof(string)); - vector v6 (c6, c6+sizeof(c6)/sizeof(string)); - vector v7 (c7, c7+sizeof(c7)/sizeof(string)); - vector v8 (c8, c8+sizeof(c8)/sizeof(string)); - vector v9 (c9, c9+sizeof(c9)/sizeof(string)); - vector v10 (c10, c10+sizeof(c10)/sizeof(string)); - vector v11 (c11, c11+sizeof(c11)/sizeof(string)); - vector v12 (c12, c12+sizeof(c12)/sizeof(string)); - vector v13 (c13, c13+sizeof(c13)/sizeof(string)); - - vector > allCommands; - allCommands.push_back(v0); - allCommands.push_back(v1); - allCommands.push_back(v2); - allCommands.push_back(v3); - allCommands.push_back(v4); - allCommands.push_back(v5); - allCommands.push_back(v6); - allCommands.push_back(v7); - allCommands.push_back(v8); - allCommands.push_back(v9); - allCommands.push_back(v10); - allCommands.push_back(v11); - allCommands.push_back(v12); - allCommands.push_back(v13); - - string commands[] = { - "read.dist", //0 - "read.otu", //1 - "cluster", //2 - "deconvolute", //3 - "collect.single", //4 - "collect.shared", //5 - "get.group", //6 - "get.label", //7 - "get.line", //8 - "rarefaction.single", //9 - "rarefaction.shared", //10 - "summary.single", //11 - "summary.shared", //12 - "quit" //13 - }; - - for(int i = 0; i < allCommands.size(); i++) - commandParameters[commands[i]] = allCommands.at(i); - - //{Lowerbound(piSent if no lowerbound), Upperbound(piSent if no upperbound), 1 if only the first 2 values, 0 if greater than, 0 if less than}; - piSent = 3.14159; - double ip0[] = {10, piSent, 0, 1, 0}; - double ip1[] = {10, piSent, 0, 1, 0}; - double ip2[] = {0, 1, 1, 0, 0}; - double ip3[] = {1, piSent, 0, 0, 0}; - double ip4[] = {1, piSent, 0, 1, 0}; - double ip5[] = {5, piSent, 0, 1, 0}; - - vector ipv0 (ip0, ip0+sizeof(ip0)/sizeof(double)); - vector ipv1 (ip1, ip1+sizeof(ip1)/sizeof(double)); - vector ipv2 (ip2, ip2+sizeof(ip2)/sizeof(double)); - vector ipv3 (ip3, ip3+sizeof(ip3)/sizeof(double)); - vector ipv4 (ip4, ip4+sizeof(ip4)/sizeof(double)); - vector ipv5 (ip5, ip5+sizeof(ip5)/sizeof(double)); - - intParams[p[11]] = ipv0; - intParams[p[12]] = ipv1; - intParams[p[13]] = ipv2; - intParams[p[14]] = ipv3; - intParams[p[17]] = ipv4; - intParams[p[26]] = ipv5; - - randomtree = globaldata->getRandomTree(); - sharedfile = globaldata->getSharedFile(); + //columnfile = globaldata->getColumnFile(); + //phylipfile = globaldata->getPhylipFile(); + //listfile = globaldata->getListFile(); + //rabundfile = globaldata->getRabundFile(); + //sabundfile = globaldata->getSabundFile(); + //namefile = globaldata->getNameFile(); + //groupfile = globaldata->getGroupFile(); + //orderfile = globaldata->getOrderFile(); + //fastafile = globaldata->getFastaFile(); + //treefile = globaldata->getTreeFile(); + //cutoff = globaldata->getCutOff(); + //format = globaldata->getFormat(); + //method = globaldata->getMethod(); + //randomtree = globaldata->getRandomTree(); + //sharedfile = globaldata->getSharedFile(); + } /*******************************************************/ /******************************************************/ -ErrorCheck::~ErrorCheck() {} +ErrorCheck::~ErrorCheck() { + delete validCommand; + delete validParameter; +} /*******************************************************/ @@ -193,7 +76,6 @@ bool ErrorCheck::checkInput(string input) { //is it a valid command if (validCommand->isValidCommand(commandName) != true) { return false; } - string parameter, value; //reads in parameters and values @@ -203,49 +85,8 @@ bool ErrorCheck::checkInput(string input) { splitAtEquals(parameter, value); //is it a valid parameter - if (validParameter->isValidParameter(parameter) != true) { return false; } - if(!validCommandParameter(parameter,commandName)) { - cout << "'" << parameter << "' is not a valid parameter for the " << commandName << " command.\n"; - return false; - } - if(!validParameterValue(value, parameter)) { - if(parameter.compare("precision") == 0) - cout << "The precision parameter can only take powers of 10 as a value (e.g. 10,1000,1000, etc.)\n"; - else { - vector bounds = intParams[parameter]; - double a = bounds.at(0); - double b = bounds.at(1); - double c = bounds.at(2); - double d = bounds.at(3); - double e = bounds.at(4); - cout << "The '" << parameter << "' parameter needs to be "; - if(c == 1) - cout << "either '" << a << "' or '" << b << "'.\n"; - else - { - if(a != piSent) - { - cout << ">"; - if(d != 0) - cout << "="; - cout << " '" << a << "'"; - } - if(b == piSent) - cout << ".\n"; - else if(a != piSent) - cout << " and "; - if(b != piSent) - { - cout << "<"; - if(e != 0) - cout << "="; - cout << " '" << b << ".\n"; - } - } - } - return false; - } - + if (validParameter->isValidParameter(parameter, commandName, value) != true) { return false; } + if (parameter == "phylip" ) { phylipfile = value; } if (parameter == "column" ) { columnfile = value; } if (parameter == "list" ) { listfile = value; } @@ -254,9 +95,11 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "name" ) { namefile = value; } if (parameter == "order" ) { orderfile = value; } if (parameter == "fasta" ) { fastafile = value; } + if (parameter == "nexus" ) { nexusfile = value; } + if (parameter == "clustal" ) { clustalfile = value; } if (parameter == "tree" ) { treefile = value; } - if (parameter == "group" ) { groupfile = value; } - if (parameter == "shared" ) { sharedfile = value; } + if (parameter == "group" ) { groupfile = value; } + if (parameter == "shared" ) { sharedfile = value; } if (parameter == "cutoff" ) { cutoff = value; } if (parameter == "precision" ) { precision = value; } if (parameter == "iters" ) { iters = value; } @@ -267,7 +110,23 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "line" ) { line = value; } if (parameter == "label" ) { label = value; } if (parameter == "abund" ) { abund = value; } - if (parameter == "random" ) { randomtree = value; } + if (parameter == "random" ) { randomtree = value; } + if (parameter == "sorted" ) { sorted = value; } + if (parameter == "trump" ) { trump = value; } + if (parameter == "soft" ) { soft = value; } + if (parameter == "filter" ) { filter = value; } + if (parameter == "scale" ) { scale = value; } + if (parameter == "countends" ) { countends = value; } + if (parameter == "processors" ) { processors = value; } + if (parameter == "size" ) { size = value; } + if (parameter == "candidate") { candidatefile = value; } + if (parameter == "search") { search = value; } + if (parameter == "ksize") { ksize = value; } + if (parameter == "align") { align = value; } + if (parameter == "match") { match = value; } + if (parameter == "mismatch") { mismatch = value; } + if (parameter == "gapopen") { gapopen = value; } + if (parameter == "gapextend" ) { gapextend = value; } } //gets the last parameter and value @@ -275,48 +134,9 @@ bool ErrorCheck::checkInput(string input) { value = optionText; splitAtEquals(parameter, value); //is it a valid parameter - if (validParameter->isValidParameter(parameter) != true) { return false; } - if(!validCommandParameter(parameter,commandName)) { - cout << "'" << parameter << "' is not a valid parameter for the " << commandName << " command.\n"; - return false; - } - if(!validParameterValue(value, parameter)) { - if(parameter.compare("precision") == 0) - cout << "The precision parameter can only take powers of 10 as a value (e.g. 10,1000,1000, etc.)\n"; - else { - vector bounds = intParams[parameter]; - double a = bounds.at(0); - double b = bounds.at(1); - double c = bounds.at(2); - double d = bounds.at(3); - double e = bounds.at(4); - cout << "The '" << parameter << "' parameter needs to be "; - if(c == 1) - cout << "either '" << a << "' or '" << b << "'.\n"; - else - { - if(a != piSent) - { - cout << ">"; - if(d != 0) - cout << "="; - cout << " '" << a << "'"; - } - if(b == piSent) - cout << ".\n"; - else if(a != piSent) - cout << " and "; - if(b != piSent) - { - cout << "<"; - if(e != 0) - cout << "="; - cout << " '" << b << ".\n"; - } - } - } - return false; - } + if (validParameter->isValidParameter(parameter, commandName, value) != true) { return false; } + + if (parameter == "phylip" ) { phylipfile = value; } if (parameter == "column" ) { columnfile = value; } if (parameter == "list" ) { listfile = value; } @@ -327,6 +147,8 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "group" ) { groupfile = value; } if (parameter == "shared" ) { sharedfile = value; } if (parameter == "fasta" ) { fastafile = value; } + if (parameter == "nexus" ) { nexusfile = value; } + if (parameter == "clustal" ) { clustalfile = value; } if (parameter == "tree" ) { treefile = value; } if (parameter == "cutoff" ) { cutoff = value; } if (parameter == "precision" ) { precision = value; } @@ -339,12 +161,30 @@ bool ErrorCheck::checkInput(string input) { if (parameter == "label" ) { label = value; } if (parameter == "random" ) { randomtree = value; } if (parameter == "abund" ) { abund = value; } + if (parameter == "sorted" ) { sorted = value; } + if (parameter == "trump" ) { trump = value; } + if (parameter == "soft" ) { soft = value; } + if (parameter == "filter" ) { filter = value; } + if (parameter == "scale" ) { scale = value; } + if (parameter == "countends" ) { countends = value; } + if (parameter == "processors" ) { processors = value; } + if (parameter == "size" ) { size = value; } + if (parameter == "candidate") { candidatefile = value; } + if (parameter == "search") { search = value; } + if (parameter == "ksize") { ksize = value; } + if (parameter == "align") { align = value; } + if (parameter == "match") { match = value; } + if (parameter == "mismatch") { mismatch = value; } + if (parameter == "gapopen") { gapopen = value; } + if (parameter == "gapextend" ) { gapextend = value; } + } } //make sure the user does not use both the line and label parameters if ((line != "") && (label != "")) { cout << "You may use either the line or label parameters, but not both." << endl; return false; } + //check for valid files if (commandName == "read.dist") { validateReadFiles(); validateReadDist(); @@ -352,27 +192,35 @@ bool ErrorCheck::checkInput(string input) { //you want to do shared commands if ((listfile != "") && (groupfile != "")) { validateParseFiles(); //checks the listfile and groupfile parameters - }else { //you want to do single commands + //you want to do single commands + }else if ((listfile != "") || (rabundfile != "") || (sabundfile != "")){ validateReadFiles(); validateReadPhil(); + //you have not given a file + }else if ((listfile == "") && (sharedfile == "") && (rabundfile == "") && (sabundfile == "")) { + cout << "You must enter either a listfile, rabundfile, sabundfile or a sharedfile with the read.otu command. " << endl; return false; + //you want to do shared commands with a shared file + }else if (sharedfile != "") {//you are reading a shared file + validateReadFiles(); } - }else if (commandName == "read.shared") { - //you want to do shared commands with just the shared file - validateReadFiles(); }else if (commandName == "read.tree") { validateTreeFiles(); //checks the treefile and groupfile parameters - }else if (commandName == "deconvolute") { - if (fastafile == "") { cout << "You must enter a fastafile with the deconvolute() command." << endl; return false; } + }else if (commandName == "unique.seqs") { + if (fastafile == "") { cout << "You must enter a fastafile with the unique.seqs() command." << endl; return false; } validateReadFiles(); } - //are you trying to cluster before you have read something - if ((commandName == "cluster") && (globaldata->getSparseMatrix() == NULL) || - (commandName == "cluster") && (globaldata->getListVector() == NULL)) { + //are you trying to cluster before you have read something + if (((commandName == "cluster") && (globaldata->gSparseMatrix == NULL)) || + ((commandName == "cluster") && (globaldata->gListVector == NULL))) { cout << "Before you use the cluster command, you first need to read in a distance matrix." << endl; errorFree = false; } + if ((commandName == "libshuff") && ((globaldata->gMatrix == NULL) || (globaldata->gGroupmap == NULL))) { + cout << "You must read in a matrix and groupfile using the read.dist command, before you use the libshuff command. " << endl; return false; + } + if (commandName == "parsimony") { //are you trying to use parsimony without reading a tree or saying you want random distribution if (randomtree == "") { @@ -381,14 +229,14 @@ bool ErrorCheck::checkInput(string input) { } } - if ((commandName == "unifrac.weighted") || (commandName == "unifrac.unweighted")) { + if ((commandName == "unifrac.weighted") || (commandName == "unifrac.unweighted") || (commandName == "concensus")) { if (globaldata->gTree.size() == 0) {//no trees were read - cout << "You must execute the read.tree command, before you may execute the unifrac.weighted or unifrac.unweighted command." << endl; return false; } + cout << "You must execute the read.tree command, before you may execute the unifrac.weighted, unifrac.unweighted or concensus command." << endl; return false; } } //check for valid method if(commandName == "get.group") { - if ((globaldata->getGroupFile() == "")) { cout << "You must read a group before you can use the get.group command." << endl; return false; } + if ((globaldata->getSharedFile() == "")) { cout << "You must read a groupfile or a sharedfile before you can use the get.group command." << endl; return false; } } if (commandName == "get.label" || commandName == "get.line") { if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a list, sabund or rabund before you can use the get.label or get.line command." << endl; return false; } @@ -398,16 +246,70 @@ bool ErrorCheck::checkInput(string input) { else {cout << "Not a valid clustering method. Valid clustering algorithms are furthest, nearest or average." << endl; return false; } } - if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single") ){ + if ((commandName == "collect.single") || (commandName == "rarefaction.single") || (commandName == "summary.single")){ if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a list, sabund or rabund before you can use the collect.single, rarefaction.single or summary.single commands." << endl; return false; } } - if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") ){ + if (commandName == "get.rabund") { + if (globaldata->getListFile() == "") { cout << "You must read a listfile before you can use the get.rabund command." << endl; return false; } + } + + if (commandName == "get.sabund") { + if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "")) { cout << "You must read a list or rabund before you can use the get.sabund command." << endl; return false; } + } + + if ((commandName == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") || (commandName == "bootstrap.shared") || (commandName == "dist.shared")){ if (globaldata->getSharedFile() == "") { - if (globaldata->getListFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared or summary.shared commands." << endl; return false; } - else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared or summary.shared commands." << endl; return false; } + if (globaldata->getListFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared, summary.shared, tree.shared, bootstrap.shared or dist.shared commands." << endl; return false; } + else if (globaldata->getGroupFile() == "") { cout << "You must read a list and a group, or a shared before you can use the collect.shared, rarefaction.shared, summary.shared, tree.shared, bootstrap.shared or dist.shared commands." << endl; return false; } + } + } + + if (commandName == "tree.shared") { + //given no files + if ((globaldata->getSharedFile() == "") && ((phylipfile == "") && (columnfile == ""))) { cout << "You must run the read.otu command or provide a distance file before running the tree.shared command." << endl; return false; } + //you want to do single commands + else if ((globaldata->getSharedFile() == "") && ((phylipfile != "") || (columnfile != ""))) { + validateReadDist(); } } + + if ((commandName == "heatmap") || (commandName == "venn")) { + if ((globaldata->getListFile() == "") && (globaldata->getSharedFile() == "")) { + cout << "You must read a list, or a list and a group, or a shared before you can use the heatmap or venn commands." << endl; return false; + } + } + + if ((commandName == "filter.seqs") || (commandName == "dist.seqs")) { + if (fastafile == "") { + cout << "You must enter either a fasta file before you can use the filter.seqs or dist.seqs command." << endl; return false; + } + validateSeqsFiles(); + } + + if (commandName == "align.seqs") { + if ((fastafile == "") || (candidatefile == "")) { + cout << "You must enter fasta and a candidate file to use the align.seqs command." << endl; return false; + } + validateSeqsFiles(); + } + + if ((commandName == "bin.seqs")) { + if ((globaldata->getListFile() == "")) { cout << "You must read a list file before you can use the bin.seqs commands." << endl; return false; } + validateBinFiles(); + } + + + if ((commandName == "get.oturep")) { + if ((globaldata->gSparseMatrix == NULL) || (globaldata->gListVector == NULL)) { + cout << "Before you use the get.oturep command, you first need to read in a distance matrix." << endl; + errorFree = false; + } + if (listfile == "") { cout << "list is a required parameter for the get.oturep command." << endl; errorFree = false; } + if (fastafile == "") { cout << "fasta is a required parameter for the get.oturep command." << endl; errorFree = false; } + validateBinFiles(); + } + return errorFree; } @@ -430,7 +332,7 @@ void ErrorCheck::validateReadFiles() { //unable to open if (ableToOpen == 1) { errorFree = false; } else { globaldata->inputFileName = phylipfile; } - //are we reading a phylipfile + //are we reading a columnfile }else if (columnfile != "") { ableToOpen = openInputFile(columnfile, filehandle); filehandle.close(); @@ -470,6 +372,12 @@ void ErrorCheck::validateReadFiles() { //unable to open if (ableToOpen == 1) { errorFree = false; } else { globaldata->inputFileName = sharedfile; } + }else if (groupfile != "") { + ableToOpen = openInputFile(groupfile, filehandle); + filehandle.close(); + if (ableToOpen == 1) { //unable to open + errorFree = false; + } }else{ //no file given errorFree = false; } @@ -486,113 +394,6 @@ void ErrorCheck::validateReadFiles() { } /*******************************************************/ -/******************************************************/ -//This function checks to see if the given paramter -//is a valid paramter for the given command. -bool ErrorCheck::validCommandParameter(string parameter, string commandName) { - try { - for(int i = 0; i < commandParameters[commandName].size(); i++) - if(parameter.compare(commandParameters[commandName][i]) == 0) - return true; - return false; - } - - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ErrorCheck class function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*******************************************************/ - -/******************************************************/ -//This function checks to see if the given paramter value -//is convertable into an int if that parameter requires it. -bool ErrorCheck::validParameterValue(string value, string parameter) { - try { - int pVal; - if(intParams.count(parameter) == 1) - { - vector bounds = intParams[parameter]; - bool valid = convertTest(value, pVal); - if(!valid) - return false; - if(parameter.compare("precision") == 0) - { - double logNum = log10((double)pVal); - double diff = (double)((int)logNum - logNum); - if(diff != 0) - return false; - } - double a = bounds.at(0); - double b = bounds.at(1); - double c = bounds.at(2); - double d = bounds.at(3); - double e = bounds.at(4); - bool a0 = pVal > a; - bool a1 = pVal >= a; - bool b0 = pVal < b; - bool b1 = pVal <= b; - - if(c != 1) - { - if(a == piSent && b == piSent) - return true; - if(a != piSent && b == piSent) - { - if(d == 0) - return a0; - else - return a1; - } - else if(a == piSent && b != piSent) - { - if(e == 0) - return b0; - else - return b1; - } - else - { - if(d == 0 && e == 0) - return (a0 && b0); - else if(d == 0 && e == 1) - return (a0 && b1); - else if(d == 1 && e == 0) - return (a1 && b0); - else - return (a1 && b1); - } - } - else - { - if(a == piSent && b == piSent) - return true; - if(a != piSent && b == piSent) - return (pVal == a); - else if(a == piSent && b != piSent) - return (pVal == b); - else - return (pVal == a || pVal == b); - } - } - return true; - } - - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the ErrorCheck class function validateReadFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/*******************************************************/ - /******************************************************/ //This function checks to make sure the user entered appropriate // format parameters on a distfile read @@ -601,8 +402,15 @@ void ErrorCheck::validateReadDist() { ifstream filehandle; int ableToOpen; - if ((phylipfile == "") && (columnfile == "")) { cout << "When executing a read.dist you must enter a phylip or a column." << endl; errorFree = false; } - else if ((phylipfile != "") && (columnfile != "")) { cout << "When executing a read.dist you must enter ONLY ONE of the following: phylip or column." << endl; errorFree = false; } + if (groupfile != "") { + ableToOpen = openInputFile(groupfile, filehandle); + filehandle.close(); + //unable to open + if (ableToOpen == 1) { errorFree = false; } + } + + if ((phylipfile == "") && (columnfile == "")) { cout << "When executing a read.dist or a tree.shared command with a distance file you must enter a phylip or a column." << endl; errorFree = false; } + else if ((phylipfile != "") && (columnfile != "")) { cout << "When executing a read.dist or a tree.shared command with a distance file you must enter ONLY ONE of the following: phylip or column." << endl; errorFree = false; } if (columnfile != "") { if (namefile == "") { @@ -651,7 +459,7 @@ void ErrorCheck::validateParseFiles() { ableToOpen = openInputFile(groupfile, filehandle); filehandle.close(); if (ableToOpen == 1) { //unable to open - errorFree = false;; + errorFree = false; } } } @@ -726,7 +534,7 @@ void ErrorCheck::validateReadPhil() { }else if (sabundfile != "") { if ((listfile != "") || (rabundfile != "")) { cout << "When executing a read.otu you must enter ONLY ONE of the following: list, rabund or sabund." << endl; errorFree = false; } - }else if ((listfile == "") && (rabundfile == "") && (sabundfile == "")) { + }else if ((listfile == "") && (rabundfile == "") && (sabundfile == "") && (sharedfile == "")) { cout << "When executing a read.otu you must enter one of the following: list, rabund or sabund." << endl; errorFree = false; } @@ -750,6 +558,137 @@ void ErrorCheck::validateReadPhil() { } /*******************************************************/ +/******************************************************/ +//This function checks to make sure the user entered appropriate +// format parameters on a distfile read +void ErrorCheck::validateSeqsFiles() { + try { + ifstream filehandle; + int ableToOpen; + + //checks to make sure only one file type is given + if (phylipfile != "") { + if ((nexusfile != "") || (fastafile != "") || (clustalfile != "")) { + cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; } + else { + ableToOpen = openInputFile(phylipfile, filehandle); + filehandle.close(); + if (ableToOpen == 1) { //unable to open + errorFree = false; + } + } + }else if (nexusfile != "") { + if ((phylipfile != "") || (fastafile != "") || (clustalfile != "")) { + cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; } + else { + ableToOpen = openInputFile(nexusfile, filehandle); + filehandle.close(); + if (ableToOpen == 1) { //unable to open + errorFree = false; + } + } + }else if (fastafile != "") { + if ((phylipfile != "") || (nexusfile != "") || (clustalfile != "")) { + cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; } + else { + ableToOpen = openInputFile(fastafile, filehandle); + filehandle.close(); + if (ableToOpen == 1) { //unable to open + errorFree = false; + } + } + }else if (clustalfile != "") { + if ((phylipfile != "") || (nexusfile != "") || (fastafile != "")) { + cout << "You may enter ONLY ONE of the following: phylip, fasta, nexus or clustal." << endl; errorFree = false; } + else { + ableToOpen = openInputFile(clustalfile, filehandle); + filehandle.close(); + if (ableToOpen == 1) { //unable to open + errorFree = false; + } + } + }else if (candidatefile != "") { + ableToOpen = openInputFile(candidatefile, filehandle); + filehandle.close(); + if (ableToOpen == 1) { //unable to open + errorFree = false; + } + } + + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateSeqsFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ErrorCheck class function validateSeqsFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/*******************************************************/ + +/******************************************************/ +//This function checks to make sure the user entered appropriate +// format parameters on a bin.seq command +void ErrorCheck::validateBinFiles() { + try { + ifstream filehandle; + int ableToOpen; + + if (fastafile == "") { + cout << "fasta is a required parameter for bin.seqs, get.oturep and get.repseqs commands." << endl; errorFree = false; + }else if (fastafile != "") { + //is it a valid filename' + ableToOpen = openInputFile(fastafile, filehandle); + filehandle.close(); + //unable to open + if (ableToOpen == 1) { errorFree = false; } + }else if (listfile != "") { + //is it a valid filename' + ableToOpen = openInputFile(listfile, filehandle); + filehandle.close(); + //unable to open + if (ableToOpen == 1) { errorFree = false; } + }else if (globaldata->getNameFile() != "") { + //is it a valid filename' + ifstream filehandle; + int ableToOpen = openInputFile(globaldata->getNameFile(), filehandle); + filehandle.close(); + //unable to open + if (ableToOpen == 1) { errorFree = false; } + }else if (namefile != "") { + //is it a valid filename' + ifstream filehandle; + int ableToOpen = openInputFile(namefile, filehandle); + filehandle.close(); + //unable to open + if (ableToOpen == 1) { errorFree = false; } + }else if (groupfile != "") { + //is it a valid filename' + ifstream filehandle; + int ableToOpen = openInputFile(groupfile, filehandle); + filehandle.close(); + //unable to open + if (ableToOpen == 1) { errorFree = false; } + } + + + + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the ErrorCheck class Function validateBinFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the ErrorCheck class function validateBinFiles. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} + +/*******************************************************/ + /******************************************************/ void ErrorCheck::clear() { @@ -763,6 +702,10 @@ void ErrorCheck::clear() { groupfile = ""; orderfile = ""; sharedfile = ""; + fastafile = ""; + nexusfile = ""; + clustalfile = ""; + candidatefile = ""; line = ""; label = ""; method = "furthest";