+
+ string qualityReverseFileName = getOutputFileName("errorqualreverse",variables);
+ ofstream qualityReverseFile;
+ m->openOutputFile(qualityReverseFileName, qualityReverseFile);
+ outputNames.push_back(qualityReverseFileName); outputTypes["errorqualreverse"].push_back(qualityReverseFileName);
+
+ for(int i=0;i<numColumns;i++){ qualityReverseFile << '\t' << i; } qualityReverseFile << endl;
+ for(int i=0;i<numRows;i++){
+
+ qualityReverseFile << i+1;
+ for(int j=0;j<numColumns;j++){
+ qualityReverseFile << '\t' << qualReverseMap[i][j];
+ }
+ qualityReverseFile << endl;
+ }
+ qualityReverseFile.close();
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SeqErrorCommand", "printErrorFRFile");
+ exit(1);
+ }
+
+}
+/**************************************************************************************************/
+
+int SeqErrorCommand::setLines(string filename, string qfilename, string rfilename, vector<unsigned long long>& fastaFilePos, vector<unsigned long long>& qfileFilePos, vector<unsigned long long>& rfileFilePos) {
+ try {
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
+ //set file positions for fasta file
+ fastaFilePos = m->divideFile(filename, processors);
+
+ if (qfilename == "") { return processors; }
+
+ //get name of first sequence in each chunk
+ map<string, int> firstSeqNames;
+ for (int i = 0; i < (fastaFilePos.size()-1); i++) {
+ ifstream in;
+ m->openInputFile(filename, in);
+ in.seekg(fastaFilePos[i]);
+
+ Sequence temp(in);
+ firstSeqNames[temp.getName()] = i;
+
+ in.close();
+ }
+
+ //make copy to use below
+ map<string, int> firstSeqNamesReport = firstSeqNames;
+
+ //seach for filePos of each first name in the qfile and save in qfileFilePos
+ ifstream inQual;
+ m->openInputFile(qfilename, inQual);
+
+ string input;
+ while(!inQual.eof()){
+ input = m->getline(inQual);
+
+ if (input.length() != 0) {
+ if(input[0] == '>'){ //this is a sequence name line
+ istringstream nameStream(input);
+
+ string sname = ""; nameStream >> sname;
+ sname = sname.substr(1);
+
+ map<string, int>::iterator it = firstSeqNames.find(sname);
+
+ if(it != firstSeqNames.end()) { //this is the start of a new chunk
+ unsigned long long pos = inQual.tellg();
+ qfileFilePos.push_back(pos - input.length() - 1);
+ firstSeqNames.erase(it);
+ }
+ }
+ }
+
+ if (firstSeqNames.size() == 0) { break; }
+ }
+ inQual.close();
+
+ if (firstSeqNames.size() != 0) {
+ for (map<string, int>::iterator it = firstSeqNames.begin(); it != firstSeqNames.end(); it++) {
+ m->mothurOut(it->first + " is in your fasta file and not in your quality file, aborting."); m->mothurOutEndLine();
+ }
+ m->control_pressed = true;
+ return processors;
+ }
+
+ //get last file position of qfile
+ FILE * pFile;
+ unsigned long long size;
+
+ //get num bytes in file
+ pFile = fopen (qfilename.c_str(),"rb");
+ if (pFile==NULL) perror ("Error opening file");
+ else{
+ fseek (pFile, 0, SEEK_END);
+ size=ftell (pFile);
+ fclose (pFile);
+ }
+
+ qfileFilePos.push_back(size);
+
+ //seach for filePos of each first name in the rfile and save in rfileFilePos
+ string junk;
+ ifstream inR;
+ m->openInputFile(rfilename, inR);
+
+ //read column headers
+ for (int i = 0; i < 16; i++) {
+ if (!inR.eof()) { inR >> junk; }
+ else { break; }
+ }
+
+ while(!inR.eof()){
+
+ if (m->control_pressed) { inR.close(); return processors; }
+
+ input = m->getline(inR);
+
+ if (input.length() != 0) {
+
+ istringstream nameStream(input);
+ string sname = ""; nameStream >> sname;
+
+ map<string, int>::iterator it = firstSeqNamesReport.find(sname);
+
+ if(it != firstSeqNamesReport.end()) { //this is the start of a new chunk
+ unsigned long long pos = inR.tellg();
+ rfileFilePos.push_back(pos - input.length() - 1);
+ firstSeqNamesReport.erase(it);
+ }
+ }
+
+ if (firstSeqNamesReport.size() == 0) { break; }
+ m->gobble(inR);
+ }
+ inR.close();
+
+ if (firstSeqNamesReport.size() != 0) {
+ for (map<string, int>::iterator it = firstSeqNamesReport.begin(); it != firstSeqNamesReport.end(); it++) {
+ m->mothurOut(it->first + " is in your fasta file and not in your report file, aborting."); m->mothurOutEndLine();
+ }
+ m->control_pressed = true;
+ return processors;
+ }
+
+ //get last file position of qfile
+ FILE * rFile;
+ unsigned long long sizeR;
+
+ //get num bytes in file
+ rFile = fopen (rfilename.c_str(),"rb");
+ if (rFile==NULL) perror ("Error opening file");
+ else{
+ fseek (rFile, 0, SEEK_END);
+ sizeR=ftell (rFile);
+ fclose (rFile);
+ }
+
+ rfileFilePos.push_back(sizeR);
+
+ return processors;
+
+#else
+
+ fastaFilePos.push_back(0); qfileFilePos.push_back(0);
+ //get last file position of fastafile
+ FILE * pFile;
+ unsigned long long size;
+
+ //get num bytes in file
+ pFile = fopen (filename.c_str(),"rb");
+ if (pFile==NULL) perror ("Error opening file");
+ else{
+ fseek (pFile, 0, SEEK_END);
+ size=ftell (pFile);
+ fclose (pFile);
+ }
+ fastaFilePos.push_back(size);
+
+ //get last file position of fastafile
+ FILE * qFile;
+
+ //get num bytes in file
+ qFile = fopen (qfilename.c_str(),"rb");
+ if (qFile==NULL) perror ("Error opening file");
+ else{
+ fseek (qFile, 0, SEEK_END);
+ size=ftell (qFile);
+ fclose (qFile);
+ }
+ qfileFilePos.push_back(size);
+
+ return 1;
+
+#endif
+ }
+ catch(exception& e) {
+ m->errorOut(e, "SeqErrorCommand", "setLines");
+ exit(1);
+ }
+}
+//***************************************************************************************************************