]> git.donarmstrong.com Git - mothur.git/blobdiff - libshuffcommand.cpp
added logfile feature
[mothur.git] / libshuffcommand.cpp
index fd4139100bf3155fd3d9bfb1020e03d5c9056b7c..73c0a74f050a99a42f41dcce4ad18594e8621cc4 100644 (file)
@@ -48,7 +48,7 @@ LibShuffCommand::LibShuffCommand(string option){
                        
                        //make sure the user has already run the read.dist command
                        if ((globaldata->gMatrix == NULL) || (globaldata->gGroupmap == NULL)) {
-                               cout << "You must read in a matrix and groupfile using the read.dist command, before you use the libshuff command. " << endl; abort = true;; 
+                               mothurOut("You must read in a matrix and groupfile using the read.dist command, before you use the libshuff command. "); mothurOutEndLine(); abort = true;; 
                        }
                                                
                        //check for optional parameter and set defaults
@@ -90,39 +90,30 @@ LibShuffCommand::LibShuffCommand(string option){
                
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the LibShuffCommand class Function LibShuffCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "LibShuffCommand", "LibShuffCommand");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the LibShuffCommand class function LibShuffCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
-                       
 }
 //**********************************************************************************************************************
 
 void LibShuffCommand::help(){
        try {
-               cout << "The libshuff command can only be executed after a successful read.dist command including a groupfile." << "\n";
-               cout << "The libshuff command parameters are groups, iters, step, form and cutoff.  No parameters are required." << "\n";
-               cout << "The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed.  You must enter at least 2 valid groups." << "\n";
-               cout << "The group names are separated by dashes.  The iters parameter allows you to specify how many random matrices you would like compared to your matrix." << "\n";
-               cout << "The step parameter allows you to specify change in distance you would like between each output if you are using the discrete form." << "\n";
-               cout << "The form parameter allows you to specify if you would like to analyze your matrix using the discrete or integral form. Your options are integral or discrete." << "\n";
-               cout << "The libshuff command should be in the following format: libshuff(groups=yourGroups, iters=yourIters, cutOff=yourCutOff, form=yourForm, step=yourStep)." << "\n";
-               cout << "Example libshuff(groups=A-B-C, iters=500, form=discrete, step=0.01, cutOff=2.0)." << "\n";
-               cout << "The default value for groups is all the groups in your groupfile, iters is 10000, cutoff is 1.0, form is integral and step is 0.01." << "\n";
-               cout << "The libshuff command output two files: .coverage and .slsummary their descriptions are in the manual." << "\n";
-               cout << "Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e.yourIters)." << "\n" << "\n";
+               mothurOut("The libshuff command can only be executed after a successful read.dist command including a groupfile.\n");
+               mothurOut("The libshuff command parameters are groups, iters, step, form and cutoff.  No parameters are required.\n");
+               mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed.  You must enter at least 2 valid groups.\n");
+               mothurOut("The group names are separated by dashes.  The iters parameter allows you to specify how many random matrices you would like compared to your matrix.\n");
+               mothurOut("The step parameter allows you to specify change in distance you would like between each output if you are using the discrete form.\n");
+               mothurOut("The form parameter allows you to specify if you would like to analyze your matrix using the discrete or integral form. Your options are integral or discrete.\n");
+               mothurOut("The libshuff command should be in the following format: libshuff(groups=yourGroups, iters=yourIters, cutOff=yourCutOff, form=yourForm, step=yourStep).\n");
+               mothurOut("Example libshuff(groups=A-B-C, iters=500, form=discrete, step=0.01, cutOff=2.0).\n");
+               mothurOut("The default value for groups is all the groups in your groupfile, iters is 10000, cutoff is 1.0, form is integral and step is 0.01.\n");
+               mothurOut("The libshuff command output two files: .coverage and .slsummary their descriptions are in the manual.\n");
+               mothurOut("Note: No spaces between parameter labels (i.e. iters), '=' and parameters (i.e.yourIters).\n\n");
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the LibShuffCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "LibShuffCommand", "help");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the LibShuffCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 //**********************************************************************************************************************
@@ -158,7 +149,7 @@ int LibShuffCommand::execute(){
                reading->finish();
                delete reading;
 
-               cout << endl;
+               mothurOutEndLine();
                printSummaryFile();
                printCoverageFile();
                
@@ -172,13 +163,9 @@ int LibShuffCommand::execute(){
                return 0;
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the LibShuffCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "LibShuffCommand", "execute");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the LibShuffCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 }
 
 //**********************************************************************************************************************
@@ -190,7 +177,7 @@ void LibShuffCommand::printCoverageFile() {
                summaryFile = getRootName(globaldata->getPhylipFile()) + "libshuff.coverage";
                openOutputFile(summaryFile, outCov);
                outCov.setf(ios::fixed, ios::floatfield); outCov.setf(ios::showpoint);
-               cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint);
+               //cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint);
                
                map<double,vector<int> > allDistances;
                map<double,vector<int> >::iterator it;
@@ -216,7 +203,7 @@ void LibShuffCommand::printCoverageFile() {
                }
                it=allDistances.begin();
                
-               cout << setprecision(8);
+               //cout << setprecision(8);
 
                vector<int> prevRow = it->second;
                it++;
@@ -259,13 +246,9 @@ void LibShuffCommand::printCoverageFile() {
                outCov.close();
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the LibShuffCommand class Function printCoverageFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "LibShuffCommand", "printCoverageFile");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the LibShuffCommand class function printCoverageFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 } 
 
 //**********************************************************************************************************************
