]> git.donarmstrong.com Git - mothur.git/blobdiff - preclustercommand.cpp
added count file to get.groups and remove.groups. added shortcut parameter to classif...
[mothur.git] / preclustercommand.cpp
index 32080870d4be38de900e5b2b881c6d360faebc32..951b2008b062c26c5fabb54dfd8ef2d2a858da67 100644 (file)
@@ -51,7 +51,28 @@ string PreClusterCommand::getHelpString(){
                exit(1);
        }
 }
-
+//**********************************************************************************************************************
+string PreClusterCommand::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 =  "precluster" + m->getExtension(inputName); }
+            else if (type == "name") {  outputFileName =  "precluster.names"; }
+            else if (type == "map") {  outputFileName =  "precluster.map"; }
+            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, "PreClusterCommand", "getOutputFileNameTag");
+               exit(1);
+       }
+}
 //**********************************************************************************************************************
 PreClusterCommand::PreClusterCommand(){        
        try {
@@ -184,9 +205,9 @@ int PreClusterCommand::execute(){
                int start = time(NULL);
                
                string fileroot = outputDir + m->getRootName(m->getSimpleName(fastafile));
-               string newFastaFile = fileroot + "precluster" + m->getExtension(fastafile);
-               string newNamesFile = fileroot + "precluster.names";
-               string newMapFile = fileroot + "precluster.map"; //add group name if by group
+               string newFastaFile = fileroot + getOutputFileNameTag("fasta", fastafile);
+               string newNamesFile = fileroot + getOutputFileNameTag("name");
+               string newMapFile = fileroot + getOutputFileNameTag("map"); //add group name if by group
                outputNames.push_back(newFastaFile); outputTypes["fasta"].push_back(newFastaFile);
                outputNames.push_back(newNamesFile); outputTypes["name"].push_back(newNamesFile);
                
@@ -217,17 +238,19 @@ int PreClusterCommand::execute(){
                        m->mothurOutEndLine(); 
                        m->mothurOut("/******************************************/"); m->mothurOutEndLine(); 
                        m->mothurOut("Running command: unique.seqs(" + inputString + ")"); m->mothurOutEndLine(); 
-                       
+                       m->mothurCalling = true;
+            
                        Command* uniqueCommand = new DeconvoluteCommand(inputString);
                        uniqueCommand->execute();
                        
                        map<string, vector<string> > filenames = uniqueCommand->getOutputFiles();
                        
                        delete uniqueCommand;
-                       
+                       m->mothurCalling = false;
                        m->mothurOut("/******************************************/"); m->mothurOutEndLine(); 
                        
                        m->renameFile(filenames["fasta"][0], newFastaFile);
+            m->renameFile(filenames["name"][0], newNamesFile);
                        
                        m->mothurOut("It took " + toString(time(NULL) - start) + " secs to run pre.cluster."); m->mothurOutEndLine(); 
                                
@@ -312,7 +335,17 @@ int PreClusterCommand::createProcessesGroups(SequenceParser* parser, string newF
                                processIDS.push_back(pid);  //create map from line number to pid so you can append files in correct order later
                                process++;
                        }else if (pid == 0){
+                outputNames.clear();
                                num = driverGroups(parser, newFName + toString(getpid()) + ".temp", newNName + toString(getpid()) + ".temp", newMFile, lines[process].start, lines[process].end, groups);
+                
+                string tempFile = toString(getpid()) + ".outputNames.temp";
+                ofstream outTemp;
+                m->openOutputFile(tempFile, outTemp);
+                
+                outTemp << outputNames.size();
+                for (int i = 0; i < outputNames.size(); i++) { outTemp << outputNames[i] << endl; }
+                outTemp.close();
+                
                                exit(0);
                        }else { 
                                m->mothurOut("[ERROR]: unable to spawn the necessary processes."); m->mothurOutEndLine(); 
@@ -329,7 +362,23 @@ int PreClusterCommand::createProcessesGroups(SequenceParser* parser, string newF
                        int temp = processIDS[i];
                        wait(&temp);
                }
-               
+        
+        for (int i = 0; i < processIDS.size(); i++) {
+            string tempFile = toString(processIDS[i]) +  ".outputNames.temp";
+            ifstream intemp;
+            m->openInputFile(tempFile, intemp);
+            
+            int num;
+            intemp >> num;
+            for (int k = 0; k < num; k++) {
+                string name = "";
+                intemp >> name; m->gobble(intemp);
+                
+                outputNames.push_back(name); outputTypes["map"].push_back(name);
+            }
+            intemp.close();
+            m->mothurRemove(tempFile);
+        }
 #else
                
                //////////////////////////////////////////////////////////////////////////////////////////////////////