]> git.donarmstrong.com Git - mothur.git/blobdiff - errorchecking.cpp
added get.repseqs command, started matrix output command
[mothur.git] / errorchecking.cpp
index abd2a9ffeca07f4f11e9d69f283f09afc535a056..19d1f8aeacf25878fee069f1083b0465974d4645 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; }
@@ -96,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; }
@@ -109,8 +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 == "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 == "ends" )                       { ends = value; }
+                               if (parameter == "processors" )         { processors = value;   }
+                               if (parameter == "size" )                       { size = value; }
+                               if (parameter == "template")            { templatefile = 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
@@ -131,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; }
@@ -144,6 +162,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 == "ends" )                       { ends = value; }
+                               if (parameter == "processors" )         { processors = value;   }
+                               if (parameter == "size" )                       { size = value; }
+                               if (parameter == "template")            { templatefile = 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;    }
+                               
                        }
                }
                
@@ -176,7 +210,7 @@ bool ErrorCheck::checkInput(string input) {
                        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,9 +229,9 @@ 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
@@ -216,10 +250,10 @@ bool ErrorCheck::checkInput(string input) {
                        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 == "collect.shared") || (commandName == "rarefaction.shared") || (commandName == "summary.shared") || (commandName == "tree.shared") || (commandName == "bootstrap.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 or bootstrap.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 or bootstrap.shared commands." << endl; return false; }
                        }
                }
                
@@ -229,11 +263,27 @@ bool ErrorCheck::checkInput(string input) {
                        }
                }
                
+               if ((commandName == "filter.seqs") || (commandName == "dist.seqs") || (commandName == "align.seqs")) { 
+                       if ((fastafile == "") && (nexusfile == "") && (clustalfile == "") && (phylipfile == "")) {
+                                cout << "You must enter either a fasta, nexus, clustal, or phylip file before you can use the filter.seqs, dist.seqs or align.seqs command." << endl; return false; 
+                       }else if ((commandName == "align.seqs") && (templatefile == "")) {
+                               cout << "You must enter a template 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 command." << endl; return false; }
                        validateBinFiles();
                }
                
+               if ((commandName == "get.repseqs")) { 
+                       if ((globaldata->getListFile() == "")) { cout << "You must read a list file before you can use the get.repseqs command." << endl; return false; }
+                       else if (groupfile == "") { cout << "You must provide a groupfile before you can use the get.repseqs command." << 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; 
@@ -485,6 +535,77 @@ 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 (templatefile != "") {
+                       ableToOpen = openInputFile(templatefile, 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
@@ -494,7 +615,7 @@ void ErrorCheck::validateBinFiles() {
                int ableToOpen;
                
                if (fastafile == "") {
-                               cout << "fasta is a required parameter for bin.seqs and get.oturep commands." << endl; errorFree = false; 
+                               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);
@@ -521,9 +642,17 @@ void ErrorCheck::validateBinFiles() {
                        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";
@@ -550,6 +679,10 @@ void ErrorCheck::clear() {
        groupfile               =       ""; 
        orderfile               =       "";
        sharedfile              =       "";
+       fastafile       =   "";
+       nexusfile       =   "";
+       clustalfile     =   "";
+       templatefile    =       "";
        line                    =       "";
        label                   =       "";
        method                  =   "furthest";