X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=groupmap.cpp;h=58e04c5db858791f28a99a5cb50795a570da0690;hb=92de7f976371d41441ad41f02ca83af8b43cef5c;hp=9cf5d7a53acf2f421bea5aeb7601a3efe674aee3;hpb=20a2d0350a737a434c89f303662d64a8eeea7b05;p=mothur.git diff --git a/groupmap.cpp b/groupmap.cpp index 9cf5d7a..58e04c5 100644 --- a/groupmap.cpp +++ b/groupmap.cpp @@ -3,7 +3,7 @@ * Dotur * * Created by Sarah Westcott on 12/1/08. - * Copyright 2008 __MyCompanyName__. All rights reserved. + * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved. * */ @@ -12,36 +12,70 @@ /************************************************************/ GroupMap::GroupMap(string filename) { + m = MothurOut::getInstance(); groupFileName = filename; - openInputFile(filename, fileHandle); + m->openInputFile(filename, fileHandle); + index = 0; } /************************************************************/ - GroupMap::~GroupMap(){}; + GroupMap::~GroupMap(){} /************************************************************/ -void GroupMap::readMap() { +int GroupMap::readMap() { string seqName, seqGroup; - + int error = 0; + while(fileHandle){ - fileHandle >> seqName; //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; } + setNamesOfGroups(seqGroup); - - groupmap[seqName] = seqGroup; //store data in map - - gobble(fileHandle); + + it = groupmap.find(seqName); + + if (it != groupmap.end()) { error = 1; m->mothurOut("Your groupfile contains more than 1 sequence named " + seqName + ", sequence 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->namesOfGroups = namesOfGroups; + return error; } /************************************************************/ +int GroupMap::readDesignMap() { + string seqName, seqGroup; + int error = 0; -int GroupMap::getNumGroups() { + while(fileHandle){ + fileHandle >> seqName; m->gobble(fileHandle); //read from first column + fileHandle >> seqGroup; //read from second column - return namesOfGroups.size(); - + 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->namesOfGroups = namesOfGroups; + return error; } + +/************************************************************/ +int GroupMap::getNumGroups() { return namesOfGroups.size(); } /************************************************************/ string GroupMap::getGroup(string sequenceName) { @@ -52,23 +86,102 @@ string GroupMap::getGroup(string sequenceName) { }else { return "not found"; } - } /************************************************************/ +void GroupMap::setGroup(string sequenceName, string groupN) { + groupmap[sequenceName] = groupN; +} + +/************************************************************/ void GroupMap::setNamesOfGroups(string seqGroup) { - int i, count; - count = 0; - for (i=0; ierrorOut(e, "GroupMap", "isValidGroup"); + exit(1); + } +} +/************************************************************/ +int GroupMap::getNumSeqs(string group) { + try { + + map::iterator itNum; + + itNum = seqsPerGroup.find(group); + + if (itNum == seqsPerGroup.end()) { return 0; } + + return seqsPerGroup[group]; + + } + catch(exception& e) { + m->errorOut(e, "GroupMap", "getNumSeqs"); + exit(1); + } +} + +/************************************************************/ +vector GroupMap::getNamesSeqs(){ + try { + + vector names; + + for (it = groupmap.begin(); it != groupmap.end(); it++) { + names.push_back(it->first); + } + + return names; + } + catch(exception& e) { + m->errorOut(e, "GroupMap", "getNamesSeqs"); + exit(1); + } +} +/************************************************************/ +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); + } } -/************************************************************/ \ No newline at end of file + +/************************************************************/ +