]> git.donarmstrong.com Git - mothur.git/blobdiff - sensspeccommand.cpp
changes to trim.flows command
[mothur.git] / sensspeccommand.cpp
index e647bf2430c629af70613b79abcaafc78ab325fa..6a22fd686096e83308faf7a68e98e9391d722fe0 100644 (file)
@@ -9,15 +9,62 @@
 
 #include "sensspeccommand.h"
 
+//**********************************************************************************************************************
+vector<string> SensSpecCommand::getValidParameters(){  
+       try {
+               string Array[] =  {"list", "phylip", "column", "name", "hard", "label", "cutoff", "precision", "outputdir", "inputdir"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SensSpecCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+SensSpecCommand::SensSpecCommand(){    
+       try {
+               abort = true; calledHelp = true; 
+               vector<string> tempOutNames;
+               outputTypes["sensspec"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SensSpecCommand", "SensSpecCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> SensSpecCommand::getRequiredParameters(){       
+       try {
+               string Array[] =  {"list","phylip","column","or"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SensSpecCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> SensSpecCommand::getRequiredFiles(){    
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "SensSpecCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
 //***************************************************************************************************************
 
 SensSpecCommand::SensSpecCommand(string option)  {
        try {
                
-               abort = false;
+               abort = false; calledHelp = false;   
                
                //allow user to run help
-               if(option == "help") { help(); abort = true; }
+               if(option == "help") { help(); abort = true; calledHelp = true; }
                
                else {
                        string temp;
@@ -38,6 +85,10 @@ SensSpecCommand::SensSpecCommand(string option)  {
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //initialize outputTypes
+                       vector<string> tempOutNames;
+                       outputTypes["sensspec"] = 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 = "";          }
@@ -46,7 +97,7 @@ SensSpecCommand::SensSpecCommand(string option)  {
                                it = parameters.find("list");
                                //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["list"] = inputDir + it->second;             }
                                }
@@ -54,7 +105,7 @@ SensSpecCommand::SensSpecCommand(string option)  {
                                it = parameters.find("phylip");
                                //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["phylip"] = inputDir + it->second;           }
                                }
@@ -62,7 +113,7 @@ SensSpecCommand::SensSpecCommand(string option)  {
                                it = parameters.find("column");
                                //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["column"] = inputDir + it->second;           }
                                }
@@ -70,7 +121,7 @@ SensSpecCommand::SensSpecCommand(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;             }
                                }
@@ -94,15 +145,15 @@ SensSpecCommand::SensSpecCommand(string option)  {
                        outputDir = validParameter.validFile(parameters, "outputdir", false);
                        if (outputDir == "not found"){  
                                outputDir = ""; 
-                               outputDir += hasPath(listFile); //if user entered a file with a path then preserve it   
+                               outputDir += m->hasPath(listFile); //if user entered a file with a path then preserve it        
                        }
 
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        temp = validParameter.validFile(parameters, "hard", false);
                        if (temp == "not found"){       hard = 0;       }
-                       else if(!isTrue(temp))  {       hard = 0;       }
-                       else if(isTrue(temp))   {       hard = 1;       }
+                       else if(!m->isTrue(temp))       {       hard = 0;       }
+                       else if(m->isTrue(temp))        {       hard = 1;       }
                        
 //                     temp = validParameter.validFile(parameters, "name", true);
 //                     if (temp == "not found")        {       nameFile = "";          }
@@ -156,9 +207,10 @@ SensSpecCommand::~SensSpecCommand(){       /*      do nothing      */      }
 
 int SensSpecCommand::execute(){
        try{
-               if (abort == true) { return 0; }
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
 
                setUpOutput();
+               outputNames.push_back(sensSpecFileName); outputTypes["sensspec"].push_back(sensSpecFileName);
                if(format == "phylip")          {       processPhylip();        }
                else if(format == "column")     {       processColumn();        }
                
@@ -178,7 +230,7 @@ void SensSpecCommand::processPhylip(){
                //probably need some checking to confirm that the names in the distance matrix are the same as those in the list file
                
                ifstream inputListFile;
-               openInputFile(listFile, inputListFile);
+               m->openInputFile(listFile, inputListFile);
                
                string origCutoff = "";
                bool getCutoff = 0;
@@ -210,13 +262,13 @@ void SensSpecCommand::processPhylip(){
                                }
                                seqMap[seqName] = i;
                        }
-                       gobble(inputListFile);
+                       m->gobble(inputListFile);
                
                        int lNumSeqs = seqMap.size();
                        int pNumSeqs = 0;
 
                        ifstream phylipFile;
-                       openInputFile(distFile, phylipFile);
+                       m->openInputFile(distFile, phylipFile);
                        phylipFile >> pNumSeqs;
                        if(pNumSeqs != lNumSeqs){       cout << "numSeq mismatch!" << endl;     }
                        
@@ -278,7 +330,7 @@ void SensSpecCommand::processPhylip(){
 void SensSpecCommand::processColumn(){
        try{            
                ifstream inputListFile;
-               openInputFile(listFile, inputListFile);
+               m->openInputFile(listFile, inputListFile);
                
                string origCutoff = "";
                bool getCutoff = 0;
@@ -326,12 +378,12 @@ void SensSpecCommand::processColumn(){
                                        }
                                }
                        }
-                       gobble(inputListFile);
+                       m->gobble(inputListFile);
                        
                        int numDists = (numSeqs * (numSeqs-1) / 2);
 
                        ifstream columnFile;
-                       openInputFile(distFile, columnFile);
+                       m->openInputFile(distFile, columnFile);
                        string seqNameA, seqNameB, seqPairString;
                        double distance;
                        
@@ -377,7 +429,7 @@ void SensSpecCommand::processColumn(){
                                        seqPairSet.erase(it);   
                                }
                                
-                               gobble(columnFile);
+                               m->gobble(columnFile);
                        }
                        falsePositives += seqPairSet.size();
                        
@@ -395,7 +447,7 @@ void SensSpecCommand::processColumn(){
 void SensSpecCommand::setUpOutput(){
        try{            
                ofstream sensSpecFile;
-               openOutputFile(sensSpecFileName, sensSpecFile);
+               m->openOutputFile(sensSpecFileName, sensSpecFile);
                
                sensSpecFile << "label\tcutoff\ttp\ttn\tfp\tfn\tsensitivity\tspecificity\tppv\tnpv\tfdr\taccuracy\tmcc\tf1score\n";
 
@@ -440,7 +492,7 @@ void SensSpecCommand::outputStatistics(string label, string cutoff){
                if(nPrime == 0)         {       negativePredictiveValue = 0;    matthewsCorrCoef = 0;                                                   }
                
                ofstream sensSpecFile;
-               openOutputFileAppend(sensSpecFileName, sensSpecFile);
+               m->openOutputFileAppend(sensSpecFileName, sensSpecFile);
                
                sensSpecFile << label << '\t' << cutoff << '\t';
                sensSpecFile << truePositives << '\t' << trueNegatives << '\t' << falsePositives << '\t' << falseNegatives << '\t';