@@ -281,6 +264,7 @@ void LibShuffCommand::printSummaryFile() {
                cout.setf(ios::fixed, ios::floatfield); cout.setf(ios::showpoint);
                
                cout << setw(20) << left << "Comparison" << '\t' << setprecision(8) << "dCXYScore" << '\t' << "Significance" << endl;
+               mothurOutJustToLog("Comparison\tdCXYScore\tSignificance"); mothurOutEndLine();
                outSum << setw(20) << left << "Comparison" << '\t' << setprecision(8) << "dCXYScore" << '\t' << "Significance" << endl;
        
                int precision = (int)log10(iters);
@@ -288,18 +272,22 @@ void LibShuffCommand::printSummaryFile() {
                        for(int j=i+1;j<numGroups;j++){
                                if(pValueCounts[i][j]){
                                        cout << setw(20) << left << groupNames[i]+'-'+groupNames[j] << '\t' << setprecision(8) << savedDXYValues[i][j] << '\t' << setprecision(precision) << pValueCounts[i][j]/(float)iters << endl;
+                                       mothurOutJustToLog(groupNames[i]+"-"+groupNames[j] + "\t" + toString(savedDXYValues[i][j]) + "\t" + toString((pValueCounts[i][j]/(float)iters))); mothurOutEndLine();
                                        outSum << setw(20) << left << groupNames[i]+'-'+groupNames[j] << '\t' << setprecision(8) << savedDXYValues[i][j] << '\t' << setprecision(precision) << pValueCounts[i][j]/(float)iters << endl;
                                }
                                else{
                                        cout << setw(20) << left << groupNames[i]+'-'+groupNames[j] << '\t' << setprecision(8) << savedDXYValues[i][j] << '\t' << '<' <<setprecision(precision) << 1/(float)iters << endl;
+                                       mothurOutJustToLog(groupNames[i]+"-"+groupNames[j] + "\t" + toString(savedDXYValues[i][j]) + "\t" + toString((1/(float)iters))); mothurOutEndLine();
                                        outSum << setw(20) << left << groupNames[i]+'-'+groupNames[j] << '\t' << setprecision(8) << savedDXYValues[i][j] << '\t' << '<' <<setprecision(precision) << 1/(float)iters << endl;
                                }
                                if(pValueCounts[j][i]){
                                        cout << setw(20) << left << groupNames[j]+'-'+groupNames[i] << '\t' << setprecision(8) << savedDXYValues[j][i] << '\t' << setprecision (precision) << pValueCounts[j][i]/(float)iters << endl;
+                                       mothurOutJustToLog(groupNames[j]+"-"+groupNames[i] + "\t" + toString(savedDXYValues[j][i]) + "\t" + toString((pValueCounts[j][i]/(float)iters))); mothurOutEndLine();
                                        outSum << setw(20) << left << groupNames[j]+'-'+groupNames[i] << '\t' << setprecision(8) << savedDXYValues[j][i] << '\t' << setprecision (precision) << pValueCounts[j][i]/(float)iters << endl;
                                }
                                else{
                                        cout << setw(20) << left << groupNames[j]+'-'+groupNames[i] << '\t' << setprecision(8) << savedDXYValues[j][i] << '\t' << '<' <<setprecision (precision) << 1/(float)iters << endl;
+                                       mothurOutJustToLog(groupNames[j]+"-"+groupNames[i] + "\t" + toString(savedDXYValues[j][i]) + "\t" + toString((1/(float)iters))); mothurOutEndLine();
                                        outSum << setw(20) << left << groupNames[j]+'-'+groupNames[i] << '\t' << setprecision(8) << savedDXYValues[j][i] << '\t' << '<' <<setprecision (precision) << 1/(float)iters << endl;
                                }
                        }
@@ -308,13 +296,9 @@ void LibShuffCommand::printSummaryFile() {
                outSum.close();
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the LibShuffCommand class Function printSummaryFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "LibShuffCommand", "printSummaryFile");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the LibShuffCommand class function printSummaryFile. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }       
 } 
 
 //**********************************************************************************************************************
@@ -332,7 +316,7 @@ void LibShuffCommand::setGroups() {
                                //check that groups are valid
                                for (int i = 0; i < globaldata->Groups.size(); i++) {
                                        if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
-                                               cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
+                                               mothurOut(globaldata->Groups[i] + " is not a valid group, and will be disregarded."); mothurOutEndLine();
                                                // erase the invalid group from globaldata->Groups
                                                globaldata->Groups.erase(globaldata->Groups.begin()+i);
                                        }
@@ -344,7 +328,7 @@ void LibShuffCommand::setGroups() {
                                        for (int i=0; i < numGroups; i++) { 
                                                globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
                                        }
-                                       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; 
+                                       mothurOut("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."); mothurOutEndLine();
                                } else { numGroups = globaldata->Groups.size(); }
                        } else { //users wants all groups
                                numGroups = globaldata->gGroupmap->getNumGroups();
@@ -363,20 +347,9 @@ void LibShuffCommand::setGroups() {
 
                groupNames = globaldata->Groups;
 
-               // number of comparisons i.e. with groups A,B,C = AA, AB, AC, BA, BB, BC...;
-//             for (int i=0; i<numGroups; i++) { 
-//                     for (int l = 0; l < numGroups; l++) {
-//                             //set group comparison labels
-//                             groupComb.push_back(globaldata->Groups[i] + "-" + globaldata->Groups[l]);
-//                     }
-//             }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the LibShuffCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
-               exit(1);
-       }
-       catch(...) {
-               cout << "An unknown error has occurred in the LibShuffCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               errorOut(e, "LibShuffCommand", "setGroups");
                exit(1);
        }
 }