]> git.donarmstrong.com Git - mothur.git/blobdiff - alignmentdb.cpp
changes while testing
[mothur.git] / alignmentdb.cpp
index 7c2916c54970c72f73942db5726fe3a0d8c85655..9fec737778e01704e98f5c813e3c0554e7ab0981 100644 (file)
 #include "blastdb.hpp"
 #include "referencedb.h"
 
-
 /**************************************************************************************************/
-AlignmentDB::AlignmentDB(string fastaFileName, string s, int kmerSize, float gapOpen, float gapExtend, float match, float misMatch){           //      This assumes that the template database is in fasta format, may 
+AlignmentDB::AlignmentDB(string fastaFileName, string s, int kmerSize, float gapOpen, float gapExtend, float match, float misMatch, int tid){          //      This assumes that the template database is in fasta format, may 
        try {                                                                                   //      need to alter this in the future?
                m = MothurOut::getInstance();
                longest = 0;
                method = s;
                bool needToGenerate = true;
                ReferenceDB* rdb = ReferenceDB::getInstance();
+               bool silent = false;
+               threadID = tid;
+               
+               if (fastaFileName == "saved-silent") {
+                       fastaFileName = "saved"; silent = true;
+               }
                
                if (fastaFileName == "saved") {
                        int start = time(NULL);
-                       m->mothurOutEndLine();  m->mothurOut("Using sequences from " + rdb->getSavedReference() + " that are saved in memory.");        m->mothurOutEndLine();
+                       
+                       if (!silent) { m->mothurOutEndLine();  m->mothurOut("Using sequences from " + rdb->getSavedReference() + " that are saved in memory."); m->mothurOutEndLine(); }
 
                        for (int i = 0; i < rdb->referenceSeqs.size(); i++) {
                                templateSequences.push_back(rdb->referenceSeqs[i]);
@@ -35,16 +41,18 @@ AlignmentDB::AlignmentDB(string fastaFileName, string s, int kmerSize, float gap
                        fastaFileName = rdb->getSavedReference();
                        
                        numSeqs = templateSequences.size();
-                       m->mothurOut("It took " + toString(time(NULL) - start) + " to load " + toString(rdb->referenceSeqs.size()) + " sequences.");m->mothurOutEndLine();  
-
+                       if (!silent) { m->mothurOut("It took " + toString(time(NULL) - start) + " to load " + toString(rdb->referenceSeqs.size()) + " sequences.");m->mothurOutEndLine();  }
+            
                }else {
                        int start = time(NULL);
                        m->mothurOutEndLine();
                        m->mothurOut("Reading in the " + fastaFileName + " template sequences...\t");   cout.flush();
-                       
+                       //bool aligned = false;
+            int tempLength = 0;
+            
                        #ifdef USE_MPI  
                                int pid, processors;
-                               vector<unsigned long int> positions;
+                               vector<unsigned long long> positions;
                        
                                MPI_Status status; 
                                MPI_File inMPI;
@@ -96,6 +104,9 @@ AlignmentDB::AlignmentDB(string fastaFileName, string s, int kmerSize, float gap
                                                
                                                //save longest base
                                                if (temp.getUnaligned().length() >= longest)  { longest = temp.getUnaligned().length()+1; }
+                        if (tempLength != 0) {
+                            if (tempLength != temp.getAligned().length()) { m->mothurOut("[ERROR]: template is not aligned, aborting.\n"); m->control_pressed=true; }
+                        }else { tempLength = temp.getAligned().length(); }
                                        }
                                }
                                
@@ -119,6 +130,10 @@ AlignmentDB::AlignmentDB(string fastaFileName, string s, int kmerSize, float gap
                                        
                                        //save longest base
                                        if (temp.getUnaligned().length() >= longest)  { longest = (temp.getUnaligned().length()+1); }
+                    
+                    if (tempLength != 0) {
+                        if (tempLength != temp.getAligned().length()) { m->mothurOut("[ERROR]: template is not aligned, aborting.\n"); m->control_pressed=true; }
+                    }else { tempLength = temp.getAligned().length(); }
                                }
                        }
                        fastaFile.close();
@@ -129,7 +144,7 @@ AlignmentDB::AlignmentDB(string fastaFileName, string s, int kmerSize, float gap
                        
                        m->mothurOut("DONE.");
                        m->mothurOutEndLine();  cout.flush();
-                       m->mothurOut("It took " + toString(time(NULL) - start) + " to read  " + toString(rdb->referenceSeqs.size()) + " sequences."); m->mothurOutEndLine();  
+                       m->mothurOut("It took " + toString(time(NULL) - start) + " to read  " + toString(templateSequences.size()) + " sequences."); m->mothurOutEndLine();  
 
                }
                
@@ -157,8 +172,9 @@ AlignmentDB::AlignmentDB(string fastaFileName, string s, int kmerSize, float gap
                        #endif
                }
                else if(method == "suffix")             {       search = new SuffixDB(numSeqs);                                                         }
-               else if(method == "blast")              {       search = new BlastDB(fastaFileName.substr(0,fastaFileName.find_last_of(".")+1), gapOpen, gapExtend, match, misMatch, "");       }
+               else if(method == "blast")              {       search = new BlastDB(fastaFileName.substr(0,fastaFileName.find_last_of(".")+1), gapOpen, gapExtend, match, misMatch, "", threadID);     }
                else {
+                       method = "kmer";
                        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);
@@ -198,7 +214,7 @@ AlignmentDB::AlignmentDB(string s){
                method = s;
                
                if(method == "suffix")          {       search = new SuffixDB();        }
-               else if(method == "blast")      {       search = new BlastDB("");               }
+               else if(method == "blast")      {       search = new BlastDB("", 0);            }
                else                                            {       search = new KmerDB();          }