X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=unifracweightedcommand.cpp;h=4ec2773d38eba93933015d8be8a77b8d078124bc;hb=3c5c4e255ee8c36feb9e97aebc4e792e6ff8c440;hp=fef08ff5268517744f2b185317352df28e607dd2;hpb=0190105145fbd3e02da8f23cb50841229e5d696f;p=mothur.git diff --git a/unifracweightedcommand.cpp b/unifracweightedcommand.cpp index fef08ff..4ec2773 100644 --- a/unifracweightedcommand.cpp +++ b/unifracweightedcommand.cpp @@ -20,49 +20,8 @@ UnifracWeightedCommand::UnifracWeightedCommand() { openOutputFile(weightedFile, out); sumFile = globaldata->getTreeFile() + ".wsummary"; openOutputFile(sumFile, outSum); - distFile = globaldata->getTreeFile() + ".wdistrib"; - openOutputFile(distFile, outDist); - - //if the user has not entered specific groups to analyze then do them all - if (globaldata->Groups.size() == 0) { - numGroups = tmap->getNumGroups(); - }else { - //check that groups are valid - for (int i = 0; i < globaldata->Groups.size(); i++) { - if (tmap->isValidGroup(globaldata->Groups[i]) != true) { - cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl; - // erase the invalid group from globaldata->Groups - globaldata->Groups.erase (globaldata->Groups.begin()+i); - } - } - - //if the user only entered invalid groups - if (globaldata->Groups.size() == 0) { - numGroups = tmap->getNumGroups(); - 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 if (globaldata->Groups.size() == 1) { - 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; - numGroups = tmap->getNumGroups(); - globaldata->Groups.clear(); - }else { numGroups = globaldata->Groups.size(); } - } - - //calculate number of comparisons i.e. with groups A,B,C = AB, AC, BC = 3; - numComp = 0; - int n = 1; - for (int i=1; iGroups.size() != 0) { - groupComb.push_back(globaldata->Groups[i-1]+globaldata->Groups[l]); - }else { - groupComb.push_back(tmap->namesOfGroups[i-1]+tmap->namesOfGroups[l]); - } - } - n++; - } - + + setGroups(); //sets the groups the user wants to analyze convert(globaldata->getIters(), iters); //how many random trees to generate weighted = new Weighted(tmap); @@ -88,11 +47,6 @@ int UnifracWeightedCommand::execute() { totalrscoreFreq.resize(numComp); uCumul.resize(numComp); - //format output - outDist.setf(ios::fixed, ios::floatfield); outDist.setf(ios::showpoint); - outDist << "Tree#" << '\t' << "Iter" << '\t' << "Groups"<< '\t' << "WScore" << endl; - - //create new tree with same num nodes and leaves as users randT = new Tree(); @@ -141,9 +95,6 @@ int UnifracWeightedCommand::execute() { //add random score to valid scores validScores[p][randomData[p]] = randomData[p]; - - //output info to uwdistrib file - outDist << i+1 << '\t' << '\t'<< j+1 << '\t' << '\t' << groupComb[p] << '\t'<< randomData[p] << endl; } } @@ -198,9 +149,6 @@ int UnifracWeightedCommand::execute() { printWeightedFile(); printWSummaryFile(); - //reset randomTree parameter to 0 - globaldata->setRandomTree("0"); - //clear out users groups globaldata->Groups.clear(); @@ -255,6 +203,7 @@ void UnifracWeightedCommand::printWSummaryFile() { try { //column headers outSum << "Tree#" << '\t' << "Groups" << '\t' << '\t' << "WScore" << '\t' << '\t' << "WSig" << endl; + cout << "Tree#" << '\t' << "Groups" << '\t' << '\t' << "WScore" << '\t' << '\t' << "WSig" << endl; //format output outSum.setf(ios::fixed, ios::floatfield); outSum.setf(ios::showpoint); @@ -264,6 +213,7 @@ void UnifracWeightedCommand::printWSummaryFile() { for (int i = 0; i < T.size(); i++) { for (int j = 0; j < numComp; j++) { outSum << setprecision(6) << i+1 << '\t' << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << WScoreSig[count] << endl; + cout << setprecision(6) << i+1 << '\t' << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << WScoreSig[count] << endl; count++; } } @@ -307,3 +257,61 @@ void UnifracWeightedCommand::saveRandomScores() { } /***********************************************************/ +void UnifracWeightedCommand::setGroups() { + try { + //if the user has not entered specific groups to analyze then do them all + if (globaldata->Groups.size() == 0) { + numGroups = tmap->getNumGroups(); + }else { + if (globaldata->getGroups() != "all") { + //check that groups are valid + for (int i = 0; i < globaldata->Groups.size(); i++) { + if (tmap->isValidGroup(globaldata->Groups[i]) != true) { + cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl; + // erase the invalid group from globaldata->Groups + globaldata->Groups.erase (globaldata->Groups.begin()+i); + } + } + + //if the user only entered invalid groups + if (globaldata->Groups.size() == 0) { + numGroups = tmap->getNumGroups(); + 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 if (globaldata->Groups.size() == 1) { + 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; + numGroups = tmap->getNumGroups(); + globaldata->Groups.clear(); + }else { numGroups = globaldata->Groups.size(); } + }else { //users wants all groups + numGroups = tmap->getNumGroups(); + globaldata->Groups.clear(); + globaldata->setGroups(""); + } + } + + //calculate number of comparisons i.e. with groups A,B,C = AB, AC, BC = 3; + numComp = 0; + int n = 1; + for (int i=1; iGroups.size() != 0) { + groupComb.push_back(globaldata->Groups[i-1]+globaldata->Groups[l]); + }else { + groupComb.push_back(tmap->namesOfGroups[i-1]+tmap->namesOfGroups[l]); + } + } + n++; + } + } + catch(exception& e) { + cout << "Standard Error: " << e.what() << " has occurred in the UnifracWeightedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } + catch(...) { + cout << "An unknown error has occurred in the UnifracWeightedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n"; + exit(1); + } +} +