]> git.donarmstrong.com Git - mothur.git/blobdiff - treemap.cpp
created mothurOut class to handle logfiles
[mothur.git] / treemap.cpp
index bee0d11ed21323ee9dff1bc38c860a3042231150..bb624480e79640d8a23fc6fe4c47c8ba8c6b82a4 100644 (file)
@@ -17,7 +17,7 @@
 }
 
 /************************************************************/
- TreeMap::~TreeMap(){};
+ TreeMap::~TreeMap(){}
 
 /************************************************************/
 void TreeMap::readMap() {
@@ -44,10 +44,29 @@ void TreeMap::readMap() {
                fileHandle.close();
 }
 /************************************************************/
+void TreeMap::removeSeq(string seqName) {
+       
+       //erase name from namesOfSeqs
+       for (int i = 0; i < namesOfSeqs.size(); i++) {
+               if (namesOfSeqs[i] == seqName)  {
+                       namesOfSeqs.erase(namesOfSeqs.begin()+i);
+                       break;
+               }
+       }
+       
+       //decrement sequences in this group
+       string group = treemap[seqName].groupname;
+       seqsPerGroup[group]--;
+       
+       //remove seq from treemap
+       it = treemap.find(seqName);
+       treemap.erase(it);
+}
+/************************************************************/
 
 int TreeMap::getNumGroups() {
                        
-       return seqsPerGroup.size();     
+       return namesOfGroups.size();    
                
 }
 /************************************************************/
@@ -72,7 +91,13 @@ string TreeMap::getGroup(string sequenceName) {
 }
 /************************************************************/
 void TreeMap::setIndex(string seq, int index) {
-       treemap[seq].vectorIndex = index;
+       it = treemap.find(seq);
+       if (it != treemap.end()) { //sequence name was in group file
+               treemap[seq].vectorIndex = index;       
+       }else {
+               treemap[seq].vectorIndex = index;
+               treemap[seq].groupname = "not found";
+       }
 }
 /************************************************************/
 int TreeMap::getIndex(string seq) {
@@ -100,7 +125,20 @@ void TreeMap::setNamesOfGroups(string seqGroup) {
                                namesOfGroups.push_back(seqGroup); //new group
                        }
 }
-
+/************************************************************/
+bool TreeMap::isValidGroup(string groupname) {
+       try {
+               for (int i = 0; i < namesOfGroups.size(); i++) {
+                       if (groupname == namesOfGroups[i]) { return true; }
+               }
+               
+               return false;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "TreeMap", "isValidGroup");
+               exit(1);
+       }
+}
 /***********************************************************************/
 
 void TreeMap::print(ostream& output){
@@ -111,13 +149,60 @@ void TreeMap::print(ostream& output){
                }
        }
        catch(exception& e) {
-               cout << "Standard Error: " << e.what() << " has occurred in the TreeMap class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               m->errorOut(e, "TreeMap", "print");
+               exit(1);
+       }
+}
+
+/************************************************************/
+void TreeMap::makeSim(GroupMap* groupmap) {
+       try {
+               //set names of groups
+               namesOfGroups = groupmap->namesOfGroups;
+               
+               //set names of seqs to names of groups
+               namesOfSeqs = groupmap->namesOfGroups;
+               
+               // make map where key and value are both the group name since that what the tree.shared command wants
+               for (int i = 0; i < namesOfGroups.size(); i++) {
+                       treemap[namesOfGroups[i]].groupname = namesOfGroups[i];
+                       seqsPerGroup[namesOfGroups[i]] = 1;
+               }
+               
+               numGroups = namesOfGroups.size();
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "TreeMap", "makeSim");
                exit(1);
        }
-       catch(...) {
-               cout << "An unknown error has occurred in the TreeMap class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+}
+/************************************************************/
+void TreeMap::makeSim(ListVector* list) {
+       try {
+               //set names of groups
+               namesOfGroups.clear();
+               for(int i = 0; i < list->size(); i++) {
+                       namesOfGroups.push_back(list->get(i));
+               }
+               
+               //set names of seqs to names of groups
+               namesOfSeqs = namesOfGroups;
+               
+               // make map where key and value are both the group name since that what the tree.shared command wants
+               for (int i = 0; i < namesOfGroups.size(); i++) {
+                       treemap[namesOfGroups[i]].groupname = namesOfGroups[i];
+                       seqsPerGroup[namesOfGroups[i]] = 1;
+               }
+               
+               numGroups = namesOfGroups.size();
+               
+       }
+       catch(exception& e) {
+               m->errorOut(e, "TreeMap", "makeSim");
                exit(1);
        }
 }
 
 /************************************************************/
+