]> git.donarmstrong.com Git - mothur.git/blobdiff - classify.cpp
pds - modified strip barcode funcrtion in trimseqscommand
[mothur.git] / classify.cpp
index 557f17c6b85c7eb61865591ad3a8481ffa38ed38..147f499b87357f5782b98fc882db80f3233f2aee 100644 (file)
 #include "distancedb.hpp"
 
 /**************************************************************************************************/
-Classify::Classify(string tfile, string tempFile, string method, int kmerSize, float gapOpen, float gapExtend, float match, float misMatch) : taxFile(tfile), templateFile(tempFile) {         
+void Classify::generateDatabaseAndNames(string tfile, string tempFile, string method, int kmerSize, float gapOpen, float gapExtend, float match, float misMatch)  {            
        try {   
-               m = MothurOut::getInstance();                                                                   
+               taxFile = tfile;
                readTaxonomy(taxFile);  
                
+               templateFile = tempFile;        
+               
                int start = time(NULL);
                int numSeqs = 0;
                
@@ -31,12 +33,16 @@ Classify::Classify(string tfile, string tempFile, string method, int kmerSize, f
                        MPI_Status status; 
                        MPI_File inMPI;
                        MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
-       
-                       char inFileName[tempFile.length()];
+
+                       //char* inFileName = new char[tempFile.length()];
+                       //memcpy(inFileName, tempFile.c_str(), tempFile.length());
+                       
+                       char inFileName[1024];
                        strcpy(inFileName, tempFile.c_str());
-       
+
                        MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI);  //comm, filename, mode, info, filepointer
-       
+                       //delete inFileName;
+
                        if (pid == 0) { //only one process needs to scan file
                                positions = setFilePosFasta(tempFile, numSeqs); //fills MPIPos, returns numSeqs
 
@@ -63,12 +69,12 @@ Classify::Classify(string tfile, string tempFile, string method, int kmerSize, f
                        for(int i=0;i<numSeqs;i++){
                                //read next sequence
                                int length = positions[i+1] - positions[i];
-                               char buf4[length];
+                               char* buf4 = new char[length];
                                MPI_File_read_at(inMPI, positions[i], buf4, length, MPI_CHAR, &status);
                                
                                string tempBuf = buf4;
                                if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length); }
-                               
+                               delete buf4;
                                istringstream iss (tempBuf,istringstream::in);
                                
                                Sequence temp(iss);  
@@ -134,7 +140,7 @@ Classify::Classify(string tfile, string tempFile, string method, int kmerSize, f
                        while (!fastaFile.eof()) {
                                Sequence temp(fastaFile);
                                gobble(fastaFile);
-                       
+
                                names.push_back(temp.getName());
                        }
                        fastaFile.close();
@@ -147,13 +153,15 @@ Classify::Classify(string tfile, string tempFile, string method, int kmerSize, f
 
        }
        catch(exception& e) {
-               m->errorOut(e, "Classify", "Classify");
+               m->errorOut(e, "Classify", "generateDatabaseAndNames");
                exit(1);
        }
 }
 /**************************************************************************************************/
+Classify::Classify() {         m = MothurOut::getInstance();   database = NULL;        }
+/**************************************************************************************************/
 
-void Classify::readTaxonomy(string file) {
+int Classify::readTaxonomy(string file) {
        try {
                
                phyloTree = new PhyloTree();
@@ -169,12 +177,16 @@ void Classify::readTaxonomy(string file) {
                MPI_Status status; 
                MPI_File inMPI;
                MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
+
+               //char* inFileName = new char[file.length()];
+               //memcpy(inFileName, file.c_str(), file.length());
                
-               char inFileName[file.length()];
+               char inFileName[1024];
                strcpy(inFileName, file.c_str());
-               
+
                MPI_File_open(MPI_COMM_WORLD, inFileName, MPI_MODE_RDONLY, MPI_INFO_NULL, &inMPI);  //comm, filename, mode, info, filepointer
-               
+               //delete inFileName;
+
                if (pid == 0) {
                        positions = setFilePosEachLine(file, num);
                        
@@ -191,13 +203,14 @@ void Classify::readTaxonomy(string file) {
                for(int i=0;i<num;i++){
                        //read next sequence
                        int length = positions[i+1] - positions[i];
-                       char buf4[length];
+                       char* buf4 = new char[length];
 
                        MPI_File_read_at(inMPI, positions[i], buf4, length, MPI_CHAR, &status);
 
                        string tempBuf = buf4;
                        if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length); }
-                       
+                       delete buf4;
+
                        istringstream iss (tempBuf,istringstream::in);
                        iss >> name >> taxInfo;
                        taxonomy[name] = taxInfo;
@@ -224,8 +237,12 @@ void Classify::readTaxonomy(string file) {
        
                phyloTree->assignHeirarchyIDs(0);
                
+               phyloTree->setUp(file);
+               
                m->mothurOut("DONE.");
                m->mothurOutEndLine();  cout.flush();
+               
+               return phyloTree->getNumSeqs();
        
        }
        catch(exception& e) {