5 * Created by westcott on 11/3/09.
6 * Copyright 2009 Schloss Lab. All rights reserved.
11 #include "sequence.hpp"
13 #include "suffixdb.hpp"
14 #include "blastdb.hpp"
16 /**************************************************************************************************/
18 Classify::Classify(string tfile, string tempFile, string method, int kmerSize, int gapOpen, int gapExtend, int match, int misMatch) : taxFile(tfile), templateFile(tempFile) {
21 readTaxonomy(taxFile);
24 //need to know number of template seqs for suffixdb
25 if (method == "suffix") {
27 openInputFile(tempFile, inFASTA);
28 numSeqs = count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
32 mothurOut("Generating search database... "); cout.flush();
34 bool needToGenerate = true;
36 if(method == "kmer") {
37 database = new KmerDB(tempFile, kmerSize);
39 kmerDBName = tempFile.substr(0,tempFile.find_last_of(".")+1) + char('0'+ kmerSize) + "mer";
40 ifstream kmerFileTest(kmerDBName.c_str());
41 if(kmerFileTest){ needToGenerate = false; }
43 else if(method == "suffix") { database = new SuffixDB(numSeqs); }
44 else if(method == "blast") { database = new BlastDB(gapOpen, gapExtend, match, misMatch); }
46 mothurOut(method + " is not a valid search option. I will run the command using kmer, ksize=8.");
48 database = new KmerDB(tempFile, 8);
53 openInputFile(tempFile, fastaFile);
55 while (!fastaFile.eof()) {
56 Sequence temp(fastaFile);
59 names.push_back(temp.getName());
60 database->addSequence(temp);
64 database->generateDB();
66 }else if ((method == "kmer") && (!needToGenerate)) {
67 ifstream kmerFileTest(kmerDBName.c_str());
68 database->readKmerDB(kmerFileTest);
71 openInputFile(tempFile, fastaFile);
73 while (!fastaFile.eof()) {
74 Sequence temp(fastaFile);
77 names.push_back(temp.getName());
82 database->setNumSeqs(names.size());
84 mothurOut("DONE."); mothurOutEndLine();
88 errorOut(e, "Classify", "Classify");
92 /**************************************************************************************************/
94 void Classify::readTaxonomy(string file) {
98 openInputFile(file, inTax);
101 mothurOut("Reading in the " + file + " taxonomy...\t"); cout.flush();
103 string name, taxInfo;
104 //read template seqs and save
105 while (!inTax.eof()) {
106 inTax >> name >> taxInfo;
108 taxonomy[name] = taxInfo;
115 mothurOutEndLine(); cout.flush();
118 catch(exception& e) {
119 errorOut(e, "Classify", "readTaxonomy");
123 /**************************************************************************************************/