X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=normalizesharedcommand.cpp;h=acd8208ea7ebb20a3d3810d254d0b24f5386d4d3;hp=bcec00a0bc6dd47e15ddcf72000dc4a9dbec9469;hb=1a20e24ee786195ab0e1cccd4f5aede7a88f3f4e;hpb=55386dddad84cc1140d736cabaf4dd0ae16f2e01 diff --git a/normalizesharedcommand.cpp b/normalizesharedcommand.cpp index bcec00a..acd8208 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,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; } } @@ -449,7 +462,11 @@ int NormalizeSharedCommand::normalize(vector& thisLookUp){ if (pickedGroups) { eliminateZeroOTUS(thisLookUp); } - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputfile)) + thisLookUp[0]->getLabel() + ".norm.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); @@ -540,7 +557,10 @@ int NormalizeSharedCommand::normalize(vector& thisLook //save mothurOut's binLabels to restore for next label vector saveBinLabels = m->currentBinLabels; - string outputFileName = outputDir + m->getRootName(m->getSimpleName(inputfile)) + thisLookUp[0]->getLabel() + ".norm.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); @@ -632,6 +652,7 @@ int NormalizeSharedCommand::eliminateZeroOTUS(vector& thisl //for each bin vector newBinLabels; + string snumBins = toString(thislookup[0]->getNumBins()); for (int i = 0; i < thislookup[0]->getNumBins(); i++) { if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } @@ -647,7 +668,13 @@ int NormalizeSharedCommand::eliminateZeroOTUS(vector& thisl newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup()); } //if there is a bin label use it otherwise make one - string binLabel = "Otu" + toString(i+1); + string binLabel = "Otu"; + string sbinNumber = toString(i+1); + if (sbinNumber.length() < snumBins.length()) { + int diff = snumBins.length() - sbinNumber.length(); + for (int h = 0; h < diff; h++) { binLabel += "0"; } + } + binLabel += sbinNumber; if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; } newBinLabels.push_back(binLabel); @@ -681,6 +708,7 @@ int NormalizeSharedCommand::eliminateZeroOTUS(vector& //for each bin vector newBinLabels; + string snumBins = toString(thislookup[0]->getNumBins()); for (int i = 0; i < thislookup[0]->getNumBins(); i++) { if (m->control_pressed) { for (int j = 0; j < newLookup.size(); j++) { delete newLookup[j]; } return 0; } @@ -696,7 +724,13 @@ int NormalizeSharedCommand::eliminateZeroOTUS(vector& newLookup[j]->push_back(thislookup[j]->getAbundance(i), thislookup[j]->getGroup()); } //if there is a bin label use it otherwise make one - string binLabel = "Otu" + toString(i+1); + string binLabel = "Otu"; + string sbinNumber = toString(i+1); + if (sbinNumber.length() < snumBins.length()) { + int diff = snumBins.length() - sbinNumber.length(); + for (int h = 0; h < diff; h++) { binLabel += "0"; } + } + binLabel += sbinNumber; if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; } newBinLabels.push_back(binLabel);