X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=unifracunweightedcommand.cpp;h=65f30ebc949f4945023fd295224d00d52827d82b;hb=f18d75f9c996cb619a5051a7664620c0c5ae05fb;hp=3fa44b50014de39006037771bdc9899f0bc357f3;hpb=8f92612d5a69f5245e63a20657e7d93519c0769e;p=mothur.git diff --git a/unifracunweightedcommand.cpp b/unifracunweightedcommand.cpp index 3fa44b5..65f30eb 100644 --- a/unifracunweightedcommand.cpp +++ b/unifracunweightedcommand.cpp @@ -36,33 +36,36 @@ UnifracUnweightedCommand::UnifracUnweightedCommand() { /***********************************************************/ int UnifracUnweightedCommand::execute() { try { - + userData.resize(numComp,0); //data[0] = unweightedscore randomData.resize(numComp,0); //data[0] = unweightedscore //create new tree with same num nodes and leaves as users - + + outSum << "Tree#" << '\t' << "Groups" << '\t' << "UWScore" <<'\t' << "UWSig" << endl; + cout << "Tree#" << '\t' << "Groups" << '\t' << "UWScore" << '\t' << "UWSig" << endl; + //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; - + + outSum << i+1 << '\t'; + cout << i+1 << '\t'; + //get unweighted for users tree rscoreFreq.resize(numComp); rCumul.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++) { //saves users score utreeScores[k].push_back(userData[k]); + } //get unweighted scores for random trees @@ -71,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 @@ -83,6 +85,7 @@ int UnifracUnweightedCommand::execute() { //add randoms score to validscores validScores[randomData[k]] = randomData[k]; } + } for(int a = 0; a < numComp; a++) { @@ -99,6 +102,8 @@ int UnifracUnweightedCommand::execute() { UWScoreSig[a].push_back(rCumul[a][userData[a]]); } + + printUnweightedFile(); printUWSummaryFile(); @@ -161,11 +166,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' << utreeScores[a][0] << '\t' << setprecision(globaldata->getIters().length()) << UWScoreSig[a][0] << endl; + cout << setprecision(6) << groupComb[a] << '\t' << utreeScores[a][0] << '\t' << setprecision(globaldata->getIters().length()) << UWScoreSig[a][0] << endl; + }else { + outSum << setprecision(6) << groupComb[a] << '\t' << utreeScores[a][0] << '\t' << setprecision(globaldata->getIters().length()) << "<" << (1/float(iters)) << endl; + cout << setprecision(6) << groupComb[a] << '\t' << utreeScores[a][0] << '\t' << setprecision(globaldata->getIters().length()) << "<" << (1/float(iters)) << endl; + } } } @@ -202,26 +213,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; } @@ -229,7 +245,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++; } } @@ -261,7 +277,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; @@ -287,11 +303,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; } }