#include "slibshuff.h"
#include "dlibshuff.h"
+//**********************************************************************************************************************
+vector<string> LibShuffCommand::getValidParameters(){
+ try {
+ string Array[] = {"iters","groups","step","form","cutoff","outputdir","inputdir"};
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "LibShuffCommand", "getValidParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+LibShuffCommand::LibShuffCommand(){
+ try {
+ abort = true; calledHelp = true;
+ vector<string> tempOutNames;
+ outputTypes["coverage"] = tempOutNames;
+ outputTypes["libshuffsummary"] = tempOutNames;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "LibShuffCommand", "LibShuffCommand");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> LibShuffCommand::getRequiredParameters(){
+ try {
+ vector<string> myArray;
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "LibShuffCommand", "getRequiredParameters");
+ exit(1);
+ }
+}
+//**********************************************************************************************************************
+vector<string> LibShuffCommand::getRequiredFiles(){
+ try {
+ string Array[] = {"phylip","group"};
+ vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+ return myArray;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "LibShuffCommand", "getRequiredFiles");
+ exit(1);
+ }
+}
//**********************************************************************************************************************
LibShuffCommand::LibShuffCommand(string option) {
try {
globaldata = GlobalData::getInstance();
- abort = false;
+ abort = false; calledHelp = false;
Groups.clear();
//allow user to run help
- if(option == "help") { help(); abort = true; }
+ if(option == "help") { help(); abort = true; calledHelp = true; }
else {
//valid paramters for this command
if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
}
+ //initialize outputTypes
+ vector<string> tempOutNames;
+ outputTypes["coverage"] = tempOutNames;
+ outputTypes["libshuffsummary"] = tempOutNames;
+
//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 = "";
- outputDir += hasPath(globaldata->getPhylipFile()); //if user entered a file with a path then preserve it
+ outputDir += m->hasPath(globaldata->getPhylipFile()); //if user entered a file with a path then preserve it
}
//make sure the user has already run the read.dist command
if (groups == "not found") { groups = ""; savegroups = groups; }
else {
savegroups = groups;
- splitAtDash(groups, Groups);
+ m->splitAtDash(groups, Groups);
globaldata->Groups = Groups;
}
int LibShuffCommand::execute(){
try {
- if (abort == true) { return 0; }
+ if (abort == true) { if (calledHelp) { return 0; } return 2; }
savedDXYValues = form->evaluateAll();
savedMinValues = form->getSavedMins();
+
+ if (m->control_pressed) { delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; return 0; }
pValueCounts.resize(numGroups);
for(int i=0;i<numGroups;i++){
pValueCounts[i].assign(numGroups, 0);
}
-
+
+ if (m->control_pressed) { outputTypes.clear(); delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; return 0; }
+
Progress* reading = new Progress();
for(int i=0;i<numGroups-1;i++) {
for(int j=i+1;j<numGroups;j++) {
+
+ if (m->control_pressed) { outputTypes.clear(); delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; }
+
reading->newLine(groupNames[i]+'-'+groupNames[j], iters);
int spoti = globaldata->gGroupmap->groupIndex[groupNames[i]]; //neccessary in case user selects groups so you know where they are in the matrix
int spotj = globaldata->gGroupmap->groupIndex[groupNames[j]];
- for(int p=0;p<iters;p++) {
+ for(int p=0;p<iters;p++) {
+
+ if (m->control_pressed) { outputTypes.clear(); delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; }
+
form->randomizeGroups(spoti,spotj);
if(form->evaluatePair(spoti,spotj) >= savedDXYValues[spoti][spotj]) { pValueCounts[i][j]++; }
if(form->evaluatePair(spotj,spoti) >= savedDXYValues[spotj][spoti]) { pValueCounts[j][i]++; }
+
+ if (m->control_pressed) { outputTypes.clear(); delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; }
+
reading->update(p);
}
form->resetGroup(spoti);
form->resetGroup(spotj);
}
}
+
+ if (m->control_pressed) { outputTypes.clear(); delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; delete reading; return 0; }
+
reading->finish();
delete reading;
m->mothurOutEndLine();
printSummaryFile();
printCoverageFile();
-
+
//clear out users groups
globaldata->Groups.clear();
delete form;
//delete globaldata's copy of the gmatrix to free up memory
delete globaldata->gMatrix; globaldata->gMatrix = NULL;
+ if (m->control_pressed) { outputTypes.clear(); 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(); }
//**********************************************************************************************************************
-void LibShuffCommand::printCoverageFile() {
+int LibShuffCommand::printCoverageFile() {
try {
ofstream outCov;
- summaryFile = outputDir + getRootName(getSimpleName(globaldata->getPhylipFile())) + "libshuff.coverage";
- openOutputFile(summaryFile, outCov);
- outputNames.push_back(summaryFile);
+ summaryFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getPhylipFile())) + "libshuff.coverage";
+ m->openOutputFile(summaryFile, outCov);
+ outputNames.push_back(summaryFile); outputTypes["coverage"].push_back(summaryFile);
outCov.setf(ios::fixed, ios::floatfield); outCov.setf(ios::showpoint);
//cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint);
int spotj = globaldata->gGroupmap->groupIndex[groupNames[j]];
for(int k=0;k<savedMinValues[spoti][spotj].size();k++){
+
+ if(m->control_pressed) { outCov.close(); return 0; }
+
if(allDistances[savedMinValues[spoti][spotj][k]].size() != 0){
allDistances[savedMinValues[spoti][spotj][k]][indices[i][j]]++;
}
}
for (int i=0;i<numGroups;i++){
for(int j=i+1;j<numGroups;j++){
+ if(m->control_pressed) { outCov.close(); return 0; }
outCov << '\t' << groupNames[i] << '-' << groupNames[j] << '\t';
outCov << groupNames[j] << '-' << groupNames[i];
}
}
for(int i=0;i<numGroups;i++){
for(int j=i+1;j<numGroups;j++){
+ if(m->control_pressed) { outCov.close(); return 0; }
+
outCov << it->second[indices[i][j]]/(float)lastRow[indices[i][j]] << '\t';
outCov << it->second[indices[j][i]]/(float)lastRow[indices[j][i]] << '\t';
}
outCov << endl;
}
outCov.close();
+
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "LibShuffCommand", "printCoverageFile");
//**********************************************************************************************************************
-void LibShuffCommand::printSummaryFile() {
+int LibShuffCommand::printSummaryFile() {
try {
ofstream outSum;
- summaryFile = outputDir + getRootName(getSimpleName(globaldata->getPhylipFile())) + "libshuff.summary";
- openOutputFile(summaryFile, outSum);
- outputNames.push_back(summaryFile);
+ summaryFile = outputDir + m->getRootName(m->getSimpleName(globaldata->getPhylipFile())) + "libshuff.summary";
+ m->openOutputFile(summaryFile, outSum);
+ outputNames.push_back(summaryFile); outputTypes["libshuffsummary"].push_back(summaryFile);
outSum.setf(ios::fixed, ios::floatfield); outSum.setf(ios::showpoint);
cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint);
int precision = (int)log10(iters);
for(int i=0;i<numGroups;i++){
for(int j=i+1;j<numGroups;j++){
+ if(m->control_pressed) { outSum.close(); return 0; }
+
int spoti = globaldata->gGroupmap->groupIndex[groupNames[i]]; //neccessary in case user selects groups so you know where they are in the matrix
int spotj = globaldata->gGroupmap->groupIndex[groupNames[j]];
}
outSum.close();
+ return 0;
}
catch(exception& e) {
m->errorOut(e, "LibShuffCommand", "printSummaryFile");