]> git.donarmstrong.com Git - mothur.git/blob - groupmap.cpp
fixed summary.shared bug and set jumble default to 1.
[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 }
18
19 /************************************************************/
20  GroupMap::~GroupMap(){};
21
22 /************************************************************/
23 void GroupMap::readMap() {
24                 string seqName, seqGroup;
25         
26                 while(fileHandle){
27                         fileHandle >> seqName;                  //read from first column
28                         fileHandle >> seqGroup;                 //read from second column
29                         
30                         setNamesOfGroups(seqGroup);
31                                                 
32                         groupmap[seqName] = seqGroup;   //store data in map
33                 
34                         gobble(fileHandle);
35                 }
36                 fileHandle.close();
37 }
38 /************************************************************/
39
40 int GroupMap::getNumGroups() {
41                         
42         return namesOfGroups.size();    
43                 
44 }
45 /************************************************************/
46
47 string GroupMap::getGroup(string sequenceName) {
48                         
49         it = groupmap.find(sequenceName);
50         if (it != groupmap.end()) { //sequence name was in group file
51                 return it->second;      
52         }else {
53                 return "not found";
54         }
55                 
56 }
57
58 /************************************************************/
59
60 void GroupMap::setNamesOfGroups(string seqGroup) {
61                         int i, count;
62                         count = 0;
63                         for (i=0; i<namesOfGroups.size(); i++) {
64                                 if (namesOfGroups[i] != seqGroup) {
65                                         count++; //you have not found this group
66                                 }else {
67                                         break; //you already have it
68                                 }
69                         }
70                         if (count == namesOfGroups.size()) {
71                                 namesOfGroups.push_back(seqGroup); //new group
72                         }
73 }