]> git.donarmstrong.com Git - mothur.git/blobdiff - seqerrorcommand.cpp
finished sub.sample command
[mothur.git] / seqerrorcommand.cpp
index 82af49ed27f5e6dffbe52e50d413439c3983c270..0da4d1cd76cd51864c5442777180043f3c699fa2 100644 (file)
@@ -9,6 +9,55 @@
 
 #include "seqerrorcommand.h"
 
+//**********************************************************************************************************************
+vector<string> SeqErrorCommand::getValidParameters(){  
+       try {
+               string Array[] =  {"query", "reference", "name", "threshold", "inputdir", "outputdir"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SeqErrorCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+SeqErrorCommand::SeqErrorCommand(){    
+       try {
+               abort = true;
+               //initialize outputTypes
+               vector<string> tempOutNames;
+               outputTypes["error"] = tempOutNames;
+               outputTypes["count"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SeqErrorCommand", "SeqErrorCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> SeqErrorCommand::getRequiredParameters(){       
+       try {
+               string Array[] =  {"query","reference"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SeqErrorCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> SeqErrorCommand::getRequiredFiles(){    
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SeqErrorCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
 //***************************************************************************************************************
 
 SeqErrorCommand::SeqErrorCommand(string option)  {
@@ -23,7 +72,7 @@ SeqErrorCommand::SeqErrorCommand(string option)  {
                        string temp;
                        
                        //valid paramters for this command
-                       string AlignArray[] =  {"query", "reference", "name", "threshold"};
+                       string AlignArray[] =  {"query", "reference", "name", "threshold", "inputdir", "outputdir"};
                        
 //need to implement name file option
                        
@@ -40,6 +89,11 @@ SeqErrorCommand::SeqErrorCommand(string option)  {
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //initialize outputTypes
+                       vector<string> tempOutNames;
+                       outputTypes["error"] = tempOutNames;
+                       outputTypes["count"] = tempOutNames;
+                       
                        //if the user changes the input directory command factory will send this info to us in the output parameter 
                        string inputDir = validParameter.validFile(parameters, "inputdir", false);              
                        if (inputDir == "not found"){   inputDir = "";          }
@@ -48,7 +102,7 @@ SeqErrorCommand::SeqErrorCommand(string option)  {
                                it = parameters.find("query");
                                //user has given a template file
                                if(it != parameters.end()){ 
-                                       path = hasPath(it->second);
+                                       path = m->hasPath(it->second);
                                        //if the user has not given a path then, add inputdir. else leave path alone.
                                        if (path == "") {       parameters["query"] = inputDir + it->second;            }
                                }
@@ -56,7 +110,7 @@ SeqErrorCommand::SeqErrorCommand(string option)  {
                                it = parameters.find("reference");
                                //user has given a template file
                                if(it != parameters.end()){ 
-                                       path = hasPath(it->second);
+                                       path = m->hasPath(it->second);
                                        //if the user has not given a path then, add inputdir. else leave path alone.
                                        if (path == "") {       parameters["reference"] = inputDir + it->second;                }
                                }
@@ -64,7 +118,7 @@ SeqErrorCommand::SeqErrorCommand(string option)  {
                                it = parameters.find("name");
                                //user has given a template file
                                if(it != parameters.end()){ 
-                                       path = hasPath(it->second);
+                                       path = m->hasPath(it->second);
                                        //if the user has not given a path then, add inputdir. else leave path alone.
                                        if (path == "") {       parameters["name"] = inputDir + it->second;             }
                                }
@@ -87,7 +141,7 @@ SeqErrorCommand::SeqErrorCommand(string option)  {
                        outputDir = validParameter.validFile(parameters, "outputdir", false);
                        if (outputDir == "not found"){  
                                outputDir = ""; 
-                               outputDir += hasPath(queryFileName); //if user entered a file with a path then preserve it      
+                               outputDir += m->hasPath(queryFileName); //if user entered a file with a path then preserve it   
                        }
                        
                        //check for optional parameter and set defaults
@@ -96,7 +150,8 @@ SeqErrorCommand::SeqErrorCommand(string option)  {
                        convert(temp, threshold);  
                                                
                        errorFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".errors";
-                       openOutputFile(errorFileName, errorFile);
+                       m->openOutputFile(errorFileName, errorFile);
+                       outputNames.push_back(errorFileName); outputTypes["error"].push_back(errorFileName);
                        printErrorHeader();
                }
        }
@@ -140,7 +195,7 @@ int SeqErrorCommand::execute(){
                if(namesFileName != ""){        weights = getWeights(); }
                
                ifstream queryFile;
-               openInputFile(queryFileName, queryFile);
+               m->openInputFile(queryFileName, queryFile);
                                
                int totalBases = 0;
                int totalMatches = 0;
@@ -194,7 +249,8 @@ int SeqErrorCommand::execute(){
                
                string errorCountFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".count";
                ofstream errorCountFile;
-               openOutputFile(errorCountFileName, errorCountFile);
+               m->openOutputFile(errorCountFileName, errorCountFile);
+               outputNames.push_back(errorCountFileName);  outputTypes["count"].push_back(errorCountFileName);
                
                m->mothurOut("Overall error rate:\t" + toString((double)(totalBases - totalMatches) / (double)totalBases) + "\n\n");
                m->mothurOut("Errors\tSequences\n");
@@ -220,7 +276,7 @@ void SeqErrorCommand::getReferences(){
        try {
                
                ifstream referenceFile;
-               openInputFile(referenceFileName, referenceFile);
+               m->openInputFile(referenceFileName, referenceFile);
                
                while(referenceFile){
                        Sequence currentSeq(referenceFile);
@@ -231,7 +287,7 @@ void SeqErrorCommand::getReferences(){
                                currentSeq.removeAmbigBases();
                        }
                        referenceSeqs.push_back(currentSeq);
-                       gobble(referenceFile);
+                       m->gobble(referenceFile);
                }
                numRefs = referenceSeqs.size();
                
@@ -335,7 +391,7 @@ Compare SeqErrorCommand::getErrors(Sequence query, Sequence reference){
 
 map<string, int> SeqErrorCommand::getWeights(){
        ifstream nameFile;
-       openInputFile(namesFileName, nameFile);
+       m->openInputFile(namesFileName, nameFile);
        
        string seqName;
        string redundantSeqs;
@@ -343,8 +399,8 @@ map<string, int> SeqErrorCommand::getWeights(){
        
        while(nameFile){
                nameFile >> seqName >> redundantSeqs;
-               nameCountMap[seqName] = getNumNames(redundantSeqs); 
-               gobble(nameFile);
+               nameCountMap[seqName] = m->getNumNames(redundantSeqs); 
+               m->gobble(nameFile);
        }
        return nameCountMap;
 }