]> git.donarmstrong.com Git - mothur.git/blobdiff - classifyseqscommand.cpp
changed reading of name file to use buffered reads. note the splitAtWhiteSpace functi...
[mothur.git] / classifyseqscommand.cpp
index 664db6b3fdf7f991b851472405dc1493b0369147..158069e7ae596e3eebd6a9d2da5834ec3529dcdc 100644 (file)
@@ -457,13 +457,15 @@ ClassifySeqsCommand::ClassifySeqsCommand(string option)  {
                                search = "kmer";
                        }
                        
-                       if (namefileNames.size() == 0){
-                               vector<string> files; files.push_back(fastaFileNames[fastaFileNames.size()-1]); 
-                               parser.getNameFile(files);
-                       }
-                       
-               }
-               
+            if (!abort) {
+                if (namefileNames.size() == 0){
+                    if (fastaFileNames.size() != 0) {
+                        vector<string> files; files.push_back(fastaFileNames[fastaFileNames.size()-1]); 
+                        parser.getNameFile(files);
+                    }
+                }
+            }
+        }
        }
        catch(exception& e) {
                m->errorOut(e, "ClassifySeqsCommand", "ClassifySeqsCommand");
@@ -482,7 +484,7 @@ ClassifySeqsCommand::~ClassifySeqsCommand(){
 int ClassifySeqsCommand::execute(){
        try {
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
-               
+        
                if(method == "bayesian"){       classify = new Bayesian(taxonomyFileName, templateFileName, search, kmerSize, cutoff, iters, rand(), flip);             }
                else if(method == "knn"){       classify = new Knn(taxonomyFileName, templateFileName, search, kmerSize, gapOpen, gapExtend, match, misMatch, numWanted, rand());                               }
                else {
@@ -500,11 +502,17 @@ int ClassifySeqsCommand::execute(){
                        string baseTName = taxonomyFileName;
                        if (taxonomyFileName == "saved") {baseTName = rdb->getSavedTaxonomy();  }
                        
-                       string RippedTaxName = m->getRootName(m->getSimpleName(baseTName));
-                       RippedTaxName = m->getExtension(RippedTaxName.substr(0, RippedTaxName.length()-1));
-                       if (RippedTaxName[0] == '.') { RippedTaxName = RippedTaxName.substr(1, RippedTaxName.length()); }
-                       RippedTaxName +=  "."; 
-               
+            //set rippedTaxName to 
+                       string RippedTaxName = "";
+            bool foundDot = false;
+            for (int i = baseTName.length()-1; i >= 0; i--) {
+                cout << baseTName[i] << endl;
+                if (foundDot && (baseTName[i] != '.')) {  RippedTaxName = baseTName[i] + RippedTaxName; }
+                else if (foundDot && (baseTName[i] == '.')) {  break; }
+                else if (!foundDot && (baseTName[i] == '.')) {  foundDot = true; }
+            }
+            if (RippedTaxName != "") { RippedTaxName +=  "."; }   
+          
                        if (outputDir == "") { outputDir += m->hasPath(fastaFileNames[s]); }
                        string newTaxonomyFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + RippedTaxName + "taxonomy";
                        string newaccnosFile = outputDir + m->getRootName(m->getSimpleName(fastaFileNames[s])) + RippedTaxName + "flip.accnos";
@@ -911,8 +919,8 @@ int ClassifySeqsCommand::createProcesses(string taxFileName, string tempTaxFile,
                else { m->mothurRemove(accnos); } //remove so other files can be renamed to it
         
                for(int i=0;i<processIDS.size();i++){
-                       appendTaxFiles((taxFileName + toString(processIDS[i]) + ".temp"), taxFileName);
-                       appendTaxFiles((tempTaxFile + toString(processIDS[i]) + ".temp"), tempTaxFile);
+                       m->appendFiles((taxFileName + toString(processIDS[i]) + ".temp"), taxFileName);
+                       m->appendFiles((tempTaxFile + toString(processIDS[i]) + ".temp"), tempTaxFile);
             if (!(m->isBlank(accnos + toString(processIDS[i]) + ".temp"))) {
                                nonBlankAccnosFiles.push_back(accnos + toString(processIDS[i]) + ".temp");
                        }else { m->mothurRemove((accnos + toString(processIDS[i]) + ".temp"));  }
@@ -926,7 +934,7 @@ int ClassifySeqsCommand::createProcesses(string taxFileName, string tempTaxFile,
                        rename(nonBlankAccnosFiles[0].c_str(), accnos.c_str());
                        
                        for (int h=1; h < nonBlankAccnosFiles.size(); h++) {
-                               appendTaxFiles(nonBlankAccnosFiles[h], accnos);
+                               m->appendFiles(nonBlankAccnosFiles[h], accnos);
                                m->mothurRemove(nonBlankAccnosFiles[h]);
                        }
                }else { //recreate the accnosfile if needed
@@ -943,30 +951,6 @@ int ClassifySeqsCommand::createProcesses(string taxFileName, string tempTaxFile,
                exit(1);
        }
 }
-/**************************************************************************************************/
-
-void ClassifySeqsCommand::appendTaxFiles(string temp, string filename) {
-       try{
-               
-               ofstream output;
-               ifstream input;
-               m->openOutputFileAppend(filename, output);
-               m->openInputFile(temp, input);
-               
-               while(char c = input.get()){
-                       if(input.eof())         {       break;                  }
-                       else                            {       output << c;    }
-               }
-               
-               input.close();
-               output.close();
-       }
-       catch(exception& e) {
-               m->errorOut(e, "ClassifySeqsCommand", "appendTaxFiles");
-               exit(1);
-       }
-}
-
 //**********************************************************************************************************************
 
 int ClassifySeqsCommand::driver(linePair* filePos, string taxFName, string tempTFName, string accnos, string filename){