]> git.donarmstrong.com Git - mothur.git/blobdiff - readotucommand.cpp
added parse.list command
[mothur.git] / readotucommand.cpp
index 584eb8543d57dd5e5da10775b5ce684250d28229..89013e68bfd0235678ac6664838e3259596956f3 100644 (file)
@@ -21,21 +21,81 @@ ReadOtuCommand::ReadOtuCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"list","order","shared", "label","group","sabund", "rabund","groups"};
+                       string Array[] =  {"list","order","shared", "label","group","sabund", "rabund","groups","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
                        
                        OptionParser parser(option);
                        map<string, string> parameters = parser.getParameters();
                        
                        ValidParameters validParameter;
+                       map<string, string>::iterator it;
                
                        //check to make sure all parameters are valid for command
-                       for (map<string, string>::iterator it = parameters.begin(); it != parameters.end(); it++) { 
+                       for (it = parameters.begin(); it != parameters.end(); it++) { 
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
                        globaldata->newRead();
                        
+                       //if the user changes the input directory command factory will send this info to us in the output parameter 
+                       string inputDir = validParameter.validFile(parameters, "inputdir", false);              
+                       if (inputDir == "not found"){   inputDir = "";          }
+                       else {
+                               string path;
+                               it = parameters.find("list");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["list"] = inputDir + it->second;             }
+                               }
+                               
+                               it = parameters.find("order");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["order"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("shared");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["shared"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("group");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["group"] = inputDir + it->second;            }
+                               }
+                               
+                               it = parameters.find("sabund");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["sabund"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("rabund");
+                               //user has given a template file
+                               if(it != parameters.end()){ 
+                                       path = hasPath(it->second);
+                                       //if the user has not given a path then, add inputdir. else leave path alone.
+                                       if (path == "") {       parameters["rabund"] = inputDir + it->second;           }
+                               }
+
+                       }
+
+                       
+                       //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 = ""; }
+
                        //check for required parameters
                        listfile = validParameter.validFile(parameters, "list", true);
                        if (listfile == "not open") { abort = true; }
@@ -63,7 +123,10 @@ ReadOtuCommand::ReadOtuCommand(string option){
                        else {  
                                globaldata->setGroupFile(groupfile); 
                                groupMap = new GroupMap(groupfile);
-                               groupMap->readMap();
+                               
+                               int error = groupMap->readMap();
+                               if (error == 1) { abort = true; }
+                               
                                globaldata->gGroupmap = groupMap;
                        }
                        
@@ -119,7 +182,7 @@ void ReadOtuCommand::help(){
        try {
                mothurOut("The read.otu command must be run before you execute a collect.single, rarefaction.single, summary.single, \n");
                mothurOut("collect.shared, rarefaction.shared or summary.shared command.   Mothur will generate a .list, .rabund and .sabund upon completion of the cluster command \n");
-               mothurOut("or you may use your own. The read.otu command parameter options are list, rabund, sabund, shared, group, order and label.\n");
+               mothurOut("or you may use your own. The read.otu command parameter options are list, rabund, sabund, shared, group, order, label and groups.\n");
                mothurOut("The read.otu command can be used in two ways.  The first is to read a list, rabund or sabund and run the collect.single, rarefaction.single or summary.single.\n");
                mothurOut("For this use the read.otu command should be in the following format: read.otu(list=yourListFile, order=yourOrderFile, label=yourLabels).\n");
                mothurOut("The list, rabund or sabund parameter is required, but you may only use one of them.\n");
@@ -128,6 +191,7 @@ void ReadOtuCommand::help(){
                mothurOut("In this case the read.otu command should be in the following format: read.otu(list=yourListFile, group=yourGroupFile) or read.otu(shared=yourSharedFile).  \n");
                mothurOut("The list parameter and group paramaters or the shared paremeter is required. When using the command the second way with a list and group file read.otu command parses the .list file\n");
                mothurOut("and separates it into groups.  It outputs a .shared file containing the OTU information for each group. The read.otu command also outputs a .rabund file for each group. \n");
+               mothurOut("You can use the groups parameter to choose only specific groups to be used in the .shared and .rabund files. \n");
                mothurOut("Note: No spaces between parameter labels (i.e. list), '=' and parameters (i.e.yourListfile).\n\n");
 
        }
@@ -153,23 +217,17 @@ int ReadOtuCommand::execute(){
                
                if (globaldata->getFormat() == "shared") {
                        
-                       shared = new SharedCommand();
+                       shared = new SharedCommand(outputDir);
                        int okay = shared->execute();
-                       delete shared;
                        
                        //problem with shared
                        if (okay == 1) {
                                globaldata->setListFile("");
                                globaldata->setGroupFile("");
                                globaldata->setSharedFile("");
-                       }else{
-                               
-                               //change format to shared  to speed up commands
-                               globaldata->setFormat("sharedfile");
-                               globaldata->setListFile("");
-                               globaldata->setGroupFile("");
-                               globaldata->setSharedFile(getRootName(filename) + "shared");
                        }
+                       
+                       delete shared;
                }
                return 0;
        }