]> git.donarmstrong.com Git - mothur.git/blobdiff - shhhercommand.cpp
fixed bug in sffinfo when ~ was used in the sff filename. fixed issue in shhh.flows...
[mothur.git] / shhhercommand.cpp
index a09825e4b9a3cd11dbe77b3dd82e703481c650bc..be410d9d9f4ecec2fc885a239c9ba57b5f409e89 100644 (file)
@@ -150,14 +150,21 @@ ShhherCommand::ShhherCommand(string option) {
                        else{
                                ofstream temp;
                 
-                string thisoutputDir = m->hasPath(flowFilesFileName); //if user entered a file with a path then preserve it
+                string thisoutputDir = outputDir;
+                if (outputDir == "") {  thisoutputDir =  m->hasPath(flowFilesFileName); } //if user entered a file with a path then preserve it
                 
-                               //flow.files = 9 character offset
-                               compositeFASTAFileName = thisoutputDir + m->getRootName(m->getSimpleName(flowFilesFileName)) + "shhh.fasta";
+                               //we want to rip off .files, and also .flow if its there
+                string fileroot = m->getRootName(m->getSimpleName(flowFilesFileName));
+                if (fileroot[fileroot.length()-1] == '.') {  fileroot = fileroot.substr(0, fileroot.length()-1); } //rip off dot
+                string extension = m->getExtension(fileroot);
+                if (extension == ".flow") { fileroot = m->getRootName(fileroot);  }
+                else { fileroot += "."; } //add back if needed
+                
+                               compositeFASTAFileName = thisoutputDir + fileroot + "shhh.fasta";
                                m->openOutputFile(compositeFASTAFileName, temp);
                                temp.close();
                                
-                               compositeNamesFileName = thisoutputDir + m->getRootName(m->getSimpleName(flowFilesFileName)) + "shhh.names";
+                               compositeNamesFileName = thisoutputDir + fileroot + "shhh.names";
                                m->openOutputFile(compositeNamesFileName, temp);
                                temp.close();
                        }
@@ -2046,18 +2053,24 @@ vector<string> ShhherCommand::parseFlowFiles(string filename){
             out << thisNumFLows << endl;
             files.push_back(outputFileName);
             
+            int numLinesWrote = 0;
             for (int i = 0; i < largeSize; i++) {
                 if (in.eof()) { break; }
-                string line = m->getline(in);
+                string line = m->getline(in); m->gobble(in);
                 out << line << endl;
+                numLinesWrote++;
             }
             out.close();
+            
+            if (numLinesWrote == 0) {  m->mothurRemove(outputFileName); files.pop_back();  }
             count++;
         }
         in.close();
         
         if (m->control_pressed) { for (int i = 0; i < files.size(); i++) { m->mothurRemove(files[i]); }  files.clear(); }
         
+        m->mothurOut("\nDivided " + filename + " into " + toString(files.size()) + " files.\n\n"); 
+        
         return files;
     }
        catch(exception& e) {
@@ -2263,8 +2276,8 @@ int ShhherCommand::driver(vector<string> filenames, string thisCompositeFASTAFil
                         m->mothurRemove(otuCountsFileName);
                         m->appendFiles(groupFileName, (thisOutputDir + m->getRootName(m->getSimpleName(theseFlowFileNames[0])) + "shhh.groups"));
                         m->mothurRemove(groupFileName);
-                        m->mothurRemove(theseFlowFileNames[g]);
                     }
+                    m->mothurRemove(theseFlowFileNames[g]);
                 }
                        }
             
@@ -3319,7 +3332,9 @@ void ShhherCommand::writeClusters(string otuCountsFileName, int numOTUs, int num
                                                        //otuCountsFile << base;
                                                }
                                        }
-                                       otuCountsFile << newSeq.substr(4) << endl;
+                                       
+                    if (newSeq.length() >= 4) {  otuCountsFile << newSeq.substr(4) << endl;  }
+                    else {  otuCountsFile << "NNNN" << endl;  }
                                }
                                otuCountsFile << endl;
                        }