]> git.donarmstrong.com Git - mothur.git/blobdiff - readtreecommand.cpp
made read.tree not require a groupfile, if one is not given all seqs are assumed...
[mothur.git] / readtreecommand.cpp
index deae495a2171c6af3d117436920558f2e10e7a27..89efc9abcf0057f68189ddad6975b5e1464fca09 100644 (file)
@@ -76,8 +76,20 @@ ReadTreeCommand::ReadTreeCommand(string option)  {
                        
                        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 {  
+                       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
+                               
+                               globaldata->setGroupFile(groupfile); 
+                               //read in group map info.
+                               treeMap = new TreeMap();
+                               for (int i = 0; i < globaldata->Treenames.size(); i++) { treeMap->addSeq(globaldata->Treenames[i], "Group1"); }
+                               globaldata->gTreemap = treeMap;
+                                       
+                       }else {  
                                globaldata->setGroupFile(groupfile); 
                                //read in group map info.
                                treeMap = new TreeMap(groupfile);
@@ -153,8 +165,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 +206,7 @@ int ReadTreeCommand::execute(){
                        
                        globaldata->gTreemap = treeMap;
                }
-               
+
                return 0;
        }
        catch(exception& e) {
@@ -197,6 +218,7 @@ int ReadTreeCommand::execute(){
 int ReadTreeCommand::readNamesFile() {
        try {
                globaldata->names.clear();
+               numUniquesInName = 0;
                
                ifstream in;
                m->openInputFile(namefile, in);
@@ -207,6 +229,8 @@ int ReadTreeCommand::readNamesFile() {
                while(!in.eof()) {
                        in >> first >> second; m->gobble(in);
                        
+                       numUniquesInName++;
+
                        itNames = globaldata->names.find(first);
                        if (itNames == globaldata->names.end()) {  
                                globaldata->names[first] = second; 
@@ -215,8 +239,8 @@ 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();