]> git.donarmstrong.com Git - mothur.git/blobdiff - nameassignment.cpp
working on pam
[mothur.git] / nameassignment.cpp
index 0c30898dd4085f5000a68c005ccbeee1bcd3650c..1e42111e574baacf2eb2f5c3407416c9029f9041 100644 (file)
@@ -6,23 +6,24 @@
 
 NameAssignment::NameAssignment(string nameMapFile){
        m = MothurOut::getInstance();
-       openInputFile(nameMapFile, fileHandle);
+       m->openInputFile(nameMapFile, fileHandle);
        
 }
-
+//**********************************************************************************************************************
+NameAssignment::NameAssignment(){ m = MothurOut::getInstance(); }
 //**********************************************************************************************************************
 
 void NameAssignment::readMap(){
        try{
                string firstCol, secondCol, skip;
        //      int index = 0;
-       
+        
                
                map<string, int>::iterator itData;
                int rowIndex = 0;
                
                while(fileHandle){
-                       fileHandle >> firstCol;                         //read from first column
+                       fileHandle >> firstCol; m->gobble(fileHandle);                  //read from first column
                        fileHandle >> secondCol;                        //read from second column
                                                
                        itData = (*this).find(firstCol);
@@ -34,7 +35,7 @@ void NameAssignment::readMap(){
                                
                        }else{  m->mothurOut(firstCol + " is already in namesfile. I will use first definition."); m->mothurOutEndLine();  }
                        
-                       gobble(fileHandle);
+                       m->gobble(fileHandle);
                }
                fileHandle.close();
        
@@ -76,6 +77,7 @@ void NameAssignment::print(ostream& out){
 //cout << (*this).size() << endl;
                for(it = (*this).begin(); it!=(*this).end(); it++){
                        out << it->first << '\t' <<  it->second << endl;  //prints out keys and values of the map this.
+                       //out << it->first << '\t' <<  it->first << endl;
                }
        }
        catch(exception& e) {
@@ -87,16 +89,35 @@ void NameAssignment::print(ostream& out){
 //**********************************************************************************************************************
 
 int NameAssignment::get(string key){
-       
-       return  (*this)[key];   
-
+       try {
+               map<string, int>::iterator itGet = (*this).find(key);
+               
+               //if you can't find it
+               if (itGet == (*this).end()) { return -1; }
+               
+               return  (*this)[key];   
+       }
+       catch(exception& e) {
+               m->errorOut(e, "NameAssignment", "get");
+               exit(1);
+       }
 }
 //**********************************************************************************************************************
 
 string NameAssignment::get(int key){
+       try {
        
-       return  reverse[key];   
-
+               map<int, string>::iterator itGet = reverse.find(key);
+       
+               if (itGet == reverse.end()) { return "not found"; }
+       
+               return  reverse[key];   
+       
+       }
+       catch(exception& e) {
+               m->errorOut(e, "NameAssignment", "get");
+               exit(1);
+       }
 }
 //**********************************************************************************************************************