5 * Created by Sarah Westcott on 12/1/08.
6 * Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
12 /************************************************************/
14 GroupMap::GroupMap(string filename) {
15 m = MothurOut::getInstance();
16 groupFileName = filename;
17 openInputFile(filename, fileHandle);
21 /************************************************************/
22 GroupMap::~GroupMap(){}
24 /************************************************************/
25 int GroupMap::readMap() {
26 string seqName, seqGroup;
30 fileHandle >> seqName; //read from first column
31 fileHandle >> seqGroup; //read from second column
33 setNamesOfGroups(seqGroup);
35 it = groupmap.find(seqName);
37 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(); }
39 groupmap[seqName] = seqGroup; //store data in map
40 seqsPerGroup[seqGroup]++; //increment number of seqs in that group
47 /************************************************************/
48 int GroupMap::getNumGroups() { return namesOfGroups.size(); }
49 /************************************************************/
51 string GroupMap::getGroup(string sequenceName) {
53 it = groupmap.find(sequenceName);
54 if (it != groupmap.end()) { //sequence name was in group file
61 /************************************************************/
62 void GroupMap::setGroup(string sequenceName, string groupN) {
63 groupmap[sequenceName] = groupN;
65 /************************************************************/
66 void GroupMap::setNamesOfGroups(string seqGroup) {
69 for (i=0; i<namesOfGroups.size(); i++) {
70 if (namesOfGroups[i] != seqGroup) {
71 count++; //you have not found this group
73 break; //you already have it
76 if (count == namesOfGroups.size()) {
77 namesOfGroups.push_back(seqGroup); //new group
78 seqsPerGroup[seqGroup] = 0;
79 groupIndex[seqGroup] = index;
83 /************************************************************/
84 bool GroupMap::isValidGroup(string groupname) {
86 for (int i = 0; i < namesOfGroups.size(); i++) {
87 if (groupname == namesOfGroups[i]) { return true; }
93 m->errorOut(e, "GroupMap", "isValidGroup");
97 /************************************************************/
98 int GroupMap::getNumSeqs(string group) {
101 map<string, int>::iterator itNum;
103 itNum = seqsPerGroup.find(group);
105 if (itNum == seqsPerGroup.end()) { return 0; }
107 return seqsPerGroup[group];
110 catch(exception& e) {
111 m->errorOut(e, "GroupMap", "getNumSeqs");
116 /************************************************************/
117 vector<string> GroupMap::getNamesSeqs(){
120 vector<string> names;
122 for (it = groupmap.begin(); it != groupmap.end(); it++) {
123 names.push_back(it->first);
128 catch(exception& e) {
129 m->errorOut(e, "GroupMap", "getNamesSeqs");
133 /************************************************************/