//**********************************************************************************************************************
-SummaryCommand::SummaryCommand(string option){
+SummaryCommand::SummaryCommand(string option) {
try {
globaldata = GlobalData::getInstance();
abort = false;
}
//make sure the user has already run the read.otu command
- if ((globaldata->getSharedFile() == "") && (globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { mothurOut("You must read a list, sabund, rabund or shared file before you can use the summary.single command."); mothurOutEndLine(); abort = true; }
+ if ((globaldata->getSharedFile() == "") && (globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { m->mothurOut("You must read a list, sabund, rabund or shared file before you can use the summary.single command."); m->mothurOutEndLine(); 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"){
}
}
catch(exception& e) {
- errorOut(e, "SummaryCommand", "SummaryCommand");
+ m->errorOut(e, "SummaryCommand", "SummaryCommand");
exit(1);
}
}
void SummaryCommand::help(){
try {
- mothurOut("The summary.single command can only be executed after a successful read.otu WTIH ONE EXECEPTION.\n");
- mothurOut("The summary.single command can be executed after a successful cluster command. It will use the .list file from the output of the cluster.\n");
- mothurOut("The summary.single command parameters are label, calc, abund. No parameters are required.\n");
- mothurOut("The summary.single command should be in the following format: \n");
- mothurOut("summary.single(label=yourLabel, calc=yourEstimators).\n");
- mothurOut("Example summary.single(label=unique-.01-.03, calc=sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson).\n");
+ m->mothurOut("The summary.single command can only be executed after a successful read.otu WTIH ONE EXECEPTION.\n");
+ m->mothurOut("The summary.single command can be executed after a successful cluster command. It will use the .list file from the output of the cluster.\n");
+ m->mothurOut("The summary.single command parameters are label, calc, abund. No parameters are required.\n");
+ m->mothurOut("The summary.single command should be in the following format: \n");
+ m->mothurOut("summary.single(label=yourLabel, calc=yourEstimators).\n");
+ m->mothurOut("Example summary.single(label=unique-.01-.03, calc=sobs-chao-ace-jack-bootstrap-shannon-npshannon-simpson).\n");
validCalculator->printCalc("summary", cout);
- mothurOut("The default value calc is sobs-chao-ace-jack-shannon-npshannon-simpson\n");
- mothurOut("The label parameter is used to analyze specific labels in your input.\n");
- mothurOut("Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabels).\n\n");
+ m->mothurOut("The default value calc is sobs-chao-ace-jack-shannon-npshannon-simpson\n");
+ m->mothurOut("The label parameter is used to analyze specific labels in your input.\n");
+ m->mothurOut("Note: No spaces between parameter labels (i.e. label), '=' and parameters (i.e.yourLabels).\n\n");
}
catch(exception& e) {
- errorOut(e, "SummaryCommand", "help");
+ m->errorOut(e, "SummaryCommand", "help");
exit(1);
}
}
if (abort == true) { return 0; }
+ vector<string> outputNames;
+
if ((globaldata->getFormat() != "sharedfile")) { inputFileNames.push_back(globaldata->inputFileName); }
else { inputFileNames = parseSharedFile(globaldata->getSharedFile()); globaldata->setFormat("rabund"); }
+ if (m->control_pressed) { return 0; }
+
for (int p = 0; p < inputFileNames.size(); p++) {
string fileNameRoot = outputDir + getRootName(getSimpleName(inputFileNames[p])) + "summary";
globaldata->inputFileName = inputFileNames[p];
+ outputNames.push_back(fileNameRoot);
if (inputFileNames.size() > 1) {
- mothurOutEndLine(); mothurOut("Processing group " + groups[p]); mothurOutEndLine(); mothurOutEndLine();
+ m->mothurOutEndLine(); m->mothurOut("Processing group " + groups[p]); m->mothurOutEndLine(); m->mothurOutEndLine();
}
sumCalculators.clear();
set<string> processedLabels;
set<string> userLabels = labels;
+ if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = NULL; delete input; globaldata->ginput = NULL; return 0; }
+
while((sabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
+ if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = NULL; delete input; globaldata->ginput = NULL; return 0; }
+
if(allLines == 1 || labels.count(sabund->getLabel()) == 1){
- mothurOut(sabund->getLabel()); mothurOutEndLine();
+ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
processedLabels.insert(sabund->getLabel());
userLabels.erase(sabund->getLabel());
outputFileHandle << sabund->getLabel();
for(int i=0;i<sumCalculators.size();i++){
vector<double> data = sumCalculators[i]->getValues(sabund);
+
+ if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = NULL; delete input; globaldata->ginput = NULL; return 0; }
+
outputFileHandle << '\t';
sumCalculators[i]->print(outputFileHandle);
}
delete sabund;
sabund = input->getSAbundVector(lastLabel);
- mothurOut(sabund->getLabel()); mothurOutEndLine();
+ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
processedLabels.insert(sabund->getLabel());
userLabels.erase(sabund->getLabel());
outputFileHandle << sabund->getLabel();
for(int i=0;i<sumCalculators.size();i++){
vector<double> data = sumCalculators[i]->getValues(sabund);
+
+ if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = NULL; delete input; globaldata->ginput = NULL; return 0; }
+
outputFileHandle << '\t';
sumCalculators[i]->print(outputFileHandle);
}
sabund = input->getSAbundVector();
}
+ if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete validCalculator; delete read; delete input; globaldata->ginput = NULL; return 0; }
+
//output error messages about any remaining user labels
set<string>::iterator it;
bool needToRun = false;
for (it = userLabels.begin(); it != userLabels.end(); it++) {
- mothurOut("Your file does not include the label " + *it);
+ m->mothurOut("Your file does not include the label " + *it);
if (processedLabels.count(lastLabel) != 1) {
- mothurOut(". I will use " + lastLabel + "."); mothurOutEndLine();
+ m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
needToRun = true;
}else {
- mothurOut(". Please refer to " + lastLabel + "."); mothurOutEndLine();
+ m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
}
}
if (sabund != NULL) { delete sabund; }
sabund = input->getSAbundVector(lastLabel);
- mothurOut(sabund->getLabel()); mothurOutEndLine();
+ m->mothurOut(sabund->getLabel()); m->mothurOutEndLine();
outputFileHandle << sabund->getLabel();
for(int i=0;i<sumCalculators.size();i++){
vector<double> data = sumCalculators[i]->getValues(sabund);
+
+ if (m->control_pressed) { outputFileHandle.close(); for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete validCalculator; delete read; delete sabund; globaldata->sabund = NULL; delete input; globaldata->ginput = NULL; return 0; }
+
outputFileHandle << '\t';
sumCalculators[i]->print(outputFileHandle);
}
outputFileHandle.close();
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; } delete validCalculator; delete read; delete input; globaldata->ginput = NULL; return 0; }
+
+
delete input; globaldata->ginput = NULL;
delete read;
delete validCalculator;
globaldata->sabund = NULL;
+ for(int i=0;i<sumCalculators.size();i++){ delete sumCalculators[i]; }
}
+ if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } return 0; }
+
+ m->mothurOutEndLine();
+ m->mothurOut("Output File Names: "); m->mothurOutEndLine();
+ for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
+ m->mothurOutEndLine();
+
return 0;
}
catch(exception& e) {
- errorOut(e, "SummaryCommand", "execute");
+ m->errorOut(e, "SummaryCommand", "execute");
exit(1);
}
}
return filenames;
}
catch(exception& e) {
- errorOut(e, "SummaryCommand", "parseSharedFile");
+ m->errorOut(e, "SummaryCommand", "parseSharedFile");
exit(1);
}
}