]> git.donarmstrong.com Git - mothur.git/blobdiff - database.cpp
version working on mac with .tellg changed to unget for windows
[mothur.git] / database.cpp
index 8c080dbf95e79d6dc574e52d5679747018df00fa..852e2d294a3887c747fa8a95bb56f36151d2890e 100644 (file)
@@ -7,9 +7,7 @@
  *
  */
 
-using namespace std;
-
-
+#include "mothur.h"
 #include "sequence.hpp"
 #include "database.hpp"
 
@@ -23,6 +21,7 @@ Database::Database(string fastaFileName){             //      This assumes that the template dat
 
        cout << endl << "Reading in the " << fastaFileName << " template sequences...\t";       cout.flush();
 
+       //all of this is elsewhere already!
        numSeqs=count(istreambuf_iterator<char>(fastaFile),istreambuf_iterator<char>(), '>');   //      count the number of
        fastaFile.seekg(0);                                                                                                                                             //      sequences
        
@@ -30,11 +29,8 @@ Database::Database(string fastaFileName){            //      This assumes that the template dat
        
        string seqName, sequence;
        for(int i=0;i<numSeqs;i++){
-               templateSequences[i] = new Sequence();          //      We're storing the aligned template sequences as a vector of
-                                                                                                       //      pointers to Sequence objects
                fastaFile >> seqName;
-               templateSequences[i]->setName(seqName);
-               
+               seqName = seqName.substr(1);
                char letter;
                string aligned;
                
@@ -45,15 +41,34 @@ Database::Database(string fastaFileName){           //      This assumes that the template dat
                                aligned += letter;
                        }
                }
-               templateSequences[i]->setAligned(aligned);      //      Obviously, we need the fully aligned template sequence
-               templateSequences[i]->setUnaligned(aligned);//  We will also need the unaligned sequence for pairwise alignments
-               fastaFile.putback(letter);                                      //      and database searches
+               templateSequences[i] = Sequence(seqName, aligned);
+               fastaFile.putback(letter);
        }
        
        fastaFile.close();
+       //all of this is elsewhere already!
+       
        cout << "DONE." << endl;        cout.flush();
 
 }
+/**************************************************************************************************/
+
+Database::~Database(){                                                                                                         
+       try {
+               
+               //for (int i = 0; i < templateSequences.size(); i++) {  delete templateSequences[i];    }
+               templateSequences.clear();
+
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the Database class Function ~Database. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the Database class function ~Database. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+}
 
 /**************************************************************************************************/