]> git.donarmstrong.com Git - mothur.git/blobdiff - readtreecommand.cpp
removed read.dist, read.otu, read.tree and globaldata. added current to defaults...
[mothur.git] / readtreecommand.cpp
index deae495a2171c6af3d117436920558f2e10e7a27..c476f5a89928cf131593178b40eb50d60130a7bd 100644 (file)
@@ -9,16 +9,17 @@
 
 #include "readtreecommand.h"
 
+
 //**********************************************************************************************************************
 ReadTreeCommand::ReadTreeCommand(string option)  {
        try {
-               globaldata = GlobalData::getInstance();
-               abort = false;
+               abort = false; calledHelp = false;   
                                
                //allow user to run help
-               if(option == "help") { help(); abort = true; }
+               if(option == "help") { help(); abort = true; calledHelp = true; }
                
                else {
+                       /*
                        //valid paramters for this command
                        string Array[] =  {"tree","group","name","outputdir","inputdir"};
                        vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
@@ -72,17 +73,24 @@ ReadTreeCommand::ReadTreeCommand(string option)  {
                        treefile = validParameter.validFile(parameters, "tree", true);
                        if (treefile == "not open") { abort = true; }
                        else if (treefile == "not found") { treefile = ""; m->mothurOut("tree is a required parameter for the read.tree command."); m->mothurOutEndLine(); abort = true;  }     
-                       else {  globaldata->setTreeFile(treefile);  globaldata->setFormat("tree");      }
                        
                        groupfile = validParameter.validFile(parameters, "group", true);
                        if (groupfile == "not open") { abort = true; }  
-                       else if (groupfile == "not found") { groupfile = ""; m->mothurOut("group is a required parameter for the read.tree command."); m->mothurOutEndLine(); abort = true;     }
-                       else {  
-                               globaldata->setGroupFile(groupfile); 
+                       else if (groupfile == "not found") { 
+                               groupfile = ""; 
+                               
+                               m->mothurOut("You have not provided a group file. I am assumming all sequence are from the same group."); m->mothurOutEndLine();        
+                               
+                               if (treefile != "") {  Tree* tree = new Tree(treefile); delete tree;  } //extracts names from tree to make faked out groupmap
+                               
+                               //read in group map info.
+                               treeMap = new TreeMap();
+                               for (int i = 0; i < m->Treenames.size(); i++) { treeMap->addSeq(m->Treenames[i], "Group1"); }
+                                       
+                       }else {  
                                //read in group map info.
                                treeMap = new TreeMap(groupfile);
                                treeMap->readMap();
-                               globaldata->gTreemap = treeMap;
                        }
                        
                        namefile = validParameter.validFile(parameters, "name", true);
@@ -94,7 +102,7 @@ ReadTreeCommand::ReadTreeCommand(string option)  {
                                filename = treefile;
                                read = new ReadNewickTree(filename);
                        }
-                                               
+                       */                      
                }
        }
        catch(exception& e) {
@@ -104,42 +112,19 @@ ReadTreeCommand::ReadTreeCommand(string option)  {
 }
 //**********************************************************************************************************************
 
-void ReadTreeCommand::help(){
-       try {
-               m->mothurOut("The read.tree command must be run before you execute a unifrac.weighted, unifrac.unweighted. \n");
-               m->mothurOut("It also must be run before using the parsimony command, unless you are using the randomtree parameter.\n");
-               m->mothurOut("The read.tree command parameters are tree, group and name.\n");
-               m->mothurOut("The read.tree command should be in the following format: read.tree(tree=yourTreeFile, group=yourGroupFile).\n");
-               m->mothurOut("The tree and group parameters are both required.\n");
-               m->mothurOut("The name parameter allows you to enter a namefile.\n");
-               m->mothurOut("Note: No spaces between parameter labels (i.e. tree), '=' and parameters (i.e.yourTreefile).\n\n");
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ReadTreeCommand", "help");      
-               exit(1);
-       }
-}
-
-//**********************************************************************************************************************
-
-ReadTreeCommand::~ReadTreeCommand(){
-       if (abort == false) { delete read; }
-}
-
-//**********************************************************************************************************************
-
 int ReadTreeCommand::execute(){
        try {
        
-               if (abort == true) { return 0; }
-               
+               if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
+               m->mothurOut(getHelpString()); m->mothurOutEndLine();
+               /*
                int readOk;
                
-               readOk = read->read(); 
+               readOk = read->read(treeMap); 
                
                if (readOk != 0) { m->mothurOut("Read Terminated."); m->mothurOutEndLine(); globaldata->gTree.clear(); delete globaldata->gTreemap; return 0; }
                
-               vector<Tree*> T = globaldata->gTree;
+               vector<Tree*> T = read->gTree;
 
                //assemble users trees
                for (int i = 0; i < T.size(); i++) {
@@ -153,8 +138,17 @@ int ReadTreeCommand::execute(){
                        T[i]->assembleTree();
                }
 
+               
+               //if you provide a namefile we will use the numNames in the namefile as long as the number of unique match the tree names size.
+               int numNamesInTree;
+               if (namefile != "")  {  
+                       if (numUniquesInName == globaldata->Treenames.size()) {  numNamesInTree = nameMap.size();  }
+                       else {   numNamesInTree = globaldata->Treenames.size();  }
+               }else {  numNamesInTree = globaldata->Treenames.size();  }
+               
+               
                //output any names that are in group file but not in tree
-               if (globaldata->Treenames.size() < treeMap->getNumSeqs()) {
+               if (numNamesInTree < treeMap->getNumSeqs()) {
                        for (int i = 0; i < treeMap->namesOfSeqs.size(); i++) {
                                //is that name in the tree?
                                int count = 0;
@@ -185,7 +179,7 @@ int ReadTreeCommand::execute(){
                        
                        globaldata->gTreemap = treeMap;
                }
-               
+                */
                return 0;
        }
        catch(exception& e) {
@@ -196,7 +190,9 @@ int ReadTreeCommand::execute(){
 /*****************************************************************/
 int ReadTreeCommand::readNamesFile() {
        try {
-               globaldata->names.clear();
+               /*
+               m->names.clear();
+               numUniquesInName = 0;
                
                ifstream in;
                m->openInputFile(namefile, in);
@@ -207,7 +203,9 @@ int ReadTreeCommand::readNamesFile() {
                while(!in.eof()) {
                        in >> first >> second; m->gobble(in);
                        
-                       itNames = globaldata->names.find(first);
+                       numUniquesInName++;
+
+                       itNames = m->names.find(first);
                        if (itNames == globaldata->names.end()) {  
                                globaldata->names[first] = second; 
                                
@@ -215,11 +213,11 @@ int ReadTreeCommand::readNamesFile() {
                                vector<string> dupNames;
                                m->splitAtComma(second, dupNames);
                                
-                               for (int i = 0; i < dupNames.size(); i++) {     nameMap[dupNames[i]] = dupNames[i];  }
-                       }else {  m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); globaldata->names.clear(); return 1; }                        
+                               for (int i = 0; i < dupNames.size(); i++) {     nameMap[dupNames[i]] = dupNames[i];  if ((groupfile == "") && (i != 0)) { globaldata->gTreemap->addSeq(dupNames[i], "Group1"); }  }
+                       }else {  m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); globaldata->names.clear(); namefile = ""; return 1; }                 
                }
                in.close();
-               
+               */
                return 0;
        }
        catch(exception& e) {