]> git.donarmstrong.com Git - mothur.git/blobdiff - unifracunweightedcommand.cpp
added set.dir command and modified commands to redirect input and output, removed...
[mothur.git] / unifracunweightedcommand.cpp
index 1512284544b0e7d4cb7ba6ddac4663bf60d6d777..957a4aaab458d5f65256d8f9bf43579ad383d493 100644 (file)
@@ -21,7 +21,7 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) {
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"groups","iters","distance","random"};
+                       string Array[] =  {"groups","iters","distance","random", "outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
@@ -36,7 +36,13 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) {
                        
                        if (globaldata->gTree.size() == 0) {//no trees were read
                                mothurOut("You must execute the read.tree command, before you may execute the unifrac.unweighted command."); mothurOutEndLine(); 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->inputFileName); //if user entered a file with a path then preserve it  
+                       }
+                                                       
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                        groups = validParameter.validFile(parameters, "groups", false);                 
@@ -67,7 +73,7 @@ UnifracUnweightedCommand::UnifracUnweightedCommand(string option) {
                        if (abort == false) {
                                T = globaldata->gTree;
                                tmap = globaldata->gTreemap;
-                               sumFile = globaldata->getTreeFile() + ".uwsummary";
+                               sumFile = outputDir + getSimpleName(globaldata->getTreeFile()) + ".uwsummary";
                                openOutputFile(sumFile, outSum);
                                
                                util = new SharedUtil();
@@ -129,7 +135,7 @@ int UnifracUnweightedCommand::execute() {
                for (int i = 0; i < T.size(); i++) {
                        counter = 0;
                        
-                       if (random)  {  output = new ColumnFile(globaldata->getTreeFile()  + toString(i+1) + ".unweighted", itersString);  }
+                       if (random)  {  output = new ColumnFile(outputDir + getSimpleName(globaldata->getTreeFile())  + toString(i+1) + ".unweighted", itersString);  }
                        
                        //get unweighted for users tree
                        rscoreFreq.resize(numComp);  
@@ -272,7 +278,7 @@ void UnifracUnweightedCommand::printUWSummaryFile(int i) {
 /***********************************************************/
 void UnifracUnweightedCommand::createPhylipFile(int i) {
        try {
-               string phylipFileName = globaldata->getTreeFile()  + toString(i+1) + ".unweighted.dist";
+               string phylipFileName = outputDir + getSimpleName(globaldata->getTreeFile())  + toString(i+1) + ".unweighted.dist";
                ofstream out;
                openOutputFile(phylipFileName, out);