]> git.donarmstrong.com Git - mothur.git/blobdiff - counttable.cpp
added get.dists and remove.dists commands. fixed bug in trim.seqs windows paralelliza...
[mothur.git] / counttable.cpp
index a79047d0af943e1c2bbef6d169aeefa884c1e164..ad0b2dadfcba7eb2f866b44d3d9b3011242b096a 100644 (file)
@@ -131,6 +131,9 @@ int CountTable::createTable(string namefile, string groupfile, bool createGroup)
             string firstCol, secondCol;
             in >> firstCol; m->gobble(in); in >> secondCol; m->gobble(in);
             
+            m->checkName(firstCol);
+            m->checkName(secondCol);
+            
             vector<string> names;
             m->splitAtChar(secondCol, names, ',');
             
@@ -481,6 +484,10 @@ int CountTable::addGroup(string groupName) {
 int CountTable::removeGroup(string groupName) {
     try {        
         if (hasGroups) {
+            //save for later in case removing a group means we need to remove a seq.
+            map<int, string> reverse;
+            for (map<string, int>::iterator it = indexNameMap.begin(); it !=indexNameMap.end(); it++) { reverse[it->second] = it->first;  }
+            
             map<string, int>::iterator it = indexGroupMap.find(groupName);
             if (it == indexGroupMap.end()) {
                 m->mothurOut("[ERROR]: " + groupName + " is not in your count table. Please correct.\n"); m->control_pressed = true;
@@ -491,13 +498,15 @@ int CountTable::removeGroup(string groupName) {
                 for (int i = 0; i < groups.size(); i++) {
                     if (groups[i] != groupName) { 
                         newGroups.push_back(groups[i]);
-                        indexGroupMap[groups[i]] = i;
+                        indexGroupMap[groups[i]] = newGroups.size()-1;
                     }
                 }
                 indexGroupMap.erase(groupName);
                 groups = newGroups;
                 totalGroups.erase(totalGroups.begin()+indexOfGroupToRemove);
-                 
+                
+                int thisIndex = 0;
+                map<string, int> newIndexNameMap;
                 for (int i = 0; i < counts.size(); i++) {
                     int num = counts[i][indexOfGroupToRemove];
                     counts[i].erase(counts[i].begin()+indexOfGroupToRemove);
@@ -509,7 +518,11 @@ int CountTable::removeGroup(string groupName) {
                         uniques--;
                         i--;
                     }
+                    newIndexNameMap[reverse[thisIndex]] = i;
+                    thisIndex++;
                 }
+                indexNameMap = newIndexNameMap;
+                
                 if (groups.size() == 0) { hasGroups = false; }
             }
         }else { m->mothurOut("[ERROR]: your count table does not contain group information, can not remove group " + groupName + ".\n"); m->control_pressed = true; }