X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=unifracunweightedcommand.cpp;h=dd1a3f9c236f9a86b022c99a3e6dd2d2109b1dfa;hb=9651e8e7172d86707b34af15e95ec60ad4c3c3f9;hp=5a7cc367cd12212743f836cda998a10c339b5c09;hpb=626e77d477ecca8b03c942bdc66f8bb8c413b356;p=mothur.git diff --git a/unifracunweightedcommand.cpp b/unifracunweightedcommand.cpp index 5a7cc36..dd1a3f9 100644 --- a/unifracunweightedcommand.cpp +++ b/unifracunweightedcommand.cpp @@ -43,27 +43,27 @@ int UnifracUnweightedCommand::execute() { //get pscores for users trees for (int i = 0; i < T.size(); i++) { + counter = 0; unweightedFile = globaldata->getTreeFile() + toString(i+1) + ".unweighted"; unweightedFileout = globaldata->getTreeFile() + "temp." + toString(i+1) + ".unweighted"; - //column headers - outSum << "Tree# " << i+1 << endl; - outSum << "Comb" << '\t' << "UWScore" << '\t' << '\t' << "UWSig" << endl; + + //column headers +// outSum << "Tree# " << i+1 << endl; + outSum << "Tree#" << '\t' << "Groups" << '\t' << "UWScore" <<'\t' << "UWSig" << endl; +// cout << "Tree# " << i+1 << endl; + cout << "Tree#" << '\t' << "Groups" << '\t' << "UWScore" << '\t' << "UWSig" << endl; + //get unweighted for users tree rscoreFreq.resize(numComp); rCumul.resize(numComp); - validScores.resize(numComp); utreeScores.resize(numComp); UWScoreSig.resize(numComp); - cout << "Processing tree " << i+1 << endl; userData = unweighted->getValues(T[i]); //userData[0] = unweightedscore //output scores for each combination for(int k = 0; k < numComp; k++) { - //add users score to valid scores - validScores[k][userData[k]] = userData[k]; - //saves users score utreeScores[k].push_back(userData[k]); } @@ -74,7 +74,6 @@ int UnifracUnweightedCommand::execute() { randomData = unweighted->getValues(T[i], "", ""); for(int k = 0; k < numComp; k++) { -//cout << "iter " << j << " comp " << k << " = " << randomData[k] << endl; //add trees unweighted score to map of scores it2 = rscoreFreq[k].find(randomData[k]); if (it2 != rscoreFreq[k].end()) {//already have that score @@ -84,14 +83,14 @@ int UnifracUnweightedCommand::execute() { } //add randoms score to validscores - validScores[k][randomData[k]] = randomData[k]; + validScores[randomData[k]] = randomData[k]; } } for(int a = 0; a < numComp; a++) { float rcumul = 1.0000; //this loop fills the cumulative maps and put 0.0000 in the score freq map to make it easier to print. - for (it = validScores[a].begin(); it != validScores[a].end(); it++) { + for (it = validScores.begin(); it != validScores.end(); it++) { //make rscoreFreq map and rCumul it2 = rscoreFreq[a].find(it->first); rCumul[a][it->first] = rcumul; @@ -135,7 +134,7 @@ void UnifracUnweightedCommand::printUnweightedFile() { for(int a = 0; a < numComp; a++) { initFile(groupComb[a]); //print each line - for (it = validScores[a].begin(); it != validScores[a].end(); it++) { + for (it = validScores.begin(); it != validScores.end(); it++) { data.push_back(it->first); data.push_back(rscoreFreq[a][it->first]); data.push_back(rCumul[a][it->first]); output(data); data.clear(); @@ -164,11 +163,17 @@ void UnifracUnweightedCommand::printUWSummaryFile() { //format output outSum.setf(ios::fixed, ios::floatfield); outSum.setf(ios::showpoint); - + //print each line + for(int a = 0; a < numComp; a++) { - outSum << setprecision(6) << groupComb[a] << '\t' << '\t' << utreeScores[a][0] << '\t' << UWScoreSig[a][0] << endl; - cout << setprecision(6) << groupComb[a] << '\t' << '\t' << utreeScores[a][0] << '\t' << UWScoreSig[a][0] << endl; + if (UWScoreSig[a][0] > (1/(float)iters)) { + outSum << setprecision(6) << groupComb[a] << '\t' << '\t' << utreeScores[a][0] << '\t' << setprecision(globaldata->getIters().length()) << UWScoreSig[a][0] << endl; + cout << setprecision(6) << groupComb[a] << '\t' << '\t' << utreeScores[a][0] << '\t' << setprecision(globaldata->getIters().length()) << UWScoreSig[a][0] << endl; + }else { + outSum << setprecision(6) << groupComb[a] << '\t' << '\t' << utreeScores[a][0] << '\t' << setprecision(globaldata->getIters().length()) << "<" << (1/float(iters)) << endl; + cout << setprecision(6) << groupComb[a] << '\t' << '\t' << utreeScores[a][0] << '\t' << setprecision(globaldata->getIters().length()) << "<" << (1/float(iters)) << endl; + } } } @@ -205,26 +210,31 @@ void UnifracUnweightedCommand::setGroups() { for (int i = 0; i < tmap->namesOfGroups.size(); i++) { globaldata->Groups.push_back(tmap->namesOfGroups[i]); numGroups++; - allGroups += tmap->namesOfGroups[i]; + allGroups += tmap->namesOfGroups[i] + "-"; } + allGroups = allGroups.substr(0, allGroups.length()-1); }else { for (int i = 0; i < globaldata->Groups.size(); i++) { - allGroups += globaldata->Groups[i]; + allGroups += globaldata->Groups[i] + "-"; numGroups++; } + 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]; + 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]; + allGroups += tmap->namesOfGroups[i] + "-"; } + allGroups = allGroups.substr(0, allGroups.length()-1); numGroups = 1; } @@ -232,7 +242,7 @@ void UnifracUnweightedCommand::setGroups() { numComp = 0; for (int r=0; rGroups[r]+globaldata->Groups[l]); + groupComb.push_back(globaldata->Groups[r]+ "-" + globaldata->Groups[l]); numComp++; } } @@ -264,7 +274,7 @@ void UnifracUnweightedCommand::initFile(string label){ string inputBuffer; getline(inFile, inputBuffer); - out << inputBuffer << '\t' << label + "Score" << '\t' << label + "RandFreq" << '\t' << label + "RandCumul" << endl; + out << inputBuffer << '\t' << label + "RandFreq" << '\t' << label + "RandCumul" << endl; }else{ openOutputFile(unweightedFileout, out); out << label + "Score" << '\t' << label + "RandFreq" << '\t' << label + "RandCumul" << endl; @@ -290,11 +300,12 @@ void UnifracUnweightedCommand::output(vector data){ if(counter != 0){ string inputBuffer; getline(inFile, inputBuffer); +// out << inputBuffer << setprecision(6) << '\t' << data[0] << setprecision(globaldata->getIters().length()) << '\t' << data[1] << '\t' << data[2] << endl; - out << inputBuffer << setprecision(6) << '\t' << 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{ - out << setprecision(6) << 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; } }