X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=counttable.cpp;h=2ab0e345dbd110cc5c0402d0caa36becc1820bd2;hb=5c5c0428f6d548c28a8b903ac80efed4f92d59db;hp=a79047d0af943e1c2bbef6d169aeefa884c1e164;hpb=96dbe925073caefaed6e6db85659c144a806aeb1;p=mothur.git diff --git a/counttable.cpp b/counttable.cpp index a79047d..2ab0e34 100644 --- a/counttable.cpp +++ b/counttable.cpp @@ -481,6 +481,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 reverse; + for (map::iterator it = indexNameMap.begin(); it !=indexNameMap.end(); it++) { reverse[it->second] = it->first; } + map::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 +495,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 newIndexNameMap; for (int i = 0; i < counts.size(); i++) { int num = counts[i][indexOfGroupToRemove]; counts[i].erase(counts[i].begin()+indexOfGroupToRemove); @@ -509,7 +515,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; }