]> git.donarmstrong.com Git - mothur.git/blob - groupmap.cpp
fixed bug with displaying info for collect.shared() and summary.shared().
[mothur.git] / groupmap.cpp
1 /*
2  *  groupmap.cpp
3  *  Dotur
4  *
5  *  Created by Sarah Westcott on 12/1/08.
6  *  Copyright 2008 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "groupmap.h"
11
12 /************************************************************/
13
14  GroupMap::GroupMap(string filename) {
15         groupFileName = filename;
16         openInputFile(filename, fileHandle);
17         index = 0;
18 }
19
20 /************************************************************/
21  GroupMap::~GroupMap(){};
22
23 /************************************************************/
24 void GroupMap::readMap() {
25                 string seqName, seqGroup;
26         
27                 while(fileHandle){
28                         fileHandle >> seqName;                  //read from first column
29                         fileHandle >> seqGroup;                 //read from second column
30                         
31                         setNamesOfGroups(seqGroup);
32                                                 
33                         groupmap[seqName] = seqGroup;   //store data in map
34                 
35                         gobble(fileHandle);
36                 }
37                 fileHandle.close();
38 }
39 /************************************************************/
40
41 int GroupMap::getNumGroups() {
42                         
43         return namesOfGroups.size();    
44                 
45 }
46 /************************************************************/
47
48 string GroupMap::getGroup(string sequenceName) {
49                         
50         it = groupmap.find(sequenceName);
51         if (it != groupmap.end()) { //sequence name was in group file
52                 return it->second;      
53         }else {
54                 return "not found";
55         }
56                 
57 }
58
59 /************************************************************/
60
61 void GroupMap::setNamesOfGroups(string seqGroup) {
62                         int i, count;
63                         count = 0;
64                         for (i=0; i<namesOfGroups.size(); i++) {
65                                 if (namesOfGroups[i] != seqGroup) {
66                                         count++; //you have not found this group
67                                 }else {
68                                         break; //you already have it
69                                 }
70                         }
71                         if (count == namesOfGroups.size()) {
72                                 namesOfGroups.push_back(seqGroup); //new group
73                                 groupIndex[seqGroup] = index;
74                                 index++;
75                         }
76 }