5 * Created by Thomas Ryabin on 2/2/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "getgroupcommand.h"
12 //**********************************************************************************************************************
13 GetgroupCommand::GetgroupCommand(string option){
15 globaldata = GlobalData::getInstance();
18 //allow user to run help
19 if(option == "help") { help(); abort = true; }
22 //valid paramters for this command
23 string Array[] = {"outputdir","inputdir"};
24 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
26 OptionParser parser(option);
27 map<string,string> parameters = parser.getParameters();
29 ValidParameters validParameter;
30 //check to make sure all parameters are valid for command
31 for (map<string,string>::iterator it = parameters.begin(); it != parameters.end(); it++) {
32 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; }
35 //if the user changes the output directory command factory will send this info to us in the output parameter
36 string outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; }
38 if ((globaldata->getSharedFile() == "")) { mothurOut("You must use the read.otu command to read a groupfile or a sharedfile before you can use the get.group command."); mothurOutEndLine(); abort = true; }
42 sharedfile = globaldata->getSharedFile();
43 openInputFile(sharedfile, in);
46 if (outputDir == "") { outputDir += hasPath(sharedfile); }
47 outputFile = outputDir + getRootName(getSimpleName(sharedfile)) + "bootGroups";
48 openOutputFile(outputFile, out);
54 errorOut(e, "GetgroupCommand", "GetgroupCommand");
58 //**********************************************************************************************************************
60 void GetgroupCommand::help(){
62 mothurOut("The get.group command can only be executed after a successful read.otu command.\n");
63 //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");
64 mothurOut("You may not use any parameters with the get.group command.\n");
65 mothurOut("The get.group command should be in the following format: \n");
66 mothurOut("get.group()\n");
67 mothurOut("Example get.group().\n");
71 errorOut(e, "GetgroupCommand", "help");
76 //**********************************************************************************************************************
78 GetgroupCommand::~GetgroupCommand(){
81 //**********************************************************************************************************************
83 int GetgroupCommand::execute(){
86 if (abort == true) { return 0; }
88 int num, inputData, count;
90 string holdLabel, nextLabel, groupN, label;
92 //read in first row since you know there is at least 1 group.
93 in >> label >> groupN >> num;
97 mothurOut(groupN); mothurOutEndLine();
98 out << groupN << '\t' << groupN << endl;
101 for(int i=0;i<num;i++){
105 if (in.eof() != true) { in >> nextLabel; }
107 //read the rest of the groups info in
108 while ((nextLabel == holdLabel) && (in.eof() != true)) {
113 mothurOut(groupN); mothurOutEndLine();
114 out << groupN << '\t' << groupN << endl;
117 for(int i=0;i<num;i++){
121 if (in.eof() != true) { in >> nextLabel; }
129 catch(exception& e) {
130 errorOut(e, "GetgroupCommand", "execute");