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 groupFileName = filename;
16 openInputFile(filename, fileHandle);
20 /************************************************************/
21 GroupMap::~GroupMap(){}
23 /************************************************************/
24 int GroupMap::readMap() {
25 string seqName, seqGroup;
29 fileHandle >> seqName; //read from first column
30 fileHandle >> seqGroup; //read from second column
32 setNamesOfGroups(seqGroup);
34 it = groupmap.find(seqName);
36 if (it != groupmap.end()) { error = 1; mothurOut("Your groupfile contains more than 1 sequence named " + seqName + ", sequence names must be unique. Please correct."); mothurOutEndLine(); }
38 groupmap[seqName] = seqGroup; //store data in map
39 seqsPerGroup[seqGroup]++; //increment number of seqs in that group
46 /************************************************************/
47 int GroupMap::getNumGroups() { return namesOfGroups.size(); }
48 /************************************************************/
50 string GroupMap::getGroup(string sequenceName) {
52 it = groupmap.find(sequenceName);
53 if (it != groupmap.end()) { //sequence name was in group file
60 /************************************************************/
61 void GroupMap::setGroup(string sequenceName, string groupN) {
62 groupmap[sequenceName] = groupN;
64 /************************************************************/
65 void GroupMap::setNamesOfGroups(string seqGroup) {
68 for (i=0; i<namesOfGroups.size(); i++) {
69 if (namesOfGroups[i] != seqGroup) {
70 count++; //you have not found this group
72 break; //you already have it
75 if (count == namesOfGroups.size()) {
76 namesOfGroups.push_back(seqGroup); //new group
77 seqsPerGroup[seqGroup] = 0;
78 groupIndex[seqGroup] = index;
82 /************************************************************/
83 bool GroupMap::isValidGroup(string groupname) {
85 for (int i = 0; i < namesOfGroups.size(); i++) {
86 if (groupname == namesOfGroups[i]) { return true; }
92 errorOut(e, "GroupMap", "isValidGroup");
96 /************************************************************/
97 int GroupMap::getNumSeqs(string group) {
100 map<string, int>::iterator itNum;
102 itNum = seqsPerGroup.find(group);
104 if (itNum == seqsPerGroup.end()) { return 0; }
106 return seqsPerGroup[group];
109 catch(exception& e) {
110 errorOut(e, "GroupMap", "getNumSeqs");
115 /************************************************************/
116 vector<string> GroupMap::getNamesSeqs(){
119 vector<string> names;
121 for (it = groupmap.begin(); it != groupmap.end(); it++) {
122 names.push_back(it->first);
127 catch(exception& e) {
128 errorOut(e, "GroupMap", "getNamesSeqs");
132 /************************************************************/