]> git.donarmstrong.com Git - mothur.git/blobdiff - screenseqscommand.cpp
removing chime source files from mother project.
[mothur.git] / screenseqscommand.cpp
index 9a6998e28fdb7f41a8c7be6b00b86a7f0c5be8ee..7ac910d4a74b9fc1bffeacb32f5893941f3eb60f 100644 (file)
@@ -8,7 +8,7 @@
  */
 
 #include "screenseqscommand.h"
-#include "sequence.hpp"
+
 
 //**********************************************************************************************************************
 vector<string> ScreenSeqsCommand::setParameters(){     
@@ -220,26 +220,26 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option)  {
                        // ...at some point should added some additional type checking...
                        string temp;
                        temp = validParameter.validFile(parameters, "start", false);            if (temp == "not found") { temp = "-1"; }
-                       convert(temp, startPos); 
+                       m->mothurConvert(temp, startPos); 
                
                        temp = validParameter.validFile(parameters, "end", false);                      if (temp == "not found") { temp = "-1"; }
-                       convert(temp, endPos);  
+                       m->mothurConvert(temp, endPos);  
 
                        temp = validParameter.validFile(parameters, "maxambig", false);         if (temp == "not found") { temp = "-1"; }
-                       convert(temp, maxAmbig);  
+                       m->mothurConvert(temp, maxAmbig);  
 
                        temp = validParameter.validFile(parameters, "maxhomop", false);         if (temp == "not found") { temp = "-1"; }
-                       convert(temp, maxHomoP);  
+                       m->mothurConvert(temp, maxHomoP);  
 
                        temp = validParameter.validFile(parameters, "minlength", false);        if (temp == "not found") { temp = "-1"; }
-                       convert(temp, minLength); 
+                       m->mothurConvert(temp, minLength); 
                        
                        temp = validParameter.validFile(parameters, "maxlength", false);        if (temp == "not found") { temp = "-1"; }
-                       convert(temp, maxLength); 
+                       m->mothurConvert(temp, maxLength); 
                        
                        temp = validParameter.validFile(parameters, "processors", false);       if (temp == "not found"){       temp = m->getProcessors();      }
                        m->setProcessors(temp);
-                       convert(temp, processors);
+                       m->mothurConvert(temp, processors);
                        
                        temp = validParameter.validFile(parameters, "optimize", false); //optimizing trumps the optimized values original value
                        if (temp == "not found"){       temp = "none";          }
@@ -259,7 +259,12 @@ ScreenSeqsCommand::ScreenSeqsCommand(string option)  {
                        if (optimize.size() == 1) { if (optimize[0] == "none") { optimize.clear(); } }
                        
                        temp = validParameter.validFile(parameters, "criteria", false); if (temp == "not found"){       temp = "90";                            }
-                       convert(temp, criteria); 
+                       m->mothurConvert(temp, criteria); 
+                       
+                       if (namefile == "") {
+                               vector<string> files; files.push_back(fastafile);
+                               parser.getNameFile(files);
+                       }
                }
 
        }
@@ -283,12 +288,27 @@ int ScreenSeqsCommand::execute(){
                        getSummary(positions); 
                } 
                else { 
-                       positions = m->divideFile(fastafile, processors);
-                       for (int i = 0; i < (positions.size()-1); i++) {
-                               lines.push_back(new linePair(positions[i], positions[(i+1)]));
-                       }       
+                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+                positions = m->divideFile(fastafile, processors);
+                for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); }
+                       #else 
+                if(processors == 1){ lines.push_back(linePair(0, 1000));  }
+                else {
+                    int numFastaSeqs = 0;
+                    positions = m->setFilePosFasta(fastafile, numFastaSeqs); 
+                    if (positions.size() < processors) { processors = positions.size(); }
+                
+                    //figure out how many sequences you have to process
+                    int numSeqsPerProcessor = numFastaSeqs / processors;
+                    for (int i = 0; i < processors; i++) {
+                        int startIndex =  i * numSeqsPerProcessor;
+                        if(i == (processors - 1)){     numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor;   }
+                        lines.push_back(linePair(positions[startIndex], numSeqsPerProcessor));
+                    }
+                }
+                       #endif
                }
