X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=counttable.cpp;h=a664228b17c35fff4ce48ca0ea5255b5b99bb1f3;hb=5a4ac4f954c4b4445bcee272f1f8220ddcc9c1e4;hp=c4e2732e8554cd81a934af7f2ee3bfcff7705db6;hpb=fdfbfe59134dd7dd3e49d90609d129128ba2d370;p=mothur.git diff --git a/counttable.cpp b/counttable.cpp index c4e2732..a664228 100644 --- a/counttable.cpp +++ b/counttable.cpp @@ -42,7 +42,8 @@ int CountTable::readTable(string file) { if (m->control_pressed) { break; } - in >> name >> thisTotal; m->gobble(in); + in >> name; m->gobble(in); in >> thisTotal; m->gobble(in); + if (m->debug) { m->mothurOut("[DEBUG]: " + name + '\t' + toString(thisTotal) + "\n"); } //if group info, then read it vector groupCounts; groupCounts.resize(numGroups, 0); @@ -157,7 +158,41 @@ int CountTable::getNumSeqs(string seqName) { } } /************************************************************/ -//returns names of seqs +//returns unique index for sequence like get in NameAssignment +int CountTable::get(string seqName) { + try { + + map::iterator it = indexNameMap.find(seqName); + if (it == indexNameMap.end()) { + m->mothurOut("[ERROR]: " + seqName + " is not in your count table. Please correct.\n"); m->control_pressed = true; + }else { return it->second; } + + return -1; + } + catch(exception& e) { + m->errorOut(e, "CountTable", "get"); + exit(1); + } +} +/************************************************************/ +//create ListVector from uniques +ListVector CountTable::getListVector() { + try { + ListVector list(indexNameMap.size()); + for (map::iterator it = indexNameMap.begin(); it != indexNameMap.end(); it++) { + if (m->control_pressed) { break; } + list.set(it->second, it->first); + } + return list; + } + catch(exception& e) { + m->errorOut(e, "CountTable", "getListVector"); + exit(1); + } +} + +/************************************************************/ +//returns the names of all unique sequences in file vector CountTable::getNamesOfSeqs() { try { vector names; @@ -173,5 +208,37 @@ vector CountTable::getNamesOfSeqs() { } } /************************************************************/ +//returns names of seqs +int CountTable::mergeCounts(string seq1, string seq2) { + try { + map::iterator it = indexNameMap.find(seq1); + if (it == indexNameMap.end()) { + m->mothurOut("[ERROR]: " + seq1 + " is not in your count table. Please correct.\n"); m->control_pressed = true; + }else { + map::iterator it2 = indexNameMap.find(seq2); + if (it2 == indexNameMap.end()) { + m->mothurOut("[ERROR]: " + seq2 + " is not in your count table. Please correct.\n"); m->control_pressed = true; + }else { + //merge data + for (int i = 0; i < groups.size(); i++) { + counts[it->second][i] += counts[it2->second][i]; + counts[it2->second][i] = 0; + } + totals[it->second] += totals[it2->second]; + totals[it2->second] = 0; + uniques--; + indexNameMap.erase(it2); + } + } + + return 0; + } + catch(exception& e) { + m->errorOut(e, "CountTable", "getNamesOfSeqs"); + exit(1); + } +} + +/************************************************************/