]> git.donarmstrong.com Git - mothur.git/blobdiff - normalizesharedcommand.cpp
fixed bug with normalize.shared, printed out numbins twice. fixed bug with summary...
[mothur.git] / normalizesharedcommand.cpp
index 4a333322d5ff7893dd349e11eb3cc624d8c2b6f5..8aec029d9ec718327cc8c2e677f215e7b9e5cc88 100644 (file)
@@ -9,6 +9,54 @@
 
 #include "normalizesharedcommand.h"
 
+//**********************************************************************************************************************
+vector<string> NormalizeSharedCommand::getValidParameters(){   
+       try {
+               string Array[] =  {"groups","label","method","outputdir","inputdir","norm"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "NormalizeSharedCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+NormalizeSharedCommand::NormalizeSharedCommand(){      
+       try {
+               abort = true;
+               //initialize outputTypes
+               vector<string> tempOutNames;
+               outputTypes["shared"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "NormalizeSharedCommand", "NormalizeSharedCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> NormalizeSharedCommand::getRequiredParameters(){        
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "NormalizeSharedCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> NormalizeSharedCommand::getRequiredFiles(){     
+       try {
+               string Array[] =  {"shared"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "NormalizeSharedCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 
 NormalizeSharedCommand::NormalizeSharedCommand(string option) {
@@ -23,7 +71,7 @@ NormalizeSharedCommand::NormalizeSharedCommand(string option) {
                
                else {
                        //valid paramters for this command
-                       string AlignArray[] =  {"groups","label","scale","outputdir","inputdir","norm"};
+                       string AlignArray[] =  {"groups","label","method","outputdir","inputdir","norm"};
                        vector<string> myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -36,6 +84,10 @@ NormalizeSharedCommand::NormalizeSharedCommand(string option) {
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //initialize outputTypes
+                       vector<string> tempOutNames;
+                       outputTypes["shared"] = tempOutNames;
+                       
                        //if the user changes the output directory command factory will send this info to us in the output parameter 
                        outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
                                outputDir = ""; 
@@ -100,7 +152,7 @@ void NormalizeSharedCommand::help(){
                m->mothurOut("The method parameter allows you to select what method you would like to use to normalize. The only choice is totalgroup. We hope to add more ways to normalize in the future, suggestions are welcome!\n");
                m->mothurOut("The norm parameter allows you to number you would like to normalize to. By default this is set to the number of sequences in your smallest group.\n");
                m->mothurOut("The normalize.shared command should be in the following format: normalize.shared(groups=yourGroups, label=yourLabels).\n");
-               m->mothurOut("Example normalize.shared(groups=A-B-C, scale=averagegroup).\n");
+               m->mothurOut("Example normalize.shared(groups=A-B-C, scale=totalgroup).\n");
                m->mothurOut("The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n");
                m->mothurOut("The normalize.shared command outputs a .norm.shared file.\n");
                m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n");
@@ -150,7 +202,7 @@ int NormalizeSharedCommand::execute(){
                //as long as you are not at the end of the file or done wih the lines you want
                while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
                        
-                       if (m->control_pressed) {  for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } globaldata->Groups.clear(); delete read;  out.close(); remove(outputFileName.c_str()); return 0; }
+                       if (m->control_pressed) { outputTypes.clear();  for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } globaldata->Groups.clear(); delete read;  out.close(); remove(outputFileName.c_str()); return 0; }
        
                        if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){                  
 
@@ -181,13 +233,13 @@ int NormalizeSharedCommand::execute(){
                        //prevent memory leak
                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i]; lookup[i] = NULL; }
                        
-                       if (m->control_pressed) {  globaldata->Groups.clear(); delete read;  out.close(); remove(outputFileName.c_str()); return 0; }
+                       if (m->control_pressed) {  outputTypes.clear(); globaldata->Groups.clear(); delete read;  out.close(); remove(outputFileName.c_str()); return 0; }
 
                        //get next line to process
                        lookup = input->getSharedRAbundVectors();                               
                }
                
-               if (m->control_pressed) { globaldata->Groups.clear(); delete read;  out.close(); remove(outputFileName.c_str());  return 0; }
+               if (m->control_pressed) { outputTypes.clear(); globaldata->Groups.clear(); delete read;  out.close(); remove(outputFileName.c_str());  return 0; }
 
                //output error messages about any remaining user labels
                set<string>::iterator it;
@@ -220,11 +272,11 @@ int NormalizeSharedCommand::execute(){
                delete read;
                out.close();
                
-               if (m->control_pressed) { remove(outputFileName.c_str()); return 0;}
+               if (m->control_pressed) { outputTypes.clear(); remove(outputFileName.c_str()); return 0;}
                
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();
-               m->mothurOut(outputFileName); m->mothurOutEndLine();
+               m->mothurOut(outputFileName); m->mothurOutEndLine(); outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName);
                m->mothurOutEndLine();
                
                return 0;
@@ -270,7 +322,7 @@ int NormalizeSharedCommand::normalize(vector<SharedRAbundVector*>& thisLookUp, o
                 eliminateZeroOTUS(thisLookUp);
                 
                  for (int i = 0; i < thisLookUp.size(); i++) {
-                       out << thisLookUp[i]->getLabel() << '\t' << thisLookUp[i]->getGroup() << '\t' << thisLookUp[i]->getNumBins() << '\t';
+                       out << thisLookUp[i]->getLabel() << '\t' << thisLookUp[i]->getGroup() << '\t';
                        thisLookUp[i]->print(out);
                 }