]> git.donarmstrong.com Git - mothur.git/blob - database.cpp
Initial revision
[mothur.git] / database.cpp
1 /*
2  *  database.cpp
3  *  
4  *
5  *  Created by Pat Schloss on 12/16/08.
6  *  Copyright 2008 Patrick D. Schloss. All rights reserved.
7  *
8  */
9
10 using namespace std;
11
12 #include <string>
13 #include <vector>
14 #include <fstream>
15 #include <iostream>
16
17 #include "sequence.hpp"
18 #include "database.hpp"
19
20 /**************************************************************************************************/
21
22 Database::Database(string fastaFileName){
23         
24         ifstream fastaFile(fastaFileName.c_str());
25         if(!fastaFile) {
26                 cerr << "Error: Could not open " << fastaFileName << endl;
27                 exit(1);
28         }
29         cout << endl << "Reading in the " << fastaFileName << " template sequences...\t";       cout.flush();
30
31         numSeqs=count(istreambuf_iterator<char>(fastaFile),istreambuf_iterator<char>(), '>');
32         fastaFile.seekg(0);
33         
34         templateSequences.resize(numSeqs);
35         
36         string seqName, sequence;
37         for(int i=0;i<numSeqs;i++){
38                 templateSequences[i] = new Sequence();
39                 
40                 fastaFile >> seqName;
41                 templateSequences[i]->setName(seqName);
42                 
43                 char letter;
44                 string aligned;
45                 
46                 while(fastaFile && (letter=fastaFile.get()) != '>'){
47                         if(isprint(letter)){
48                                 letter = toupper(letter);
49                                 aligned += letter;
50                         }
51                 }
52                 templateSequences[i]->setAligned(aligned);
53                 templateSequences[i]->setUnaligned(aligned);
54                 fastaFile.putback(letter);
55         }
56         
57         fastaFile.close();
58         cout << "DONE." << endl;        cout.flush();
59
60 }
61
62 /**************************************************************************************************/