-                               
+                                       
                string goodSeqFile = outputDir + m->getRootName(m->getSimpleName(fastafile)) + "good" + m->getExtension(fastafile);
                string badAccnosFile =  outputDir + m->getRootName(m->getSimpleName(fastafile)) + "bad.accnos";
                
@@ -341,29 +361,16 @@ int ScreenSeqsCommand::execute(){
                                numSeqsPerProcessor = numFastaSeqs / processors;
                                int startIndex =  pid * numSeqsPerProcessor;
                                if(pid == (processors - 1)){    numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor;         }
-               //      cout << pid << '\t' << numSeqsPerProcessor << '\t' <<   startIndex << endl;
+
                                //align your part
                                driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIGood, outMPIBadAccnos, MPIPos, badSeqNames);
-               //cout << pid << " done" << endl;
+
                                if (m->control_pressed) { MPI_File_close(&inMPI);  MPI_File_close(&outMPIGood);  MPI_File_close(&outMPIBadAccnos);  return 0; }
 
                                for (int i = 1; i < processors; i++) {
-                               
                                        //get bad lists
                                        int badSize;
                                        MPI_Recv(&badSize, 1, MPI_INT, i, tag, MPI_COMM_WORLD, &status);
-                                       /*for (int j = 0; j < badSize; j++) {
-                                               int length;
-                                               MPI_Recv(&length, 1, MPI_INT, i, tag, MPI_COMM_WORLD, &status);  //recv the length of the name
-                                               char* buf2 = new char[length];                                                                          //make space to recieve it
-                                               MPI_Recv(buf2, length, MPI_CHAR, i, tag, MPI_COMM_WORLD, &status);  //get name
-                                               
-                                               string tempBuf = buf2;
-                                               if (tempBuf.length() > length) { tempBuf = tempBuf.substr(0, length); }
-                                               delete buf2;
-                                               
-                                               badSeqNames.insert(tempBuf);
-                                       }*/
                                }
                        }else{ //you are a child process
                                MPI_Recv(&numFastaSeqs, 1, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
@@ -374,27 +381,15 @@ int ScreenSeqsCommand::execute(){
                                numSeqsPerProcessor = numFastaSeqs / processors;
                                int startIndex =  pid * numSeqsPerProcessor;
                                if(pid == (processors - 1)){    numSeqsPerProcessor = numFastaSeqs - pid * numSeqsPerProcessor;         }
-               //cout << pid << '\t' << numSeqsPerProcessor << '\t' <<         startIndex << endl;             
+
                                //align your part
                                driverMPI(startIndex, numSeqsPerProcessor, inMPI, outMPIGood, outMPIBadAccnos, MPIPos, badSeqNames);
-//cout << pid << " done" << endl;
+
                                if (m->control_pressed) { MPI_File_close(&inMPI);  MPI_File_close(&outMPIGood);  MPI_File_close(&outMPIBadAccnos); return 0; }
                                
                                //send bad list 
                                int badSize = badSeqNames.size();
                                MPI_Send(&badSize, 1, MPI_INT, 0, tag, MPI_COMM_WORLD);
-                               
-                               /*
-                               set<string>::iterator it;
-                               for (it = badSeqNames.begin(); it != badSeqNames.end(); it++) {
-                                       string name = *it;
-                                       int length = name.length();
-                                       char* buf2 = new char[length];
-                                       memcpy(buf2, name.c_str(), length);
-                                       
-                                       MPI_Send(&length, 1, MPI_INT, 0, tag, MPI_COMM_WORLD);
-                                       MPI_Send(buf2, length, MPI_CHAR, 0, tag, MPI_COMM_WORLD);
-                               }*/
                        }
                        
                        //close files 
@@ -404,53 +399,10 @@ int ScreenSeqsCommand::execute(){
                        MPI_Barrier(MPI_COMM_WORLD); //make everyone wait - just in case
                                        
 #else
-                                               
-       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-                       if(processors == 1){
-                               numFastaSeqs = driver(lines[0], goodSeqFile, badAccnosFile, fastafile, badSeqNames);
-                               
-                               if (m->control_pressed) { m->mothurRemove(goodSeqFile); return 0; }
-                               
-                       }else{
-                               processIDS.resize(0);
-                               
-                               numFastaSeqs = createProcesses(goodSeqFile, badAccnosFile, fastafile, badSeqNames); 
-                               
-                               rename((goodSeqFile + toString(processIDS[0]) + ".temp").c_str(), goodSeqFile.c_str());
-                               rename((badAccnosFile + toString(processIDS[0]) + ".temp").c_str(), badAccnosFile.c_str());
-                               
-                               //append alignment and report files
-                               for(int i=1;i<processors;i++){
-                                       m->appendFiles((goodSeqFile + toString(processIDS[i]) + ".temp"), goodSeqFile);
-                                       m->mothurRemove((goodSeqFile + toString(processIDS[i]) + ".temp"));
-                       
-                                       m->appendFiles((badAccnosFile + toString(processIDS[i]) + ".temp"), badAccnosFile);
-                                       m->mothurRemove((badAccnosFile + toString(processIDS[i]) + ".temp"));
-                               }
-                               
-                               if (m->control_pressed) { m->mothurRemove(goodSeqFile); return 0; }
-                               
-                               //read badSeqs in because root process doesnt know what other "bad" seqs the children found
-                               ifstream inBad;
-                               int ableToOpen = m->openInputFile(badAccnosFile, inBad, "no error");
-                               
-                               if (ableToOpen == 0) {
-                                       badSeqNames.clear();
-                                       string tempName;
-                                       while (!inBad.eof()) {
-                                               inBad >> tempName; m->gobble(inBad);
-                                               badSeqNames.insert(tempName);
-                                       }
-                                       inBad.close();
-                               }
-                       }
-       #else
-                       numFastaSeqs = driver(lines[0], goodSeqFile, badAccnosFile, fastafile, badSeqNames);
-                       
-                       if (m->control_pressed) { m->mothurRemove(goodSeqFile); return 0; }
-                       
-       #endif
-
+        if(processors == 1){ numFastaSeqs = driver(lines[0], goodSeqFile, badAccnosFile, fastafile, badSeqNames);      }       
+        else{ numFastaSeqs = createProcesses(goodSeqFile, badAccnosFile, fastafile, badSeqNames); }
+        
+        if (m->control_pressed) { m->mothurRemove(goodSeqFile); return 0; }
 #endif         
 
                #ifdef USE_MPI
@@ -659,12 +611,26 @@ int ScreenSeqsCommand::getSummary(vector<unsigned long long>& positions){
                vector<int> ambigBases;
                vector<int> longHomoPolymer;
                
-               vector<unsigned long long> positions = m->divideFile(fastafile, processors);
-                               
-               for (int i = 0; i < (positions.size()-1); i++) {
-                       lines.push_back(new linePair(positions[i], positions[(i+1)]));
-               }       
-               
+        vector<unsigned long long> positions;
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+               positions = m->divideFile(fastafile, processors);
+               for (int i = 0; i < (positions.size()-1); i++) { lines.push_back(linePair(positions[i], positions[(i+1)])); }   
+#else
+               if(processors == 1){ lines.push_back(linePair(0, 1000));  }
+        else {
+            int numFastaSeqs = 0;
+            positions = m->setFilePosFasta(fastafile, numFastaSeqs); 
+            if (positions.size() < processors) { processors = positions.size(); }
+            
+            //figure out how many sequences you have to process
+            int numSeqsPerProcessor = numFastaSeqs / processors;
+            for (int i = 0; i < processors; i++) {
+                int startIndex =  i * numSeqsPerProcessor;
+                if(i == (processors - 1)){     numSeqsPerProcessor = numFastaSeqs - i * numSeqsPerProcessor;   }
+                lines.push_back(linePair(positions[startIndex], numSeqsPerProcessor));
+            }
+        }
+#endif
                
 #ifdef USE_MPI
                int pid;
@@ -674,7 +640,7 @@ int ScreenSeqsCommand::getSummary(vector<unsigned long long>& positions){
                        driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[0]);
 #else
                int numSeqs = 0;
-               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+               //#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                        if(processors == 1){
                                numSeqs = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[0]);
                        }else{
@@ -682,10 +648,10 @@ int ScreenSeqsCommand::getSummary(vector<unsigned long long>& positions){
                        }
                                
                        if (m->control_pressed) {  return 0; }
-               #else
-                       numSeqs = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[0]);
-                       if (m->control_pressed) {  return 0; }
-               #endif
+               //#else
+               //      numSeqs = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[0]);
+               //      if (m->control_pressed) {  return 0; }
+               //#endif
 #endif
                sort(startPosition.begin(), startPosition.end());
                sort(endPosition.begin(), endPosition.end());
@@ -740,13 +706,13 @@ int ScreenSeqsCommand::getSummary(vector<unsigned long long>& positions){
        }
 }
 /**************************************************************************************/
-int ScreenSeqsCommand::driverCreateSummary(vector<int>& startPosition, vector<int>& endPosition, vector<int>& seqLength, vector<int>& ambigBases, vector<int>& longHomoPolymer, string filename, linePair* filePos) {  
+int ScreenSeqsCommand::driverCreateSummary(vector<int>& startPosition, vector<int>& endPosition, vector<int>& seqLength, vector<int>& ambigBases, vector<int>& longHomoPolymer, string filename, linePair filePos) {   
        try {
                
                ifstream in;
                m->openInputFile(filename, in);
                                
-               in.seekg(filePos->start);
+               in.seekg(filePos.start);
 
                bool done = false;
                int count = 0;
@@ -778,10 +744,10 @@ int ScreenSeqsCommand::driverCreateSummary(vector<int>& startPosition, vector<in
                                
                                count++;
                        }
-                       
-                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                       //if((count) % 100 == 0){       m->mothurOut("Optimizing sequence: " + toString(count)); m->mothurOutEndLine();         }
+                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                                unsigned long long pos = in.tellg();
-                               if ((pos == -1) || (pos >= filePos->end)) { break; }
+                               if ((pos == -1) || (pos >= filePos.end)) { break; }
                        #else
                                if (in.eof()) { break; }
                        #endif
@@ -800,11 +766,13 @@ int ScreenSeqsCommand::driverCreateSummary(vector<int>& startPosition, vector<in
 /**************************************************************************************************/
 int ScreenSeqsCommand::createProcessesCreateSummary(vector<int>& startPosition, vector<int>& endPosition, vector<int>& seqLength, vector<int>& ambigBases, vector<int>& longHomoPolymer, string filename) {
        try {
-#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-               int process = 1;
+        
+        int process = 1;
                int num = 0;
-               processIDS.clear();
-               
+               vector<int> processIDS;
+
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+                               
                //loop through and create all the processes you want
                while (process != processors) {
                        int pid = fork();
@@ -865,8 +833,50 @@ int ScreenSeqsCommand::createProcessesCreateSummary(vector<int>& startPosition,
                        m->mothurRemove(tempFilename);
                }
                
-               return num;
+               
+#else 
+        //////////////////////////////////////////////////////////////////////////////////////////////////////
+               //Windows version shared memory, so be careful when passing variables through the seqSumData struct. 
+               //Above fork() will clone, so memory is separate, but that's not the case with windows, 
+               //Taking advantage of shared memory to allow both threads to add info to vectors.
+               //////////////////////////////////////////////////////////////////////////////////////////////////////
+               
+               vector<sumData*> pDataArray; 
+               DWORD   dwThreadIdArray[processors-1];
+               HANDLE  hThreadArray[processors-1]; 
+               
+               //Create processor worker threads.
+               for( int i=0; i<processors-1; i++ ){
+            
+                       // Allocate memory for thread data.
+                       sumData* tempSum = new sumData(filename, m, lines[i].start, lines[i].end, namefile, nameMap);
+                       pDataArray.push_back(tempSum);
+                       
+                       //MySeqSumThreadFunction is in header. It must be global or static to work with the threads.
+                       //default security attributes, thread function name, argument to thread function, use default creation flags, returns the thread identifier
+                       hThreadArray[i] = CreateThread(NULL, 0, MySumThreadFunction, pDataArray[i], 0, &dwThreadIdArray[i]);   
+               }
+               
+        //do your part
+               num = driverCreateSummary(startPosition, endPosition, seqLength, ambigBases, longHomoPolymer, fastafile, lines[processors-1]);
+         
+               //Wait until all threads have terminated.
+               WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE);
+               
+               //Close all thread handles and free memory allocations.
+               for(int i=0; i < pDataArray.size(); i++){
+                       num += pDataArray[i]->count;
+            for (int k = 0; k < pDataArray[i]->startPosition.size(); k++) {    startPosition.push_back(pDataArray[i]->startPosition[k]);       }
+                       for (int k = 0; k < pDataArray[i]->endPosition.size(); k++) {   endPosition.push_back(pDataArray[i]->endPosition[k]);       }
+            for (int k = 0; k < pDataArray[i]->seqLength.size(); k++) {        seqLength.push_back(pDataArray[i]->seqLength[k]);       }
+            for (int k = 0; k < pDataArray[i]->ambigBases.size(); k++) {       ambigBases.push_back(pDataArray[i]->ambigBases[k]);       }
+            for (int k = 0; k < pDataArray[i]->longHomoPolymer.size(); k++) {  longHomoPolymer.push_back(pDataArray[i]->longHomoPolymer[k]);       }
+                       CloseHandle(hThreadArray[i]);
+                       delete pDataArray[i];
+               }
+
 #endif         
+        return num;
        }
        catch(exception& e) {
                m->errorOut(e, "ScreenSeqsCommand", "createProcessesCreateSummary");
@@ -1115,7 +1125,7 @@ int ScreenSeqsCommand::screenQual(set<string> badSeqNames){
 }
 //**********************************************************************************************************************
 
-int ScreenSeqsCommand::driver(linePair* filePos, string goodFName, string badAccnosFName, string filename, set<string>& badSeqNames){
+int ScreenSeqsCommand::driver(linePair filePos, string goodFName, string badAccnosFName, string filename, set<string>& badSeqNames){
        try {
                ofstream goodFile;
                m->openOutputFile(goodFName, goodFile);
@@ -1126,7 +1136,7 @@ int ScreenSeqsCommand::driver(linePair* filePos, string goodFName, string badAcc
                ifstream inFASTA;
                m->openInputFile(filename, inFASTA);
 
-               inFASTA.seekg(filePos->start);
+               inFASTA.seekg(filePos.start);
 
                bool done = false;
                int count = 0;
@@ -1155,9 +1165,9 @@ int ScreenSeqsCommand::driver(linePair* filePos, string goodFName, string badAcc
                        count++;
                        }
                        
-                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                                unsigned long long pos = inFASTA.tellg();
-                               if ((pos == -1) || (pos >= filePos->end)) { break; }
+                               if ((pos == -1) || (pos >= filePos.end)) { break; }
                        #else
                                if (inFASTA.eof()) { break; }
                        #endif
@@ -1262,10 +1272,13 @@ int ScreenSeqsCommand::driverMPI(int start, int num, MPI_File& inMPI, MPI_File&
 
 int ScreenSeqsCommand::createProcesses(string goodFileName, string badAccnos, string filename, set<string>& badSeqNames) {
        try {
-#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
-               int process = 0;
+        
+        vector<int> processIDS;   
+        int process = 1;
                int num = 0;
-               
+
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+                               
                //loop through and create all the processes you want
                while (process != processors) {
                        int pid = fork();
@@ -1291,8 +1304,10 @@ int ScreenSeqsCommand::createProcesses(string goodFileName, string badAccnos, st
                        }
                }
                
+        num = driver(lines[0], goodFileName, badAccnos, filename, badSeqNames);
+        
                //force parent to wait until all the processes are done
-               for (int i=0;i<processors;i++) { 
+               for (int i=0;i<processIDS.size();i++) { 
                        int temp = processIDS[i];
                        wait(&temp);
                }
@@ -1303,10 +1318,80 @@ int ScreenSeqsCommand::createProcesses(string goodFileName, string badAccnos, st
                        m->openInputFile(tempFile, in);
                        if (!in.eof()) { int tempNum = 0; in >> tempNum; num += tempNum; }
                        in.close(); m->mothurRemove(tempFile);
+            
+            m->appendFiles((goodFileName + toString(processIDS[i]) + ".temp"), goodFileName);
+            m->mothurRemove((goodFileName + toString(processIDS[i]) + ".temp"));
+                       
+            m->appendFiles((badAccnos + toString(processIDS[i]) + ".temp"), badAccnos);
+            m->mothurRemove((badAccnos + toString(processIDS[i]) + ".temp"));
                }
                
-               return num;
-#endif         
+        //read badSeqs in because root process doesnt know what other "bad" seqs the children found
+        ifstream inBad;
+        int ableToOpen = m->openInputFile(badAccnos, inBad, "no error");
+        
+        if (ableToOpen == 0) {
+            badSeqNames.clear();
+            string tempName;
+            while (!inBad.eof()) {
+                inBad >> tempName; m->gobble(inBad);
+                badSeqNames.insert(tempName);
+            }
+            inBad.close();
+        }
+#else
+        
+        //////////////////////////////////////////////////////////////////////////////////////////////////////
+               //Windows version shared memory, so be careful when passing variables through the sumScreenData struct. 
+               //Above fork() will clone, so memory is separate, but that's not the case with windows, 
+               //Taking advantage of shared memory to allow both threads to add info to badSeqNames.
+               //////////////////////////////////////////////////////////////////////////////////////////////////////
+               
+               vector<sumScreenData*> pDataArray; 
+               DWORD   dwThreadIdArray[processors-1];
+               HANDLE  hThreadArray[processors-1]; 
+               
+               //Create processor worker threads.
+               for( int i=0; i<processors-1; i++ ){
+            
+            string extension = "";
+            if (i!=0) {extension += toString(i) + ".temp"; processIDS.push_back(i); }
+            
+                       // Allocate memory for thread data.
+                       sumScreenData* tempSum = new sumScreenData(startPos, endPos, maxAmbig, maxHomoP, minLength, maxLength, filename, m, lines[i].start, lines[i].end,goodFileName+extension, badAccnos+extension);
+                       pDataArray.push_back(tempSum);
+                       
+                       //default security attributes, thread function name, argument to thread function, use default creation flags, returns the thread identifier
+                       hThreadArray[i] = CreateThread(NULL, 0, MySumScreenThreadFunction, pDataArray[i], 0, &dwThreadIdArray[i]);   
+               }
+               
+        //do your part
+        num = driver(lines[processors-1], (goodFileName+toString(processors-1)+".temp"), (badAccnos+toString(processors-1)+".temp"), filename, badSeqNames);
+        processIDS.push_back(processors-1);
+        
+               //Wait until all threads have terminated.
+               WaitForMultipleObjects(processors-1, hThreadArray, TRUE, INFINITE);
+               
+               //Close all thread handles and free memory allocations.
+               for(int i=0; i < pDataArray.size(); i++){
+                       num += pDataArray[i]->count;
+            for (set<string>::iterator it = pDataArray[i]->badSeqNames.begin(); it != pDataArray[i]->badSeqNames.end(); it++) {        badSeqNames.insert(*it);       }
+                       CloseHandle(hThreadArray[i]);
+                       delete pDataArray[i];
+               }
+        
+        for (int i = 0; i < processIDS.size(); i++) {
+            m->appendFiles((goodFileName + toString(processIDS[i]) + ".temp"), goodFileName);
+            m->mothurRemove((goodFileName + toString(processIDS[i]) + ".temp"));
+                       
+            m->appendFiles((badAccnos + toString(processIDS[i]) + ".temp"), badAccnos);
+            m->mothurRemove((badAccnos + toString(processIDS[i]) + ".temp"));
+               }
+
+#endif 
+        
+        return num;
+        
        }
        catch(exception& e) {
                m->errorOut(e, "ScreenSeqsCommand", "createProcesses");