X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=libshuffcommand.cpp;h=e48cf33d7dd4a60405841e124a35c5250f76bd86;hb=8bc3e5b38c2317a1715f53be22fa96455868c281;hp=2ed7ee5089691c5bf02e3e39589b2dc04cc5426f;hpb=8770435f2eedcbf4e69daba716144e83da1dd939;p=mothur.git diff --git a/libshuffcommand.cpp b/libshuffcommand.cpp index 2ed7ee5..e48cf33 100644 --- a/libshuffcommand.cpp +++ b/libshuffcommand.cpp @@ -7,275 +7,416 @@ * */ -#include "libshuffcommand.h" +/* This class is designed to implement an integral form of the Cramer-von Mises statistic. + you may refer to the "Integration of Microbial Ecology and Statistics: A Test To Compare Gene Libraries" + paper in Applied and Environmental Microbiology, Sept. 2004, p. 5485-5492 0099-2240/04/$8.00+0 + DOI: 10.1128/AEM.70.9.5485-5492.2004 Copyright 2004 American Society for Microbiology for more information. */ -//********************************************************************************************************************** +#include "libshuffcommand.h" +#include "libshuff.h" +#include "slibshuff.h" +#include "dlibshuff.h" -LibShuffCommand::LibShuffCommand(){ +//********************************************************************************************************************** +vector LibShuffCommand::getValidParameters(){ try { - globaldata = GlobalData::getInstance(); - convert(globaldata->getCutOff(), cutOff); - convert(globaldata->getIters(), iters); - convert(globaldata->getStep(), step); - form = globaldata->getForm(); - matrix = globaldata->gMatrix; - coverageFile = getRootName(globaldata->getPhylipFile()) + "coverage"; - summaryFile = getRootName(globaldata->getPhylipFile()) + "slsummary"; - openOutputFile(coverageFile, out); - openOutputFile(summaryFile, outSum); - - //set the groups to be analyzed - setGroups(); - - //file headers for coverage file - out << "D" << '\t'; - for (int i = 0; i < groupComb.size(); i++) { - out << "C" + groupComb[i] << '\t'; - } - - for (int i = 0; i < numGroups; i++) { - for (int j = 0; j < numGroups; j++) { - //don't output AA to AA - if (i != j) { - out << "Delta" + globaldata->Groups[i] + "-" + globaldata->Groups[j] << '\t'; - } - } - } - out << endl; - - numComp = numGroups*numGroups; - - coverage = new Coverage(); - + string Array[] = {"iters","groups","step","form","cutoff","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the LibShuffCommand class Function LibShuffCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "LibShuffCommand", "getValidParameters"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the LibShuffCommand class function LibShuffCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; +} +//********************************************************************************************************************** +LibShuffCommand::LibShuffCommand(){ + try { + //initialize outputTypes + vector tempOutNames; + outputTypes["coverage"] = tempOutNames; + outputTypes["libshuffsummary"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "LibShuffCommand", "LibShuffCommand"); exit(1); - } - + } } - //********************************************************************************************************************** - -LibShuffCommand::~LibShuffCommand(){ - delete coverage; +vector LibShuffCommand::getRequiredParameters(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "LibShuffCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector LibShuffCommand::getRequiredFiles(){ + try { + string Array[] = {"phylip","group"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "LibShuffCommand", "getRequiredFiles"); + exit(1); + } } - //********************************************************************************************************************** -int LibShuffCommand::execute(){ +LibShuffCommand::LibShuffCommand(string option) { try { - //deltaValues[0] = scores for the difference between AA and AB. - //cValues[0][0][0] = AA at distance 0.0, cValues[0][0][1] = AB at distance 0.0, cValues[0][0][2] = AC at distance 0.0, cValues[0][1][0] = BA at distance 0.0, cValues[0][1][1] = BB... - - sumDelta.resize(numComp-numGroups, 0.0); + globaldata = GlobalData::getInstance(); + abort = false; + Groups.clear(); - matrix->setBounds(); + //allow user to run help + if(option == "help") { help(); abort = true; } - //load distances - if (form != "discrete") { matrix->getDist(dist); } else { - float f = 0.0; - while (f <= cutOff) { - dist.push_back(f); - f += step; - } - } - - /*****************************/ - //get values for users matrix - /*****************************/ + //valid paramters for this command + string Array[] = {"iters","groups","step","form","cutoff","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); - //clear out old Values - deltaValues.clear(); - deltaValues.resize(dist.size()); - - coverage->getValues(matrix, cValues, dist, "user"); + OptionParser parser(option); + map parameters = parser.getParameters(); + + ValidParameters validParameter; - //loop through each distance and load rsumdelta - for (int p = 0; p < cValues.size(); p++) { - //find delta values - int count = 0; - for (int i = 0; i < numGroups; i++) { - for (int j = 0; j < numGroups; j++) { - //don't save AA to AA - if (i != j) { - //(Caa - Cab)^2 - deltaValues[p].push_back( (abs(cValues[p][i][i]-cValues[p][i][j]) * abs(cValues[p][i][i]-cValues[p][i][j])) ); - sumDelta[count] += deltaValues[p][count]; - count++; - } - } + //check to make sure all parameters are valid for command + for (map::iterator it = parameters.begin(); it != parameters.end(); it++) { + if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - } - printCoverageFile(); + //initialize outputTypes + vector tempOutNames; + outputTypes["coverage"] = tempOutNames; + outputTypes["libshuffsummary"] = tempOutNames; - /*******************************************************************************/ - //create and score random matrixes finding the sumDelta values for summary file - /******************************************************************************/ - - //initialize rsumDelta - rsumDelta.resize(numComp-numGroups); - for (int l = 0; l < rsumDelta.size(); l++) { - for (int w = 0; w < iters; w++) { - rsumDelta[l].push_back(0.0); + //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 += m->hasPath(globaldata->getPhylipFile()); //if user entered a file with a path then preserve it } - } - - - for (int m = 0; m < iters; m++) { - //generate random matrix in getValues - //values for random matrix + + //make sure the user has already run the read.dist command + if ((globaldata->gMatrix == NULL) || (globaldata->gGroupmap == NULL)) { + m->mothurOut("You must read in a matrix and groupfile using the read.dist command, before you use the libshuff command. "); m->mothurOutEndLine(); abort = true;; + } + + //check for optional parameter and set defaults + // ...at some point should added some additional type checking... + groups = validParameter.validFile(parameters, "groups", false); + if (groups == "not found") { groups = ""; savegroups = groups; } + else { + savegroups = groups; + m->splitAtDash(groups, Groups); + globaldata->Groups = Groups; + } + + string temp; + temp = validParameter.validFile(parameters, "iters", false); if (temp == "not found") { temp = "10000"; } + convert(temp, iters); + + temp = validParameter.validFile(parameters, "cutoff", false); if (temp == "not found") { temp = "1.0"; } + convert(temp, cutOff); + + temp = validParameter.validFile(parameters, "step", false); if (temp == "not found") { temp = "0.01"; } + convert(temp, step); + + userform = validParameter.validFile(parameters, "form", false); if (userform == "not found") { userform = "integral"; } + + if (abort == false) { - coverage->getValues(matrix, cValues, dist, "random"); + matrix = globaldata->gMatrix; //get the distance matrix + setGroups(); //set the groups to be analyzed and sorts them + + /********************************************************************************************/ + //this is needed because when we read the matrix we sort it into groups in alphabetical order + //the rest of the command and the classes used in this command assume specific order + /********************************************************************************************/ + matrix->setGroups(globaldata->gGroupmap->namesOfGroups); + vector sizes; + for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) { sizes.push_back(globaldata->gGroupmap->getNumSeqs(globaldata->gGroupmap->namesOfGroups[i])); } + matrix->setSizes(sizes); - //loop through each distance and load rsumdelta - for (int p = 0; p < cValues.size(); p++) { - //find delta values - int count = 0; - for (int i = 0; i < numGroups; i++) { - for (int j = 0; j < numGroups; j++) { - //don't save AA to AA - if (i != j) { - //(Caa - Cab)^2 - rsumDelta[count][m] += ((abs(cValues[p][i][i]-cValues[p][i][j]) * abs(cValues[p][i][i]-cValues[p][i][j]))); - count++; - } - } + + if(userform == "discrete"){ + form = new DLibshuff(matrix, iters, step, cutOff); + } + else{ + form = new SLibshuff(matrix, iters, cutOff); } - } -//cout << "iter " << m << endl; - //clear out old Values - cValues.clear(); -//cout << "random sum delta for iter " << m << endl; -//for (int i = 0; i < rsumDelta.size(); i++) { -// cout << setprecision(6) << rsumDelta[i][m] << '\t'; -//} -//cout << endl; - } + } + catch(exception& e) { + m->errorOut(e, "LibShuffCommand", "LibShuffCommand"); + exit(1); + } +} +//********************************************************************************************************************** + +void LibShuffCommand::help(){ + try { + m->mothurOut("The libshuff command can only be executed after a successful read.dist command including a groupfile.\n"); + m->mothurOut("The libshuff command parameters are groups, iters, step, form and cutoff. No parameters are required.\n"); + m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 2 valid groups.\n"); + m->mothurOut("The group names are separated by dashes. The iters parameter allows you to specify how many random matrices you would like compared to your matrix.\n"); + m->mothurOut("The step parameter allows you to specify change in distance you would like between each output if you are using the discrete form.\n"); + m->mothurOut("The form parameter allows you to specify if you would like to analyze your matrix using the discrete or integral form. Your options are integral or discrete.\n"); + m->mothurOut("The libshuff command should be in the following format: libshuff(groups=yourGroups, iters=yourIters, cutOff=yourCutOff, form=yourForm, step=yourStep).\n"); + m->mothurOut("Example libshuff(groups=A-B-C, iters=500, form=discrete, step=0.01, cutOff=2.0).\n"); + m->mothurOut("The default value for groups is all the groups in your groupfile, iters is 10000, cutoff is 1.0, form is integral and step is 0.01.\n"); + m->mothurOut("The libshuff command output two files: .coverage and .slsummary their descriptions are in the manual.\n"); + m->mothurOut("Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e.yourIters).\n\n"); + } + catch(exception& e) { + m->errorOut(e, "LibShuffCommand", "help"); + exit(1); + } +} + +//********************************************************************************************************************** + +int LibShuffCommand::execute(){ + try { + + if (abort == true) { return 0; } + + 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;icontrol_pressed) { outputTypes.clear(); delete form; globaldata->Groups.clear(); delete globaldata->gMatrix; globaldata->gMatrix = NULL; return 0; } - /**********************************************************/ - //find the signifigance of the user matrix' sumdelta values - /**********************************************************/ + Progress* reading = new Progress(); - for (int t = 0; t < rsumDelta.size(); t++) { - //sort rsumDelta t - sort(rsumDelta[t].begin(), rsumDelta[t].end()); - - //the index of the score higher than yours is returned - //so if you have 1000 random matrices the index returned is 100 - //then there are 900 matrices with a score greater then you. - //giving you a signifigance of 0.900 - int index = findIndex(sumDelta[t], t); - - //the signifigance is the number of trees with the users score or higher - sumDeltaSig.push_back((iters-index)/(float)iters); + for(int i=0;icontrol_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;pcontrol_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(); } + m->mothurOutEndLine(); return 0; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the LibShuffCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "LibShuffCommand", "execute"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the LibShuffCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } + //********************************************************************************************************************** -void LibShuffCommand::printCoverageFile() { + +int LibShuffCommand::printCoverageFile() { try { - //format output - out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint); + + ofstream outCov; + 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); - //loop through each distance - for (int p = 0; p < cValues.size(); p++) { - out << setprecision(6) << dist[p] << '\t'; - //print out coverage values - for (int i = 0; i < numGroups; i++) { - for (int j = 0; j < numGroups; j++) { - out << cValues[p][i][j] << '\t'; + map > allDistances; + map >::iterator it; + + vector > indices(numGroups); + int numIndices = numGroups * numGroups; + + int index = 0; + for(int i=0;igGroupmap->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 k=0;kcontrol_pressed) { outCov.close(); return 0; } + + if(allDistances[savedMinValues[spoti][spotj][k]].size() != 0){ + allDistances[savedMinValues[spoti][spotj][k]][indices[i][j]]++; + } + else{ + allDistances[savedMinValues[spoti][spotj][k]].assign(numIndices, 0); + allDistances[savedMinValues[spoti][spotj][k]][indices[i][j]] = 1; + } } } - - for (int h = 0; h < deltaValues[p].size(); h++) { - out << deltaValues[p][h] << '\t'; + } + it=allDistances.begin(); + + //cout << setprecision(8); + + vector prevRow = it->second; + it++; + + for(;it!=allDistances.end();it++){ + for(int i=0;isecond.size();i++){ + it->second[i] += prevRow[i]; } - - out << endl; + prevRow = it->second; + } + + vector lastRow = allDistances.rbegin()->second; + outCov << setprecision(8); + + outCov << "dist"; + for (int i = 0; i < numGroups; i++){ + outCov << '\t' << groupNames[i]; } + for (int i=0;icontrol_pressed) { outCov.close(); return 0; } + outCov << '\t' << groupNames[i] << '-' << groupNames[j] << '\t'; + outCov << groupNames[j] << '-' << groupNames[i]; + } + } + outCov << endl; + for(it=allDistances.begin();it!=allDistances.end();it++){ + outCov << it->first << '\t'; + for(int i=0;isecond[indices[i][i]]/(float)lastRow[indices[i][i]] << '\t'; + } + for(int i=0;icontrol_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) { - cout << "Standard Error: " << e.what() << " has occurred in the LibShuffCommand class Function printCoverageFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "LibShuffCommand", "printCoverageFile"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the LibShuffCommand class function printCoverageFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } + //********************************************************************************************************************** -void LibShuffCommand::printSummaryFile() { + +int LibShuffCommand::printSummaryFile() { try { - //format output + + ofstream outSum; + 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); - for (int i = 0; i < numGroups; i++) { - for (int j = 0; j < numGroups; j++) { - //don't output AA to AA - if (i != j) { - outSum << "Delta " + globaldata->Groups[i] + "-" + globaldata->Groups[j] << '\t'<< "DeltaSig " + globaldata->Groups[i] + "-" + globaldata->Groups[j] << '\t'; - cout << "Delta " + globaldata->Groups[i] + "-" + globaldata->Groups[j] << '\t'<< "DeltaSig " + globaldata->Groups[i] + "-" + globaldata->Groups[j] << '\t'; + cout << setw(20) << left << "Comparison" << '\t' << setprecision(8) << "dCXYScore" << '\t' << "Significance" << endl; + m->mothurOutJustToLog("Comparison\tdCXYScore\tSignificance"); m->mothurOutEndLine(); + outSum << setw(20) << left << "Comparison" << '\t' << setprecision(8) << "dCXYScore" << '\t' << "Significance" << endl; + + int precision = (int)log10(iters); + for(int i=0;icontrol_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]]; + + if(pValueCounts[i][j]){ + cout << setw(20) << left << groupNames[i]+'-'+groupNames[j] << '\t' << setprecision(8) << savedDXYValues[spoti][spotj] << '\t' << setprecision(precision) << pValueCounts[i][j]/(float)iters << endl; + m->mothurOutJustToLog(groupNames[i]+"-"+groupNames[j] + "\t" + toString(savedDXYValues[spoti][spotj]) + "\t" + toString((pValueCounts[i][j]/(float)iters))); m->mothurOutEndLine(); + outSum << setw(20) << left << groupNames[i]+'-'+groupNames[j] << '\t' << setprecision(8) << savedDXYValues[spoti][spotj] << '\t' << setprecision(precision) << pValueCounts[i][j]/(float)iters << endl; + } + else{ + cout << setw(20) << left << groupNames[i]+'-'+groupNames[j] << '\t' << setprecision(8) << savedDXYValues[spoti][spotj] << '\t' << '<' <mothurOutJustToLog(groupNames[i]+"-"+groupNames[j] + "\t" + toString(savedDXYValues[spoti][spotj]) + "\t" + toString((1/(float)iters))); m->mothurOutEndLine(); + outSum << setw(20) << left << groupNames[i]+'-'+groupNames[j] << '\t' << setprecision(8) << savedDXYValues[spoti][spotj] << '\t' << '<' <mothurOutJustToLog(groupNames[j]+"-"+groupNames[i] + "\t" + toString(savedDXYValues[spotj][spoti]) + "\t" + toString((pValueCounts[j][i]/(float)iters))); m->mothurOutEndLine(); + outSum << setw(20) << left << groupNames[j]+'-'+groupNames[i] << '\t' << setprecision(8) << savedDXYValues[spotj][spoti] << '\t' << setprecision (precision) << pValueCounts[j][i]/(float)iters << endl; + } + else{ + cout << setw(20) << left << groupNames[j]+'-'+groupNames[i] << '\t' << setprecision(8) << savedDXYValues[spotj][spoti] << '\t' << '<' <mothurOutJustToLog(groupNames[j]+"-"+groupNames[i] + "\t" + toString(savedDXYValues[spotj][spoti]) + "\t" + toString((1/(float)iters))); m->mothurOutEndLine(); + outSum << setw(20) << left << groupNames[j]+'-'+groupNames[i] << '\t' << setprecision(8) << savedDXYValues[spotj][spoti] << '\t' << '<' < (1/(float)iters)) { - outSum << setprecision(6) << sumDelta[i] << '\t' << setprecision(globaldata->getIters().length()) << sumDeltaSig[i] << '\t'; - cout << setprecision(6) << sumDelta[i] << '\t' << setprecision(globaldata->getIters().length()) << sumDeltaSig[i] << '\t'; - }else { - outSum << setprecision(6) << sumDelta[i] << '\t' << setprecision(globaldata->getIters().length()) << "<" << (1/float(iters)) << '\t'; - cout << setprecision(6) << sumDelta[i] << '\t' << setprecision(globaldata->getIters().length()) << "<" << (1/float(iters)) << '\t'; } } - outSum << endl; - cout << endl; - + outSum.close(); + return 0; } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the LibShuffCommand class Function printSummaryFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "LibShuffCommand", "printSummaryFile"); exit(1); } - catch(...) { - cout << "An unknown error has occurred in the LibShuffCommand class function printSummaryFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } } //********************************************************************************************************************** + void LibShuffCommand::setGroups() { try { //if the user has not entered specific groups to analyze then do them all @@ -284,14 +425,14 @@ void LibShuffCommand::setGroups() { for (int i=0; i < numGroups; i++) { globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]); } - }else { - if (globaldata->getGroups() != "all") { + } else { + if (savegroups != "all") { //check that groups are valid for (int i = 0; i < globaldata->Groups.size(); i++) { if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) { - cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl; + m->mothurOut(globaldata->Groups[i] + " is not a valid group, and will be disregarded."); m->mothurOutEndLine(); // erase the invalid group from globaldata->Groups - globaldata->Groups.erase (globaldata->Groups.begin()+i); + globaldata->Groups.erase(globaldata->Groups.begin()+i); } } @@ -301,9 +442,9 @@ void LibShuffCommand::setGroups() { for (int i=0; i < numGroups; i++) { globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]); } - cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile." << endl; - }else { numGroups = globaldata->Groups.size(); } - }else { //users wants all groups + m->mothurOut("When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile."); m->mothurOutEndLine(); + } else { numGroups = globaldata->Groups.size(); } + } else { //users wants all groups numGroups = globaldata->gGroupmap->getNumGroups(); globaldata->Groups.clear(); for (int i=0; i < numGroups; i++) { @@ -311,44 +452,22 @@ void LibShuffCommand::setGroups() { } } } - + //sort so labels match sort(globaldata->Groups.begin(), globaldata->Groups.end()); - // number of comparisons i.e. with groups A,B,C = AA, AB, AC, BA, BB, BC...; - for (int i=0; iGroups[i] + "-" + globaldata->Groups[l]); - } - } - } - catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the LibShuffCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the LibShuffCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } -} -/***********************************************************/ -int LibShuffCommand::findIndex(float score, int index) { - try{ - for (int i = 0; i < rsumDelta[index].size(); i++) { - if (rsumDelta[index][i] >= score) { return i; } - } - return rsumDelta[index].size(); + //sort + sort(globaldata->gGroupmap->namesOfGroups.begin(), globaldata->gGroupmap->namesOfGroups.end()); + + for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) { globaldata->gGroupmap->groupIndex[globaldata->gGroupmap->namesOfGroups[i]] = i; } + + groupNames = globaldata->Groups; + } catch(exception& e) { - cout << "Standard Error: " << e.what() << " has occurred in the LibShuffCommand class Function findIndex. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; - exit(1); - } - catch(...) { - cout << "An unknown error has occurred in the LibShuffCommand class function findIndex. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + m->errorOut(e, "LibShuffCommand", "setGroups"); exit(1); } } /***********************************************************/ -