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; gobble(fileHandle); //read from first column
31 fileHandle >> seqGroup; //read from second column
33 if (m->control_pressed) { fileHandle.close(); return 1; }
35 setNamesOfGroups(seqGroup);
37 it = groupmap.find(seqName);
39 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(); }
41 groupmap[seqName] = seqGroup; //store data in map
42 seqsPerGroup[seqGroup]++; //increment number of seqs in that group
49 /************************************************************/
50 int GroupMap::getNumGroups() { return namesOfGroups.size(); }
51 /************************************************************/
53 string GroupMap::getGroup(string sequenceName) {
55 it = groupmap.find(sequenceName);
56 if (it != groupmap.end()) { //sequence name was in group file
63 /************************************************************/
64 void GroupMap::setGroup(string sequenceName, string groupN) {
65 groupmap[sequenceName] = groupN;
67 /************************************************************/
68 void GroupMap::setNamesOfGroups(string seqGroup) {
71 for (i=0; i<namesOfGroups.size(); i++) {
72 if (namesOfGroups[i] != seqGroup) {
73 count++; //you have not found this group
75 break; //you already have it
78 if (count == namesOfGroups.size()) {
79 namesOfGroups.push_back(seqGroup); //new group
80 seqsPerGroup[seqGroup] = 0;
81 groupIndex[seqGroup] = index;
85 /************************************************************/
86 bool GroupMap::isValidGroup(string groupname) {
88 for (int i = 0; i < namesOfGroups.size(); i++) {
89 if (groupname == namesOfGroups[i]) { return true; }
95 m->errorOut(e, "GroupMap", "isValidGroup");
99 /************************************************************/
100 int GroupMap::getNumSeqs(string group) {
103 map<string, int>::iterator itNum;
105 itNum = seqsPerGroup.find(group);
107 if (itNum == seqsPerGroup.end()) { return 0; }
109 return seqsPerGroup[group];
112 catch(exception& e) {
113 m->errorOut(e, "GroupMap", "getNumSeqs");
118 /************************************************************/
119 vector<string> GroupMap::getNamesSeqs(){
122 vector<string> names;
124 for (it = groupmap.begin(); it != groupmap.end(); it++) {
125 names.push_back(it->first);
130 catch(exception& e) {
131 m->errorOut(e, "GroupMap", "getNamesSeqs");
135 /************************************************************/