X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=parsimonycommand.cpp;h=86f8d013c59449b96009ba07859be7e0985cc141;hb=2e5ec5cbbd23637ed20da9bdd544d178a3b5d949;hp=474f732ef9b3c448e6bfe27753df7d59c4dec300;hpb=ed04a159be4f1fab2850fa4dd2f40bf51e94e974;p=mothur.git diff --git a/parsimonycommand.cpp b/parsimonycommand.cpp index 474f732..86f8d01 100644 --- a/parsimonycommand.cpp +++ b/parsimonycommand.cpp @@ -28,8 +28,8 @@ ParsimonyCommand::ParsimonyCommand() { }else { //user wants random distribution savetmap = globaldata->gTreemap; getUserInput(); - parsFile = randomtree + ".rd_parsimony"; - openOutputFile(parsFile, out); + parsFile = randomtree; + parsFileout = globaldata->getTreeFile() + "temp"; } //set users groups to analyze @@ -51,7 +51,9 @@ ParsimonyCommand::ParsimonyCommand() { /***********************************************************/ int ParsimonyCommand::execute() { try { - + Progress* reading; + reading = new Progress("Comparing to random:", iters); + //get pscore for users tree userData.resize(numComp,0); //data = AB, AC, BC, ABC. randomData.resize(numComp,0); //data = AB, AC, BC, ABC. @@ -66,9 +68,10 @@ int ParsimonyCommand::execute() { //get pscores for users trees for (int i = 0; i < T.size(); i++) { userData = pars->getValues(T[i]); //data = AB, AC, BC, ABC. - + //output scores for each combination for(int k = 0; k < numComp; k++) { + //update uscoreFreq it = uscoreFreq[k].find(userData[k]); if (it == uscoreFreq[k].end()) {//new score @@ -87,11 +90,13 @@ int ParsimonyCommand::execute() { for (int j = 0; j < iters; j++) { //create new tree with same num nodes and leaves as users randT = new Tree(); + //create random relationships between nodes randT->assembleRandomTree(); + //get pscore of random tree randomData = pars->getValues(randT); - + for(int r = 0; r < numComp; r++) { //add trees pscore to map of scores it2 = rscoreFreq[r].find(randomData[r]); @@ -105,18 +110,24 @@ int ParsimonyCommand::execute() { validScores[randomData[r]] = randomData[r]; } + //update progress bar + reading->update(j); + delete randT; } + }else { //get pscores for random trees for (int j = 0; j < iters; j++) { //create new tree with same num nodes and leaves as users randT = new Tree(); //create random relationships between nodes + randT->assembleRandomTree(); + //get pscore of random tree randomData = pars->getValues(randT); - + for(int r = 0; r < numComp; r++) { //add trees pscore to map of scores it2 = rscoreFreq[r].find(randomData[r]); @@ -130,10 +141,13 @@ int ParsimonyCommand::execute() { validScores[randomData[r]] = randomData[r]; } + //update progress bar + reading->update(j); + delete randT; } } - + for(int a = 0; a < numComp; a++) { float rcumul = 0.0000; float ucumul = 0.0000; @@ -162,11 +176,20 @@ int ParsimonyCommand::execute() { } } + //finish progress bar + reading->finish(); + delete reading; + + printParsimonyFile(); if (randomtree == "") { printUSummaryFile(); } //reset globaldata's treemap if you just did random distrib - if (randomtree != "") { globaldata->gTreemap = savetmap; } + if (randomtree != "") { + //memory leak prevention + //if (globaldata->gTreemap != NULL) { delete globaldata->gTreemap; } + globaldata->gTreemap = savetmap; + } //reset randomTree parameter to "" globaldata->setRandomTree(""); @@ -226,8 +249,8 @@ void ParsimonyCommand::printParsimonyFile() { void ParsimonyCommand::printUSummaryFile() { try { //column headers - outSum << "Tree#" << '\t' << "Comb" << '\t' << "ParsScore" << '\t' << '\t' << "ParsSig" << endl; - cout << "Tree#" << '\t' << "Comb" << '\t' << "ParsScore" << '\t' << '\t' << "ParsSig" << endl; + outSum << "Tree#" << '\t' << "Groups" << '\t' << "ParsScore" << '\t' << "ParsSig" << endl; + cout << "Tree#" << '\t' << "Groups" << '\t' << "ParsScore" << '\t' << "ParsSig" << endl; //format output outSum.setf(ios::fixed, ios::floatfield); outSum.setf(ios::showpoint); @@ -237,11 +260,11 @@ void ParsimonyCommand::printUSummaryFile() { for (int i = 0; i< T.size(); i++) { for(int a = 0; a < numComp; a++) { if (UScoreSig[a][i] > (1/(float)iters)) { - outSum << setprecision(globaldata->getIters().length()) << i+1 << '\t' << groupComb[a] << '\t' << '\t' << userTreeScores[a][i] << '\t' << UScoreSig[a][i] << endl; - cout << setprecision(globaldata->getIters().length()) << i+1 << '\t' << groupComb[a] << '\t' << '\t' << userTreeScores[a][i] << '\t' << UScoreSig[a][i] << endl; + outSum << setprecision(6) << i+1 << '\t' << groupComb[a] << '\t' << userTreeScores[a][i] << setprecision(globaldata->getIters().length()) << '\t' << UScoreSig[a][i] << endl; + cout << setprecision(6) << i+1 << '\t' << groupComb[a] << '\t' << userTreeScores[a][i] << setprecision(globaldata->getIters().length()) << '\t' << UScoreSig[a][i] << endl; }else { - outSum << setprecision(globaldata->getIters().length()) << i+1 << '\t' << groupComb[a] << '\t' << '\t' << userTreeScores[a][i] << '\t' << "<" << (1/float(iters)) << endl; - cout << setprecision(globaldata->getIters().length()) << i+1 << '\t' << groupComb[a] << '\t' << '\t' << userTreeScores[a][i] << '\t' << "<" << (1/float(iters)) << endl; + outSum << setprecision(6) << i+1 << '\t' << groupComb[a] << '\t' << userTreeScores[a][i] << setprecision(globaldata->getIters().length()) << '\t' << "<" << (1/float(iters)) << endl; + cout << setprecision(6) << i+1 << '\t' << groupComb[a] << '\t' << userTreeScores[a][i] << setprecision(globaldata->getIters().length()) << '\t' << "<" << (1/float(iters)) << endl; } } } @@ -293,6 +316,8 @@ void ParsimonyCommand::getUserInput() { getline(cin, s); //save tmap for later + //memory leak prevention + //if (globaldata->gTreemap != NULL) { delete globaldata->gTreemap; } globaldata->gTreemap = tmap; } @@ -327,9 +352,11 @@ void ParsimonyCommand::setGroups() { if (globaldata->Groups.size() == 0) { cout << "When using the groups parameter you must have at least 1 valid group. I will run the command using all the groups in your groupfile." << endl; for (int i = 0; i < tmap->namesOfGroups.size(); i++) { - globaldata->Groups.push_back(tmap->namesOfGroups[i]); - numGroups++; - allGroups += tmap->namesOfGroups[i] + "-"; + if (tmap->namesOfGroups[i] != "xxx") { + allGroups += tmap->namesOfGroups[i] + "-"; + globaldata->Groups.push_back(tmap->namesOfGroups[i]); + numGroups++; + } } allGroups = allGroups.substr(0, allGroups.length()-1); }else { @@ -340,17 +367,22 @@ void ParsimonyCommand::setGroups() { allGroups = allGroups.substr(0, allGroups.length()-1); } }else{//user has enter "all" and wants the default groups + globaldata->Groups.clear(); for (int i = 0; i < tmap->namesOfGroups.size(); i++) { - globaldata->Groups.push_back(tmap->namesOfGroups[i]); - numGroups++; - allGroups += tmap->namesOfGroups[i] + "-"; + if (tmap->namesOfGroups[i] != "xxx") { + globaldata->Groups.push_back(tmap->namesOfGroups[i]); + numGroups++; + allGroups += tmap->namesOfGroups[i] + "-"; + } } allGroups = allGroups.substr(0, allGroups.length()-1); globaldata->setGroups(""); } }else { for (int i = 0; i < tmap->namesOfGroups.size(); i++) { - allGroups += tmap->namesOfGroups[i] + "-"; + if (tmap->namesOfGroups[i] != "xxx") { + allGroups += tmap->namesOfGroups[i] + "-"; + } } allGroups = allGroups.substr(0, allGroups.length()-1); numGroups = 1; @@ -396,7 +428,7 @@ void ParsimonyCommand::initFile(string label){ if (randomtree == "") { out << inputBuffer << '\t' << label + "Score" << '\t' << label + "UserFreq" << '\t' << label + "UserCumul" << '\t' << label + "RandFreq" << '\t' << label + "RandCumul" << endl; }else { - out << inputBuffer << '\t' << label + "Score" << '\t' << label + "RandFreq" << '\t' << label + "RandCumul" << endl; + out << inputBuffer << '\t' << "Score" << '\t' << "RandFreq" << '\t' << "RandCumul" << endl; } }else{ openOutputFile(parsFileout, out); @@ -404,7 +436,7 @@ void ParsimonyCommand::initFile(string label){ if (randomtree == "") { out << label + "Score" << '\t' << label + "UserFreq" << '\t' << label + "UserCumul" << '\t' << label + "RandFreq" << '\t' << label + "RandCumul" << endl; }else { - out << label + "Score" << '\t' << label + "RandFreq" << '\t' << label + "RandCumul" << endl; + out << "Score" << '\t' << "RandFreq" << '\t' << "RandCumul" << endl; } } @@ -430,16 +462,16 @@ void ParsimonyCommand::output(vector data){ getline(inFile, inputBuffer); if (randomtree == "") { - out << inputBuffer << '\t' << setprecision(globaldata->getIters().length()) << data[0] << '\t' << data[1] << '\t' << data[2] << '\t' << data[3] << '\t' << data[4] << endl; + out << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << '\t' << data[3] << '\t' << data[4] << endl; }else{ - out << inputBuffer << '\t' << setprecision(globaldata->getIters().length()) << data[0] << '\t' << data[1] << '\t' << data[2] << endl; + out << inputBuffer << '\t' << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl; } } else{ if (randomtree == "") { - out << setprecision(globaldata->getIters().length()) << data[0] << '\t' << data[1] << '\t' << data[2] << '\t' << data[3] << '\t' << data[4] << endl; + out << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << '\t' << data[3] << '\t' << data[4] << endl; }else{ - out << setprecision(globaldata->getIters().length()) << data[0] << '\t' << data[1] << '\t' << data[2] << endl; + out << setprecision(6) << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl; } }