+int SplitAbundCommand::parseCount(string tag) { //namefile
+ try {
+
+ map<string, ofstream*> filehandles;
+
+ if (Groups.size() == 0) {
+ string rare = outputDir + m->getRootName(m->getSimpleName(countfile)) + tag + "rare." + getOutputFileNameTag("count");
+ outputNames.push_back(rare); outputTypes["count"].push_back(rare);
+
+ string abund = outputDir + m->getRootName(m->getSimpleName(countfile)) + tag + "abund." + getOutputFileNameTag("count");
+ outputNames.push_back(abund); outputTypes["count"].push_back(abund);
+
+ CountTable rareTable;
+ CountTable abundTable;
+ if (ct.hasGroupInfo()) {
+ vector<string> ctGroups = ct.getNamesOfGroups();
+ for (int i = 0; i < ctGroups.size(); i++) { rareTable.addGroup(ctGroups[i]); abundTable.addGroup(ctGroups[i]); }
+ }
+
+ if (rareNames.size() != 0) {
+ for (set<string>::iterator itRare = rareNames.begin(); itRare != rareNames.end(); itRare++) {
+ if (ct.hasGroupInfo()) {
+ vector<int> groupCounts = ct.getGroupCounts(*itRare);
+ rareTable.push_back(*itRare, groupCounts);
+ }else {
+ int groupCounts = ct.getNumSeqs(*itRare);
+ rareTable.push_back(*itRare, groupCounts);
+ }
+ }
+ if (rareTable.hasGroupInfo()) {
+ vector<string> ctGroups = rareTable.getNamesOfGroups();
+ for (int i = 0; i < ctGroups.size(); i++) {
+ if (rareTable.getGroupCount(ctGroups[i]) == 0) { rareTable.removeGroup(ctGroups[i]); }
+ }
+ }
+ rareTable.printTable(rare);
+ }
+
+
+ if (abundNames.size() != 0) {
+ for (set<string>::iterator itAbund = abundNames.begin(); itAbund != abundNames.end(); itAbund++) {
+ if (ct.hasGroupInfo()) {
+ vector<int> groupCounts = ct.getGroupCounts(*itAbund);
+ abundTable.push_back(*itAbund, groupCounts);
+ }else {
+ int groupCounts = ct.getNumSeqs(*itAbund);
+ abundTable.push_back(*itAbund, groupCounts);
+ }
+ }
+ if (abundTable.hasGroupInfo()) {
+ vector<string> ctGroups = abundTable.getNamesOfGroups();
+ for (int i = 0; i < ctGroups.size(); i++) {
+ if (abundTable.getGroupCount(ctGroups[i]) == 0) { abundTable.removeGroup(ctGroups[i]); }
+ }
+ }
+ abundTable.printTable(abund);
+ }
+
+ }else{ //parse names by abundance and group
+ map<string, CountTable*> countTableMap;
+ map<string, CountTable*>::iterator it3;
+
+ for (int i=0; i<Groups.size(); i++) {
+ CountTable* rareCt = new CountTable();
+ rareCt->addGroup(Groups[i]);
+ countTableMap[Groups[i]+".rare"] = rareCt;
+ CountTable* abundCt = new CountTable();
+ abundCt->addGroup(Groups[i]);
+ countTableMap[Groups[i]+".abund"] = abundCt;
+ }
+
+ vector<string> allNames = ct.getNamesOfSeqs();
+ for (int i = 0; i < allNames.size(); i++) {
+ string rareAbund;
+ if (rareNames.count(allNames[i]) != 0) { //you are a rare name
+ rareAbund = ".rare";
+ }else{ //you are a abund name
+ rareAbund = ".abund";
+ }
+
+ vector<string> thisSeqsGroups = ct.getGroups(allNames[i]);
+ for (int j = 0; j < thisSeqsGroups.size(); j++) {
+ if (m->inUsersGroups(thisSeqsGroups[j], Groups)) { //only add if this is in a group we want
+ int num = ct.getGroupCount(allNames[i], thisSeqsGroups[j]);
+ vector<int> nums; nums.push_back(num);
+ countTableMap[thisSeqsGroups[j]+rareAbund]->push_back(allNames[i], nums);
+ }
+ }
+ }
+
+
+ for (it3 = countTableMap.begin(); it3 != countTableMap.end(); it3++) {
+ string fileroot = outputDir + m->getRootName(m->getSimpleName(countfile));
+ string filename = fileroot + it3->first + "." + getOutputFileNameTag("count");
+ outputNames.push_back(filename); outputTypes["count"].push_back(filename);
+ (it3->second)->printTable(filename);
+ delete it3->second;
+ }
+ }
+
+ return 0;
+
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SplitAbundCommand", "parseCount");
+ exit(1);
+ }
+}
+/**********************************************************************************************************************/