]> git.donarmstrong.com Git - mothur.git/blobdiff - alignmentdb.cpp
modified mpi code to save ram by writing out every 10 seqs.
[mothur.git] / alignmentdb.cpp
index 493521e716cc0e7574214048bde9b7fb5cea8154..51fb17517f3598fa975c5349fcf9fe4af1dbec90 100644 (file)
 
 
 /**************************************************************************************************/
-AlignmentDB::AlignmentDB(string fastaFileName, string method, int kmerSize, int gapOpen, int gapExtend, int match, int misMatch){              //      This assumes that the template database is in fasta format, may 
+AlignmentDB::AlignmentDB(string fastaFileName, string method, int kmerSize, float gapOpen, float gapExtend, float match, float misMatch){              //      This assumes that the template database is in fasta format, may 
        try {                                                                                   //      need to alter this in the future?
+               m = MothurOut::getInstance();
                longest = 0;
-               
+
                ifstream fastaFile;
                openInputFile(fastaFileName, fastaFile);
                
-               mothurOutEndLine();
-               mothurOut("Reading in the " + fastaFileName + " template sequences...\t");      cout.flush();
+               m->mothurOutEndLine();
+               m->mothurOut("Reading in the " + fastaFileName + " template sequences...\t");   cout.flush();
                
                while (!fastaFile.eof()) {
-                       Sequence temp(fastaFile);
+                       Sequence temp(fastaFile);  gobble(fastaFile);
                        
-                       templateSequences.push_back(temp);
+                       if (m->control_pressed) {  templateSequences.clear(); break;  }
                        
-                       //save longest base
-                       if (temp.getUnaligned().length() > longest)  { longest = temp.getUnaligned().length(); }
-                       
-                       gobble(fastaFile);
+                       if (temp.getName() != "") {
+                               templateSequences.push_back(temp);
+                               //save longest base
+                               if (temp.getUnaligned().length() > longest)  { longest = temp.getUnaligned().length()+1; }
+                       }
                }
                
                numSeqs = templateSequences.size();
@@ -40,8 +42,8 @@ AlignmentDB::AlignmentDB(string fastaFileName, string method, int kmerSize, int
                fastaFile.close();
                //all of this is elsewhere already!
                
-               mothurOut("DONE.");
-               mothurOutEndLine();     cout.flush();
+               m->mothurOut("DONE.");
+               m->mothurOutEndLine();  cout.flush();
                
                //in case you delete the seqs and then ask for them
                emptySequence = Sequence();
@@ -62,28 +64,29 @@ AlignmentDB::AlignmentDB(string fastaFileName, string method, int kmerSize, int
                else if(method == "suffix")             {       search = new SuffixDB(numSeqs);                                                         }
                else if(method == "blast")              {       search = new BlastDB(gapOpen, gapExtend, match, misMatch);      }
                else {
-                       mothurOut(method + " is not a valid search option. I will run the command using kmer, ksize=8.");
-                       mothurOutEndLine();
+                       m->mothurOut(method + " is not a valid search option. I will run the command using kmer, ksize=8.");
+                       m->mothurOutEndLine();
                        search = new KmerDB(fastaFileName, 8);
                }
                
-               if (needToGenerate) {
-               
-                       //add sequences to search 
-                       for (int i = 0; i < templateSequences.size(); i++) {
-                               search->addSequence(templateSequences[i]);
+               if (!(m->control_pressed)) {
+                       if (needToGenerate) {
+                               //add sequences to search 
+                               for (int i = 0; i < templateSequences.size(); i++) {
+                                       search->addSequence(templateSequences[i]);
+                               }
+                               search->generateDB();
+                               
+                       }else if ((method == "kmer") && (!needToGenerate)) {
+                               ifstream kmerFileTest(kmerDBName.c_str());
+                               search->readKmerDB(kmerFileTest);       
                        }
-                       search->generateDB();
                        
-               }else if ((method == "kmer") && (!needToGenerate)) {
-                       ifstream kmerFileTest(kmerDBName.c_str());
-                       search->readKmerDB(kmerFileTest);       
+                       search->setNumSeqs(numSeqs);
                }
-               
-               search->setNumSeqs(numSeqs);
        }
        catch(exception& e) {
-               errorOut(e, "AlignmentDB", "AlignmentDB");
+               m->errorOut(e, "AlignmentDB", "AlignmentDB");
                exit(1);
        }
 }
@@ -100,7 +103,7 @@ Sequence AlignmentDB::findClosestSequence(Sequence* seq) {
                
        }
        catch(exception& e) {
-               errorOut(e, "AlignmentDB", "findClosestSequence");
+               m->errorOut(e, "AlignmentDB", "findClosestSequence");
                exit(1);
        }
 }