if (randomtree == "") {
T = globaldata->gTree;
tmap = globaldata->gTreemap;
- parsFile = globaldata->getTreeFile() + ".parsimony";
- parsFileout = globaldata->getTreeFile() + "temp" + ".parsimony";
+ output = new ColumnFile(globaldata->getTreeFile() + ".parsimony");
sumFile = globaldata->getTreeFile() + ".psummary";
openOutputFile(sumFile, outSum);
}else { //user wants random distribution
savetmap = globaldata->gTreemap;
getUserInput();
- parsFile = randomtree + ".rd_parsimony";
- parsFileout = globaldata->getTreeFile() + "temp" + ".rd_parsimony";
+ output = new ColumnFile(randomtree);
}
//set users groups to analyze
- setGroups();
+ util = new SharedUtil();
+ util->setGroups(globaldata->Groups, tmap->namesOfGroups, allGroups, numGroups, "unweighted"); //sets the groups the user wants to analyze
+ util->getCombos(groupComb, globaldata->Groups, numComp);
+ globaldata->setGroups("");
+
+ if (numGroups == 1) { numComp++; groupComb.push_back(allGroups); }
+
convert(globaldata->getIters(), iters); //how many random trees to generate
pars = new Parsimony(tmap);
counter = 0;
/***********************************************************/
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.
//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
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]);
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]);
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;
}
}
+ //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("");
//reset groups parameter
- globaldata->Groups.clear(); globaldata->setGroups("");
+ globaldata->Groups.clear();
return 0;
void ParsimonyCommand::printParsimonyFile() {
try {
vector<double> data;
+ vector<string> tags;
- //format output
- out.setf(ios::fixed, ios::floatfield); out.setf(ios::showpoint);
+ if (randomtree == "") {
+ tags.push_back("Score"); tags.push_back("UserFreq"); tags.push_back("UserCumul"); tags.push_back("RandFreq"); tags.push_back("RandCumul");
+ }else {
+ tags.push_back("Score"); tags.push_back("RandFreq"); tags.push_back("RandCumul");
+ }
for(int a = 0; a < numComp; a++) {
- initFile(groupComb[a]);
+ output->initFile(groupComb[a], tags);
//print each line
for (it = validScores.begin(); it != validScores.end(); it++) {
if (randomtree == "") {
}else{
data.push_back(it->first); data.push_back(rscoreFreq[a][it->first]); data.push_back(rCumul[a][it->first]);
}
- output(data);
+ output->output(data);
data.clear();
}
- resetFile();
+ output->resetFile();
}
-
- out.close();
- inFile.close();
- remove(parsFileout.c_str());
}
catch(exception& e) {
cout << "Standard Error: " << e.what() << " has occurred in the ParsimonyCommand class Function printParsimonyFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
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);
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;
}
}
}
getline(cin, s);
//save tmap for later
+ //memory leak prevention
+ //if (globaldata->gTreemap != NULL) { delete globaldata->gTreemap; }
globaldata->gTreemap = tmap;
}
exit(1);
}
}
-/***********************************************************/
-void ParsimonyCommand::setGroups() {
- try {
- string allGroups = "";
- numGroups = 0;
- //if the user has not entered specific groups to analyze then do them all
- if (globaldata->Groups.size() != 0) {
- if (globaldata->Groups[0] != "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) {
- 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] + "-";
- }
- allGroups = allGroups.substr(0, allGroups.length()-1);
- }else {
- for (int i = 0; i < globaldata->Groups.size(); 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 = allGroups.substr(0, allGroups.length()-1);
- globaldata->setGroups("");
- }
- }else {
- for (int i = 0; i < tmap->namesOfGroups.size(); i++) {
- allGroups += tmap->namesOfGroups[i] + "-";
- }
- allGroups = allGroups.substr(0, allGroups.length()-1);
- numGroups = 1;
- }
-
- //calculate number of comparsions
- numComp = 0;
- for (int r=0; r<numGroups; r++) {
- for (int l = r+1; l < numGroups; l++) {
- groupComb.push_back(globaldata->Groups[r]+ "-" +globaldata->Groups[l]);
- numComp++;
- }
- }
-
- //ABC
- if (numComp != 1) {
- groupComb.push_back(allGroups);
- numComp++;
- }
-
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the ParsimonyCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the ParsimonyCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-
-}
-/*****************************************************************/
-
-void ParsimonyCommand::initFile(string label){
- try {
- if(counter != 0){
- openOutputFile(parsFileout, out);
- openInputFile(parsFile, inFile);
-
- string inputBuffer;
- getline(inFile, inputBuffer);
-
- 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;
- }
- }else{
- openOutputFile(parsFileout, out);
- //column headers
- 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.setf(ios::fixed, ios::floatfield);
- out.setf(ios::showpoint);
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the ParsimonyCommand class Function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the ParsimonyCommand class function initFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-}
-
-/***********************************************************************/
-
-void ParsimonyCommand::output(vector<double> data){
- try {
- if(counter != 0){
- string inputBuffer;
- 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;
- }else{
- out << inputBuffer << '\t' << setprecision(globaldata->getIters().length()) << data[0] << '\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;
- }else{
- out << setprecision(globaldata->getIters().length()) << data[0] << '\t' << data[1] << '\t' << data[2] << endl;
- }
- }
-
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the ParsimonyCommand class Function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the ParsimonyCommand class function output. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-}
-
-/***********************************************************************/
-
-void ParsimonyCommand::resetFile(){
- try {
- if(counter != 0){
- out.close();
- inFile.close();
- }
- else{
- out.close();
- }
- counter = 1;
-
- remove(parsFile.c_str());
- rename(parsFileout.c_str(), parsFile.c_str());
- }
- catch(exception& e) {
- cout << "Standard Error: " << e.what() << " has occurred in the ParsimonyCommand class Function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
- catch(...) {
- cout << "An unknown error has occurred in the ParsimonyCommand class function resetFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
- exit(1);
- }
-}
+/***********************************************************/