]> git.donarmstrong.com Git - mothur.git/blobdiff - getgroupcommand.cpp
added otu.association command. added calcSpearman, calcKendall and calcPearson functi...
[mothur.git] / getgroupcommand.cpp
index ce3cf73d28e455fd3b111f3a10b7e74ba7f67186..8dae3f30092d0ae94e8b709119e933252f946f4a 100644 (file)
@@ -8,6 +8,7 @@
  */
 
 #include "getgroupcommand.h"
+#include "inputdata.h"
 
 //**********************************************************************************************************************
 vector<string> GetgroupCommand::setParameters(){       
@@ -62,11 +63,10 @@ GetgroupCommand::GetgroupCommand(string option)  {
                
                //allow user to run help
                if(option == "help") { help(); abort = true; calledHelp = true; }
+               else if(option == "citation") { citation(); abort = true; calledHelp = true;}
                
                else {
-                       //valid paramters for this command
-                       string Array[] =  {"outputdir","inputdir"};
-                       vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
+                       vector<string> myArray = setParameters();
                        
                        OptionParser parser(option);
                        map<string,string> parameters = parser.getParameters();
@@ -104,7 +104,7 @@ GetgroupCommand::GetgroupCommand(string option)  {
                                sharedfile = m->getSharedFile(); 
                                if (sharedfile != "") { m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
                                else {  m->mothurOut("You have no current sharedfile and the shared parameter is required."); m->mothurOutEndLine(); abort = true; }
-                       }
+                       }else { m->setSharedFile(sharedfile); }
                        
                        
                        //if the user changes the output directory command factory will send this info to us in the output parameter 
@@ -122,58 +122,23 @@ int GetgroupCommand::execute(){
        try {
        
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
-               
-               //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;
+               InputData input(sharedfile, "sharedfile");
+               vector<SharedRAbundVector*> lookup = input.getSharedRAbundVectors();
                
-               //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;
-               }
-               
-               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; }
+               for (int i = 0; i < lookup.size(); i++) {
+                       out << lookup[i]->getGroup() << '\t' << lookup[i]->getGroup() << endl;
+                       m->mothurOut(lookup[i]->getGroup()); m->mothurOutEndLine();
+                       delete lookup[i];
                }
                
-               in.close();
                out.close();
                
-               if (m->control_pressed) {  remove(outputFile.c_str());   return 0; }
+               if (m->control_pressed) {  m->mothurRemove(outputFile);   return 0; }
                
                m->mothurOutEndLine();
                m->mothurOut("Output File Name: "); m->mothurOutEndLine();