vector<string> GetRAbundCommand::setParameters(){
try {
CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none","rabund",false,false, true); parameters.push_back(plist);
+ CommandParameter pcount("count", "InputTypes", "", "", "none", "none", "none","",false,false, false); parameters.push_back(pcount);
CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none","rabund",false,false, true); parameters.push_back(psabund);
CommandParameter psorted("sorted", "Boolean", "", "T", "", "", "","",false,false); parameters.push_back(psorted);
CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel);
string GetRAbundCommand::getHelpString(){
try {
string helpString = "";
- helpString += "The get.rabund command parameters are list, sabund, label and sorted. list or sabund parameters are required, unless you have valid current files.\n";
+ helpString += "The get.rabund command parameters are list, sabund, count, label and sorted. list or sabund parameters are required, unless you have valid current files.\n";
+ helpString += "The count parameter allows you to provide a count file associated with your list file. If you clustered with a countfile the list file only contains the unique sequences and you will want to add the redundant counts into the rabund file, providing the count file allows you to do so.\n";
helpString += "The label parameter allows you to select what distance levels you would like included in your .rabund file, and are separated by dashes.\n";
helpString += "The sorted parameters allows you to print the rabund results sorted by abundance or not. The default is sorted.\n";
helpString += "The get.rabund command should be in the following format: get.rabund(label=yourLabels, sorted=yourSorted).\n";
//if the user has not given a path then, add inputdir. else leave path alone.
if (path == "") { parameters["sabund"] = inputDir + it->second; }
}
+
+ it = parameters.find("count");
+ //user has given a template file
+ if(it != parameters.end()){
+ path = m->hasPath(it->second);
+ //if the user has not given a path then, add inputdir. else leave path alone.
+ if (path == "") { parameters["count"] = inputDir + it->second; }
+ }
}
if (sabundfile == "not open") { sabundfile = ""; abort = true; }
else if (sabundfile == "not found") { sabundfile = ""; }
else { format = "sabund"; inputfile = sabundfile; m->setSabundFile(sabundfile); }
+
+ countfile = validParameter.validFile(parameters, "count", true);
+ if (countfile == "not open") { countfile = ""; abort = true; }
+ else if (countfile == "not found") { countfile = ""; }
+ else { m->setCountTableFile(countfile); }
//check for optional parameter and set defaults
}
}
-
+ if ((countfile != "") && (listfile == "")) { m->mothurOut("[ERROR]: You can only use the count file with a list file, aborting.\n"); abort = true; }
+
//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 = m->hasPath(inputfile); }
filename = getOutputFileName("rabund", variables);
m->openOutputFile(filename, out);
- input = new InputData(inputfile, format);
- rabund = input->getRAbundVector();
- string lastLabel = rabund->getLabel();
-
- //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
- set<string> processedLabels;
- set<string> userLabels = labels;
-
- if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete rabund; delete input; return 0; }
-
- while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
-
- if(allLines == 1 || labels.count(rabund->getLabel()) == 1){
+ if (countfile != "") {
+ processList(out);
+ }else {
+ InputData input(inputfile, format);
+ RAbundVector* rabund = input.getRAbundVector();
+ string lastLabel = rabund->getLabel();
+
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = labels;
+
+ if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete rabund; return 0; }
+
+ while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+
+ if(allLines == 1 || labels.count(rabund->getLabel()) == 1){
m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
- if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete input; delete rabund; return 0; }
+ if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete rabund; return 0; }
if(sorted) { rabund->print(out); }
else { rabund->nonSortedPrint(out); }
-
+
processedLabels.insert(rabund->getLabel());
userLabels.erase(rabund->getLabel());
- }
-
- if ((m->anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
+ }
+
+ if ((m->anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
string saveLabel = rabund->getLabel();
delete rabund;
- rabund = input->getRAbundVector(lastLabel);
+ rabund = input.getRAbundVector(lastLabel);
m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
- if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete input; delete rabund; return 0; }
+ if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete rabund; return 0; }
if(sorted) { rabund->print(out); }
else { rabund->nonSortedPrint(out); }
-
+
processedLabels.insert(rabund->getLabel());
userLabels.erase(rabund->getLabel());
//restore real lastlabel to save below
rabund->setLabel(saveLabel);
- }
-
- lastLabel = rabund->getLabel();
-
- delete rabund;
- rabund = input->getRAbundVector();
+ }
+
+ lastLabel = rabund->getLabel();
+
+ delete rabund;
+ rabund = input.getRAbundVector();
+ }
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ m->mothurOut("Your file does not include the label " + *it);
+ if (processedLabels.count(lastLabel) != 1) {
+ m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
+ needToRun = true;
+ }else {
+ m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
+ }
+ }
+
+ //run last label if you need to
+ if (needToRun == true) {
+ if (rabund != NULL) { delete rabund; }
+ rabund = input.getRAbundVector(lastLabel);
+
+ m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
+
+ if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete rabund; return 0; }
+
+ if(sorted) { rabund->print(out); }
+ else { rabund->nonSortedPrint(out); }
+
+ delete rabund;
+ }
}
-
- //output error messages about any remaining user labels
- set<string>::iterator it;
- bool needToRun = false;
- for (it = userLabels.begin(); it != userLabels.end(); it++) {
- m->mothurOut("Your file does not include the label " + *it);
- if (processedLabels.count(lastLabel) != 1) {
- m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
- needToRun = true;
- }else {
- m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
- }
- }
-
- //run last label if you need to
- if (needToRun == true) {
- if (rabund != NULL) { delete rabund; }
- rabund = input->getRAbundVector(lastLabel);
-
- m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
-
- if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete input; delete rabund; return 0; }
-
- if(sorted) { rabund->print(out); }
- else { rabund->nonSortedPrint(out); }
-
- delete rabund;
- }
-
+
+ if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); return 0; }
+
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
m->mothurOut(filename); m->mothurOutEndLine(); outputNames.push_back(filename); outputTypes["rabund"].push_back(filename);
exit(1);
}
}
+//**********************************************************************************************************************
+int GetRAbundCommand::processList(ofstream& out){
+ try {
+ CountTable ct;
+ ct.readTable(countfile);
+
+ InputData input(inputfile, format);
+ ListVector* list = input.getListVector();
+ string lastLabel = list->getLabel();
+
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = labels;
+
+ if (m->control_pressed) { delete list; return 0; }
+
+ while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+
+ if(allLines == 1 || labels.count(list->getLabel()) == 1){
+ m->mothurOut(list->getLabel()); m->mothurOutEndLine();
+
+ if (m->control_pressed) { delete list; return 0; }
+
+ RAbundVector* rabund = new RAbundVector();
+ createRabund(ct, list, rabund);
+
+ if(sorted) { rabund->print(out); }
+ else { rabund->nonSortedPrint(out); }
+
+ delete rabund;
+ processedLabels.insert(list->getLabel());
+ userLabels.erase(list->getLabel());
+ }
+
+ if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
+ string saveLabel = list->getLabel();
+
+ delete list;
+ list = input.getListVector(lastLabel);
+
+ m->mothurOut(list->getLabel()); m->mothurOutEndLine();
+
+ if (m->control_pressed) { delete list; return 0; }
+
+ RAbundVector* rabund = new RAbundVector();
+ createRabund(ct, list, rabund);
+
+ if(sorted) { rabund->print(out); }
+ else { rabund->nonSortedPrint(out); }
+
+ delete rabund;
+ processedLabels.insert(list->getLabel());
+ userLabels.erase(list->getLabel());
+
+ //restore real lastlabel to save below
+ list->setLabel(saveLabel);
+ }
+
+ lastLabel = list->getLabel();
+
+ delete list;
+ list = input.getListVector();
+ }
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ m->mothurOut("Your file does not include the label " + *it);
+ if (processedLabels.count(lastLabel) != 1) {
+ m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
+ needToRun = true;
+ }else {
+ m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
+ }
+ }
+
+ //run last label if you need to
+ if (needToRun == true) {
+ if (list != NULL) { delete list; }
+ list = input.getListVector(lastLabel);
+
+ m->mothurOut(list->getLabel()); m->mothurOutEndLine();
+
+ if (m->control_pressed) { delete list; return 0; }
+
+ RAbundVector* rabund = new RAbundVector();
+ createRabund(ct, list, rabund);
+
+ if(sorted) { rabund->print(out); }
+ else { rabund->nonSortedPrint(out); }
+
+ delete rabund;
+ delete list;
+ }
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetRAbundCommand", "processList");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+
+int GetRAbundCommand::createRabund(CountTable& ct, ListVector*& list, RAbundVector*& rabund){
+ try {
+
+ rabund->setLabel(list->getLabel());
+ for(int i = 0; i < list->getNumBins(); i++) {
+ if (m->control_pressed) { return 0; }
+ vector<string> binNames;
+ string bin = list->get(i);
+ m->splitAtComma(bin, binNames);
+ int total = 0;
+ for (int j = 0; j < binNames.size(); j++) {
+ total += ct.getNumSeqs(binNames[j]);
+ }
+ rabund->push_back(total);
+ }
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetRAbundCommand", "createRabund");
+ exit(1);
+ }
+
+}
//**********************************************************************************************************************
private:
- string filename, listfile, sabundfile, inputfile, format, outputDir;
+ string filename, listfile, sabundfile, inputfile, format, outputDir, countfile;
ofstream out;
- InputData* input;
- RAbundVector* rabund;
vector<string> outputNames;
bool abort, allLines, sorted;
set<string> labels; //holds labels to be used
string label;
-
+ int processList(ofstream& out);
+ int createRabund(CountTable& ct, ListVector*& list, RAbundVector*& rabund);
};
#endif
vector<string> GetSAbundCommand::setParameters(){
try {
CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none","sabund",false,false, true); parameters.push_back(plist);
+ CommandParameter pcount("count", "InputTypes", "", "", "none", "none", "none","",false,false, false); parameters.push_back(pcount);
CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none","sabund",false,false, true); parameters.push_back(prabund);
CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel);
CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
string GetSAbundCommand::getHelpString(){
try {
string helpString = "";
- helpString += "The get.sabund command parameters is list, rabund and label. list or rabund is required unless a valid current file exists.\n";
+ helpString += "The get.sabund command parameters is list, rabund, count and label. list or rabund is required unless a valid current file exists.\n";
+ helpString += "The count parameter allows you to provide a count file associated with your list file. If you clustered with a countfile the list file only contains the unique sequences and you will want to add the redundant counts into the sabund file, providing the count file allows you to do so.\n";
helpString += "The label parameter allows you to select what distance levels you would like included in your .sabund file, and are separated by dashes.\n";
helpString += "The get.sabund command should be in the following format: get.sabund(label=yourLabels).\n";
helpString += "Example get.sabund().\n";
//if the user has not given a path then, add inputdir. else leave path alone.
if (path == "") { parameters["rabund"] = inputDir + it->second; }
}
+
+ it = parameters.find("count");
+ //user has given a template file
+ if(it != parameters.end()){
+ path = m->hasPath(it->second);
+ //if the user has not given a path then, add inputdir. else leave path alone.
+ if (path == "") { parameters["count"] = inputDir + it->second; }
+ }
}
else if (rabundfile == "not found") { rabundfile = ""; }
else { format = "rabund"; inputfile = rabundfile; m->setRabundFile(rabundfile); }
-
+ countfile = validParameter.validFile(parameters, "count", true);
+ if (countfile == "not open") { countfile = ""; abort = true; }
+ else if (countfile == "not found") { countfile = ""; }
+ else { m->setCountTableFile(countfile); }
+
//check for optional parameter and set defaults
// ...at some point should added some additional type checking...
label = validParameter.validFile(parameters, "label", false);
}
}
+ if ((countfile != "") && (listfile == "")) { m->mothurOut("[ERROR]: You can only use the count file with a list file, aborting.\n"); abort = true; }
//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 = m->hasPath(inputfile); }
filename = getOutputFileName("sabund", variables);
m->openOutputFile(filename, out);
- input = new InputData(inputfile, format);
- sabund = input->getSAbundVector();
- string lastLabel = sabund->getLabel();
-
-
- //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
- set<string> processedLabels;
- set<string> userLabels = labels;
-
- if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete sabund; delete input; return 0; }
-
-
- while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
-
- if(allLines == 1 || labels.count(sabund->getLabel()) == 1){
+ if (countfile != "") {
+ processList(out);
+ }else {
+ InputData input(inputfile, format);
+ SAbundVector* sabund = input.getSAbundVector();
+ string lastLabel = sabund->getLabel();
+
+
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = labels;
+
+ if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete sabund; return 0; }
+
+
+ while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+
+ if(allLines == 1 || labels.count(sabund->getLabel()) == 1){
m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
sabund->print(out);
- if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete sabund; delete input; return 0; }
-
+ if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete sabund; return 0; }
+
processedLabels.insert(sabund->getLabel());
userLabels.erase(sabund->getLabel());
- }
-
- if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
+ }
+
+ if ((m->anyLabelsToProcess(sabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
string saveLabel = sabund->getLabel();
- delete sabund;
- sabund = (input->getSAbundVector(lastLabel));
+ delete sabund;
+ sabund = (input.getSAbundVector(lastLabel));
m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
sabund->print(out);
- if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete sabund; delete input; return 0; }
-
+ if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete sabund; return 0; }
+
processedLabels.insert(sabund->getLabel());
userLabels.erase(sabund->getLabel());
//restore real lastlabel to save below
sabund->setLabel(saveLabel);
- }
-
-
- lastLabel = sabund->getLabel();
-
- delete sabund;
- sabund = (input->getSAbundVector());
- }
-
- //output error messages about any remaining user labels
- set<string>::iterator it;
- bool needToRun = false;
- for (it = userLabels.begin(); it != userLabels.end(); it++) {
- m->mothurOut("Your file does not include the label " + *it);
- if (processedLabels.count(lastLabel) != 1) {
- m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
- needToRun = true;
- }else {
- m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
- }
+ }
+
+
+ lastLabel = sabund->getLabel();
+
+ delete sabund;
+ sabund = (input.getSAbundVector());
+ }
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ m->mothurOut("Your file does not include the label " + *it);
+ if (processedLabels.count(lastLabel) != 1) {
+ m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
+ needToRun = true;
+ }else {
+ m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
+ }
+ }
+
+ //run last label if you need to
+ if (needToRun == true) {
+ if (sabund != NULL) { delete sabund; }
+ sabund = (input.getSAbundVector(lastLabel));
+
+ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
+ sabund->print(out);
+ delete sabund;
+
+ if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); return 0; }
+
+ }
}
-
- //run last label if you need to
- if (needToRun == true) {
- if (sabund != NULL) { delete sabund; }
- sabund = (input->getSAbundVector(lastLabel));
-
- m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
- sabund->print(out);
- delete sabund;
-
- if (m->control_pressed) { outputTypes.clear(); out.close(); m->mothurRemove(filename); delete input; return 0; }
-
- }
-
out.close();
- delete input;
+
+ if (m->control_pressed) { outputTypes.clear(); m->mothurRemove(filename); return 0; }
m->mothurOutEndLine();
m->mothurOut("Output File Names: "); m->mothurOutEndLine();
exit(1);
}
}
+//**********************************************************************************************************************
+int GetSAbundCommand::processList(ofstream& out){
+ try {
+ CountTable ct;
+ ct.readTable(countfile);
+
+ InputData input(inputfile, format);
+ ListVector* list = input.getListVector();
+ string lastLabel = list->getLabel();
+
+ //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
+ set<string> processedLabels;
+ set<string> userLabels = labels;
+
+ if (m->control_pressed) { delete list; return 0; }
+
+ while((list != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+
+ if(allLines == 1 || labels.count(list->getLabel()) == 1){
+ m->mothurOut(list->getLabel()); m->mothurOutEndLine();
+
+ if (m->control_pressed) { delete list; return 0; }
+
+ RAbundVector* rabund = new RAbundVector();
+ createRabund(ct, list, rabund);
+ SAbundVector sabund = rabund->getSAbundVector();
+ sabund.print(out);
+ delete rabund;
+
+ processedLabels.insert(list->getLabel());
+ userLabels.erase(list->getLabel());
+ }
+
+ if ((m->anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
+ string saveLabel = list->getLabel();
+
+ delete list;
+ list = input.getListVector(lastLabel);
+
+ m->mothurOut(list->getLabel()); m->mothurOutEndLine();
+
+ if (m->control_pressed) { delete list; return 0; }
+
+ RAbundVector* rabund = new RAbundVector();
+ createRabund(ct, list, rabund);
+ SAbundVector sabund = rabund->getSAbundVector();
+ sabund.print(out);
+ delete rabund;
+
+ processedLabels.insert(list->getLabel());
+ userLabels.erase(list->getLabel());
+
+ //restore real lastlabel to save below
+ list->setLabel(saveLabel);
+ }
+
+ lastLabel = list->getLabel();
+
+ delete list;
+ list = input.getListVector();
+ }
+
+ //output error messages about any remaining user labels
+ set<string>::iterator it;
+ bool needToRun = false;
+ for (it = userLabels.begin(); it != userLabels.end(); it++) {
+ m->mothurOut("Your file does not include the label " + *it);
+ if (processedLabels.count(lastLabel) != 1) {
+ m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
+ needToRun = true;
+ }else {
+ m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
+ }
+ }
+
+ //run last label if you need to
+ if (needToRun == true) {
+ if (list != NULL) { delete list; }
+ list = input.getListVector(lastLabel);
+
+ m->mothurOut(list->getLabel()); m->mothurOutEndLine();
+
+ if (m->control_pressed) { delete list; return 0; }
+
+ RAbundVector* rabund = new RAbundVector();
+ createRabund(ct, list, rabund);
+ SAbundVector sabund = rabund->getSAbundVector();
+ sabund.print(out);
+ delete rabund;
+
+ delete list;
+ }
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetSAbundCommand", "processList");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+
+int GetSAbundCommand::createRabund(CountTable& ct, ListVector*& list, RAbundVector*& rabund){
+ try {
+
+ rabund->setLabel(list->getLabel());
+ for(int i = 0; i < list->getNumBins(); i++) {
+ if (m->control_pressed) { return 0; }
+ vector<string> binNames;
+ string bin = list->get(i);
+ m->splitAtComma(bin, binNames);
+ int total = 0;
+ for (int j = 0; j < binNames.size(); j++) {
+ total += ct.getNumSeqs(binNames[j]);
+ }
+ rabund->push_back(total);
+ }
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "GetSAbundCommand", "createRabund");
+ exit(1);
+ }
+
+}
//**********************************************************************************************************************
+
+
void help() { m->mothurOut(getHelpString()); }
private:
- string filename, format, inputfile, listfile, rabundfile, outputDir;
+ string filename, format, inputfile, listfile, rabundfile, outputDir, countfile;
ofstream out;
- InputData* input;
- SAbundVector* sabund;
vector<string> outputNames;
bool abort, allLines;
set<string> labels; //holds labels to be used
string label;
+
+ int processList(ofstream& out);
+ int createRabund(CountTable& ct, ListVector*& list, RAbundVector*& rabund);
};
string extension = toString(i) + ".temp";
// Allocate memory for thread data.
- pairwiseData* tempDist = new pairwiseData((filename+extension), align, "square", Estimators[0], countends, output, alignDB, m, lines[i+1].start, lines[i+1].end, match, misMatch, gapOpen, gapExtend, longestBase, i);
+ pairwiseData* tempDist = new pairwiseData((filename+extension), align, "square", Estimators[0], countends, output, alignDB, m, lines[i+1].start, lines[i+1].end, match, misMatch, gapOpen, gapExtend, longestBase, cutoff, i);
pDataArray.push_back(tempDist);
processIDS.push_back(i);
outFile << setprecision(4);
if((output == "lt") && startLine == 0){ outFile << alignDB.getNumSeqs() << endl; }
- int countSmall = 0;
- int countAll = 0;
+
for(int i=startLine;i<endLine;i++){
if(output == "lt") {
string name = alignDB.get(i).getName();
//cout << "dist = " << dist << endl;
if(dist <= cutoff){
- if (dist < 0.01) { countSmall++; }
- countAll++;
-
if (output == "column") { outFile << alignDB.get(i).getName() << ' ' << alignDB.get(j).getName() << ' ' << dist << endl; }
}
if (output == "lt") { outFile << dist << '\t'; }
}
m->mothurOut(toString(endLine-1) + "\t" + toString(time(NULL) - startTime)); m->mothurOutEndLine();
- cout << "num less than 0.01 = " << countSmall << " of " << countAll << endl;
+
outFile.close();
delete alignment;
delete distCalculator;
SequenceDB alignDB;
pairwiseData(){}
- pairwiseData(string ofn, string al, string sq, string di, bool co, string op, SequenceDB DB, MothurOut* mout, unsigned long long st, unsigned long long en, float ma, float misMa, float gapO, float gapE, int thr, int tid) {
+ pairwiseData(string ofn, string al, string sq, string di, bool co, string op, SequenceDB DB, MothurOut* mout, unsigned long long st, unsigned long long en, float ma, float misMa, float gapO, float gapE, int thr, float cu, int tid) {
outputFileName = ofn;
m = mout;
start = st;
alignDB = DB;
count = 0;
output = op;
+ cutoff = cu;
threadID = tid;
}
};
ofstream outFile((pDataArray->outputFileName).c_str(), ios::trunc);
outFile.setf(ios::fixed, ios::showpoint);
outFile << setprecision(4);
-
- pDataArray->count = pDataArray->end;
int startTime = time(NULL);
if((pDataArray->output == "lt") && pDataArray->start == 0){ outFile << pDataArray->alignDB.getNumSeqs() << endl; }
+ pDataArray->count = 0;
for(int i=pDataArray->start;i<pDataArray->end;i++){
+ pDataArray->count++;
if(pDataArray->output == "lt") {
string name = pDataArray->alignDB.get(i).getName();
helpString += "The group parameter allows you to provide a group file so you can cluster by group. \n";
helpString += "The count parameter allows you to provide a count file so you can cluster by group. \n";
helpString += "The diffs parameter allows you to specify maximum number of mismatched bases allowed between sequences in a grouping. The default is 1.\n";
- helpString += "The topdown parameter allows you to specify whether to cluster from largest abundance to smallest or smallest to largest. Default=T, meanging largest to smallest.\n";
+ helpString += "The topdown parameter allows you to specify whether to cluster from largest abundance to smallest or smallest to largest. Default=T, meaning largest to smallest.\n";
helpString += "The pre.cluster command should be in the following format: \n";
helpString += "pre.cluster(fasta=yourFastaFile, names=yourNamesFile, diffs=yourMaxDiffs) \n";
helpString += "Example pre.cluster(fasta=amazon.fasta, diffs=2).\n";
try {
m->setGroups(Groups);
- string thisOutputDir = outputDir;
- if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); }
- map<string, string> variables;
- variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile));
- variables["[extension]"] = m->getExtension(sharedfile);
- string outputFileName = getOutputFileName("shared", variables);
- outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName);
-
- ofstream out;
- m->openOutputFile(outputFileName, out);
-
//if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
InputData input(sharedfile, "sharedfile");
vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
- if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } out.close(); return 0; }
+ if (m->control_pressed) { for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } return 0; }
if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){
processedLabels.insert(lookup[0]->getLabel());
userLabels.erase(lookup[0]->getLabel());
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
- processLookup(lookup, out);
+ processLookup(lookup);
}
if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
processedLabels.insert(lookup[0]->getLabel());
userLabels.erase(lookup[0]->getLabel());
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
- processLookup(lookup, out);
+ processLookup(lookup);
//restore real lastlabel to save below
lookup[0]->setLabel(saveLabel);
lookup = input.getSharedRAbundVectors();
}
- if (m->control_pressed) { out.close(); return 0; }
+ if (m->control_pressed) { return 0; }
//output error messages about any remaining user labels
set<string>::iterator it;
lookup = input.getSharedRAbundVectors(lastLabel);
m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
-
- if (!m->printedHeaders) { lookup[0]->printHeaders(out); }
- processLookup(lookup, out);
+ processLookup(lookup);
for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
}
}
}
//**********************************************************************************************************************
-int RemoveRareCommand::processLookup(vector<SharedRAbundVector*>& lookup, ofstream& out){
+int RemoveRareCommand::processLookup(vector<SharedRAbundVector*>& lookup){
try {
+ string thisOutputDir = outputDir;
+ if (outputDir == "") { thisOutputDir += m->hasPath(sharedfile); }
+ map<string, string> variables;
+ variables["[filename]"] = thisOutputDir + m->getRootName(m->getSimpleName(sharedfile));
+ variables["[extension]"] = m->getExtension(sharedfile);
+ variables["[tag]"] = lookup[0]->getLabel();
+ string outputFileName = getOutputFileName("shared", variables);
+ outputTypes["shared"].push_back(outputFileName); outputNames.push_back(outputFileName);
+
+ ofstream out;
+ m->openOutputFile(outputFileName, out);
+
vector<SharedRAbundVector> newRabunds; newRabunds.resize(lookup.size());
+ vector<string> headers;
for (int i = 0; i < lookup.size(); i++) {
newRabunds[i].setGroup(lookup[i]->getGroup());
newRabunds[i].setLabel(lookup[i]->getLabel());
for (int i = 0; i < lookup[0]->getNumBins(); i++) {
bool allZero = true;
- if (m->control_pressed) { return 0; }
+ if (m->control_pressed) { out.close(); return 0; }
//for each group
for (int j = 0; j < lookup.size(); j++) {
//eliminates zero otus
if (allZero) { for (int j = 0; j < newRabunds.size(); j++) { newRabunds[j].pop_back(); } }
+ else { headers.push_back(m->currentBinLabels[i]); }
}
}else {
//for each otu
for (int i = 0; i < lookup[0]->getNumBins(); i++) {
- if (m->control_pressed) { return 0; }
+ if (m->control_pressed) { out.close(); return 0; }
int totalAbund = 0;
//get total otu abundance
//eliminates otus below rare cutoff
if (totalAbund <= nseqs) { for (int j = 0; j < newRabunds.size(); j++) { newRabunds[j].pop_back(); } }
+ else { headers.push_back(m->currentBinLabels[i]); }
}
}
//do we have any otus above the rare cutoff
- if (newRabunds[0].getNumBins() != 0) {
+ if (newRabunds[0].getNumBins() != 0) {
+ out << "label\tGroup\tnumOtus\t";
+ for (int j = 0; j < headers.size(); j++) { out << headers[j] << '\t'; }
+ out << endl;
for (int j = 0; j < newRabunds.size(); j++) {
out << newRabunds[j].getLabel() << '\t' << newRabunds[j].getGroup() << '\t';
newRabunds[j].print(out);
}
}
+ out.close();
+
return 0;
}
catch(exception& e) {
int processRabund();
int processList();
int processShared();
- int processLookup(vector<SharedRAbundVector*>&, ofstream&);
+ int processLookup(vector<SharedRAbundVector*>&);
};
if (hasPairedBarcodes || hasPrimer) {
pairedOligos = true;
if ((primers.size() != 0) || (barcodes.size() != 0) || (linker.size() != 0) || (spacer.size() != 0) || (revPrimer.size() != 0)) { m->control_pressed = true; m->mothurOut("[ERROR]: cannot mix paired primers and barcodes with non paired or linkers and spacers, quitting."); m->mothurOutEndLine(); return 0; }
- }
+ }else if (reorient) { m->mothurOut("[Warning]: cannot use checkorient without paired barcodes or primers, ignoring.\n"); m->mothurOutEndLine(); reorient = false; }
if(barcodeNameVector.size() == 0 && primerNameVector[0] == ""){ allFiles = 0; }