//**********************************************************************************************************************
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); }
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 {
else {
pickedGroups = true;
m->splitAtDash(groups, Groups);
- m->Groups = Groups;
+ m->setGroups(Groups);
}
method = validParameter.validFile(parameters, "method", false); if (method == "not found") { method = "totalgroup"; }
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; }
}
//look for groups whose numseqs is below norm and remove them, warning the user
if (norm != 0) {
- m->Groups.clear();
+ m->clearGroups();
+ vector<string> mGroups;
vector<SharedRAbundVector*> temp;
for (int i = 0; i < lookup.size(); i++) {
if (lookup[i]->getNumSeqs() < norm) {
m->mothurOut(lookup[i]->getGroup() + " contains " + toString(lookup[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine();
delete lookup[i];
}else {
- m->Groups.push_back(lookup[i]->getGroup());
+ mGroups.push_back(lookup[i]->getGroup());
temp.push_back(lookup[i]);
}
}
lookup = temp;
+ m->setGroups(mGroups);
}
//if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
//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 < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->Groups.clear(); return 0; }
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } m->clearGroups(); return 0; }
if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
//prevent memory leak
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; lookup[i] = NULL; }
- if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->Groups.clear(); return 0; }
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->clearGroups(); return 0; }
//get next line to process
lookup = input->getSharedRAbundVectors();
}
- if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->Groups.clear(); return 0; }
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->clearGroups(); return 0; }
//output error messages about any remaining user labels
set<string>::iterator it;
//look for groups whose numseqs is below norm and remove them, warning the user
if (norm != 0) {
- m->Groups.clear();
+ m->clearGroups();
+ vector<string> mGroups;
vector<SharedRAbundFloatVector*> temp;
for (int i = 0; i < lookupFloat.size(); i++) {
if (lookupFloat[i]->getNumSeqs() < norm) {
m->mothurOut(lookupFloat[i]->getGroup() + " contains " + toString(lookupFloat[i]->getNumSeqs()) + ". Eliminating."); m->mothurOutEndLine();
delete lookupFloat[i];
}else {
- m->Groups.push_back(lookupFloat[i]->getGroup());
+ mGroups.push_back(lookupFloat[i]->getGroup());
temp.push_back(lookupFloat[i]);
}
}
lookupFloat = temp;
+ m->setGroups(mGroups);
}
//set norm to smallest group number
//as long as you are not at the end of the file or done wih the lines you want
while((lookupFloat[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
- if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } m->Groups.clear(); return 0; }
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; } m->clearGroups(); return 0; }
if(allLines == 1 || labels.count(lookupFloat[0]->getLabel()) == 1){
//prevent memory leak
for (int i = 0; i < lookupFloat.size(); i++) { delete lookupFloat[i]; lookupFloat[i] = NULL; }
- if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->Groups.clear(); return 0; }
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->clearGroups(); return 0; }
//get next line to process
lookupFloat = input->getSharedRAbundFloatVectors();
}
- if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->Groups.clear(); return 0; }
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->clearGroups(); return 0; }
//output error messages about any remaining user labels
set<string>::iterator it;
}
//reset groups parameter
- m->Groups.clear();
+ m->clearGroups();
delete input;
if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0;}
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);
out.close();
- m->currentBinLabels = saveBinLabels;
+ m->currentSharedBinLabels = saveBinLabels;
return 0;
}
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);
out.close();
- m->currentBinLabels = saveBinLabels;
+ m->currentSharedBinLabels = saveBinLabels;
return 0;
}
//for each bin
vector<string> 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; }
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" + (i+1);
- if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+ 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->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; }
newBinLabels.push_back(binLabel);
}
for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
thislookup = newLookup;
- m->currentBinLabels = newBinLabels;
+ m->currentSharedBinLabels = newBinLabels;
return 0;
//for each bin
vector<string> 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; }
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" + (i+1);
- if (i < m->currentBinLabels.size()) { binLabel = m->currentBinLabels[i]; }
+ 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->currentSharedBinLabels.size()) { binLabel = m->currentSharedBinLabels[i]; }
newBinLabels.push_back(binLabel);
}
for (int j = 0; j < thislookup.size(); j++) { delete thislookup[j]; }
thislookup = newLookup;
- m->currentBinLabels = newBinLabels;
+ m->currentSharedBinLabels = newBinLabels;
return 0;