]> git.donarmstrong.com Git - mothur.git/blobdiff - chimera.cpp
working on slayer bug
[mothur.git] / chimera.cpp
index b513075b4782167ce3f14b74df4f31a6f76b9529..54124872b7a5e87ce4aa545585fcb4b94c759044 100644 (file)
@@ -31,6 +31,8 @@ string Chimera::createFilter(vector<Sequence*> seqs, float t) {
                        if (m->control_pressed) { return filterString; }
                
                        string seqAligned = seqs[i]->getAligned();
+                       
+                       if (seqAligned.length() != filterString.length()) {  m->mothurOut(seqs[i]->getName() + " is not the same length as the template sequences. Aborting!\n");  exit(1); }
                
                        for (int j = 0; j < seqAligned.length(); j++) {
                                //if this spot is a gap
@@ -101,13 +103,15 @@ vector<Sequence*> Chimera::readSeqs(string file) {
                m->mothurOut("Reading sequences from " + file + "..."); cout.flush();
                
                #ifdef USE_MPI  
-                       int pid;
-                       vector<long> positions;
+                       int pid, processors;
+                       vector<unsigned long int> positions;
                        int numSeqs;
+                       int tag = 2001;
                
                        MPI_Status status; 
                        MPI_File inMPI;
                        MPI_Comm_rank(MPI_COMM_WORLD, &pid); //find out who we are
+                       MPI_Comm_size(MPI_COMM_WORLD, &processors);
 
                        //char* inFileName = new char[file.length()];
                        //memcpy(inFileName, file.c_str(), file.length());
@@ -119,15 +123,17 @@ vector<Sequence*> Chimera::readSeqs(string file) {
                        //delete inFileName;
 
                        if (pid == 0) {
-                               positions = setFilePosFasta(file, numSeqs); //fills MPIPos, returns numSeqs
+                               positions = m->setFilePosFasta(file, numSeqs); //fills MPIPos, returns numSeqs
 
                                //send file positions to all processes
-                               MPI_Bcast(&numSeqs, 1, MPI_INT, 0, MPI_COMM_WORLD);  //send numSeqs
-                               MPI_Bcast(&positions[0], (numSeqs+1), MPI_LONG, 0, MPI_COMM_WORLD); //send file pos     
+                               for(int i = 1; i < processors; i++) { 
+                                       MPI_Send(&numSeqs, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
+                                       MPI_Send(&positions[0], (numSeqs+1), MPI_LONG, i, tag, MPI_COMM_WORLD);
+                               }
                        }else{
-                               MPI_Bcast(&numSeqs, 1, MPI_INT, 0, MPI_COMM_WORLD); //get numSeqs
+                               MPI_Recv(&numSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
                                positions.resize(numSeqs+1);
-                               MPI_Bcast(&positions[0], (numSeqs+1), MPI_LONG, 0, MPI_COMM_WORLD); //get file positions
+                               MPI_Recv(&positions[0], (numSeqs+1), MPI_LONG, 0, tag, MPI_COMM_WORLD, &status);
                        }
                        
                        //read file 
@@ -157,17 +163,18 @@ vector<Sequence*> Chimera::readSeqs(string file) {
                        }
                        
                        MPI_File_close(&inMPI);
+                       MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case
        #else
 
                ifstream in;
-               openInputFile(file, in);
+               m->openInputFile(file, in);
                
                //read in seqs and store in vector
                while(!in.eof()){
                        
                        if (m->control_pressed) { return container; }
                        
-                       Sequence* current = new Sequence(in);  gobble(in);
+                       Sequence* current = new Sequence(in);  m->gobble(in);
                        
                        if (count == 0) {  length = current->getAligned().length();  count++;  } //gets first seqs length
                        else if (length != current->getAligned().length()) {    unaligned = true;       }
@@ -179,6 +186,8 @@ vector<Sequence*> Chimera::readSeqs(string file) {
        
                m->mothurOut("Done."); m->mothurOutEndLine();
                
+               filterString = (string(container[0]->getAligned().length(), '1'));
+               
                return container;
        }
        catch(exception& e) {
@@ -234,7 +243,7 @@ void Chimera::setMask(string filename) {
        #else
        
                        ifstream infile;
-                       openInputFile(filename, infile);
+                       m->openInputFile(filename, infile);
                        
                        if (!infile.eof()) {
                                Sequence temp(infile);