]> git.donarmstrong.com Git - mothur.git/blobdiff - hclustercommand.cpp
added warning about merging with something above cutoff to cluster. working on chimeras
[mothur.git] / hclustercommand.cpp
index bdec48e788121bc2d88519d98e1e8135d32020d5..365c80ee7956045fec1c1d82e848183f3138fe70 100644 (file)
@@ -21,16 +21,17 @@ HClusterCommand::HClusterCommand(string option){
                
                else {
                        //valid paramters for this command
-                       string Array[] =  {"cutoff","precision","method","phylip","column","name","sorted","showabund","timing"};
+                       string Array[] =  {"cutoff","precision","method","phylip","column","name","sorted","showabund","timing","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;
                                }
@@ -38,6 +39,39 @@ HClusterCommand::HClusterCommand(string option){
                        
                        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("phylip");
+                               //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["phylip"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("column");
+                               //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["column"] = inputDir + it->second;           }
+                               }
+                               
+                               it = parameters.find("name");
+                               //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["name"] = 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
                        phylipfile = validParameter.validFile(parameters, "phylip", true);
                        if (phylipfile == "not open") { abort = true; }
@@ -93,8 +127,9 @@ HClusterCommand::HClusterCommand(string option){
                        
                                
                        if (abort == false) {
-                                                                                       
-                               fileroot = getRootName(distfile);
+                               
+                               if (outputDir == "") {  outputDir += hasPath(distfile); }
+                               fileroot = outputDir + getRootName(getSimpleName(distfile));
                                
                                if (method == "furthest")               { tag = "fn";  }
                                else if (method == "nearest")   { tag = "nn";  }
@@ -178,9 +213,6 @@ int HClusterCommand::execute(){
                
                print_start = true;
                start = time(NULL);
-       
-               //ifstream in;
-               //openInputFile(distfile, in);
                                
                cluster = new HCluster(rabund, list, method, distfile, globaldata->nameMap, cutoff);
                vector<seqDist> seqs; seqs.resize(1); // to start loop
@@ -192,19 +224,17 @@ int HClusterCommand::execute(){
                        for (int i = 0; i < seqs.size(); i++) {  //-1 means skip me
 
                                if (seqs[i].seq1 != seqs[i].seq2) {
-                                       bool clustered = cluster->update(seqs[i].seq1, seqs[i].seq2, seqs[i].dist);
+                                       cluster->update(seqs[i].seq1, seqs[i].seq2, seqs[i].dist);
                                        
                                        float rndDist = roundDist(seqs[i].dist, precision);
                                        
-                                       if (clustered) {
-                                               if((previousDist <= 0.0000) && (seqs[i].dist != previousDist)){
-                                                       printData("unique");
-                                               }
-                                               else if((rndDist != rndPreviousDist)){
-                                                       printData(toString(rndPreviousDist,  length-1));
-                                               }
+                                       if((previousDist <= 0.0000) && (seqs[i].dist != previousDist)){
+                                               printData("unique");
                                        }
-                                       
+                                       else if((rndDist != rndPreviousDist)){
+                                               printData(toString(rndPreviousDist,  length-1));
+                                       }
+                               
                                        previousDist = seqs[i].dist;
                                        rndPreviousDist = rndDist;
                                        oldRAbund = *rabund;
@@ -212,8 +242,6 @@ int HClusterCommand::execute(){
                                }
                        }
                }
-               
-               //in.close();
 
                if(previousDist <= 0.0000){
                        printData("unique");