]> git.donarmstrong.com Git - mothur.git/blob - database.cpp
fixed some bugs
[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 #include "mothur.h"
11 #include "sequence.hpp"
12 #include "database.hpp"
13
14 /**************************************************************************************************/
15
16 Database::Database(string fastaFileName){               //      This assumes that the template database is in fasta format, may 
17                                                                                                 //      need to alter this in the future?
18
19         ifstream fastaFile;
20         openInputFile(fastaFileName, fastaFile);
21
22         cout << endl << "Reading in the " << fastaFileName << " template sequences...\t";       cout.flush();
23
24         //all of this is elsewhere already!
25         numSeqs=count(istreambuf_iterator<char>(fastaFile),istreambuf_iterator<char>(), '>');   //      count the number of
26         fastaFile.seekg(0);                                                                                                                                             //      sequences
27         
28         templateSequences.resize(numSeqs);
29         
30         string seqName, sequence;
31         for(int i=0;i<numSeqs;i++){
32                 fastaFile >> seqName;
33                 seqName = seqName.substr(1);
34                 char letter;
35                 string aligned;
36                 
37                 while(fastaFile && (letter=fastaFile.get()) != '>'){
38                         if(isprint(letter)){
39                                 letter = toupper(letter);
40                                 if(letter == 'U'){letter = 'T';}
41                                 aligned += letter;
42                         }
43                 }
44                 templateSequences[i] = new Sequence(seqName, aligned);
45                 fastaFile.putback(letter);
46         }
47         
48         fastaFile.close();
49         //all of this is elsewhere already!
50         
51         cout << "DONE." << endl;        cout.flush();
52
53 }
54
55 /**************************************************************************************************/
56
57 float Database::getSearchScore()        {       return searchScore;             }       //      we're assuming that the search is already done
58
59 /**************************************************************************************************/