]> git.donarmstrong.com Git - mothur.git/blob - nameassignment.cpp
added mothur.h and fixed includes in many files
[mothur.git] / nameassignment.cpp
1 using namespace std;
2
3 #include "nameassignment.hpp"
4
5 //**********************************************************************************************************************
6
7 NameAssignment::NameAssignment(string nameMapFile){
8         
9         openInputFile(nameMapFile, fileHandle);
10         
11 }
12
13 //**********************************************************************************************************************
14
15 void NameAssignment::readMap(int colA, int colB){
16         try{
17                 string firstCol, secondCol, skip;
18         //      int index = 0;
19         
20                 int skipNCols = colB-colA-1;
21         
22                 map<string, string> data;
23         
24                 while(fileHandle){
25                         fileHandle >> firstCol;                         //read from first column
26                 
27                         for(int i=0;i<skipNCols;i++){           //allows for anticipated file format
28                                 fileHandle >> skip;
29                         }
30                 
31                         fileHandle >> secondCol;                        //read from second column
32                 
33                         data[firstCol] = secondCol;                     //store data in map
34                 
35                         gobble(fileHandle);
36                 }
37                 fileHandle.close();
38         
39                 int rowIndex = 0;
40                 map<string, string>::iterator it = data.begin();
41                 for(it;it!=data.end();it++){
42                         list.push_back(it->second);             //adds data's value to list
43                         (*this)[it->first] = rowIndex;
44                         rowIndex++;
45                 }
46         }
47         catch(exception& e) {
48                 cout << "Standard Error: " << e.what() << " has occurred in the NameAssignment class Function readMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
49                 exit(1);
50         }
51         catch(...) {
52                 cout << "An unknown error has occurred in the NameAssignment class function readMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
53                 exit(1);
54         }
55 }
56
57 //**********************************************************************************************************************
58
59 ListVector NameAssignment::getListVector(void){
60
61         return list;
62         
63 }
64
65 //**********************************************************************************************************************
66
67 void NameAssignment::print(void){
68         try {
69                 map<string,int>::iterator it = (*this).begin();
70                 for(it;it!=(*this).end();it++){
71                         cout << it->first << '\t' << it->second << endl;  //prints out keys and values of the map this.
72                 }
73         }
74         catch(exception& e) {
75                 cout << "Standard Error: " << e.what() << " has occurred in the NameAssignment class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
76                 exit(1);
77         }
78         catch(...) {
79                 cout << "An unknown error has occurred in the NameAssignment class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
80                 exit(1);
81         }
82 }
83
84 //**********************************************************************************************************************
85
86 int NameAssignment::get(string key){
87         
88         return  (*this)[key];   
89
90 }
91
92 //**********************************************************************************************************************
93