X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=groupmap.cpp;h=481fd1decfc4516eb5e1cf618c6b4d40cffbc8a9;hb=8dd3c225255d7084e3aff8740aa4f1f1cabb367a;hp=d57646e3e3dad937d3ca0fa81b26f402cfa1ad4d;hpb=a8367302932de9be5434e77f6e5829d7609e2aec;p=mothur.git diff --git a/groupmap.cpp b/groupmap.cpp index d57646e..481fd1d 100644 --- a/groupmap.cpp +++ b/groupmap.cpp @@ -14,7 +14,7 @@ GroupMap::GroupMap(string filename) { m = MothurOut::getInstance(); groupFileName = filename; - openInputFile(filename, fileHandle); + m->openInputFile(filename, fileHandle); index = 0; } @@ -27,7 +27,7 @@ int GroupMap::readMap() { int error = 0; while(fileHandle){ - fileHandle >> seqName; gobble(fileHandle); //read from first column + fileHandle >> seqName; m->gobble(fileHandle); //read from first column fileHandle >> seqGroup; //read from second column if (m->control_pressed) { fileHandle.close(); return 1; } @@ -41,11 +41,39 @@ int GroupMap::readMap() { groupmap[seqName] = seqGroup; //store data in map seqsPerGroup[seqGroup]++; //increment number of seqs in that group } - gobble(fileHandle); + m->gobble(fileHandle); } fileHandle.close(); + m->setAllGroups(namesOfGroups); return error; } +/************************************************************/ +int GroupMap::readDesignMap() { + string seqName, seqGroup; + int error = 0; + + while(fileHandle){ + fileHandle >> seqName; m->gobble(fileHandle); //read from first column + fileHandle >> seqGroup; //read from second column + + if (m->control_pressed) { fileHandle.close(); return 1; } + + setNamesOfGroups(seqGroup); + + it = groupmap.find(seqName); + + if (it != groupmap.end()) { error = 1; m->mothurOut("Your designfile contains more than 1 group named " + seqName + ", group names must be unique. Please correct."); m->mothurOutEndLine(); } + else { + groupmap[seqName] = seqGroup; //store data in map + seqsPerGroup[seqGroup]++; //increment number of seqs in that group + } + m->gobble(fileHandle); + } + fileHandle.close(); + m->setAllGroups(namesOfGroups); + return error; +} + /************************************************************/ int GroupMap::getNumGroups() { return namesOfGroups.size(); } /************************************************************/ @@ -61,26 +89,36 @@ string GroupMap::getGroup(string sequenceName) { } /************************************************************/ + void GroupMap::setGroup(string sequenceName, string groupN) { - groupmap[sequenceName] = groupN; + setNamesOfGroups(groupN); + + it = groupmap.find(sequenceName); + + if (it != groupmap.end()) { m->mothurOut("Your groupfile contains more than 1 sequence named " + sequenceName + ", sequence names must be unique. Please correct."); m->mothurOutEndLine(); } + else { + groupmap[sequenceName] = groupN; //store data in map + seqsPerGroup[groupN]++; //increment number of seqs in that group + } } + /************************************************************/ void GroupMap::setNamesOfGroups(string seqGroup) { - int i, count; - count = 0; - for (i=0; i GroupMap::getNamesSeqs(){ } } /************************************************************/ +vector GroupMap::getNamesSeqs(vector picked){ + try { + + vector names; + + for (it = groupmap.begin(); it != groupmap.end(); it++) { + //if you are belong to one the the groups in the picked vector add you + if (m->inUsersGroups(it->second, picked)) { + names.push_back(it->first); + } + } + + return names; + } + catch(exception& e) { + m->errorOut(e, "GroupMap", "getNamesSeqs"); + exit(1); + } +} + +/************************************************************/