5 * Created by Pat Schloss on 7/15/10.
6 * Copyright 2010 Schloss Lab. All rights reserved.
10 #include "seqerrorcommand.h"
11 #include "reportfile.h"
12 #include "qualityscores.h"
13 #include "refchimeratest.h"
14 #include "filterseqscommand.h"
17 //**********************************************************************************************************************
18 vector<string> SeqErrorCommand::setParameters(){
20 CommandParameter pquery("fasta", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(pquery);
21 CommandParameter preference("reference", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(preference);
22 CommandParameter pqfile("qfile", "InputTypes", "", "", "none", "none", "QualReport",false,false); parameters.push_back(pqfile);
23 CommandParameter preport("report", "InputTypes", "", "", "none", "none", "QualReport",false,false); parameters.push_back(preport);
24 CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname);
25 CommandParameter pignorechimeras("ignorechimeras", "Boolean", "", "T", "", "", "",false,false); parameters.push_back(pignorechimeras);
26 CommandParameter pthreshold("threshold", "Number", "", "1.0", "", "", "",false,false); parameters.push_back(pthreshold);
27 CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors);
28 CommandParameter psave("save", "Boolean", "", "F", "", "", "",false,false); parameters.push_back(psave);
29 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
30 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
32 vector<string> myArray;
33 for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); }
37 m->errorOut(e, "SeqErrorCommand", "setParameters");
41 //**********************************************************************************************************************
42 string SeqErrorCommand::getHelpString(){
44 string helpString = "";
45 helpString += "The seq.error command reads a query alignment file and a reference alignment file and creates .....\n";
46 helpString += "The fasta parameter...\n";
47 helpString += "The reference parameter...\n";
48 helpString += "The qfile parameter...\n";
49 helpString += "The report parameter...\n";
50 helpString += "The name parameter...\n";
51 helpString += "The ignorechimeras parameter...\n";
52 helpString += "The threshold parameter...\n";
53 helpString += "The processors parameter...\n";
54 helpString += "If the save parameter is set to true the reference sequences will be saved in memory, to clear them later you can use the clear.memory command. Default=f.";
55 helpString += "Example seq.error(...).\n";
56 helpString += "Note: No spaces between parameter labels (i.e. fasta), '=' and parameters (i.e.yourFasta).\n";
57 helpString += "For more details please check out the wiki http://www.mothur.org/wiki/seq.error .\n";
61 m->errorOut(e, "SeqErrorCommand", "getHelpString");
65 //**********************************************************************************************************************
66 SeqErrorCommand::SeqErrorCommand(){
68 abort = true; calledHelp = true;
70 vector<string> tempOutNames;
71 outputTypes["error.summary"] = tempOutNames;
72 outputTypes["error.seq"] = tempOutNames;
73 outputTypes["error.quality"] = tempOutNames;
74 outputTypes["error.qual.forward"] = tempOutNames;
75 outputTypes["error.qual.reverse"] = tempOutNames;
76 outputTypes["error.forward"] = tempOutNames;
77 outputTypes["error.reverse"] = tempOutNames;
78 outputTypes["error.count"] = tempOutNames;
79 outputTypes["error.matrix"] = tempOutNames;
82 m->errorOut(e, "SeqErrorCommand", "SeqErrorCommand");
86 //***************************************************************************************************************
88 SeqErrorCommand::SeqErrorCommand(string option) {
91 abort = false; calledHelp = false;
92 rdb = ReferenceDB::getInstance();
94 //allow user to run help
95 if(option == "help") { help(); abort = true; calledHelp = true; }
96 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
100 vector<string> myArray = setParameters();
102 OptionParser parser(option);
103 map<string,string> parameters = parser.getParameters();
105 ValidParameters validParameter;
106 map<string,string>::iterator it;
108 //check to make sure all parameters are valid for command
109 for (it = parameters.begin(); it != parameters.end(); it++) {
110 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
113 //initialize outputTypes
114 vector<string> tempOutNames;
115 outputTypes["error.summary"] = tempOutNames;
116 outputTypes["error.seq"] = tempOutNames;
117 outputTypes["error.quality"] = tempOutNames;
118 outputTypes["error.qual.forward"] = tempOutNames;
119 outputTypes["error.qual.reverse"] = tempOutNames;
120 outputTypes["error.forward"] = tempOutNames;
121 outputTypes["error.reverse"] = tempOutNames;
122 outputTypes["error.count"] = tempOutNames;
123 outputTypes["error.matrix"] = tempOutNames;
126 //if the user changes the input directory command factory will send this info to us in the output parameter
127 string inputDir = validParameter.validFile(parameters, "inputdir", false);
128 if (inputDir == "not found"){ inputDir = ""; }
131 it = parameters.find("fasta");
132 //user has given a template file
133 if(it != parameters.end()){
134 path = m->hasPath(it->second);
135 //if the user has not given a path then, add inputdir. else leave path alone.
136 if (path == "") { parameters["fasta"] = inputDir + it->second; }
139 it = parameters.find("reference");
140 //user has given a template file
141 if(it != parameters.end()){
142 path = m->hasPath(it->second);
143 //if the user has not given a path then, add inputdir. else leave path alone.
144 if (path == "") { parameters["reference"] = inputDir + it->second; }
147 it = parameters.find("name");
148 //user has given a names file
149 if(it != parameters.end()){
150 path = m->hasPath(it->second);
151 //if the user has not given a path then, add inputdir. else leave path alone.
152 if (path == "") { parameters["name"] = inputDir + it->second; }
155 it = parameters.find("qfile");
156 //user has given a quality score file
157 if(it != parameters.end()){
158 path = m->hasPath(it->second);
159 //if the user has not given a path then, add inputdir. else leave path alone.
160 if (path == "") { parameters["qfile"] = inputDir + it->second; }
163 it = parameters.find("report");
164 //user has given a alignment report file
165 if(it != parameters.end()){
166 path = m->hasPath(it->second);
167 //if the user has not given a path then, add inputdir. else leave path alone.
168 if (path == "") { parameters["report"] = inputDir + it->second; }
172 //check for required parameters
173 queryFileName = validParameter.validFile(parameters, "fasta", true);
174 if (queryFileName == "not found") {
175 queryFileName = m->getFastaFile();
176 if (queryFileName != "") { m->mothurOut("Using " + queryFileName + " as input file for the fasta parameter."); m->mothurOutEndLine(); }
177 else { m->mothurOut("You have no current fasta file and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; }
179 else if (queryFileName == "not open") { abort = true; }
180 else { m->setFastaFile(queryFileName); }
182 referenceFileName = validParameter.validFile(parameters, "reference", true);
183 if (referenceFileName == "not found") { m->mothurOut("reference is a required parameter for the seq.error command."); m->mothurOutEndLine(); abort = true; }
184 else if (referenceFileName == "not open") { abort = true; }
186 //check for optional parameters
187 namesFileName = validParameter.validFile(parameters, "name", true);
188 if(namesFileName == "not found"){ namesFileName = ""; }
189 else if (namesFileName == "not open") { namesFileName = ""; abort = true; }
190 else { m->setNameFile(namesFileName); }
192 qualFileName = validParameter.validFile(parameters, "qfile", true);
193 if(qualFileName == "not found"){ qualFileName = ""; }
194 else if (qualFileName == "not open") { qualFileName = ""; abort = true; }
195 else { m->setQualFile(qualFileName); }
197 reportFileName = validParameter.validFile(parameters, "report", true);
198 if(reportFileName == "not found"){ reportFileName = ""; }
199 else if (reportFileName == "not open") { reportFileName = ""; abort = true; }
201 if((reportFileName != "" && qualFileName == "") || (reportFileName == "" && qualFileName != "")){
202 m->mothurOut("if you use either a qual file or a report file, you have to have both.");
203 m->mothurOutEndLine();
207 outputDir = validParameter.validFile(parameters, "outputdir", false);
208 if (outputDir == "not found"){
210 outputDir += m->hasPath(queryFileName); //if user entered a file with a path then preserve it
213 //check for optional parameter and set defaults
214 // ...at some point should added some additional type checking...
215 temp = validParameter.validFile(parameters, "threshold", false); if (temp == "not found") { temp = "1.00"; }
216 m->mothurConvert(temp, threshold);
218 temp = validParameter.validFile(parameters, "save", false); if (temp == "not found"){ temp = "f"; }
219 save = m->isTrue(temp);
221 if (save) { //clear out old references
225 //this has to go after save so that if the user sets save=t and provides no reference we abort
226 referenceFileName = validParameter.validFile(parameters, "reference", true);
227 if (referenceFileName == "not found") {
228 //check for saved reference sequences
229 if (rdb->referenceSeqs.size() != 0) {
230 referenceFileName = "saved";
232 m->mothurOut("[ERROR]: You don't have any saved reference sequences and the reference parameter is a required.");
233 m->mothurOutEndLine();
236 }else if (referenceFileName == "not open") { abort = true; }
237 else { if (save) { rdb->setSavedReference(referenceFileName); } }
240 temp = validParameter.validFile(parameters, "ignorechimeras", false); if (temp == "not found") { temp = "T"; }
241 ignoreChimeras = m->isTrue(temp);
243 temp = validParameter.validFile(parameters, "processors", false); if (temp == "not found"){ temp = m->getProcessors(); }
244 m->setProcessors(temp);
245 m->mothurConvert(temp, processors);
247 substitutionMatrix.resize(6);
248 for(int i=0;i<6;i++){ substitutionMatrix[i].resize(6,0); }
251 catch(exception& e) {
252 m->errorOut(e, "SeqErrorCommand", "SeqErrorCommand");
256 //***************************************************************************************************************
258 int SeqErrorCommand::execute(){
260 if (abort == true) { if (calledHelp) { return 0; } return 2; }
262 int start = time(NULL);
267 string errorSummaryFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.summary";
268 outputNames.push_back(errorSummaryFileName); outputTypes["error.summary"].push_back(errorSummaryFileName);
270 string errorSeqFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.seq";
271 outputNames.push_back(errorSeqFileName); outputTypes["error.seq"].push_back(errorSeqFileName);
273 string errorChimeraFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.chimera";
274 outputNames.push_back(errorChimeraFileName); outputTypes["error.chimera"].push_back(errorChimeraFileName);
276 getReferences(); //read in reference sequences - make sure there's no ambiguous bases
278 if(namesFileName != ""){ weights = getWeights(); }
280 vector<unsigned long long> fastaFilePos;
281 vector<unsigned long long> qFilePos;
282 vector<unsigned long long> reportFilePos;
284 setLines(queryFileName, qualFileName, reportFileName, fastaFilePos, qFilePos, reportFilePos);
286 if (m->control_pressed) { return 0; }
288 for (int i = 0; i < (fastaFilePos.size()-1); i++) {
289 lines.push_back(linePair(fastaFilePos[i], fastaFilePos[(i+1)]));
290 if (qualFileName != "") { qLines.push_back(linePair(qFilePos[i], qFilePos[(i+1)])); }
291 if (reportFileName != "") { rLines.push_back(linePair(reportFilePos[i], reportFilePos[(i+1)])); }
293 if(qualFileName == "") { qLines = lines; rLines = lines; } //fills with duds
296 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
298 numSeqs = driver(queryFileName, qualFileName, reportFileName, errorSummaryFileName, errorSeqFileName, errorChimeraFileName, lines[0], qLines[0], rLines[0]);
300 numSeqs = createProcesses(queryFileName, qualFileName, reportFileName, errorSummaryFileName, errorSeqFileName, errorChimeraFileName);
303 numSeqs = driver(queryFileName, qualFileName, reportFileName, errorSummaryFileName, errorSeqFileName, errorChimeraFileName, lines[0], qLines[0], rLines[0]);
306 if(qualFileName != "" && reportFileName != ""){
307 printErrorQuality(qScoreErrorMap);
308 printQualityFR(qualForwardMap, qualReverseMap);
311 printErrorFRFile(errorForward, errorReverse);
313 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
315 string errorCountFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.count";
316 ofstream errorCountFile;
317 m->openOutputFile(errorCountFileName, errorCountFile);
318 outputNames.push_back(errorCountFileName); outputTypes["error.count"].push_back(errorCountFileName);
319 m->mothurOut("Overall error rate:\t" + toString((double)(totalBases - totalMatches) / (double)totalBases) + "\n");
320 m->mothurOut("Errors\tSequences\n");
321 errorCountFile << "Errors\tSequences\n";
322 for(int i=0;i<misMatchCounts.size();i++){
323 m->mothurOut(toString(i) + '\t' + toString(misMatchCounts[i]) + '\n');
324 errorCountFile << i << '\t' << misMatchCounts[i] << endl;
326 errorCountFile.close();
328 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } return 0; }
332 string megAlignmentFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.ref-query";
333 ofstream megAlignmentFile;
334 m->openOutputFile(megAlignmentFileName, megAlignmentFile);
335 outputNames.push_back(megAlignmentFileName); outputTypes["error.ref-query"].push_back(megAlignmentFileName);
337 for(int i=0;i<numRefs;i++){
338 megAlignmentFile << referenceSeqs[i].getInlineSeq() << endl;
339 megAlignmentFile << megaAlignVector[i] << endl;
342 m->mothurOut("It took " + toString(time(NULL) - start) + " secs to check " + toString(numSeqs) + " sequences.");
343 m->mothurOutEndLine();
345 m->mothurOutEndLine();
346 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
347 for (int i = 0; i < outputNames.size(); i++) { m->mothurOut(outputNames[i]); m->mothurOutEndLine(); }
348 m->mothurOutEndLine();
352 catch(exception& e) {
353 m->errorOut(e, "SeqErrorCommand", "execute");
357 //**********************************************************************************************************************
358 int SeqErrorCommand::createProcesses(string filename, string qFileName, string rFileName, string summaryFileName, string errorOutputFileName, string chimeraOutputFileName) {
362 map<char, vector<int> >::iterator it;
364 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
366 //loop through and create all the processes you want
367 while (process != processors) {
371 processIDS.push_back(pid); //create map from line number to pid so you can append files in correct order later
375 num = driver(filename, qFileName, rFileName, summaryFileName + toString(getpid()) + ".temp", errorOutputFileName+ toString(getpid()) + ".temp", chimeraOutputFileName + toString(getpid()) + ".temp", lines[process], qLines[process], rLines[process]);
377 //pass groupCounts to parent
379 string tempFile = filename + toString(getpid()) + ".info.temp";
380 m->openOutputFile(tempFile, out);
382 //output totalBases and totalMatches
383 out << num << '\t' << totalBases << '\t' << totalMatches << endl << endl;
385 //output substitutionMatrix
386 for(int i = 0; i < substitutionMatrix.size(); i++) {
387 for (int j = 0; j < substitutionMatrix[i].size(); j++) {
388 out << substitutionMatrix[i][j] << '\t';
394 //output qScoreErrorMap
395 for (it = qScoreErrorMap.begin(); it != qScoreErrorMap.end(); it++) {
396 vector<int> thisScoreErrorMap = it->second;
397 out << it->first << '\t';
398 for (int i = 0; i < thisScoreErrorMap.size(); i++) {
399 out << thisScoreErrorMap[i] << '\t';
405 //output qualForwardMap
406 for(int i = 0; i < qualForwardMap.size(); i++) {
407 for (int j = 0; j < qualForwardMap[i].size(); j++) {
408 out << qualForwardMap[i][j] << '\t';
414 //output qualReverseMap
415 for(int i = 0; i < qualReverseMap.size(); i++) {
416 for (int j = 0; j < qualReverseMap[i].size(); j++) {
417 out << qualReverseMap[i][j] << '\t';
424 //output errorForward
425 for (it = errorForward.begin(); it != errorForward.end(); it++) {
426 vector<int> thisErrorForward = it->second;
427 out << it->first << '\t';
428 for (int i = 0; i < thisErrorForward.size(); i++) {
429 out << thisErrorForward[i] << '\t';
435 //output errorReverse
436 for (it = errorReverse.begin(); it != errorReverse.end(); it++) {
437 vector<int> thisErrorReverse = it->second;
438 out << it->first << '\t';
439 for (int i = 0; i < thisErrorReverse.size(); i++) {
440 out << thisErrorReverse[i] << '\t';
446 //output misMatchCounts
447 out << misMatchCounts.size() << endl;
448 for (int j = 0; j < misMatchCounts.size(); j++) {
449 out << misMatchCounts[j] << '\t';
454 //output megaAlignVector
455 for (int j = 0; j < megaAlignVector.size(); j++) {
456 out << megaAlignVector[j] << endl;
464 m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine();
465 for (int i = 0; i < processIDS.size(); i++) { kill (processIDS[i], SIGINT); }
471 num = driver(filename, qFileName, rFileName, summaryFileName, errorOutputFileName, chimeraOutputFileName, lines[0], qLines[0], rLines[0]);
473 //force parent to wait until all the processes are done
474 for (int i=0;i<processIDS.size();i++) {
475 int temp = processIDS[i];
480 for(int i=0;i<processIDS.size();i++){
482 m->mothurOut("Appending files from process " + toString(processIDS[i])); m->mothurOutEndLine();
484 m->appendFiles((summaryFileName + toString(processIDS[i]) + ".temp"), summaryFileName);
485 m->mothurRemove((summaryFileName + toString(processIDS[i]) + ".temp"));
486 m->appendFiles((errorOutputFileName + toString(processIDS[i]) + ".temp"), errorOutputFileName);
487 m->mothurRemove((errorOutputFileName + toString(processIDS[i]) + ".temp"));
488 m->appendFiles((chimeraOutputFileName + toString(processIDS[i]) + ".temp"), chimeraOutputFileName);
489 m->mothurRemove((chimeraOutputFileName + toString(processIDS[i]) + ".temp"));
492 string tempFile = filename + toString(processIDS[i]) + ".info.temp";
493 m->openInputFile(tempFile, in);
495 //input totalBases and totalMatches
496 int tempBases, tempMatches, tempNumSeqs;
497 in >> tempNumSeqs >> tempBases >> tempMatches; m->gobble(in);
498 totalBases += tempBases; totalMatches += tempMatches; num += tempNumSeqs;
500 //input substitutionMatrix
502 for(int i = 0; i < substitutionMatrix.size(); i++) {
503 for (int j = 0; j < substitutionMatrix[i].size(); j++) {
504 in >> tempNum; substitutionMatrix[i][j] += tempNum;
510 //input qScoreErrorMap
512 for (int i = 0; i < qScoreErrorMap.size(); i++) {
514 vector<int> thisScoreErrorMap = qScoreErrorMap[first];
516 for (int i = 0; i < thisScoreErrorMap.size(); i++) {
517 in >> tempNum; thisScoreErrorMap[i] += tempNum;
519 qScoreErrorMap[first] = thisScoreErrorMap;
524 //input qualForwardMap
525 for(int i = 0; i < qualForwardMap.size(); i++) {
526 for (int j = 0; j < qualForwardMap[i].size(); j++) {
527 in >> tempNum; qualForwardMap[i][j] += tempNum;
533 //input qualReverseMap
534 for(int i = 0; i < qualReverseMap.size(); i++) {
535 for (int j = 0; j < qualReverseMap[i].size(); j++) {
536 in >> tempNum; qualReverseMap[i][j] += tempNum;
543 for (int i = 0; i < errorForward.size(); i++) {
545 vector<int> thisErrorForward = errorForward[first];
547 for (int i = 0; i < thisErrorForward.size(); i++) {
548 in >> tempNum; thisErrorForward[i] += tempNum;
550 errorForward[first] = thisErrorForward;
556 for (int i = 0; i < errorReverse.size(); i++) {
558 vector<int> thisErrorReverse = errorReverse[first];
560 for (int i = 0; i < thisErrorReverse.size(); i++) {
561 in >> tempNum; thisErrorReverse[i] += tempNum;
563 errorReverse[first] = thisErrorReverse;
568 //input misMatchCounts
570 in >> misMatchSize; m->gobble(in);
571 if (misMatchSize > misMatchCounts.size()) { misMatchCounts.resize(misMatchSize, 0); }
572 for (int j = 0; j < misMatchCounts.size(); j++) {
573 in >> tempNum; misMatchCounts[j] += tempNum;
577 //input megaAlignVector
579 for (int j = 0; j < megaAlignVector.size(); j++) {
580 thisLine = m->getline(in); m->gobble(in); megaAlignVector[j] += thisLine + '\n';
584 in.close(); m->mothurRemove(tempFile);
590 catch(exception& e) {
591 m->errorOut(e, "SeqErrorCommand", "createProcesses");
595 //**********************************************************************************************************************
596 int SeqErrorCommand::driver(string filename, string qFileName, string rFileName, string summaryFileName, string errorOutputFileName, string chimeraOutputFileName, linePair line, linePair qline, linePair rline) {
600 QualityScores quality;
602 misMatchCounts.resize(11, 0);
606 map<string, int>::iterator it;
607 qScoreErrorMap['m'].assign(41, 0);
608 qScoreErrorMap['s'].assign(41, 0);
609 qScoreErrorMap['i'].assign(41, 0);
610 qScoreErrorMap['a'].assign(41, 0);
612 errorForward['m'].assign(maxLength,0);
613 errorForward['s'].assign(maxLength,0);
614 errorForward['i'].assign(maxLength,0);
615 errorForward['d'].assign(maxLength,0);
616 errorForward['a'].assign(maxLength,0);
618 errorReverse['m'].assign(maxLength,0);
619 errorReverse['s'].assign(maxLength,0);
620 errorReverse['i'].assign(maxLength,0);
621 errorReverse['d'].assign(maxLength,0);
622 errorReverse['a'].assign(maxLength,0);
624 //open inputfiles and go to beginning place for this processor
626 m->openInputFile(filename, queryFile);
627 queryFile.seekg(line.start);
631 if(qFileName != "" && rFileName != ""){
632 m->openInputFile(qFileName, qualFile);
633 qualFile.seekg(qline.start);
636 if (rline.start == 0) { report = ReportFile(reportFile, rFileName); }
638 m->openInputFile(rFileName, reportFile);
639 reportFile.seekg(rline.start);
642 qualForwardMap.resize(maxLength);
643 qualReverseMap.resize(maxLength);
644 for(int i=0;i<maxLength;i++){
645 qualForwardMap[i].assign(41,0);
646 qualReverseMap[i].assign(41,0);
650 ofstream outChimeraReport;
651 m->openOutputFile(chimeraOutputFileName, outChimeraReport);
652 RefChimeraTest chimeraTest(referenceSeqs);
653 if (line.start == 0) { chimeraTest.printHeader(outChimeraReport); }
655 ofstream errorSummaryFile;
656 m->openOutputFile(summaryFileName, errorSummaryFile);
657 if (line.start == 0) { printErrorHeader(errorSummaryFile); }
659 ofstream errorSeqFile;
660 m->openOutputFile(errorOutputFileName, errorSeqFile);
662 megaAlignVector.resize(numRefs, "");
670 if (m->control_pressed) { queryFile.close(); if(qFileName != "" && rFileName != ""){ reportFile.close(); qualFile.close(); } outChimeraReport.close(); errorSummaryFile.close();errorSeqFile.close(); return 0; }
672 Sequence query(queryFile);
674 int numParentSeqs = chimeraTest.analyzeQuery(query.getName(), query.getAligned(), outChimeraReport);
675 int closestRefIndex = chimeraTest.getClosestRefIndex();
677 if(numParentSeqs > 1 && ignoreChimeras == 1) { ignoreSeq = 1; }
678 else { ignoreSeq = 0; }
680 Compare minCompare = getErrors(query, referenceSeqs[closestRefIndex]);
682 if(namesFileName != ""){
683 it = weights.find(query.getName());
684 minCompare.weight = it->second;
686 else{ minCompare.weight = 1; }
688 printErrorData(minCompare, numParentSeqs, errorSummaryFile, errorSeqFile);
692 for(int i=0;i<minCompare.sequence.length();i++){
693 char letter = minCompare.sequence[i];
696 errorForward[letter][i] += minCompare.weight;
697 errorReverse[letter][minCompare.total-i-1] += minCompare.weight;
702 if(qualFileName != "" && reportFileName != ""){
703 report = ReportFile(reportFile);
705 // int origLength = report.getQueryLength();
706 int startBase = report.getQueryStart();
707 int endBase = report.getQueryEnd();
709 quality = QualityScores(qualFile);
712 // cout << query.getName() << '\t';
714 quality.updateQScoreErrorMap(qScoreErrorMap, minCompare.sequence, startBase, endBase, minCompare.weight);
715 quality.updateForwardMap(qualForwardMap, startBase, endBase, minCompare.weight);
716 quality.updateReverseMap(qualReverseMap, startBase, endBase, minCompare.weight);
722 if(minCompare.errorRate < threshold && !ignoreSeq){
723 totalBases += (minCompare.total * minCompare.weight);
724 totalMatches += minCompare.matches * minCompare.weight;
725 if(minCompare.mismatches > maxMismatch){
726 maxMismatch = minCompare.mismatches;
727 misMatchCounts.resize(maxMismatch + 1, 0);
729 misMatchCounts[minCompare.mismatches] += minCompare.weight;
732 megaAlignVector[closestRefIndex] += query.getInlineSeq() + '\n';
737 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
738 unsigned long long pos = queryFile.tellg();
739 if ((pos == -1) || (pos >= line.end)) { break; }
741 if (queryFile.eof()) { break; }
744 if(index % 100 == 0){ m->mothurOut(toString(index) + '\n'); }
747 if(qFileName != "" && rFileName != ""){ reportFile.close(); qualFile.close(); }
748 errorSummaryFile.close();
749 errorSeqFile.close();
752 if(index % 100 != 0){ m->mothurOut(toString(index) + '\n'); }
756 catch(exception& e) {
757 m->errorOut(e, "SeqErrorCommand", "driver");
761 //***************************************************************************************************************
763 void SeqErrorCommand::getReferences(){
765 int numAmbigSeqs = 0;
768 int minEndPos = 100000;
770 if (referenceFileName == "saved") {
771 int start = time(NULL);
772 m->mothurOutEndLine(); m->mothurOut("Using sequences from " + rdb->getSavedReference() + " that are saved in memory."); m->mothurOutEndLine();
774 for (int i = 0; i < rdb->referenceSeqs.size(); i++) {
775 int numAmbigs = rdb->referenceSeqs[i].getAmbigBases();
776 if(numAmbigs > 0){ numAmbigSeqs++; }
778 // int startPos = rdb->referenceSeqs[i].getStartPos();
779 // if(startPos > maxStartPos) { maxStartPos = startPos; }
781 // int endPos = rdb->referenceSeqs[i].getEndPos();
782 // if(endPos < minEndPos) { minEndPos = endPos; }
784 referenceSeqs.push_back(rdb->referenceSeqs[i]);
786 referenceFileName = rdb->getSavedReference();
788 m->mothurOut("It took " + toString(time(NULL) - start) + " to load " + toString(rdb->referenceSeqs.size()) + " sequences.");m->mothurOutEndLine();
791 int start = time(NULL);
793 ifstream referenceFile;
794 m->openInputFile(referenceFileName, referenceFile);
796 while(referenceFile){
797 Sequence currentSeq(referenceFile);
798 int numAmbigs = currentSeq.getAmbigBases();
799 if(numAmbigs > 0){ numAmbigSeqs++; }
801 // int startPos = currentSeq.getStartPos();
802 // if(startPos > maxStartPos) { maxStartPos = startPos; }
804 // int endPos = currentSeq.getEndPos();
805 // if(endPos < minEndPos) { minEndPos = endPos; }
806 referenceSeqs.push_back(currentSeq);
808 if (rdb->save) { rdb->referenceSeqs.push_back(currentSeq); }
810 m->gobble(referenceFile);
812 referenceFile.close();
814 m->mothurOut("It took " + toString(time(NULL) - start) + " to read " + toString(referenceSeqs.size()) + " sequences.");m->mothurOutEndLine();
817 numRefs = referenceSeqs.size();
819 for(int i=0;i<numRefs;i++){
820 referenceSeqs[i].padToPos(maxStartPos);
821 referenceSeqs[i].padFromPos(minEndPos);
824 if(numAmbigSeqs != 0){
825 m->mothurOut("Warning: " + toString(numAmbigSeqs) + " reference sequences have ambiguous bases, these bases will be ignored\n");
829 catch(exception& e) {
830 m->errorOut(e, "SeqErrorCommand", "getReferences");
835 //***************************************************************************************************************
837 Compare SeqErrorCommand::getErrors(Sequence query, Sequence reference){
839 if(query.getAlignLength() != reference.getAlignLength()){
840 m->mothurOut("Warning: " + toString(query.getName()) + " and " + toString(reference.getName()) + " are different lengths\n");
842 int alignLength = query.getAlignLength();
844 string q = query.getAligned();
845 string r = reference.getAligned();
850 for(int i=0;i<alignLength;i++){
851 // cout << r[i] << '\t' << q[i] << '\t';
852 if(q[i] != '.' && r[i] != '.' && (q[i] != '-' || r[i] != '-')){ // no missing data and no double gaps
857 if(r[i] == 'A'){ errors.AA++; errors.matches++; errors.sequence += 'm'; }
858 if(r[i] == 'T'){ errors.AT++; errors.sequence += 's'; }
859 if(r[i] == 'G'){ errors.AG++; errors.sequence += 's'; }
860 if(r[i] == 'C'){ errors.AC++; errors.sequence += 's'; }
861 if(r[i] == '-'){ errors.Ai++; errors.sequence += 'i'; }
863 else if(q[i] == 'T'){
864 if(r[i] == 'A'){ errors.TA++; errors.sequence += 's'; }
865 if(r[i] == 'T'){ errors.TT++; errors.matches++; errors.sequence += 'm'; }
866 if(r[i] == 'G'){ errors.TG++; errors.sequence += 's'; }
867 if(r[i] == 'C'){ errors.TC++; errors.sequence += 's'; }
868 if(r[i] == '-'){ errors.Ti++; errors.sequence += 'i'; }
870 else if(q[i] == 'G'){
871 if(r[i] == 'A'){ errors.GA++; errors.sequence += 's'; }
872 if(r[i] == 'T'){ errors.GT++; errors.sequence += 's'; }
873 if(r[i] == 'G'){ errors.GG++; errors.matches++; errors.sequence += 'm'; }
874 if(r[i] == 'C'){ errors.GC++; errors.sequence += 's'; }
875 if(r[i] == '-'){ errors.Gi++; errors.sequence += 'i'; }
877 else if(q[i] == 'C'){
878 if(r[i] == 'A'){ errors.CA++; errors.sequence += 's'; }
879 if(r[i] == 'T'){ errors.CT++; errors.sequence += 's'; }
880 if(r[i] == 'G'){ errors.CG++; errors.sequence += 's'; }
881 if(r[i] == 'C'){ errors.CC++; errors.matches++; errors.sequence += 'm'; }
882 if(r[i] == '-'){ errors.Ci++; errors.sequence += 'i'; }
884 else if(q[i] == 'N'){
885 if(r[i] == 'A'){ errors.NA++; errors.sequence += 'a'; }
886 if(r[i] == 'T'){ errors.NT++; errors.sequence += 'a'; }
887 if(r[i] == 'G'){ errors.NG++; errors.sequence += 'a'; }
888 if(r[i] == 'C'){ errors.NC++; errors.sequence += 'a'; }
889 if(r[i] == '-'){ errors.Ni++; errors.sequence += 'a'; }
891 else if(q[i] == '-' && r[i] != '-'){
892 if(r[i] == 'A'){ errors.dA++; errors.sequence += 'd'; }
893 if(r[i] == 'T'){ errors.dT++; errors.sequence += 'd'; }
894 if(r[i] == 'G'){ errors.dG++; errors.sequence += 'd'; }
895 if(r[i] == 'C'){ errors.dC++; errors.sequence += 'd'; }
902 errors.sequence += 'd'; errors.total++;
905 errors.sequence += 'r';
910 else if(q[i] == '.' && r[i] != '.'){ // reference extends beyond query
911 if(started == 1){ break; }
913 else if(q[i] != '.' && r[i] == '.'){ // query extends beyond reference
914 if(started == 1){ break; }
916 else if(q[i] == '.' && r[i] == '.'){ // both are missing data
917 if(started == 1){ break; }
919 // cout << errors.sequence[errors.sequence.length()-1] << endl;
921 // cout << errors.sequence << endl;
922 errors.mismatches = errors.total-errors.matches;
923 errors.errorRate = (double)(errors.total-errors.matches) / (double)errors.total;
924 errors.queryName = query.getName();
925 errors.refName = reference.getName();
929 catch(exception& e) {
930 m->errorOut(e, "SeqErrorCommand", "getErrors");
935 //***************************************************************************************************************
937 map<string, int> SeqErrorCommand::getWeights(){
939 m->openInputFile(namesFileName, nameFile);
942 string redundantSeqs;
943 map<string, int> nameCountMap;
946 nameFile >> seqName >> redundantSeqs;
947 nameCountMap[seqName] = m->getNumNames(redundantSeqs);
954 //***************************************************************************************************************
956 void SeqErrorCommand::printErrorHeader(ofstream& errorSummaryFile){
958 errorSummaryFile << "query\treference\tweight\t";
959 errorSummaryFile << "AA\tAT\tAG\tAC\tTA\tTT\tTG\tTC\tGA\tGT\tGG\tGC\tCA\tCT\tCG\tCC\tNA\tNT\tNG\tNC\tAi\tTi\tGi\tCi\tNi\tdA\tdT\tdG\tdC\t";
960 errorSummaryFile << "insertions\tdeletions\tsubstitutions\tambig\tmatches\tmismatches\ttotal\terror\tnumparents\n";
962 errorSummaryFile << setprecision(6);
963 errorSummaryFile.setf(ios::fixed);
965 catch(exception& e) {
966 m->errorOut(e, "SeqErrorCommand", "printErrorHeader");
971 //***************************************************************************************************************
973 void SeqErrorCommand::printErrorData(Compare error, int numParentSeqs, ofstream& errorSummaryFile, ofstream& errorSeqFile){
976 errorSummaryFile << error.queryName << '\t' << error.refName << '\t' << error.weight << '\t';
977 errorSummaryFile << error.AA << '\t' << error.AT << '\t' << error.AG << '\t' << error.AC << '\t';
978 errorSummaryFile << error.TA << '\t' << error.TT << '\t' << error.TG << '\t' << error.TC << '\t';
979 errorSummaryFile << error.GA << '\t' << error.GT << '\t' << error.GG << '\t' << error.GC << '\t';
980 errorSummaryFile << error.CA << '\t' << error.CT << '\t' << error.CG << '\t' << error.CC << '\t';
981 errorSummaryFile << error.NA << '\t' << error.NT << '\t' << error.NG << '\t' << error.NC << '\t';
982 errorSummaryFile << error.Ai << '\t' << error.Ti << '\t' << error.Gi << '\t' << error.Ci << '\t' << error.Ni << '\t';
983 errorSummaryFile << error.dA << '\t' << error.dT << '\t' << error.dG << '\t' << error.dC << '\t';
985 errorSummaryFile << error.Ai + error.Ti + error.Gi + error.Ci << '\t'; //insertions
986 errorSummaryFile << error.dA + error.dT + error.dG + error.dC << '\t'; //deletions
987 errorSummaryFile << error.mismatches - (error.Ai + error.Ti + error.Gi + error.Ci) - (error.dA + error.dT + error.dG + error.dC) - (error.NA + error.NT + error.NG + error.NC + error.Ni) << '\t'; //substitutions
988 errorSummaryFile << error.NA + error.NT + error.NG + error.NC + error.Ni << '\t'; //ambiguities
989 errorSummaryFile << error.matches << '\t' << error.mismatches << '\t' << error.total << '\t' << error.errorRate << '\t' << numParentSeqs << endl;
991 errorSeqFile << '>' << error.queryName << "\tref:" << error.refName << '\n' << error.sequence << endl;
993 int a=0; int t=1; int g=2; int c=3;
996 if(numParentSeqs == 1 || ignoreChimeras == 0){
997 substitutionMatrix[a][a] += error.weight * error.AA;
998 substitutionMatrix[a][t] += error.weight * error.TA;
999 substitutionMatrix[a][g] += error.weight * error.GA;
1000 substitutionMatrix[a][c] += error.weight * error.CA;
1001 substitutionMatrix[a][gap] += error.weight * error.dA;
1002 substitutionMatrix[a][n] += error.weight * error.NA;
1004 substitutionMatrix[t][a] += error.weight * error.AT;
1005 substitutionMatrix[t][t] += error.weight * error.TT;
1006 substitutionMatrix[t][g] += error.weight * error.GT;
1007 substitutionMatrix[t][c] += error.weight * error.CT;
1008 substitutionMatrix[t][gap] += error.weight * error.dT;
1009 substitutionMatrix[t][n] += error.weight * error.NT;
1011 substitutionMatrix[g][a] += error.weight * error.AG;
1012 substitutionMatrix[g][t] += error.weight * error.TG;
1013 substitutionMatrix[g][g] += error.weight * error.GG;
1014 substitutionMatrix[g][c] += error.weight * error.CG;
1015 substitutionMatrix[g][gap] += error.weight * error.dG;
1016 substitutionMatrix[g][n] += error.weight * error.NG;
1018 substitutionMatrix[c][a] += error.weight * error.AC;
1019 substitutionMatrix[c][t] += error.weight * error.TC;
1020 substitutionMatrix[c][g] += error.weight * error.GC;
1021 substitutionMatrix[c][c] += error.weight * error.CC;
1022 substitutionMatrix[c][gap] += error.weight * error.dC;
1023 substitutionMatrix[c][n] += error.weight * error.NC;
1025 substitutionMatrix[gap][a] += error.weight * error.Ai;
1026 substitutionMatrix[gap][t] += error.weight * error.Ti;
1027 substitutionMatrix[gap][g] += error.weight * error.Gi;
1028 substitutionMatrix[gap][c] += error.weight * error.Ci;
1029 substitutionMatrix[gap][n] += error.weight * error.Ni;
1032 catch(exception& e) {
1033 m->errorOut(e, "SeqErrorCommand", "printErrorData");
1038 //***************************************************************************************************************
1040 void SeqErrorCommand::printSubMatrix(){
1042 string subMatrixFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.matrix";
1043 ofstream subMatrixFile;
1044 m->openOutputFile(subMatrixFileName, subMatrixFile);
1045 outputNames.push_back(subMatrixFileName); outputTypes["error.matrix"].push_back(subMatrixFileName);
1046 vector<string> bases(6);
1053 vector<int> refSums(5,1);
1055 for(int i=0;i<5;i++){
1056 subMatrixFile << "\tr" << bases[i];
1058 for(int j=0;j<6;j++){
1059 refSums[i] += substitutionMatrix[i][j];
1062 subMatrixFile << endl;
1064 for(int i=0;i<6;i++){
1065 subMatrixFile << 'q' << bases[i];
1066 for(int j=0;j<5;j++){
1067 subMatrixFile << '\t' << substitutionMatrix[j][i];
1069 subMatrixFile << endl;
1072 subMatrixFile << "total";
1073 for(int i=0;i<5;i++){
1074 subMatrixFile << '\t' << refSums[i];
1076 subMatrixFile << endl;
1077 subMatrixFile.close();
1079 catch(exception& e) {
1080 m->errorOut(e, "SeqErrorCommand", "printSubMatrix");
1084 //***************************************************************************************************************
1086 void SeqErrorCommand::printErrorFRFile(map<char, vector<int> > errorForward, map<char, vector<int> > errorReverse){
1088 string errorForwardFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.seq.forward";
1089 ofstream errorForwardFile;
1090 m->openOutputFile(errorForwardFileName, errorForwardFile);
1091 outputNames.push_back(errorForwardFileName); outputTypes["error.forward"].push_back(errorForwardFileName);
1093 errorForwardFile << "position\ttotalseqs\tmatch\tsubstitution\tinsertion\tdeletion\tambiguous" << endl;
1094 for(int i=0;i<maxLength;i++){
1095 float match = (float)errorForward['m'][i];
1096 float subst = (float)errorForward['s'][i];
1097 float insert = (float)errorForward['i'][i];
1098 float del = (float)errorForward['d'][i];
1099 float amb = (float)errorForward['a'][i];
1100 float total = match + subst + insert + del + amb;
1101 if(total == 0){ break; }
1102 errorForwardFile << i+1 << '\t' << total << '\t' << match/total << '\t' << subst/total << '\t' << insert/total << '\t' << del/total << '\t' << amb/total << endl;
1104 errorForwardFile.close();
1106 string errorReverseFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.seq.reverse";
1107 ofstream errorReverseFile;
1108 m->openOutputFile(errorReverseFileName, errorReverseFile);
1109 outputNames.push_back(errorReverseFileName); outputTypes["error.reverse"].push_back(errorReverseFileName);
1111 errorReverseFile << "position\ttotalseqs\tmatch\tsubstitution\tinsertion\tdeletion\tambiguous" << endl;
1112 for(int i=0;i<maxLength;i++){
1113 float match = (float)errorReverse['m'][i];
1114 float subst = (float)errorReverse['s'][i];
1115 float insert = (float)errorReverse['i'][i];
1116 float del = (float)errorReverse['d'][i];
1117 float amb = (float)errorReverse['a'][i];
1118 float total = match + subst + insert + del + amb;
1119 if(total == 0){ break; }
1120 errorReverseFile << i+1 << '\t' << total << '\t' << match/total << '\t' << subst/total << '\t' << insert/total << '\t' << del/total << '\t' << amb/total << endl;
1122 errorReverseFile.close();
1124 catch(exception& e) {
1125 m->errorOut(e, "SeqErrorCommand", "printErrorFRFile");
1130 //***************************************************************************************************************
1132 void SeqErrorCommand::printErrorQuality(map<char, vector<int> > qScoreErrorMap){
1135 string errorQualityFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.quality";
1136 ofstream errorQualityFile;
1137 m->openOutputFile(errorQualityFileName, errorQualityFile);
1138 outputNames.push_back(errorQualityFileName); outputTypes["error.quality"].push_back(errorQualityFileName);
1140 errorQualityFile << "qscore\tmatches\tsubstitutions\tinsertions\tambiguous" << endl;
1141 for(int i=0;i<41;i++){
1142 errorQualityFile << i << '\t' << qScoreErrorMap['m'][i] << '\t' << qScoreErrorMap['s'][i] << '\t' << qScoreErrorMap['i'][i] << '\t'<< qScoreErrorMap['a'][i] << endl;
1144 errorQualityFile.close();
1146 catch(exception& e) {
1147 m->errorOut(e, "SeqErrorCommand", "printErrorFRFile");
1153 //***************************************************************************************************************
1155 void SeqErrorCommand::printQualityFR(vector<vector<int> > qualForwardMap, vector<vector<int> > qualReverseMap){
1159 int numColumns = qualForwardMap[0].size();
1161 for(int i=0;i<qualForwardMap.size();i++){
1162 for(int j=0;j<numColumns;j++){
1163 if(qualForwardMap[i][j] != 0){
1164 if(numRows < i) { numRows = i+20; }
1169 string qualityForwardFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.qual.forward";
1170 ofstream qualityForwardFile;
1171 m->openOutputFile(qualityForwardFileName, qualityForwardFile);
1172 outputNames.push_back(qualityForwardFileName); outputTypes["error.qual.forward"].push_back(qualityForwardFileName);
1174 for(int i=0;i<numColumns;i++){ qualityForwardFile << '\t' << i; } qualityForwardFile << endl;
1176 for(int i=0;i<numRows;i++){
1177 qualityForwardFile << i+1;
1178 for(int j=0;j<numColumns;j++){
1179 qualityForwardFile << '\t' << qualForwardMap[i][j];
1182 qualityForwardFile << endl;
1184 qualityForwardFile.close();
1187 string qualityReverseFileName = queryFileName.substr(0,queryFileName.find_last_of('.')) + ".error.qual.reverse";
1188 ofstream qualityReverseFile;
1189 m->openOutputFile(qualityReverseFileName, qualityReverseFile);
1190 outputNames.push_back(qualityReverseFileName); outputTypes["error.qual.reverse"].push_back(qualityReverseFileName);
1192 for(int i=0;i<numColumns;i++){ qualityReverseFile << '\t' << i; } qualityReverseFile << endl;
1193 for(int i=0;i<numRows;i++){
1195 qualityReverseFile << i+1;
1196 for(int j=0;j<numColumns;j++){
1197 qualityReverseFile << '\t' << qualReverseMap[i][j];
1199 qualityReverseFile << endl;
1201 qualityReverseFile.close();
1203 catch(exception& e) {
1204 m->errorOut(e, "SeqErrorCommand", "printErrorFRFile");
1209 /**************************************************************************************************/
1211 int SeqErrorCommand::setLines(string filename, string qfilename, string rfilename, vector<unsigned long long>& fastaFilePos, vector<unsigned long long>& qfileFilePos, vector<unsigned long long>& rfileFilePos) {
1213 #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
1214 //set file positions for fasta file
1215 fastaFilePos = m->divideFile(filename, processors);
1217 if (qfilename == "") { return processors; }
1219 //get name of first sequence in each chunk
1220 map<string, int> firstSeqNames;
1221 for (int i = 0; i < (fastaFilePos.size()-1); i++) {
1223 m->openInputFile(filename, in);
1224 in.seekg(fastaFilePos[i]);
1227 firstSeqNames[temp.getName()] = i;
1232 //make copy to use below
1233 map<string, int> firstSeqNamesReport = firstSeqNames;
1235 //seach for filePos of each first name in the qfile and save in qfileFilePos
1237 m->openInputFile(qfilename, inQual);
1240 while(!inQual.eof()){
1241 input = m->getline(inQual);
1243 if (input.length() != 0) {
1244 if(input[0] == '>'){ //this is a sequence name line
1245 istringstream nameStream(input);
1247 string sname = ""; nameStream >> sname;
1248 sname = sname.substr(1);
1250 map<string, int>::iterator it = firstSeqNames.find(sname);
1252 if(it != firstSeqNames.end()) { //this is the start of a new chunk
1253 unsigned long long pos = inQual.tellg();
1254 qfileFilePos.push_back(pos - input.length() - 1);
1255 firstSeqNames.erase(it);
1260 if (firstSeqNames.size() == 0) { break; }
1264 if (firstSeqNames.size() != 0) {
1265 for (map<string, int>::iterator it = firstSeqNames.begin(); it != firstSeqNames.end(); it++) {
1266 m->mothurOut(it->first + " is in your fasta file and not in your quality file, aborting."); m->mothurOutEndLine();
1268 m->control_pressed = true;
1272 //get last file position of qfile
1274 unsigned long long size;
1276 //get num bytes in file
1277 pFile = fopen (qfilename.c_str(),"rb");
1278 if (pFile==NULL) perror ("Error opening file");
1280 fseek (pFile, 0, SEEK_END);
1285 qfileFilePos.push_back(size);
1287 //seach for filePos of each first name in the rfile and save in rfileFilePos
1290 m->openInputFile(rfilename, inR);
1292 //read column headers
1293 for (int i = 0; i < 16; i++) {
1294 if (!inR.eof()) { inR >> junk; }
1300 if (m->control_pressed) { inR.close(); return processors; }
1302 input = m->getline(inR);
1304 if (input.length() != 0) {
1306 istringstream nameStream(input);
1307 string sname = ""; nameStream >> sname;
1309 map<string, int>::iterator it = firstSeqNamesReport.find(sname);
1311 if(it != firstSeqNamesReport.end()) { //this is the start of a new chunk
1312 unsigned long long pos = inR.tellg();
1313 rfileFilePos.push_back(pos - input.length() - 1);
1314 firstSeqNamesReport.erase(it);
1318 if (firstSeqNamesReport.size() == 0) { break; }
1323 if (firstSeqNamesReport.size() != 0) {
1324 for (map<string, int>::iterator it = firstSeqNamesReport.begin(); it != firstSeqNamesReport.end(); it++) {
1325 m->mothurOut(it->first + " is in your fasta file and not in your report file, aborting."); m->mothurOutEndLine();
1327 m->control_pressed = true;
1331 //get last file position of qfile
1333 unsigned long long sizeR;
1335 //get num bytes in file
1336 rFile = fopen (rfilename.c_str(),"rb");
1337 if (rFile==NULL) perror ("Error opening file");
1339 fseek (rFile, 0, SEEK_END);
1340 sizeR=ftell (rFile);
1344 rfileFilePos.push_back(sizeR);
1350 fastaFilePos.push_back(0); qfileFilePos.push_back(0);
1351 //get last file position of fastafile
1353 unsigned long long size;
1355 //get num bytes in file
1356 pFile = fopen (filename.c_str(),"rb");
1357 if (pFile==NULL) perror ("Error opening file");
1359 fseek (pFile, 0, SEEK_END);
1363 fastaFilePos.push_back(size);
1365 //get last file position of fastafile
1368 //get num bytes in file
1369 qFile = fopen (qfilename.c_str(),"rb");
1370 if (qFile==NULL) perror ("Error opening file");
1372 fseek (qFile, 0, SEEK_END);
1376 qfileFilePos.push_back(size);
1382 catch(exception& e) {
1383 m->errorOut(e, "SeqErrorCommand", "setLines");
1387 //***************************************************************************************************************