]> git.donarmstrong.com Git - mothur.git/blobdiff - getgroupcommand.cpp
working on pam
[mothur.git] / getgroupcommand.cpp
index 1190f49d41036c3d3034d8555544725014ee49f0..529ed934d5b194d1a1d82869c44053ca4f7bbaf2 100644 (file)
@@ -8,13 +8,14 @@
  */
 
 #include "getgroupcommand.h"
+#include "inputdata.h"
 
 //**********************************************************************************************************************
 vector<string> GetgroupCommand::setParameters(){       
        try {
-               CommandParameter pshared("shared", "InputTypes", "", "current", "none", "none", "none",false,true); parameters.push_back(pshared);
-               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
-               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
+               CommandParameter pshared("shared", "InputTypes", "", "current", "none", "none", "none","",false,true, true); parameters.push_back(pshared);
+               CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
+               CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
                
                vector<string> myArray;
                for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
@@ -30,7 +31,6 @@ string GetgroupCommand::getHelpString(){
        try {
                string helpString = "";
                helpString += "The get.group command parameter is shared and it's required if you have no valid current file.\n";
-               //m->mothurOut("The get.group command outputs a .bootGroups file to you can use in addition to the tree file generated by the bootstrap.shared command to run the consensus command.\n");
                helpString += "You may not use any parameters with the get.group command.\n";
                helpString += "The get.group command should be in the following format: \n";
                helpString += "get.group()\n";
@@ -42,13 +42,12 @@ string GetgroupCommand::getHelpString(){
                exit(1);
        }
 }
+
 //**********************************************************************************************************************
 GetgroupCommand::GetgroupCommand(){    
        try {
                abort = true; calledHelp = true; 
                setParameters();
-               vector<string> tempOutNames;
-               outputTypes["bootgroup"] = tempOutNames;
        }
        catch(exception& e) {
                m->errorOut(e, "GetgroupCommand", "GetgroupCommand");
@@ -77,10 +76,6 @@ GetgroupCommand::GetgroupCommand(string option)  {
                                if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
                        }
                        
-                       //initialize outputTypes
-                       vector<string> tempOutNames;
-                       outputTypes["bootgroup"] = tempOutNames;
-                       
                        //if the user changes the input directory command factory will send this info to us in the output parameter 
                        string inputDir = validParameter.validFile(parameters, "inputdir", false);              
                        if (inputDir == "not found"){   inputDir = "";          }
@@ -121,62 +116,17 @@ int GetgroupCommand::execute(){
        try {
        
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
+                                       
+               InputData input(sharedfile, "sharedfile");
+               vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
                
-               //open shared file
-               m->openInputFile(sharedfile, in);
-                       
-               //open output file
-               outputFile = outputDir + m->getRootName(m->getSimpleName(sharedfile)) + "bootGroups";
-               m->openOutputFile(outputFile, out);
-                       
-               int num, inputData, count;
-               count = 0;  
-               string holdLabel, nextLabel, groupN, label;
-               
-               //read in first row since you know there is at least 1 group.
-               in >> label >> groupN >> num;
-               holdLabel = label;
-               
-               //output first group
-               m->mothurOut(groupN); m->mothurOutEndLine();
-               out << groupN << '\t' << groupN << endl;        
-                       
-               //get rest of line
-               for(int i=0;i<num;i++){
-                       in >> inputData;
+               for (int i = 0; i < lookup.size(); i++) {
+                       m->mothurOut(lookup[i]->getGroup()); m->mothurOutEndLine();
+                       delete lookup[i];
                }
-               
-               if (m->control_pressed) { outputTypes.clear(); in.close();  out.close(); remove(outputFile.c_str());   return 0; }
-
-               if (in.eof() != true) { in >> nextLabel; }
-               
-               //read the rest of the groups info in
-               while ((nextLabel == holdLabel) && (in.eof() != true)) {
-                       if (m->control_pressed) {  outputTypes.clear(); in.close();  out.close(); remove(outputFile.c_str());   return 0; }
                        
-                       in >> groupN >> num;
-                       count++;
-                       
-                       //output next group
-                       m->mothurOut(groupN); m->mothurOutEndLine();
-                       out << groupN << '\t' << groupN << endl;                                
-                       
-                       //fill vector.  
-                       for(int i=0;i<num;i++){
-                               in >> inputData;
-                       }
-                       
-                       if (in.eof() != true) { in >> nextLabel; }
-               }
-               
-               in.close();
-               out.close();
-               
-               if (m->control_pressed) {  remove(outputFile.c_str());   return 0; }
-               
                m->mothurOutEndLine();
-               m->mothurOut("Output File Name: "); m->mothurOutEndLine();
-               m->mothurOut(outputFile); m->mothurOutEndLine();        outputNames.push_back(outputFile); outputTypes["bootgroup"].push_back(outputFile);
+               m->mothurOut("Output File Names: "); m->mothurOutEndLine();
                m->mothurOutEndLine();
                
                return 0;       
@@ -187,5 +137,6 @@ int GetgroupCommand::execute(){
                exit(1);
        }
 }
+//**********************************************************************************************************************