]> git.donarmstrong.com Git - mothur.git/commitdiff
made read.tree not require a groupfile, if one is not given all seqs are assumed...
authorwestcott <westcott>
Fri, 27 Aug 2010 15:21:38 +0000 (15:21 +0000)
committerwestcott <westcott>
Fri, 27 Aug 2010 15:21:38 +0000 (15:21 +0000)
readtreecommand.cpp
tree.cpp
tree.h
treemap.cpp
treemap.h

index fdfdb050f22c4ccc281646d1d56c8a5aa6b33806..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);
@@ -227,7 +239,7 @@ int ReadTreeCommand::readNamesFile() {
                                vector<string> dupNames;
                                m->splitAtComma(second, dupNames);
                                
-                               for (int i = 0; i < dupNames.size(); i++) {     nameMap[dupNames[i]] = dupNames[i];  }
+                               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();
index dbb3f44403a124679f2e44f0de490faaacbc36ee..3cb26113f8deb8acf3bf28f7040becf2bac7385f 100644 (file)
--- a/tree.cpp
+++ b/tree.cpp
@@ -9,7 +9,19 @@
 
 #include "tree.h"
 
-
+/*****************************************************************/
+Tree::Tree(string g) {
+       try {
+               globaldata = GlobalData::getInstance();
+               m = MothurOut::getInstance();
+               
+               parseTreeFile();  globaldata->runParse = false;  
+       }
+       catch(exception& e) {
+               m->errorOut(e, "Tree", "Tree - just parse");
+               exit(1);
+       }
+}
 /*****************************************************************/
 Tree::Tree() {
        try {
diff --git a/tree.h b/tree.h
index 603f1c3160f984248e427353e3bc745bd4f5c4b0..59343d5fa828a2bcd15d4402764c070c51111e01 100644 (file)
--- a/tree.h
+++ b/tree.h
@@ -18,6 +18,7 @@ class GlobalData;
 
 class Tree {
 public: 
+       Tree(string); 
        Tree();         //to generate a tree from a file
        ~Tree();
        
@@ -40,7 +41,8 @@ public:
        int assembleTree();     
        
        vector<Node> tree;              //the first n nodes are the leaves, where n is the number of sequences.
-               
+       
+                       
 private:
        GlobalData* globaldata;
        int numNodes, numLeaves;
@@ -64,7 +66,7 @@ private:
        int readTreeString(ifstream&);
                
        MothurOut* m;
-       
+               
 };
 
 #endif
index b2fc591c0adb24820d6f603bd8016154ad1c626c..52a90031d380fedddd275bd5ebbb6a3f8600964c 100644 (file)
@@ -44,6 +44,21 @@ void TreeMap::readMap() {
                fileHandle.close();
 }
 /************************************************************/
+void TreeMap::addSeq(string seqName, string seqGroup) {
+       
+               namesOfSeqs.push_back(seqName);
+               setNamesOfGroups(seqGroup);
+                                       
+               treemap[seqName].groupname = seqGroup;  //store data in map
+                       
+               it2 = seqsPerGroup.find(seqGroup);
+               if (it2 == seqsPerGroup.end()) { //if it's a new group
+                       seqsPerGroup[seqGroup] = 1;
+               }else {//it's a group we already have
+                       seqsPerGroup[seqGroup]++;
+               }
+}
+/************************************************************/
 void TreeMap::removeSeq(string seqName) {
        
        //erase name from namesOfSeqs
index bda6926c20ea79800e9f9cc8a06b87ce6f44c68c..d4b506e6fb1d26675937f89f2cc1591e21a98c07 100644 (file)
--- a/treemap.h
+++ b/treemap.h
@@ -36,6 +36,7 @@ public:
        bool isValidGroup(string);  //return true if string is a valid group
        void removeSeq(string);  //removes a sequence, this is to accomadate trees that do not contain all the seqs in your groupfile
        string getGroup(string);
+       void addSeq(string, string);
        vector<string> namesOfGroups;
        vector<string> namesOfSeqs;
     map<string,int> seqsPerGroup;      //groupname, number of seqs in that group.