]> git.donarmstrong.com Git - mothur.git/blobdiff - filterseqscommand.cpp
paralellized phylo.diversity
[mothur.git] / filterseqscommand.cpp
index 4ee674856223d3ef6ec2e9605437ae915f6e3ac7..a12058e4785d00e1c21b84ea453ce82c4f62797d 100644 (file)
@@ -147,13 +147,14 @@ void FilterSeqsCommand::help(){
        try {
                                
                m->mothurOut("The filter.seqs command reads a file containing sequences and creates a .filter and .filter.fasta file.\n");
-               m->mothurOut("The filter.seqs command parameters are fasta, trump, soft, hard and vertical. \n");
+               m->mothurOut("The filter.seqs command parameters are fasta, trump, soft, hard, processors and vertical. \n");
                m->mothurOut("The fasta parameter is required. You may enter several fasta files to build the filter from and filter, by separating their names with -'s.\n");
                m->mothurOut("For example: fasta=abrecovery.fasta-amazon.fasta \n");
                m->mothurOut("The trump parameter .... The default is ...\n");
                m->mothurOut("The soft parameter .... The default is ....\n");
                m->mothurOut("The hard parameter allows you to enter a file containing the filter you want to use.\n");
                m->mothurOut("The vertical parameter removes columns where all sequences contain a gap character. The default is T.\n");
+               m->mothurOut("The processors parameter allows you to specify the number of processors to use. The default is 1.\n");
                m->mothurOut("The filter.seqs command should be in the following format: \n");
                m->mothurOut("filter.seqs(fasta=yourFastaFile, trump=yourTrump) \n");
                m->mothurOut("Example filter.seqs(fasta=abrecovery.fasta, trump=.).\n");
@@ -198,7 +199,11 @@ int FilterSeqsCommand::execute() {
                
                ofstream outFilter;
                
-               string filterFile = outputDir + filterFileName + ".filter";
+               //prevent giantic file name
+               string filterFile;
+               if (fastafileNames.size() > 3) { filterFile = outputDir + "merge.filter"; }
+               else {  filterFile = outputDir + filterFileName + ".filter";  }
+               
                m->openOutputFile(filterFile, outFilter);
                outFilter << filter << endl;
                outFilter.close();
@@ -305,8 +310,8 @@ int FilterSeqsCommand::filterSequences() {
                                        
                                        //wait on chidren
                                        for(int i = 1; i < processors; i++) { 
-                                               char buf[4];
-                                               MPI_Recv(buf, 4, MPI_CHAR, i, tag, MPI_COMM_WORLD, &status); 
+                                               char buf[5];
+                                               MPI_Recv(buf, 5, MPI_CHAR, i, tag, MPI_COMM_WORLD, &status); 
                                        }
                                        
                                }else { //you are a child process
@@ -326,11 +331,11 @@ int FilterSeqsCommand::filterSequences() {
                                        
                                        if (m->control_pressed) {  MPI_File_close(&inMPI);  MPI_File_close(&outMPI);  return 0;  }
                                        
-                                       char buf[4];
+                                       char buf[5];
                                        strcpy(buf, "done"); 
                                        
                                        //tell parent you are done.
-                                       MPI_Send(buf, 4, MPI_CHAR, 0, tag, MPI_COMM_WORLD);
+                                       MPI_Send(buf, 5, MPI_CHAR, 0, tag, MPI_COMM_WORLD);
                                }
                                
                                MPI_File_close(&outMPI);
@@ -362,7 +367,7 @@ int FilterSeqsCommand::filterSequences() {
                                
                                if (m->control_pressed) {  return 1; }
                #else
-                               numFastaSeqs = driverRunFilter(filter, filteredFasta, fastafileNames[s], lines[0]);
+                               int numFastaSeqs = driverRunFilter(filter, filteredFasta, fastafileNames[s], lines[0]);
                                numSeqs += numFastaSeqs;
 
                                if (m->control_pressed) {  return 1; }
@@ -485,8 +490,12 @@ int FilterSeqsCommand::driverRunFilter(string F, string outputFilename, string i
                                count++;
                        }
                        
-                       unsigned long int pos = in.tellg();
-                       if ((pos == -1) || (pos >= filePos->end)) { break; }
+                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                               unsigned long int pos = in.tellg();
+                               if ((pos == -1) || (pos >= filePos->end)) { break; }
+                       #else
+                               if (in.eof()) { break; }
+                       #endif
                        
                        //report progress
                        if((count) % 100 == 0){ m->mothurOut(toString(count)); m->mothurOutEndLine();           }
@@ -662,7 +671,7 @@ string FilterSeqsCommand::createFilter() {
                                
                                if (m->control_pressed) {  return filterString; }
                #else
-                               numFastaSeqs = driverCreateFilter(F, fastafileNames[s], lines[0]);
+                               int numFastaSeqs = driverCreateFilter(F, fastafileNames[s], lines[0]);
                                numSeqs += numFastaSeqs;
                                if (m->control_pressed) {  return filterString; }
                #endif
@@ -786,8 +795,12 @@ int FilterSeqsCommand::driverCreateFilter(Filters& F, string filename, linePair*
                                        count++;
                        }
                        
-                       unsigned long int pos = in.tellg();
-                       if ((pos == -1) || (pos >= filePos->end)) { break; }
+                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                               unsigned long int pos = in.tellg();
+                               if ((pos == -1) || (pos >= filePos->end)) { break; }
+                       #else
+                               if (in.eof()) { break; }
+                       #endif
                        
                        //report progress
                        if((count) % 100 == 0){ m->mothurOut(toString(count)); m->mothurOutEndLine();           }
@@ -855,7 +868,7 @@ int FilterSeqsCommand::MPICreateFilter(int start, int num, Filters& F, MPI_File&
 int FilterSeqsCommand::createProcessesCreateFilter(Filters& F, string filename) {
        try {
 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-               int process = 0;
+               int process = 1;
                int num = 0;
                processIDS.clear();
                
@@ -896,13 +909,16 @@ int FilterSeqsCommand::createProcessesCreateFilter(Filters& F, string filename)
                        }else { m->mothurOut("unable to spawn the necessary processes."); m->mothurOutEndLine(); exit(0); }
                }
                
+               //parent do your part
+               num = driverCreateFilter(F, filename, lines[0]);
+               
                //force parent to wait until all the processes are done
-               for (int i=0;i<processors;i++) { 
+               for (int i=0;i<(processors-1);i++) { 
                        int temp = processIDS[i];
                        wait(&temp);
                }
                
-               //parent reads in and combine Filter info
+               //parent reads in and combines Filter info
                for (int i = 0; i < processIDS.size(); i++) {
                        string tempFilename = filename + toString(processIDS[i]) + "filterValues.temp";
                        ifstream in;