]> git.donarmstrong.com Git - mothur.git/blobdiff - screenseqscommand.cpp
changed how we count sequences in a fastafile to allow for '>' in sequence names
[mothur.git] / screenseqscommand.cpp
index ab750321b8468670d626f5d5b724aba61a98c071..66e0cb07e066c27724480f1f1c6c523ff755e8d6 100644 (file)
@@ -134,7 +134,7 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option)  {
 void ScreenSeqsCommand::help(){
        try {
                m->mothurOut("The screen.seqs command reads a fastafile and creates .....\n");
-               m->mothurOut("The screen.seqs command parameters are fasta, start, end, maxambig, maxhomop, minlength, maxlength, name, and group.\n");
+               m->mothurOut("The screen.seqs command parameters are fasta, start, end, maxambig, maxhomop, minlength, maxlength, name, group and processors.\n");
                m->mothurOut("The fasta parameter is required.\n");
                m->mothurOut("The start parameter .... The default is -1.\n");
                m->mothurOut("The end parameter .... The default is -1.\n");
@@ -142,6 +142,7 @@ void ScreenSeqsCommand::help(){
                m->mothurOut("The maxhomop parameter .... The default is -1.\n");
                m->mothurOut("The minlength parameter .... The default is -1.\n");
                m->mothurOut("The maxlength parameter .... The default is -1.\n");
+               m->mothurOut("The processors parameter allows you to specify the number of processors to use while running the command. The default is 1.\n");
                m->mothurOut("The name parameter allows you to provide a namesfile, and the group parameter allows you to provide a groupfile.\n");
                m->mothurOut("The screen.seqs command should be in the following format: \n");
                m->mothurOut("screen.seqs(fasta=yourFastaFile, name=youNameFile, group=yourGroupFIle, start=yourStart, end=yourEnd, maxambig=yourMaxambig,  \n");
@@ -216,8 +217,10 @@ int ScreenSeqsCommand::execute(){
                                MPIPos = setFilePosFasta(fastafile, numFastaSeqs); //fills MPIPos, returns numSeqs
                                
                                //send file positions to all processes
-                               MPI_Bcast(&numFastaSeqs, 1, MPI_INT, 0, MPI_COMM_WORLD);  //send numSeqs
-                               MPI_Bcast(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, 0, MPI_COMM_WORLD); //send file pos   
+                               for(int i = 1; i < processors; i++) { 
+                                       MPI_Send(&numFastaSeqs, 1, MPI_INT, i, tag, MPI_COMM_WORLD);
+                                       MPI_Send(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, i, tag, MPI_COMM_WORLD);
+                               }
                                
                                //figure out how many sequences you have to align
                                numSeqsPerProcessor = numFastaSeqs / processors;
@@ -248,10 +251,10 @@ int ScreenSeqsCommand::execute(){
                                        }*/
                                }
                        }else{ //you are a child process
-                               MPI_Bcast(&numFastaSeqs, 1, MPI_INT, 0, MPI_COMM_WORLD); //get numSeqs
+                               MPI_Recv(&numFastaSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
                                MPIPos.resize(numFastaSeqs+1);
-                               MPI_Bcast(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, 0, MPI_COMM_WORLD); //get file positions
-                               
+                               MPI_Recv(&MPIPos[0], (numFastaSeqs+1), MPI_LONG, 0, tag, MPI_COMM_WORLD, &status);
+
                                //figure out how many sequences you have to align
                                numSeqsPerProcessor = numFastaSeqs / processors;
                                int startIndex =  pid * numSeqsPerProcessor;
@@ -284,6 +287,7 @@ int ScreenSeqsCommand::execute(){
                        MPI_File_close(&outMPIGood);
                        MPI_File_close(&outMPIBad);
                        MPI_File_close(&outMPIBadAccnos);
+                       MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case
                                        
 #else
                                        
@@ -291,7 +295,7 @@ int ScreenSeqsCommand::execute(){
                        if(processors == 1){
                                ifstream inFASTA;
                                openInputFile(fastafile, inFASTA);
-                               numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
+                               getNumSeqs(inFASTA, numFastaSeqs);
                                inFASTA.close();
                                
                                lines.push_back(new linePair(0, numFastaSeqs));
@@ -365,7 +369,7 @@ int ScreenSeqsCommand::execute(){
        #else
                        ifstream inFASTA;
                        openInputFile(fastafile, inFASTA);
-                       numFastaSeqs=count(istreambuf_iterator<char>(inFASTA),istreambuf_iterator<char>(), '>');
+                       getNumSeqs(inFASTA, numFastaSeqs);
                        inFASTA.close();
                        
                        lines.push_back(new linePair(0, numFastaSeqs));