+ ifstream inForwardFasta;
+ m->openInputFile(ffasta, inForwardFasta);
+
+ ifstream inReverseFasta;
+ m->openInputFile(rfasta, inReverseFasta);
+
+ ifstream inForwardQual, inReverseQual;
+ if (fqualfile != "") { m->openInputFile(fqualfile, inForwardQual); m->openInputFile(rqualfile, inReverseQual); }
+
+ count = 0;
+ map<string, fastqRead> uniques;
+ map<string, fastqRead>::iterator itUniques;
+ while ((!inForwardFasta.eof()) || (!inReverseFasta.eof())) {
+
+ if (m->control_pressed) { for (it = tempfiles.begin(); it!=tempfiles.end(); it++) { for (int i = 0; i < (it->second).size(); i++) { (*(it->second)[i]).close(); delete (it->second)[i]; } } for (int i = 0; i < files.size(); i++) { for(int j = 0; j < files[i].size(); j++) { m->mothurRemove(files[i][j]); } } inReverseFasta.close(); inForwardFasta.close(); if (fqualfile != "") { inReverseQual.close(); inReverseQual.close(); } return files; }
+
+ //get a reads from forward and reverse fasta files
+ bool ignoref, ignorer;
+ fastqRead thisFread, thisRread;
+ if (!inForwardFasta.eof()) {
+ ignoref = false;
+ Sequence temp(inForwardFasta); m->gobble(inForwardFasta);
+ thisFread.name = temp.getName();
+ thisFread.sequence = temp.getUnaligned();
+ }else { ignoref = true; }
+ if (!inReverseFasta.eof()) {
+ ignorer = false;
+ Sequence temp(inReverseFasta); m->gobble(inReverseFasta);
+ thisRread.name = temp.getName();
+ thisRread.sequence = temp.getUnaligned();
+ }else { ignorer = true; }
+
+ //get qual reads if given
+ if (fqualfile != "") {
+ if (!inForwardQual.eof() && !ignoref) {
+ QualityScores temp(inForwardQual); m->gobble(inForwardQual);
+ //if forward files dont match ignore read
+ if (thisFread.name != temp.getName()) { ignoref = true; }
+ else { thisFread.scores = temp.getQualityScores(); }
+ }else { ignoref = true; }
+ if (!inReverseQual.eof() && !ignorer) {
+ QualityScores temp(inReverseQual); m->gobble(inReverseQual);
+ //if reverse files dont match ignore read
+ if (thisRread.name != temp.getName()) { ignorer = true; }
+ else { thisRread.scores = temp.getQualityScores(); }
+ }else { ignorer = true; }
+ }
+
+ vector<pairFastqRead> reads = getReads(ignoref, ignorer, thisFread, thisRread, uniques);
+
+ for (int i = 0; i < reads.size(); i++) {
+ fastqRead fread = reads[i].forward;
+ fastqRead rread = reads[i].reverse;
+
+ if (m->debug) { m->mothurOut(toString(count) + '\t' + fread.name + '\t' + rread.name + '\n'); }
+
+ // if (checkReads(fread, rread, ffasta, rfasta)) {
+ if (m->control_pressed) { for (it = tempfiles.begin(); it!=tempfiles.end(); it++) { for (int i = 0; i < (it->second).size(); i++) { (*(it->second)[i]).close(); delete (it->second)[i]; } } for (int i = 0; i < files.size(); i++) { for(int j = 0; j < files[i].size(); j++) { m->mothurRemove(files[i][j]); } } inReverseFasta.close(); inForwardFasta.close(); if (fqualfile != "") { inReverseQual.close(); inReverseQual.close(); } return files; }
+
+ //if the reads are okay write to output files
+ int process = count % processors;
+
+ *(tempfiles[process][0]) << ">" << fread.name << endl << fread.sequence << endl;
+ *(tempfiles[process][2]) << ">" << rread.name << endl << rread.sequence << endl;
+ if (fqualfile != "") { //if you have quality info, print it
+ *(tempfiles[process][1]) << ">" << fread.name << endl;
+ for (int i = 0; i < fread.scores.size(); i++) { *(tempfiles[process][1]) << fread.scores[i] << " "; }
+ *(tempfiles[process][1]) << endl;
+ *(tempfiles[process][3]) << ">" << rread.name << endl;
+ for (int i = 0; i < rread.scores.size(); i++) { *(tempfiles[process][3]) << rread.scores[i] << " "; }
+ *(tempfiles[process][3]) << endl;
+ }
+ count++;
+
+ //report progress
+ if((count) % 10000 == 0){ m->mothurOut(toString(count)); m->mothurOutEndLine(); }
+ //}
+ }
+ }
+ //report progress
+ if((count) % 10000 != 0){ m->mothurOut(toString(count)); m->mothurOutEndLine(); }
+
+ if (uniques.size() != 0) {
+ for (itUniques = uniques.begin(); itUniques != uniques.end(); itUniques++) {
+ m->mothurOut("[WARNING]: did not find paired read for " + itUniques->first + ", ignoring.\n");
+ }
+ m->mothurOutEndLine();
+ }
+
+ //close files, delete ofstreams
+ for (it = tempfiles.begin(); it!=tempfiles.end(); it++) { for (int i = 0; i < (it->second).size(); i++) { (*(it->second)[i]).close(); delete (it->second)[i]; } }
+ inReverseFasta.close();
+ inForwardFasta.close();
+ if (fqualfile != "") { inReverseQual.close(); inReverseQual.close(); }
+