]> git.donarmstrong.com Git - mothur.git/blobdiff - mothurout.cpp
added modify names parameter to set.dir
[mothur.git] / mothurout.cpp
index dc77490e4b9bba1bc9bf6e4c16b0f402985c73d1..2900c7ec4fc8e0df952163554f6fefb7e622cd64 100644 (file)
@@ -23,6 +23,7 @@ set<string> MothurOut::getCurrentTypes()  {
         
         set<string> 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.");
         }
     }
 }
@@ -951,7 +978,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 +1195,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 +1317,15 @@ vector<unsigned long long> 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 +1334,9 @@ vector<unsigned long long> 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 +1346,10 @@ vector<unsigned long long> 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;
                
@@ -2178,9 +2242,11 @@ map<string, int> 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) {
@@ -2776,6 +2842,7 @@ void MothurOut::splitAtDash(string& estim, set<string>& container) {
                string individual = "";
                int estimLength = estim.size();
                bool prevEscape = false;
+        /*
                for(int i=0;i<estimLength;i++){
                        if(prevEscape){
                                individual += estim[i];
@@ -2796,7 +2863,25 @@ void MothurOut::splitAtDash(string& estim, set<string>& container) {
                                }
                        }
                }
-               container.insert(individual);
+               */
+        
+        for(int i=0;i<estimLength;i++){
+            if(estim[i] == '-'){
+                if (prevEscape) {  individual += estim[i]; prevEscape = false;  } //add in dash because it was escaped.
+                else {
+                    container.insert(individual);
+                    individual = "";
+                }
+            }else if(estim[i] == '\\'){
+                if (i < estimLength-1) { 
+                    if (estim[i+1] == '-') { prevEscape=true; }  //are you a backslash before a dash, if yes ignore
+                    else { individual += estim[i]; prevEscape = false;  } //if no, add in
+                }else { individual += estim[i]; }
+            }else {
+                individual += estim[i];
+            }
+        }
+        container.insert(individual);
         
        }
        catch(exception& e) {
@@ -2812,6 +2897,7 @@ void MothurOut::splitAtDash(string& estim, set<int>& container) {
                int lineNum;
                int estimLength = estim.size();
                bool prevEscape = false;
+        /*
                for(int i=0;i<estimLength;i++){
                        if(prevEscape){
                                individual += estim[i];
@@ -2832,7 +2918,26 @@ void MothurOut::splitAtDash(string& estim, set<int>& container) {
                                        prevEscape = false;
                                }
                        }
-               }
+               }*/
+        
+        for(int i=0;i<estimLength;i++){
+            if(estim[i] == '-'){
+                if (prevEscape) {  individual += estim[i]; prevEscape = false;  } //add in dash because it was escaped.
+                else {
+                    convert(individual, lineNum); //convert the string to int
+                    container.insert(lineNum);
+                    individual = "";
+                }
+            }else if(estim[i] == '\\'){
+                if (i < estimLength-1) { 
+                    if (estim[i+1] == '-') { prevEscape=true; }  //are you a backslash before a dash, if yes ignore
+                    else { individual += estim[i]; prevEscape = false;  } //if no, add in
+                }else { individual += estim[i]; }
+            }else {
+                individual += estim[i];
+            }
+        }
+        
                convert(individual, lineNum); //convert the string to int
                container.insert(lineNum);
        }