]> git.donarmstrong.com Git - mothur.git/blobdiff - errorchecking.cpp
added heatmap.sim command and changed heatmap to heatmap.bin
[mothur.git] / errorchecking.cpp
index a057e5d1b396d69af85142d3695d326176b8fd0c..e77c1663f25d41ba9a20cd22152c7f946a207b95 100644 (file)
@@ -23,21 +23,23 @@ 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();
-       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();
+
 }
 
 /*******************************************************/
@@ -74,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
@@ -85,8 +86,6 @@ bool ErrorCheck::checkInput(string input) {
                                
                                //is it a valid parameter
                                if (validParameter->isValidParameter(parameter, commandName, value) != true) { return false; }
-
-
                                
                                if (parameter == "phylip" )             { phylipfile = value; }
                                if (parameter == "column" )             { columnfile = value; }
@@ -97,8 +96,8 @@ bool ErrorCheck::checkInput(string input) {
                                if (parameter == "order" )              { orderfile = value; }
                                if (parameter == "fasta" )              { fastafile = 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; }
@@ -109,8 +108,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 == "sorted" )                     { sorted = 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
@@ -144,6 +158,22 @@ bool ErrorCheck::checkInput(string input) {
                                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;    }
+                               
                        }
                }
                
@@ -171,12 +201,12 @@ bool ErrorCheck::checkInput(string input) {
                        }
                }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                      
+               //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; 
@@ -195,14 +225,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; }
@@ -212,22 +242,88 @@ 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 == "heatmap"){ 
+               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.bin") || (commandName == "venn") || (commandName == "heatmap.sim")) { 
                        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 command." << endl; return false; 
+                                cout << "You must read a list, or a list and a group, or a shared before you can use the heatmap.bin, heatmap.sim or venn commands." << endl; return false; 
                        }
                }
+               
+               if (commandName == "filter.seqs") { 
+                       if (fastafile == "") {
+                                cout << "You must enter either a fasta file before you can use the filter.seqs command." << endl; return false; 
+                       }
+                       validateReadFiles();
+               }
+               
+               if (commandName == "dist.seqs") {
+                       if (fastafile == "") {
+                                cout << "You must enter either a fasta file before you can use the dist.seqs command." << endl; return false; 
+                       }else {
+                               ifstream filehandle;
+                               int ableToOpen = openInputFile(fastafile, filehandle);
+                               filehandle.close();
+                               //unable to open
+                               if (ableToOpen == 1) { return false; }
+                       }
+               }
+               
+               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; 
+                       }
+                       validateReadFiles();
+                       
+                       ifstream filehandle;
+                       int ableToOpen = openInputFile(candidatefile, filehandle);
+                       filehandle.close();
+                       //unable to open
+                       if (ableToOpen == 1) {  return false; }
+               }
+               
+               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;
 }
@@ -290,6 +386,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;
                }
@@ -321,8 +423,8 @@ void ErrorCheck::validateReadDist() {
                        if (ableToOpen == 1) {  errorFree = false; }
                }
                
-               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 ((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 == "") {
@@ -371,7 +473,7 @@ void ErrorCheck::validateParseFiles() {
                                ableToOpen = openInputFile(groupfile, filehandle);
                                filehandle.close();
                                if (ableToOpen == 1) { //unable to open
-                                       errorFree = false;;
+                                       errorFree = false;
                                }
                        }
                }
@@ -470,6 +572,63 @@ void ErrorCheck::validateReadPhil() {
 }
 /*******************************************************/
 
+/******************************************************/
+//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() {
@@ -483,6 +642,8 @@ void ErrorCheck::clear() {
        groupfile               =       ""; 
        orderfile               =       "";
        sharedfile              =       "";
+       fastafile       =   "";
+       candidatefile   =       "";
        line                    =       "";
        label                   =       "";
        method                  =   "furthest";