]> git.donarmstrong.com Git - mothur.git/blob - nameassignment.cpp
This is v.1.4.0
[mothur.git] / nameassignment.cpp
1
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(){
16         try{
17                 string firstCol, secondCol, skip;
18         //      int index = 0;
19         
20         
21 //              map<string, string> data;
22                 int rowIndex = 0;
23
24                 while(fileHandle){
25                         fileHandle >> firstCol;                         //read from first column
26                         fileHandle >> secondCol;                        //read from second column
27                         
28 //                      data[firstCol] = secondCol;                     //store data in map
29
30                         list.push_back(secondCol);              //adds data's value to list
31                         (*this)[firstCol] = rowIndex++;
32                         gobble(fileHandle);
33                 }
34                 fileHandle.close();
35         
36 //              map<string, string>::iterator it = data.begin();
37 //              for(it;it!=data.end();it++){
38 //                      cout << it->first << endl;
39 //                      (*this)[it->first] = rowIndex;
40 //                      rowIndex++;
41 //              }
42         }
43         catch(exception& e) {
44                 cout << "Standard Error: " << e.what() << " has occurred in the NameAssignment class Function readMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
45                 exit(1);
46         }
47         catch(...) {
48                 cout << "An unknown error has occurred in the NameAssignment class function readMap. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
49                 exit(1);
50         }
51 }
52
53 //**********************************************************************************************************************
54
55 ListVector NameAssignment::getListVector(void){
56
57         return list;
58         
59 }
60
61 //**********************************************************************************************************************
62
63 void NameAssignment::print(void){
64         try {
65                 map<string,int>::iterator it = (*this).begin();
66                 for(it;it!=(*this).end();it++){
67                         cout << it->first << '\t' << it->second << endl;  //prints out keys and values of the map this.
68                 }
69         }
70         catch(exception& e) {
71                 cout << "Standard Error: " << e.what() << " has occurred in the NameAssignment class Function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
72                 exit(1);
73         }
74         catch(...) {
75                 cout << "An unknown error has occurred in the NameAssignment class function print. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
76                 exit(1);
77         }
78 }
79
80 //**********************************************************************************************************************
81
82 int NameAssignment::get(string key){
83         
84         return  (*this)[key];   
85
86 }
87
88 //**********************************************************************************************************************
89