+/************************************************************/
+//set the number of sequences for the seq for the group
+int CountTable::setAbund(string seqName, string groupName, int num) {
+ try {
+ if (hasGroups) {
+ 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;
+ }else {
+ map<string, int>::iterator it2 = indexNameMap.find(seqName);
+ if (it2 == indexNameMap.end()) {
+ m->mothurOut("[ERROR]: " + seqName + " is not in your count table. Please correct.\n"); m->control_pressed = true;
+ }else {
+ int oldCount = counts[it2->second][it->second];
+ counts[it2->second][it->second] = num;
+ totalGroups[it->second] += (num - oldCount);
+ total += (num - oldCount);
+ totals[it2->second] += (num - oldCount);
+ }
+ }
+ }else{ m->mothurOut("[ERROR]: Your count table does not have group info. Please correct.\n"); m->control_pressed = true; }
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "CountTable", "set");
+ exit(1);
+ }
+}
+/************************************************************/
+//add group
+int CountTable::addGroup(string groupName) {
+ try {
+ bool sanity = m->inUsersGroups(groupName, groups);
+ if (sanity) { m->mothurOut("[ERROR]: " + groupName + " is already in the count table, cannot add again.\n"); m->control_pressed = true; return 0; }
+
+ groups.push_back(groupName);
+ if (!hasGroups) { counts.resize(uniques); }
+
+ for (int i = 0; i < counts.size(); i++) { counts[i].push_back(0); }
+ totalGroups.push_back(0);
+ indexGroupMap[groupName] = groups.size()-1;
+ map<string, int> originalGroupMap = indexGroupMap;
+
+ //important to play well with others, :)
+ sort(groups.begin(), groups.end());
+
+ //fix indexGroupMap && totalGroups
+ vector<int> newTotals; newTotals.resize(groups.size(), 0);
+ for (int i = 0; i < groups.size(); i++) {
+ indexGroupMap[groups[i]] = i;
+ //find original spot of group[i]
+ int index = originalGroupMap[groups[i]];
+ newTotals[i] = totalGroups[index];
+ }
+ totalGroups = newTotals;
+
+ //fix counts vectors
+ for (int i = 0; i < counts.size(); i++) {
+ vector<int> newCounts; newCounts.resize(groups.size(), 0);
+ for (int j = 0; j < groups.size(); j++) {
+ //find original spot of group[i]
+ int index = originalGroupMap[groups[j]];
+ newCounts[j] = counts[i][index];
+ }
+ counts[i] = newCounts;
+ }
+ hasGroups = true;
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "CountTable", "addGroup");
+ exit(1);
+ }
+}
+/************************************************************/
+//vector of groups for the seq
+vector<string> CountTable::getGroups(string seqName) {
+ try {
+ vector<string> thisGroups;
+ if (hasGroups) {
+ vector<int> thisCounts = getGroupCounts(seqName);
+ for (int i = 0; i < thisCounts.size(); i++) {
+ if (thisCounts[i] != 0) { thisGroups.push_back(groups[i]); }
+ }
+ }else{ m->mothurOut("[ERROR]: Your count table does not have group info. Please correct.\n"); m->control_pressed = true; }
+
+ return thisGroups;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "CountTable", "getGroups");
+ exit(1);
+ }
+}
+/************************************************************/
+//total number of seqs represented by seq
+int CountTable::renameSeq(string oldSeqName, string newSeqName) {
+ try {
+
+ map<string, int>::iterator it = indexNameMap.find(oldSeqName);
+ if (it == indexNameMap.end()) {
+ m->mothurOut("[ERROR]: " + oldSeqName + " is not in your count table. Please correct.\n"); m->control_pressed = true;
+ }else {
+ int index = it->second;
+ indexNameMap.erase(it);
+ indexNameMap[newSeqName] = index;
+ }
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "CountTable", "renameSeq");
+ exit(1);
+ }
+}
+