]> git.donarmstrong.com Git - mothur.git/blobdiff - normalizesharedcommand.cpp
working on get.communitytype command
[mothur.git] / normalizesharedcommand.cpp
index 43c8e2260c4e678bbd2e7718a6313b15d97eed8b..1000e4243e0c6fbf15f5e384871131f74d2a4ea5 100644 (file)
 //**********************************************************************************************************************
 vector<string> NormalizeSharedCommand::setParameters(){        
        try {
-               CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared);    
-               CommandParameter prelabund("relabund", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(prelabund);
-               CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
-               CommandParameter pmethod("method", "Multiple", "totalgroup-zscore", "totalgroup", "", "", "",false,false); parameters.push_back(pmethod);
-               CommandParameter pnorm("norm", "Number", "", "0", "", "", "",false,false); parameters.push_back(pnorm);
-               CommandParameter pmakerelabund("makerelabund", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(pmakerelabund);
-               CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
-               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
-               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+               CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none","shared",false,false,true); parameters.push_back(pshared);      
+               CommandParameter prelabund("relabund", "InputTypes", "", "", "LRSS", "LRSS", "none","shared",false,false,true); parameters.push_back(prelabund);
+               CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups);
+               CommandParameter pmethod("method", "Multiple", "totalgroup-zscore", "totalgroup", "", "", "","",false,false,true); parameters.push_back(pmethod);
+               CommandParameter pnorm("norm", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pnorm);
+               CommandParameter pmakerelabund("makerelabund", "Boolean", "", "F", "", "", "","",false,false); parameters.push_back(pmakerelabund);
+               CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel);
+               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
+               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
                
                vector<string> myArray;
                for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
@@ -53,8 +53,21 @@ string NormalizeSharedCommand::getHelpString(){
                exit(1);
        }
 }
-
-
+//**********************************************************************************************************************
+string NormalizeSharedCommand::getOutputPattern(string type) {
+    try {
+        string pattern = "";
+        
+        if (type == "shared") {  pattern = "[filename],[distance],norm.shared"; } 
+        else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
+        
+        return pattern;
+    }
+    catch(exception& e) {
+        m->errorOut(e, "NormalizeSharedCommand", "getOutputPattern");
+        exit(1);
+    }
+}
 //**********************************************************************************************************************
 NormalizeSharedCommand::NormalizeSharedCommand(){      
        try {
@@ -176,7 +189,7 @@ NormalizeSharedCommand::NormalizeSharedCommand(string option) {
                        if (temp == "not found") {  
                                norm = 0;  //once you have read, set norm to smallest group number
                        }else { 
-                               convert(temp, norm);
+                               m->mothurConvert(temp, norm);
                                if (norm < 0) { m->mothurOut("norm must be positive."); m->mothurOutEndLine(); abort=true; }
                        }
                        
@@ -445,11 +458,15 @@ int NormalizeSharedCommand::execute(){
 int NormalizeSharedCommand::normalize(vector<SharedRAbundVector*>& thisLookUp){
        try {
                //save mothurOut's binLabels to restore for next label
-               vector<string> saveBinLabels = m->currentBinLabels;
+               vector<string> saveBinLabels = m->currentSharedBinLabels;
                
                if (pickedGroups) { eliminateZeroOTUS(thisLookUp); }
                
-               string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputfile)) + thisLookUp[0]->getLabel() + ".norm.shared";
+        map<string, string> variables; 
+        variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile));
+        variables["[distance]"] = thisLookUp[0]->getLabel();
+               string outputFileName = getOutputFileName("shared",variables);
+        
                ofstream out;
                m->openOutputFile(outputFileName, out);
                outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName);
@@ -523,7 +540,7 @@ int NormalizeSharedCommand::normalize(vector<SharedRAbundVector*>& thisLookUp){
                
                out.close();
                
-               m->currentBinLabels = saveBinLabels;
+               m->currentSharedBinLabels = saveBinLabels;
                
                return 0;
        }
@@ -538,9 +555,12 @@ int NormalizeSharedCommand::normalize(vector<SharedRAbundFloatVector*>& thisLook
        try {
                
                //save mothurOut's binLabels to restore for next label
-               vector<string> saveBinLabels = m->currentBinLabels;
+               vector<string> saveBinLabels = m->currentSharedBinLabels;
                
-               string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputfile)) + thisLookUp[0]->getLabel() + ".norm.shared";
+        map<string, string> variables; 
+        variables["[filename]"] = outputDir + m->getRootName(m->getSimpleName(inputfile));
+        variables["[distance]"] = thisLookUp[0]->getLabel();
+               string outputFileName = getOutputFileName("shared",variables);
                ofstream out;
                m->openOutputFile(outputFileName, out);
                outputNames.push_back(outputFileName); outputTypes["shared"].push_back(outputFileName);
@@ -609,7 +629,7 @@ int NormalizeSharedCommand::normalize(vector<SharedRAbundFloatVector*>& thisLook
                
                out.close();
                
-               m->currentBinLabels = saveBinLabels;
+               m->currentSharedBinLabels = saveBinLabels;
                
                return 0;
        }
@@ -655,7 +675,7 @@ int NormalizeSharedCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thisl
                                        for (int h = 0; h < diff; h++) { binLabel += "0"; }
                                }
                                binLabel += sbinNumber; 
-                               if (i < m->currentBinLabels.size()) {  binLabel = m->currentBinLabels[i]; }
+                               if (i < m->currentSharedBinLabels.size()) {  binLabel = m->currentSharedBinLabels[i]; }
                                
                                newBinLabels.push_back(binLabel);
                        }
@@ -664,7 +684,7 @@ int NormalizeSharedCommand::eliminateZeroOTUS(vector<SharedRAbundVector*>& thisl
                for (int j = 0; j < thislookup.size(); j++) {  delete thislookup[j];  }
 
                thislookup = newLookup;
-               m->currentBinLabels = newBinLabels;
+               m->currentSharedBinLabels = newBinLabels;
                
                return 0;
  
@@ -711,7 +731,7 @@ int NormalizeSharedCommand::eliminateZeroOTUS(vector<SharedRAbundFloatVector*>&
                                        for (int h = 0; h < diff; h++) { binLabel += "0"; }
                                }
                                binLabel += sbinNumber; 
-                               if (i < m->currentBinLabels.size()) {  binLabel = m->currentBinLabels[i]; }
+                               if (i < m->currentSharedBinLabels.size()) {  binLabel = m->currentSharedBinLabels[i]; }
                                
                                newBinLabels.push_back(binLabel);
                        }
@@ -720,7 +740,7 @@ int NormalizeSharedCommand::eliminateZeroOTUS(vector<SharedRAbundFloatVector*>&
                for (int j = 0; j < thislookup.size(); j++) {  delete thislookup[j];  }
                
                thislookup = newLookup;
-               m->currentBinLabels = newBinLabels;
+               m->currentSharedBinLabels = newBinLabels;
                
                return 0;