+
+ numFPrimers = 0; //this needs to be initialized
+ numRPrimers = 0;
+ vector<string> fastaFileNames;
+ vector<string> qualFileNames;
+
+ string trimSeqFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "trim.fasta";
+ outputNames.push_back(trimSeqFile); outputTypes["fasta"].push_back(trimSeqFile);
+ string scrapSeqFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "scrap.fasta";
+ outputNames.push_back(scrapSeqFile); outputTypes["fasta"].push_back(scrapSeqFile);
+ string trimQualFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "trim.qual";
+ string scrapQualFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "scrap.qual";
+ if (qFileName != "") { outputNames.push_back(trimQualFile); outputNames.push_back(scrapQualFile); outputTypes["qual"].push_back(trimQualFile); outputTypes["qual"].push_back(scrapQualFile); }
+ string groupFile = "";
+ if (groupfile == "") { groupFile = outputDir + m->getRootName(m->getSimpleName(fastaFile)) + "groups"; }
+ else{
+ groupFile = outputDir + m->getRootName(m->getSimpleName(groupfile)) + "trim.groups";
+ outputNames.push_back(groupFile); outputTypes["group"].push_back(groupFile);
+ groupMap = new GroupMap(groupfile);
+ groupMap->readMap();
+
+ if(allFiles){
+ for (int i = 0; i < groupMap->namesOfGroups.size(); i++) {
+ groupToIndex[groupMap->namesOfGroups[i]] = i;
+ groupVector.push_back(groupMap->namesOfGroups[i]);
+ fastaFileNames.push_back((outputDir + m->getRootName(m->getSimpleName(fastaFile)) + groupMap->namesOfGroups[i] + ".fasta"));
+
+ //we append later, so we want to clear file
+ ofstream outRemove;
+ m->openOutputFile(fastaFileNames[i], outRemove);
+ outRemove.close();
+ if(qFileName != ""){
+ qualFileNames.push_back((outputDir + m->getRootName(m->getSimpleName(qFileName)) + groupMap->namesOfGroups[i] + ".qual"));
+ ofstream outRemove2;
+ m->openOutputFile(qualFileNames[i], outRemove2);
+ outRemove2.close();
+ }
+ }
+ }
+ comboStarts = fastaFileNames.size()-1;
+ }
+
+ if(oligoFile != ""){
+ outputNames.push_back(groupFile); outputTypes["group"].push_back(groupFile);
+ getOligos(fastaFileNames, qualFileNames);
+ }
+ cout << fastaFileNames.size() << '\t' << qualFileNames.size() << endl;
+ 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]);
+ }else{
+ createProcessesCreateTrim(fastaFile, qFileName, trimSeqFile, scrapSeqFile, trimQualFile, scrapQualFile, groupFile, fastaFileNames, qualFileNames);
+ }
+ #else
+ driverCreateTrim(fastaFile, qFileName, trimSeqFile, scrapSeqFile, trimQualFile, scrapQualFile, groupFile, fastaFileNames, qualFileNames, lines[0], qLines[0]);
+ #endif
+
+ if (m->control_pressed) { return 0; }
+
+ for(int i=0;i<fastaFileNames.size();i++){
+ cout << fastaFileNames[i] << endl;
+
+ 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); outputTypes["group"].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++){
+ cout << qualFileNames[i] << endl;
+ 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;
+ }