X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=normalizesharedcommand.cpp;h=1000e4243e0c6fbf15f5e384871131f74d2a4ea5;hb=250e3b11b1c9c1e1ad458ab6c7e71ac2e67e11d9;hp=e41cfd9355ce1e08157069e59880aa32066e1505;hpb=49d2b7459c5027557564b21e9487dadafbbbdc96;p=mothur.git diff --git a/normalizesharedcommand.cpp b/normalizesharedcommand.cpp index e41cfd9..1000e42 100644 --- a/normalizesharedcommand.cpp +++ b/normalizesharedcommand.cpp @@ -12,15 +12,15 @@ //********************************************************************************************************************** vector 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 myArray; for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } @@ -53,26 +53,20 @@ string NormalizeSharedCommand::getHelpString(){ exit(1); } } - //********************************************************************************************************************** -string NormalizeSharedCommand::getOutputFileNameTag(string type, string inputName=""){ - try { - string outputFileName = ""; - map >::iterator it; +string NormalizeSharedCommand::getOutputPattern(string type) { + try { + string pattern = ""; - //is this a type this command creates - it = outputTypes.find(type); - if (it == outputTypes.end()) { m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); } - else { - if (type == "shared") { outputFileName = "norm.shared"; } - else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true; } - } - return outputFileName; - } - catch(exception& e) { - m->errorOut(e, "NormalizeSharedCommand", "getOutputFileNameTag"); - exit(1); - } + 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(){ @@ -464,11 +458,15 @@ int NormalizeSharedCommand::execute(){ int NormalizeSharedCommand::normalize(vector& thisLookUp){ try { //save mothurOut's binLabels to restore for next label - vector saveBinLabels = m->currentBinLabels; + vector saveBinLabels = m->currentSharedBinLabels; if (pickedGroups) { eliminateZeroOTUS(thisLookUp); } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputfile)) + thisLookUp[0]->getLabel() + "." + getOutputFileNameTag("shared"); + map 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); @@ -542,7 +540,7 @@ int NormalizeSharedCommand::normalize(vector& thisLookUp){ out.close(); - m->currentBinLabels = saveBinLabels; + m->currentSharedBinLabels = saveBinLabels; return 0; } @@ -557,9 +555,12 @@ int NormalizeSharedCommand::normalize(vector& thisLook try { //save mothurOut's binLabels to restore for next label - vector saveBinLabels = m->currentBinLabels; + vector saveBinLabels = m->currentSharedBinLabels; - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputfile)) + thisLookUp[0]->getLabel() + "." + getOutputFileNameTag("shared"); + map 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); @@ -628,7 +629,7 @@ int NormalizeSharedCommand::normalize(vector& thisLook out.close(); - m->currentBinLabels = saveBinLabels; + m->currentSharedBinLabels = saveBinLabels; return 0; } @@ -674,7 +675,7 @@ int NormalizeSharedCommand::eliminateZeroOTUS(vector& 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); } @@ -683,7 +684,7 @@ int NormalizeSharedCommand::eliminateZeroOTUS(vector& thisl for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; } thislookup = newLookup; - m->currentBinLabels = newBinLabels; + m->currentSharedBinLabels = newBinLabels; return 0; @@ -730,7 +731,7 @@ int NormalizeSharedCommand::eliminateZeroOTUS(vector& 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); } @@ -739,7 +740,7 @@ int NormalizeSharedCommand::eliminateZeroOTUS(vector& for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; } thislookup = newLookup; - m->currentBinLabels = newBinLabels; + m->currentSharedBinLabels = newBinLabels; return 0;