]> git.donarmstrong.com Git - mothur.git/blobdiff - filterseqscommand.cpp
fixed subsample name file name issue. added count parameter to cluster command....
[mothur.git] / filterseqscommand.cpp
index 9096bb671c830a7f5b0b3638ef0ef0a1d0a5f65d..7a8fbc8cdfe6236601dbc0b369f6ef415a5c7c48 100644 (file)
@@ -57,6 +57,27 @@ string FilterSeqsCommand::getHelpString(){
        }
 }
 //**********************************************************************************************************************
+string FilterSeqsCommand::getOutputFileNameTag(string type, string inputName=""){      
+       try {
+        string outputFileName = "";
+               map<string, vector<string> >::iterator it;
+        
+        //is this a type this command creates
+        it = outputTypes.find(type);
+        if (it == outputTypes.end()) {  m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
+        else {
+            if (type == "fasta") {  outputFileName =  "filter.fasta"; }
+            else if (type == "filter") {  outputFileName =  "filter"; }
+            else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true;  }
+        }
+        return outputFileName;
+       }
+       catch(exception& e) {
+               m->errorOut(e, "FilterSeqsCommand", "getOutputFileNameTag");
+               exit(1);
+       }
+}
+//**********************************************************************************************************************
 FilterSeqsCommand::FilterSeqsCommand(){        
        try {
                abort = true; calledHelp = true; 
@@ -125,7 +146,12 @@ FilterSeqsCommand::FilterSeqsCommand(string option)  {
                        fasta = validParameter.validFile(parameters, "fasta", false);
                        if (fasta == "not found") {                             
                                fasta = m->getFastaFile(); 
-                               if (fasta != "") { fastafileNames.push_back(fasta);  m->mothurOut("Using " + fasta + " as input file for the fasta parameter."); m->mothurOutEndLine(); }
+                               if (fasta != "") { 
+                    fastafileNames.push_back(fasta);  
+                    m->mothurOut("Using " + fasta + " as input file for the fasta parameter."); m->mothurOutEndLine();
+                    string simpleName = m->getSimpleName(fasta);
+                    filterFileName += simpleName.substr(0, simpleName.find_first_of('.'));
+                }
                                else {  m->mothurOut("You have no current fastafile and the fasta parameter is required."); m->mothurOutEndLine(); abort = true; }
                        }
                        else { 
@@ -273,8 +299,8 @@ int FilterSeqsCommand::execute() {
                
                //prevent giantic file name
                string filterFile;
-               if (fastafileNames.size() > 3) { filterFile = outputDir + "merge.filter"; }
-               else {  filterFile = outputDir + filterFileName + ".filter";  }
+               if (fastafileNames.size() > 3) { filterFile = outputDir + "merge." + getOutputFileNameTag("filter"); }
+               else {  filterFile = outputDir + filterFileName + "." + getOutputFileNameTag("filter");  }
                
                m->openOutputFile(filterFile, outFilter);
                outFilter << filter << endl;
@@ -337,7 +363,7 @@ int FilterSeqsCommand::filterSequences() {
                        
                                for (int i = 0; i < lines.size(); i++) {  delete lines[i];  }  lines.clear();
                                
-                               string filteredFasta = outputDir + m->getRootName(m->getSimpleName(fastafileNames[s])) + "filter.fasta";
+                               string filteredFasta = outputDir + m->getRootName(m->getSimpleName(fastafileNames[s])) + getOutputFileNameTag("fasta");
 #ifdef USE_MPI 
                                int pid, numSeqsPerProcessor, num; 
                                int tag = 2001;
@@ -424,16 +450,17 @@ int FilterSeqsCommand::filterSequences() {
             vector<unsigned long long> positions;
             if (savedPositions.size() != 0) { positions = savedPositions[s]; }
             else {
-#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                                positions = m->divideFile(fastafileNames[s], processors);
 #else
                 if(processors != 1){
                     int numFastaSeqs = 0;
                     positions = m->setFilePosFasta(fastafileNames[s], numFastaSeqs); 
+                    if (positions.size() < processors) { processors = positions.size(); }
                 }
 #endif
             }
-               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                        //vector<unsigned long long> positions = m->divideFile(fastafileNames[s], processors);
                        
                        for (int i = 0; i < (positions.size()-1); i++) {
@@ -590,7 +617,7 @@ int FilterSeqsCommand::driverRunFilter(string F, string outputFilename, string i
                                count++;
                        }
                        
-                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                                unsigned long long pos = in.tellg();
                                if ((pos == -1) || (pos >= filePos->end)) { break; }
                        #else
@@ -623,7 +650,7 @@ int FilterSeqsCommand::createProcessesRunFilter(string F, string filename, strin
                int num = 0;
                processIDS.clear();
         
-#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                
                
                //loop through and create all the processes you want
@@ -811,7 +838,7 @@ string FilterSeqsCommand::createFilter() {
 #else
                                
                 vector<unsigned long long> positions;
-               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+               #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                                positions = m->divideFile(fastafileNames[s], processors);
                                for (int i = 0; i < (positions.size()-1); i++) {
                                        lines.push_back(new linePair(positions[i], positions[(i+1)]));
@@ -832,6 +859,7 @@ string FilterSeqsCommand::createFilter() {
                                }else {
                     int numFastaSeqs = 0;
                     positions = m->setFilePosFasta(fastafileNames[s], numFastaSeqs); 
+                    if (positions.size() < processors) { processors = positions.size(); }
                     
                     //figure out how many sequences you have to process
                     int numSeqsPerProcessor = numFastaSeqs / processors;
@@ -969,7 +997,7 @@ int FilterSeqsCommand::driverCreateFilter(Filters& F, string filename, linePair*
                                        count++;
                        }
                        
-                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+                       #if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                                unsigned long long pos = in.tellg();
                                if ((pos == -1) || (pos >= filePos->end)) { break; }
                        #else
@@ -1045,7 +1073,7 @@ int FilterSeqsCommand::createProcessesCreateFilter(Filters& F, string filename)
                int num = 0;
                processIDS.clear();
 
-#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux)
+#if defined (__APPLE__) || (__MACH__) || (linux) || (__linux) || (__linux__) || (__unix__) || (__unix)
                                
                //loop through and create all the processes you want
                while (process != processors) {