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