X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=counttable.cpp;h=ad0b2dadfcba7eb2f866b44d3d9b3011242b096a;hb=1f0e54b53b714781f3f2fee7d01177fade98a625;hp=a79047d0af943e1c2bbef6d169aeefa884c1e164;hpb=96dbe925073caefaed6e6db85659c144a806aeb1;p=mothur.git diff --git a/counttable.cpp b/counttable.cpp index a79047d..ad0b2da 100644 --- a/counttable.cpp +++ b/counttable.cpp @@ -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 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 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 +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 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; }