+ outputNames.push_back(groupFile);
+ getOligos(fastaFileNames, qualFileNames);
+ }
+
+ vector<unsigned long int> fastaFilePos;
+ vector<unsigned long int> qFilePos;
+
+ setLines(fastaFile, qFileName, fastaFilePos, qFilePos);
+
+ for (int i = 0; i < (fastaFilePos.size()-1); i++) {
+ lines.push_back(new linePair(fastaFilePos[i], fastaFilePos[(i+1)]));
+ if (qFileName != "") { qLines.push_back(new linePair(qFilePos[i], qFilePos[(i+1)])); }
+ }
+ if(qFileName == "") { qLines = lines; } //files with duds
+
+ #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+ if(processors == 1){
+
+ driverCreateTrim(fastaFile, qFileName, trimSeqFile, scrapSeqFile, trimQualFile, scrapQualFile, groupFile, fastaFileNames, qualFileNames, lines[0], qLines[0]);
+
+ for (int j = 0; j < fastaFileNames.size(); j++) {
+ rename((fastaFileNames[j] + toString(getpid()) + ".temp").c_str(), fastaFileNames[j].c_str());
+ }
+ if(qFileName != ""){
+ for (int j = 0; j < qualFileNames.size(); j++) {
+ rename((qualFileNames[j] + toString(getpid()) + ".temp").c_str(), qualFileNames[j].c_str());
+ }
+ }
+
+ }else{
+ createProcessesCreateTrim(fastaFile, qFileName, trimSeqFile, scrapSeqFile, trimQualFile, scrapQualFile, groupFile, fastaFileNames, qualFileNames);
+
+ rename((trimSeqFile + toString(processIDS[0]) + ".temp").c_str(), trimSeqFile.c_str());
+ rename((scrapSeqFile + toString(processIDS[0]) + ".temp").c_str(), scrapSeqFile.c_str());
+ rename((groupFile + toString(processIDS[0]) + ".temp").c_str(), groupFile.c_str());
+
+ if(qFileName != ""){
+ rename((trimQualFile + toString(processIDS[0]) + ".temp").c_str(), trimQualFile.c_str());
+ rename((scrapQualFile + toString(processIDS[0]) + ".temp").c_str(), scrapQualFile.c_str());
+ }
+
+
+ for (int j = 0; j < fastaFileNames.size(); j++) {
+ rename((fastaFileNames[j] + toString(processIDS[0]) + ".temp").c_str(), fastaFileNames[j].c_str());
+ }
+ if(qFileName != ""){
+ for (int j = 0; j < qualFileNames.size(); j++) {
+ rename((qualFileNames[j] + toString(getpid()) + ".temp").c_str(), qualFileNames[j].c_str());
+ }
+ }
+
+ //append files
+ for(int i=1;i<processors;i++){
+ m->appendFiles((trimSeqFile + toString(processIDS[i]) + ".temp"), trimSeqFile);
+ remove((trimSeqFile + toString(processIDS[i]) + ".temp").c_str());
+ m->appendFiles((scrapSeqFile + toString(processIDS[i]) + ".temp"), scrapSeqFile);
+ remove((scrapSeqFile + toString(processIDS[i]) + ".temp").c_str());
+
+ m->appendFiles((trimQualFile + toString(processIDS[i]) + ".temp"), trimQualFile);
+ remove((trimQualFile + toString(processIDS[i]) + ".temp").c_str());
+ m->appendFiles((scrapQualFile + toString(processIDS[i]) + ".temp"), scrapQualFile);
+ remove((scrapQualFile + toString(processIDS[i]) + ".temp").c_str());
+
+ m->appendFiles((groupFile + toString(processIDS[i]) + ".temp"), groupFile);
+ remove((groupFile + toString(processIDS[i]) + ".temp").c_str());
+ for (int j = 0; j < fastaFileNames.size(); j++) {
+ m->appendFiles((fastaFileNames[j] + toString(processIDS[i]) + ".temp"), fastaFileNames[j]);
+ remove((fastaFileNames[j] + toString(processIDS[i]) + ".temp").c_str());
+ }
+
+ if(qFileName != ""){
+ for (int j = 0; j < qualFileNames.size(); j++) {
+ m->appendFiles((qualFileNames[j] + toString(processIDS[i]) + ".temp"), qualFileNames[j]);
+ remove((qualFileNames[j] + toString(processIDS[i]) + ".temp").c_str());
+ }
+ }
+
+
+ }
+ }
+
+ if (m->control_pressed) { return 0; }
+ #else
+ driverCreateTrim(fastaFile, qFileName, trimSeqFile, scrapSeqFile, trimQualFile, scrapQualFile, groupFile, fastaFileNames, qualFileNames, lines[0], qLines[0]);
+
+ for (int j = 0; j < fastaFileNames.size(); j++) {
+ rename((fastaFileNames[j] + toString(j) + ".temp").c_str(), fastaFileNames[j].c_str());
+ }
+ if(qFileName != ""){
+ for (int j = 0; j < qualFileNames.size(); j++) {
+ rename((qualFileNames[j] + toString(j) + ".temp").c_str(), qualFileNames[j].c_str());
+ }
+ }
+
+ if (m->control_pressed) { return 0; }
+ #endif
+
+
+ for(int i=0;i<fastaFileNames.size();i++){
+ if (m->isBlank(fastaFileNames[i])) { remove(fastaFileNames[i].c_str()); }
+ else if (filesToRemove.count(fastaFileNames[i]) > 0) { remove(fastaFileNames[i].c_str()); }
+ else {
+ ifstream inFASTA;
+ string seqName;
+ m->openInputFile(fastaFileNames[i], inFASTA);
+ ofstream outGroups;
+ string outGroupFilename = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[i])) + "groups";
+ m->openOutputFile(outGroupFilename, outGroups);
+ outputNames.push_back(outGroupFilename);
+
+ string thisGroup = "";
+ if (i > comboStarts) {
+ map<string, int>::iterator itCombo;
+ for(itCombo=combos.begin();itCombo!=combos.end(); itCombo++){
+ if(itCombo->second == i){ thisGroup = itCombo->first; combos.erase(itCombo); break; }
+ }
+ }else{ thisGroup = groupVector[i]; }
+
+ while(!inFASTA.eof()){
+ if(inFASTA.get() == '>'){
+ inFASTA >> seqName;
+ outGroups << seqName << '\t' << thisGroup << endl;
+ }
+ while (!inFASTA.eof()) { char c = inFASTA.get(); if (c == 10 || c == 13){ break; } }
+ }
+ outGroups.close();
+ inFASTA.close();
+ }
+ }
+
+ if(qFileName != ""){
+ for(int i=0;i<qualFileNames.size();i++){
+ if (m->isBlank(qualFileNames[i])) { remove(qualFileNames[i].c_str()); }
+ else if (filesToRemove.count(qualFileNames[i]) > 0) { remove(qualFileNames[i].c_str()); }
+ else {
+ ifstream inQual;
+ string seqName;
+ m->openInputFile(qualFileNames[i], inQual);
+// ofstream outGroups;
+//
+// string thisGroup = "";
+// if (i > comboStarts) {
+// map<string, int>::iterator itCombo;
+// for(itCombo=combos.begin();itCombo!=combos.end(); itCombo++){
+// if(itCombo->second == i){ thisGroup = itCombo->first; combos.erase(itCombo); break; }
+// }
+// }
+// else{ thisGroup = groupVector[i]; }
+
+ inQual.close();
+ }
+ }
+ }
+
+
+ if (m->control_pressed) {
+ for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); }
+ return 0;