3 #include "nameassignment.hpp"
5 //**********************************************************************************************************************
7 NameAssignment::NameAssignment(string nameMapFile){
8 m = MothurOut::getInstance();
9 m->openInputFile(nameMapFile, fileHandle);
12 //**********************************************************************************************************************
13 NameAssignment::NameAssignment(){ m = MothurOut::getInstance(); }
14 //**********************************************************************************************************************
16 void NameAssignment::readMap(){
18 string firstCol, secondCol, skip;
22 map<string, int>::iterator itData;
26 fileHandle >> firstCol; m->gobble(fileHandle); //read from first column
27 fileHandle >> secondCol; //read from second column
29 itData = (*this).find(firstCol);
30 if (itData == (*this).end()) {
32 (*this)[firstCol] = rowIndex++;
33 list.push_back(secondCol); //adds data's value to list
34 reverse[rowIndex] = firstCol;
36 }else{ m->mothurOut(firstCol + " is already in namesfile. I will use first definition."); m->mothurOutEndLine(); }
38 m->gobble(fileHandle);
44 m->errorOut(e, "NameAssignment", "readMap");
48 //**********************************************************************************************************************
49 void NameAssignment::push_back(string name) {
52 int num = (*this).size();
59 m->errorOut(e, "NameAssignment", "push_back");
64 //**********************************************************************************************************************
66 ListVector NameAssignment::getListVector(void){
72 //**********************************************************************************************************************
74 void NameAssignment::print(ostream& out){
76 map<string,int>::iterator it;
77 //cout << (*this).size() << endl;
78 for(it = (*this).begin(); it!=(*this).end(); it++){
79 out << it->first << '\t' << it->second << endl; //prints out keys and values of the map this.
80 //out << it->first << '\t' << it->first << endl;
84 m->errorOut(e, "NameAssignment", "print");
89 //**********************************************************************************************************************
91 int NameAssignment::get(string key){
93 map<string, int>::iterator itGet = (*this).find(key);
95 //if you can't find it
96 if (itGet == (*this).end()) { return -1; }
100 catch(exception& e) {
101 m->errorOut(e, "NameAssignment", "get");
105 //**********************************************************************************************************************
107 string NameAssignment::get(int key){
110 map<int, string>::iterator itGet = reverse.find(key);
112 if (itGet == reverse.end()) { return "not found"; }
117 catch(exception& e) {
118 m->errorOut(e, "NameAssignment", "get");
122 //**********************************************************************************************************************