+ string errorCountFileName = getOutputFileName("errorcount",variables);
+ ofstream errorCountFile;
+ m->openOutputFile(errorCountFileName, errorCountFile);
+ outputNames.push_back(errorCountFileName); outputTypes["errorcount"].push_back(errorCountFileName);
+ m->mothurOut("Overall error rate:\t" + toString((double)(totalBases - totalMatches) / (double)totalBases) + "\n");
+ m->mothurOut("Errors\tSequences\n");
+ errorCountFile << "Errors\tSequences\n";
+ for(int i=0;i<misMatchCounts.size();i++){
+ m->mothurOut(toString(i) + '\t' + toString(misMatchCounts[i]) + '\n');
+ errorCountFile << i << '\t' << misMatchCounts[i] << endl;
+ }
+ errorCountFile.close();
+
+// if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
+
+ printSubMatrix();
+
+ string megAlignmentFileName = getOutputFileName("errorref-query",variables);
+ ofstream megAlignmentFile;
+ m->openOutputFile(megAlignmentFileName, megAlignmentFile);
+ outputNames.push_back(megAlignmentFileName); outputTypes["errorref-query"].push_back(megAlignmentFileName);
+
+ for(int i=0;i<numRefs;i++){
+ megAlignmentFile << referenceSeqs[i].getInlineSeq() << endl;
+ megAlignmentFile << megaAlignVector[i] << endl;
+ }
+ megAlignmentFile.close();
+
+
+ m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences.");
+ m->mothurOutEndLine();
+
+ //set fasta file as new current fastafile
+ string current = "";
+ itTypes = outputTypes.find("errorseq");
+ if (itTypes != outputTypes.end()) {
+ if ((itTypes->second).size() != 0) { current = (itTypes->second)[0]; m->setFastaFile(current); }
+ }
+
+ m->mothurOutEndLine();
+ m->mothurOut("Output File Names: "); m->mothurOutEndLine();
+ for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
+ m->mothurOutEndLine();
+
+ return 0;
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SeqErrorCommand", "execute");
+ exit(1);
+ }
+}
+
+//**********************************************************************************************************************
+
+int SeqErrorCommand::createProcesses(string filename, string qFileName, string rFileName, string summaryFileName, string errorOutputFileName, string chimeraOutputFileName) {
+ try {
+ int process = 1;
+ processIDS.clear();
+ map<char, vector<int> >::iterator it;
+ 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();
+
+ 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(filename, qFileName, rFileName, summaryFileName + toString(getpid()) + ".temp", errorOutputFileName+ toString(getpid()) + ".temp", chimeraOutputFileName + toString(getpid()) + ".temp", lines[process], qLines[process], rLines[process]);
+
+ //pass groupCounts to parent
+ ofstream out;
+ string tempFile = filename + toString(getpid()) + ".info.temp";
+ m->openOutputFile(tempFile, out);
+
+ //output totalBases and totalMatches
+ out << num << '\t' << totalBases << '\t' << totalMatches << endl << endl;
+
+ //output substitutionMatrix
+ for(int i = 0; i < substitutionMatrix.size(); i++) {
+ for (int j = 0; j < substitutionMatrix[i].size(); j++) {
+ out << substitutionMatrix[i][j] << '\t';
+ }
+ out << endl;
+ }
+ out << endl;
+
+ //output qScoreErrorMap
+ for (it = qScoreErrorMap.begin(); it != qScoreErrorMap.end(); it++) {
+ vector<int> thisScoreErrorMap = it->second;
+ out << it->first << '\t';
+ for (int i = 0; i < thisScoreErrorMap.size(); i++) {
+ out << thisScoreErrorMap[i] << '\t';
+ }
+ out << endl;
+ }
+ out << endl;
+
+ //output qualForwardMap
+ for(int i = 0; i < qualForwardMap.size(); i++) {
+ for (int j = 0; j < qualForwardMap[i].size(); j++) {
+ out << qualForwardMap[i][j] << '\t';
+ }
+ out << endl;
+ }
+ out << endl;
+
+ //output qualReverseMap
+ for(int i = 0; i < qualReverseMap.size(); i++) {
+ for (int j = 0; j < qualReverseMap[i].size(); j++) {
+ out << qualReverseMap[i][j] << '\t';
+ }
+ out << endl;
+ }
+ out << endl;
+
+
+ //output errorForward
+ for (it = errorForward.begin(); it != errorForward.end(); it++) {
+ vector<int> thisErrorForward = it->second;
+ out << it->first << '\t';
+ for (int i = 0; i < thisErrorForward.size(); i++) {
+ out << thisErrorForward[i] << '\t';
+ }
+ out << endl;
+ }
+ out << endl;
+
+ //output errorReverse
+ for (it = errorReverse.begin(); it != errorReverse.end(); it++) {
+ vector<int> thisErrorReverse = it->second;
+ out << it->first << '\t';
+ for (int i = 0; i < thisErrorReverse.size(); i++) {
+ out << thisErrorReverse[i] << '\t';
+ }
+ out << endl;
+ }
+ out << endl;
+
+ //output misMatchCounts
+ out << misMatchCounts.size() << endl;
+ for (int j = 0; j < misMatchCounts.size(); j++) {
+ out << misMatchCounts[j] << '\t';
+ }
+ out << endl;
+
+
+ //output megaAlignVector
+ for (int j = 0; j < megaAlignVector.size(); j++) {
+ out << megaAlignVector[j] << endl;
+ }
+ out << 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(filename, qFileName, rFileName, summaryFileName, errorOutputFileName, chimeraOutputFileName, lines[0], qLines[0], rLines[0]);
+
+ //force parent to wait until all the processes are done
+ for (int i=0;i<processIDS.size();i++) {
+ int temp = processIDS[i];
+ wait(&temp);