]> git.donarmstrong.com Git - mothur.git/blobdiff - treegroupscommand.cpp
fixed trim.seqs bug with qtrim parameter and added num=1 special case to database...
[mothur.git] / treegroupscommand.cpp
index eb3c33481d4ef68199f2b42e452ea93c1679bbf4..626659501a531db80f5193bef33e88793414a874 100644 (file)
 #include "sharedmorisitahorn.h"
 #include "sharedbraycurtis.h"
 
-
+//**********************************************************************************************************************
+vector<string> TreeGroupCommand::getValidParameters(){ 
+       try {
+               string Array[] =  {"label","calc","groups", "phylip", "column", "name", "precision","cutoff","outputdir","inputdir"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "TreeGroupCommand", "getValidParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+TreeGroupCommand::TreeGroupCommand(){  
+       try {
+               abort = true;
+               globaldata = GlobalData::getInstance();
+               //initialize outputTypes
+               vector<string> tempOutNames;
+               outputTypes["tree"] = tempOutNames;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "TreeGroupCommand", "TreeGroupCommand");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> TreeGroupCommand::getRequiredParameters(){      
+       try {
+               vector<string> myArray;
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "TreeGroupCommand", "getRequiredParameters");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
+vector<string> TreeGroupCommand::getRequiredFiles(){   
+       try {
+               string Array[] =  {"phylip","column","shared","or"};
+               vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+               return myArray;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "TreeGroupCommand", "getRequiredFiles");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 
 TreeGroupCommand::TreeGroupCommand(string option)  {
@@ -50,6 +98,10 @@ TreeGroupCommand::TreeGroupCommand(string option)  {
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
+                       //initialize outputTypes
+                       vector<string> tempOutNames;
+                       outputTypes["tree"] = tempOutNames;
+                       
                        //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 = "";          }
@@ -86,12 +138,12 @@ TreeGroupCommand::TreeGroupCommand(string option)  {
                        phylipfile = validParameter.validFile(parameters, "phylip", true);
                        if (phylipfile == "not open") { abort = true; }
                        else if (phylipfile == "not found") { phylipfile = ""; }        
-                       else {  format = "phylip";  globaldata->setPhylipFile(phylipfile);      }
+                       else {  globaldata->newRead(); format = "phylip";  globaldata->setPhylipFile(phylipfile);       }
                        
                        columnfile = validParameter.validFile(parameters, "column", true);
                        if (columnfile == "not open") { abort = true; } 
                        else if (columnfile == "not found") { columnfile = ""; }
-                       else {  format = "column"; globaldata->setColumnFile(columnfile);       }
+                       else {  globaldata->newRead(); format = "column"; globaldata->setColumnFile(columnfile);        }
                        
                        namefile = validParameter.validFile(parameters, "name", true);
                        if (namefile == "not open") { abort = true; }   
@@ -244,7 +296,8 @@ int TreeGroupCommand::execute(){
                if (format == "sharedfile") {
                        //if the users entered no valid calculators don't execute command
                        if (treeCalculators.size() == 0) { m->mothurOut("You have given no valid calculators."); m->mothurOutEndLine(); return 0; }
-
+                       
+                       if (globaldata->gGroupmap != NULL) {  delete globaldata->gGroupmap;   globaldata->gGroupmap = NULL;  }
                        //you have groups
                        read = new ReadOTUFile(globaldata->inputFileName);      
                        read->read(&*globaldata); 
@@ -258,17 +311,17 @@ int TreeGroupCommand::execute(){
                        //used in tree constructor 
                        globaldata->runParse = false;
                        
-                       //clear globaldatas old tree names if any
-                       globaldata->Treenames.clear();
-               
-                       //fills globaldatas tree names
-                       globaldata->Treenames = globaldata->Groups;
-               
                        //create treemap class from groupmap for tree class to use
                        tmap = new TreeMap();
                        tmap->makeSim(globaldata->gGroupmap);
                        globaldata->gTreemap = tmap;
                        
+                       //clear globaldatas old tree names if any
+                       globaldata->Treenames.clear();
+                       
+                       //fills globaldatas tree names
+                       globaldata->Treenames = globaldata->Groups;
+               
                        if (m->control_pressed) { return 0; }
                        
                        //create tree file
@@ -323,7 +376,7 @@ int TreeGroupCommand::execute(){
 
                        //create a new filename
                        outputFile = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + "tre";   
-                       outputNames.push_back(outputFile);
+                       outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile);
                                
                        createTree();
                        
@@ -594,7 +647,7 @@ int TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
                
                                        //create a new filename
                                        outputFile = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".tre";                                
-                                       outputNames.push_back(outputFile);
+                                       outputNames.push_back(outputFile); outputTypes["tree"].push_back(outputFile); 
                                                                                                
                                        for (int k = 0; k < thisLookup.size(); k++) { 
                                                for (int l = k; l < thisLookup.size(); l++) {
@@ -606,7 +659,7 @@ int TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
                                                                subset.push_back(thisLookup[k]); subset.push_back(thisLookup[l]); 
                                                                
                                                                data = treeCalculators[i]->getValues(subset); //saves the calculator outputs
-                                                               
+                                               //cout << thisLookup[k]->getGroup() << '\t' << thisLookup[l]->getGroup() << '\t' << (1.0 - data[0]) << endl;
                                                                if (m->control_pressed) { return 1; }
                                                                
                                                                //save values in similarity matrix
@@ -616,6 +669,21 @@ int TreeGroupCommand::process(vector<SharedRAbundVector*> thisLookup) {
                                                }
                                        }
                                        
+                                       //createdistance file from simMatrix
+                                       /*string o = outputDir + m->getRootName(m->getSimpleName(globaldata->inputFileName)) + treeCalculators[i]->getName() + "." + thisLookup[0]->getLabel() + ".dist";
+                                       ofstream outDist;
+                                       m->openOutputFile(o, outDist);
+                                       outDist << simMatrix.size() << endl;
+                                       for (int k = 0; k < simMatrix.size(); k++) {
+                                               outDist << thisLookup[k]->getGroup() << '\t';
+                                               for (int l = 0; l < k; l++) {
+                                                       outDist << (1.0-simMatrix[k][l]) << '\t';
+                                               }
+                                               outDist << endl;
+                                       }
+                                       outDist.close();*/
+
+                                       
                                        if (m->control_pressed) { return 1; }
                                        //creates tree from similarity matrix and write out file
                                        createTree();