]> git.donarmstrong.com Git - mothur.git/blobdiff - unifracweightedcommand.cpp
fixed bug in read.tree updates help and validparameters strings, added ability for...
[mothur.git] / unifracweightedcommand.cpp
index 49f6631b4ef0822defad95a1ce81372fa455d9e6..c2584eabfe07975d103c17c6d93e96e2ae1770e2 100644 (file)
@@ -36,6 +36,8 @@ UnifracWeightedCommand::UnifracWeightedCommand() {
 /***********************************************************/
 int UnifracWeightedCommand::execute() {
        try {
+               Progress* reading;
+               reading = new Progress("Comparing to random:", iters);
                
                //get weighted for users tree
                userData.resize(numComp,0);  //data[0] = weightedscore AB, data[1] = weightedscore AC...
@@ -51,7 +53,7 @@ int UnifracWeightedCommand::execute() {
                        uScores.resize(numComp);  //data[0] = weightedscore AB, data[1] = weightedscore AC...
                        weightedFile = globaldata->getTreeFile()  + toString(i+1) + ".weighted";
                        weightedFileout = globaldata->getTreeFile() + "temp." + toString(i+1) + ".weighted";
-                                                       
+
                        userData = weighted->getValues(T[i]);  //userData[0] = weightedscore
                        
                        //save users score
@@ -81,6 +83,10 @@ int UnifracWeightedCommand::execute() {
                                                count++;
                                        }
                                }
+                               
+                               //update progress bar
+                               reading->update(j);
+
                        }
 
                        //removeValidScoresDuplicates(); 
@@ -109,6 +115,10 @@ int UnifracWeightedCommand::execute() {
                        validScores.clear();
                }
                
+               //finish progress bar
+               reading->finish();
+               delete reading;
+               
                printWSummaryFile();
                
                //clear out users groups
@@ -175,11 +185,11 @@ void UnifracWeightedCommand::printWSummaryFile() {
                for (int i = 0; i < T.size(); i++) { 
                        for (int j = 0; j < numComp; j++) {
                                if (WScoreSig[count] > (1/(float)iters)) {
-                                       outSum << setprecision(globaldata->getIters().length()) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << WScoreSig[count] << endl; 
-                                       cout << setprecision(globaldata->getIters().length()) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << WScoreSig[count] << endl; 
+                                       outSum << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << setprecision(globaldata->getIters().length()) << WScoreSig[count] << endl; 
+                                       cout << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << setprecision(globaldata->getIters().length()) << WScoreSig[count] << endl; 
                                }else{
-                                       outSum << setprecision(globaldata->getIters().length()) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << "<" << (1/float(iters)) << endl; 
-                                       cout << setprecision(globaldata->getIters().length()) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << "<" << (1/float(iters)) << endl; 
+                                       outSum << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << setprecision(globaldata->getIters().length()) << "<" << (1/float(iters)) << endl; 
+                                       cout << setprecision(6) << i+1 << '\t' << groupComb[j] << '\t' << utreeScores[count] << '\t' << setprecision(globaldata->getIters().length()) << "<" << (1/float(iters)) << endl; 
                                }
                                count++;
                        }
@@ -217,11 +227,14 @@ int UnifracWeightedCommand::findIndex(float score, int index) {
 /***********************************************************/
 void UnifracWeightedCommand::setGroups() {
        try {
+               numGroups = 0;
                //if the user has not entered specific groups to analyze then do them all
                if (globaldata->Groups.size() == 0) {
-                       numGroups = tmap->getNumGroups();
-                       for (int i=0; i < numGroups; i++) { 
-                               globaldata->Groups.push_back(tmap->namesOfGroups[i]);
+                       for (int i=0; i < tmap->getNumGroups(); i++) { 
+                               if (tmap->namesOfGroups[i] != "xxx") {
+                                       globaldata->Groups.push_back(tmap->namesOfGroups[i]);
+                                       numGroups++;
+                               }
                        }
                }else {
                        if (globaldata->getGroups() != "all") {
@@ -236,25 +249,31 @@ void UnifracWeightedCommand::setGroups() {
                        
                                //if the user only entered invalid groups
                                if (globaldata->Groups.size() == 0) { 
-                                       numGroups = tmap->getNumGroups();
-                                       for (int i=0; i < numGroups; i++) { 
-                                               globaldata->Groups.push_back(tmap->namesOfGroups[i]);
+                                       for (int i=0; i < tmap->getNumGroups(); i++) { 
+                                               if (tmap->namesOfGroups[i] != "xxx") {
+                                                       globaldata->Groups.push_back(tmap->namesOfGroups[i]);
+                                                       numGroups++;
+                                               }
                                        }
                                        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();
-                                       for (int i=0; i < numGroups; i++) { 
-                                               globaldata->Groups.push_back(tmap->namesOfGroups[i]);
+                                       for (int i=0; i < tmap->getNumGroups(); i++) { 
+                                               if (tmap->namesOfGroups[i] != "xxx") {
+                                                       globaldata->Groups.push_back(tmap->namesOfGroups[i]);
+                                                       numGroups++;
+                                               }
                                        }
                                }else { numGroups = globaldata->Groups.size(); }
                        }else { //users wants all groups
-                               numGroups = tmap->getNumGroups();
                                globaldata->Groups.clear();
                                globaldata->setGroups("");
-                               for (int i=0; i < numGroups; i++) { 
-                                       globaldata->Groups.push_back(tmap->namesOfGroups[i]);
+                               for (int i=0; i < tmap->getNumGroups(); i++) { 
+                                       if (tmap->namesOfGroups[i] != "xxx") {
+                                               globaldata->Groups.push_back(tmap->namesOfGroups[i]);
+                                               numGroups++;
+                                       }
                                }
                        }
                }
@@ -366,11 +385,12 @@ void UnifracWeightedCommand::output(vector<double> data){
                if(counter != 0){               
                        string inputBuffer;
                        getline(inFile, inputBuffer);
-                       
-                       out     <<  inputBuffer << setprecision(globaldata->getIters().length()-1) << '\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] << setprecision(globaldata->getIters().length()-1) << '\t' << data[1] << '\t' << data[2] << endl;
+                       out << setprecision(6) << data[0] << setprecision(globaldata->getIters().length())  << '\t' << data[1] << '\t' << data[2] << endl;
+
                }
                
        }