]> git.donarmstrong.com Git - mothur.git/blobdiff - libshuffcommand.cpp
added set.dir command and modified commands to redirect input and output, removed...
[mothur.git] / libshuffcommand.cpp
index 2d84767bc998d1e8db1d1ab40e7f9836f2045595..cfccdf6514297fe16af59234d94cdfd758b94c43 100644 (file)
@@ -22,7 +22,6 @@
 
 LibShuffCommand::LibShuffCommand(string option){
        try {
-               
                globaldata = GlobalData::getInstance();
                abort = false;
                Groups.clear();
@@ -33,7 +32,7 @@ LibShuffCommand::LibShuffCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"iters","groups","step","form","cutoff"};
+                       string Array[] =  {"iters","groups","step","form","cutoff","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -46,6 +45,12 @@ LibShuffCommand::LibShuffCommand(string option){
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  
+                               outputDir = ""; 
+                               outputDir += hasPath(globaldata->getPhylipFile()); //if user entered a file with a path then preserve it        
+                       }
+                       
                        //make sure the user has already run the read.dist command
                        if ((globaldata->gMatrix == NULL) || (globaldata->gGroupmap == NULL)) {
                                mothurOut("You must read in a matrix and groupfile using the read.dist command, before you use the libshuff command. "); mothurOutEndLine(); abort = true;; 
@@ -74,19 +79,19 @@ LibShuffCommand::LibShuffCommand(string option){
                        userform = validParameter.validFile(parameters, "form", false);                 if (userform == "not found") { userform = "integral"; }
                        
                        if (abort == false) {
-                       
+               
                                matrix = globaldata->gMatrix;                           //get the distance matrix
                                setGroups();                                                            //set the groups to be analyzed and sorts them
-                               
+       
                                /********************************************************************************************/
                                //this is needed because when we read the matrix we sort it into groups in alphabetical order
                                //the rest of the command and the classes used in this command assume specific order
                                /********************************************************************************************/
                                matrix->setGroups(globaldata->gGroupmap->namesOfGroups);
                                vector<int> sizes;
-                               for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {  sizes.push_back(globaldata->gGroupmap->getNumSeqs(globaldata->gGroupmap->namesOfGroups[i]));  }
+                               for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {   sizes.push_back(globaldata->gGroupmap->getNumSeqs(globaldata->gGroupmap->namesOfGroups[i]));  }
                                matrix->setSizes(sizes);
-                               
+                       
 
                                if(userform == "discrete"){
                                        form = new DLibshuff(matrix, iters, step, cutOff);
@@ -132,10 +137,10 @@ int LibShuffCommand::execute(){
        try {
                
                if (abort == true) {    return 0;       }
-               
+       
                savedDXYValues = form->evaluateAll();
                savedMinValues = form->getSavedMins();
-               
+       
                pValueCounts.resize(numGroups);
                for(int i=0;i<numGroups;i++){
                        pValueCounts[i].assign(numGroups, 0);
@@ -187,7 +192,7 @@ void LibShuffCommand::printCoverageFile() {
        try {
 
                ofstream outCov;
-               summaryFile = getRootName(globaldata->getPhylipFile()) + "libshuff.coverage";
+               summaryFile = outputDir + getRootName(getSimpleName(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);
@@ -274,7 +279,7 @@ void LibShuffCommand::printSummaryFile() {
        try {
 
                ofstream outSum;
-               summaryFile = getRootName(globaldata->getPhylipFile()) + "libshuff.summary";
+               summaryFile = outputDir + getRootName(getSimpleName(globaldata->getPhylipFile())) + "libshuff.summary";
                openOutputFile(summaryFile, outSum);
 
                outSum.setf(ios::fixed, ios::floatfield); outSum.setf(ios::showpoint);