X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=mothurout.cpp;h=1f1c96b6f203e4f1fa8b1dca2e018c735caa6b9f;hp=dc77490e4b9bba1bc9bf6e4c16b0f402985c73d1;hb=b25ede2ad307ae76f8a610443e0ec3ec69621ce7;hpb=eb71e28b7b7afd82540f4a8f0bac9429c5b9d713 diff --git a/mothurout.cpp b/mothurout.cpp index dc77490..1f1c96b 100644 --- a/mothurout.cpp +++ b/mothurout.cpp @@ -23,6 +23,7 @@ set MothurOut::getCurrentTypes() { set types; types.insert("fasta"); + types.insert("summary"); types.insert("accnos"); types.insert("column"); types.insert("design"); @@ -81,6 +82,7 @@ void MothurOut::printCurrentFiles() { if (biomfile != "") { mothurOut("biom=" + biomfile); mothurOutEndLine(); } if (counttablefile != "") { mothurOut("count=" + counttablefile); mothurOutEndLine(); } if (processors != "1") { mothurOut("processors=" + processors); mothurOutEndLine(); } + if (summaryfile != "") { mothurOut("summary=" + summaryfile); mothurOutEndLine(); } } catch(exception& e) { @@ -115,6 +117,7 @@ bool MothurOut::hasCurrentFiles() { if (flowfile != "") { return true; } if (biomfile != "") { return true; } if (counttablefile != "") { return true; } + if (summaryfile != "") { return true; } if (processors != "1") { return true; } return hasCurrent; @@ -151,6 +154,7 @@ void MothurOut::clearCurrentFiles() { flowfile = ""; biomfile = ""; counttablefile = ""; + summaryfile = ""; processors = "1"; } catch(exception& e) { @@ -344,6 +348,27 @@ void MothurOut::mothurOut(string output) { } } /*********************************************************************************************/ +void MothurOut::mothurOutJustToScreen(string output) { + try { + +#ifdef USE_MPI + int pid; + MPI_Comm_rank(MPI_COMM_WORLD, &pid); + + if (pid == 0) { //only one process should output to screen +#endif + logger() << output; + +#ifdef USE_MPI + } +#endif + } + catch(exception& e) { + errorOut(e, "MothurOut", "MothurOut"); + exit(1); + } +} +/*********************************************************************************************/ void MothurOut::mothurOutEndLine() { try { #ifdef USE_MPI @@ -452,8 +477,10 @@ void MothurOut::errorOut(exception& e, string object, string function) { }else { //bad alloc if (object == "cluster"){ mothurOut(" has occurred in the " + object + " class function " + function + ". This error indicates your computer is running out of memory. There are two common causes for this, file size and format.\n\nFile Size:\nThe cluster command loads your distance matrix into RAM, and your distance file is most likely too large to fit in RAM. There are two options to help with this. The first is to use a cutoff. By using a cutoff mothur will only load distances that are below the cutoff. If that is still not enough, there is a command called cluster.split, http://www.mothur.org/wiki/cluster.split which divides the distance matrix, and clusters the smaller pieces separately. You may also be able to reduce the size of the original distance matrix by using the commands outlined in the Schloss SOP, http://www.mothur.org/wiki/Schloss_SOP. \n\nWrong Format:\nThis error can be caused by trying to read a column formatted distance matrix using the phylip parameter. By default, the dist.seqs command generates a column formatted distance matrix. To make a phylip formatted matrix set the dist.seqs command parameter output to lt. \n\nIf you are uable to resolve the issue, please contact Pat Schloss at mothur.bugs@gmail.com, and be sure to include the mothur.logFile with your inquiry."); + }else if (object == "shhh.flows"){ + mothurOut(" has occurred in the " + object + " class function " + function + ". This error indicates your computer is running out of memory. The shhh.flows command is very memory intensive. This error is most commonly caused by trying to process a dataset too large, using multiple processors, or failing to run trim.flows before shhh.flows. If you are running our 32bit version, your memory usage is limited to 4G. If you have more than 4G of RAM and are running a 64bit OS, using our 64bit version may resolve your issue. If you are using multiple processors, try running the command with processors=1, the more processors you use the more memory is required. Running trim.flows with an oligos file, and then shhh.flows with the file option may also resolve the issue. If for some reason you are unable to run shhh.flows with your data, a good alternative is to use the trim.seqs command using a 50-bp sliding window and to trim the sequence when the average quality score over that window drops below 35. Our results suggest that the sequencing error rates by this method are very good, but not quite as good as by shhh.flows and that the resulting sequences tend to be a bit shorter. If you are uable to resolve the issue, please contact Pat Schloss at mothur.bugs@gmail.com, and be sure to include the mothur.logFile with your inquiry. "); }else { - mothurOut(" has occurred in the " + object + " class function " + function + ". This error indicates your computer is running out of memory. This is most commonly caused by trying to process a dataset too large, or a file format issue. If you are running our 32bit version, your memory usage is limited to 4G. If you have more than 4G of RAM and are running a 64bit OS, using our 64bit version may resolve your issue. Also, you may be able to reduce the size of your dataset by using the commands outlined in the Schloss SOP, http://www.mothur.org/wiki/Schloss_SOP. If you are uable to resolve the issue, please contact Pat Schloss at mothur.bugs@gmail.com, and be sure to include the mothur.logFile with your inquiry."); + mothurOut(" has occurred in the " + object + " class function " + function + ". This error indicates your computer is running out of memory. This is most commonly caused by trying to process a dataset too large, using multiple processors, or a file format issue. If you are running our 32bit version, your memory usage is limited to 4G. If you have more than 4G of RAM and are running a 64bit OS, using our 64bit version may resolve your issue. If you are using multiple processors, try running the command with processors=1, the more processors you use the more memory is required. Also, you may be able to reduce the size of your dataset by using the commands outlined in the Schloss SOP, http://www.mothur.org/wiki/Schloss_SOP. If you are uable to resolve the issue, please contact Pat Schloss at mothur.bugs@gmail.com, and be sure to include the mothur.logFile with your inquiry."); } } } @@ -769,6 +796,39 @@ bool MothurOut::dirCheck(string& dirName){ } } +//********************************************************************************************************************** + +map > MothurOut::parseClasses(string classes){ + try { + map > parts; + + //treatment-age + vector pieces; splitAtDash(classes, pieces); // -> treatment, age + + for (int i = 0; i < pieces.size(); i++) { + string category = ""; string value = ""; + bool foundOpen = false; + for (int j = 0; j < pieces[i].length(); j++) { + if (control_pressed) { return parts; } + + if (pieces[i][j] == '<') { foundOpen = true; } + else if (pieces[i][j] == '>') { j += pieces[i].length(); } + else { + if (!foundOpen) { category += pieces[i][j]; } + else { value += pieces[i][j]; } + } + } + vector values; splitAtChar(value, values, '|'); + parts[category] = values; + } + + return parts; + } + catch(exception& e) { + errorOut(e, "MothurOut", "parseClasses"); + exit(1); + } +} /***********************************************************************/ string MothurOut::hasPath(string longName){ @@ -951,7 +1011,7 @@ string MothurOut::getFullPathName(string fileName){ } for (int i = index; i >= 0; i--) { - newFileName = dirs[i] + "\\\\" + newFileName; + newFileName = dirs[i] + "\\" + newFileName; } return newFileName; @@ -1168,7 +1228,42 @@ int MothurOut::appendFiles(string temp, string filename) { exit(1); } } - +/**************************************************************************************************/ +int MothurOut::appendFilesWithoutHeaders(string temp, string filename) { + try{ + ofstream output; + ifstream input; + + //open output file in append mode + openOutputFileAppend(filename, output); + int ableToOpen = openInputFile(temp, input, "no error"); + //int ableToOpen = openInputFile(temp, input); + + int numLines = 0; + if (ableToOpen == 0) { //you opened it + + string headers = getline(input); gobble(input); + if (debug) { mothurOut("[DEBUG]: skipping headers " + headers +'\n'); } + + char buffer[4096]; + while (!input.eof()) { + input.read(buffer, 4096); + output.write(buffer, input.gcount()); + //count number of lines + for (int i = 0; i < input.gcount(); i++) { if (buffer[i] == '\n') {numLines++;} } + } + input.close(); + } + + output.close(); + + return numLines; + } + catch(exception& e) { + errorOut(e, "MothurOut", "appendFiles"); + exit(1); + } +} /**************************************************************************************************/ string MothurOut::sortFile(string distFile, string outputDir){ try { @@ -1255,15 +1350,15 @@ vector MothurOut::setFilePosFasta(string filename, int& num) char c = inFASTA.get(); count++; if (c == '>') { positions.push_back(count-1); - //cout << count << endl; + if (debug) { mothurOut("[DEBUG]: numSeqs = " + toString(positions.size()) + " count = " + toString(count) + ".\n"); } } } inFASTA.close(); num = positions.size(); - - /*FILE * pFile; - long size; + if (debug) { mothurOut("[DEBUG]: num = " + toString(num) + ".\n"); } + FILE * pFile; + unsigned long long size; //get num bytes in file pFile = fopen (filename.c_str(),"rb"); @@ -1272,9 +1367,9 @@ vector MothurOut::setFilePosFasta(string filename, int& num) fseek (pFile, 0, SEEK_END); size=ftell (pFile); fclose (pFile); - }*/ + } - unsigned long long size = positions[(positions.size()-1)]; + /*unsigned long long size = positions[(positions.size()-1)]; ifstream in; openInputFile(filename, in); @@ -1284,8 +1379,10 @@ vector MothurOut::setFilePosFasta(string filename, int& num) if(in.eof()) { break; } else { size++; } } - in.close(); - + in.close();*/ + + if (debug) { mothurOut("[DEBUG]: size = " + toString(size) + ".\n"); } + positions.push_back(size); positions[0] = 0; @@ -1296,6 +1393,67 @@ vector MothurOut::setFilePosFasta(string filename, int& num) exit(1); } } +//********************************************************************************************************************** +vector MothurOut::readConsTax(string inputfile){ + try { + + vector taxes; + + ifstream in; + openInputFile(inputfile, in); + + //read headers + getline(in); + + while (!in.eof()) { + + if (control_pressed) { break; } + + string otu = ""; string tax = "unknown"; + int size = 0; + + in >> otu >> size >> tax; gobble(in); + consTax temp(otu, tax, size); + taxes.push_back(temp); + } + in.close(); + + return taxes; + } + catch(exception& e) { + errorOut(e, "MothurOut", "readConsTax"); + exit(1); + } +} +//********************************************************************************************************************** +int MothurOut::readConsTax(string inputfile, map& taxes){ + try { + ifstream in; + openInputFile(inputfile, in); + + //read headers + getline(in); + + while (!in.eof()) { + + if (control_pressed) { break; } + + string otu = ""; string tax = "unknown"; + int size = 0; + + in >> otu >> size >> tax; gobble(in); + consTax2 temp(tax, size); + taxes[otu] = temp; + } + in.close(); + + return 0; + } + catch(exception& e) { + errorOut(e, "MothurOut", "readConsTax"); + exit(1); + } +} /**************************************************************************************************/ vector MothurOut::setFilePosEachLine(string filename, int& num) { try { @@ -2178,9 +2336,11 @@ map MothurOut::readNames(string namefile, unsigned long int& numSeq /************************************************************/ int MothurOut::checkName(string& name) { try { - for (int i = 0; i < name.length(); i++) { - if (name[i] == ':') { name[i] = '_'; changedSeqNames = true; } - } + if (modifyNames) { + for (int i = 0; i < name.length(); i++) { + if (name[i] == ':') { name[i] = '_'; changedSeqNames = true; } + } + } return 0; } catch(exception& e) { @@ -2282,7 +2442,9 @@ set MothurOut::readAccnos(string accnosfile){ in.read(buffer, 4096); vector pieces = splitWhiteSpace(rest, buffer, in.gcount()); - for (int i = 0; i < pieces.size(); i++) { checkName(pieces[i]); names.insert(pieces[i]); } + for (int i = 0; i < pieces.size(); i++) { checkName(pieces[i]); + names.insert(pieces[i]); + } } in.close(); @@ -2776,6 +2938,7 @@ void MothurOut::splitAtDash(string& estim, set& container) { string individual = ""; int estimLength = estim.size(); bool prevEscape = false; + /* for(int i=0;i& container) { } } } - container.insert(individual); + */ + + for(int i=0;i& container) { int lineNum; int estimLength = estim.size(); bool prevEscape = false; + /* for(int i=0;i& container) { prevEscape = false; } } - } + }*/ + + for(int i=0;i MothurOut::getAverages(vector< vector >& dists) { exit(1); } } +/**************************************************************************************************/ +double MothurOut::getAverage(vector dists) { + try{ + double average = 0; + + for (int i = 0; i < dists.size(); i++) { + average += dists[i]; + } + + //finds average. + average /= (double) dists.size(); + + return average; + } + catch(exception& e) { + errorOut(e, "MothurOut", "getAverage"); + exit(1); + } +} + /**************************************************************************************************/ vector MothurOut::getStandardDeviation(vector< vector >& dists) { try{