]> git.donarmstrong.com Git - mothur.git/blobdiff - aligncommand.cpp
added oligos class. added check orient parameter to trim.flows, sffinfo, fastq.info...
[mothur.git] / aligncommand.cpp
index 3222f8c2d72a32bef9898eb71dd9d270056de0c3..bcc59675d3b545f68197a3f56911a769ebe249bb 100644 (file)
@@ -110,7 +110,7 @@ AlignCommand::AlignCommand(){
 //**********************************************************************************************************************
 AlignCommand::AlignCommand(string option)  {
        try {
-               abort = false; calledHelp = false;  
+               abort = false; calledHelp = false;
                ReferenceDB* rdb = ReferenceDB::getInstance();
                
                //allow user to run help
@@ -860,6 +860,8 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s
        try {
                int num = 0;
                processIDS.resize(0);
+        bool recalc = false;
+        
 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                int process = 1;
                
@@ -882,12 +884,48 @@ int AlignCommand::createProcesses(string alignFileName, string reportFileName, s
                                
                                exit(0);
                        }else { 
-                               m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); 
-                               for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
-                               exit(0);
+                               m->mothurOut("[ERROR]: unable to spawn the number of processes you requested, reducing number to " + toString(process) + "\n"); processors = process;
+                for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
+                recalc = true;
+                               break;
                        }
                }
                
+        if (recalc) {
+            for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
+            vector<unsigned long long> positions;
+                       positions = m->divideFile(filename, processors);
+                       for (int i = 0; i < (positions.size()-1); i++) {        lines.push_back(new linePair(positions[i], positions[(i+1)]));  }
+            
+            num = 0;
+            processIDS.resize(0);
+            process = 1;
+            
+            while (process != processors) {
+                pid_t pid = fork();
+                
+                if (pid > 0) {
+                    processIDS.push_back(pid);  //create map from line number to pid so you can append files in correct order later
+                    process++;
+                }else if (pid == 0){
+                    num = driver(lines[process], alignFileName + toString(m->mothurGetpid(process)) + ".temp", reportFileName + toString(m->mothurGetpid(process)) + ".temp", accnosFName + m->mothurGetpid(process) + ".temp", filename);
+                    
+                    //pass numSeqs to parent
+                    ofstream out;
+                    string tempFile = alignFileName + toString(m->mothurGetpid(process)) + ".num.temp";
+                    m->openOutputFile(tempFile, out);
+                    out << num << endl;
+                    out.close();
+                    
+                    exit(0);
+                }else {
+                    m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine();
+                    for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
+                    exit(0);
+                }
+            }
+        }
+        
                //do my part
                num = driver(lines[0], alignFileName, reportFileName, accnosFName, filename);