]> git.donarmstrong.com Git - mothur.git/blobdiff - getgroupcommand.cpp
version working on mac with .tellg changed to unget for windows
[mothur.git] / getgroupcommand.cpp
index 393be4e64a4fbef95244f18ca377b6098035b45e..4fa84136001aefaeb051ee592a41e54b081b0885 100644 (file)
@@ -3,20 +3,37 @@
  *  Mothur
  *
  *  Created by Thomas Ryabin on 2/2/09.
- *  Copyright 2009 __MyCompanyName__. All rights reserved.
+ *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
  *
  */
 
 #include "getgroupcommand.h"
 
-
-
-
-
-GetgroupCommand::GetgroupCommand(){
+//**********************************************************************************************************************
+GetgroupCommand::GetgroupCommand(string option){
        try {
                globaldata = GlobalData::getInstance();
-               groupMap = globaldata->gGroupmap;
+               abort = false;
+               
+               //allow user to run help
+               if(option == "help") { help(); abort = true; }
+               
+               else {
+                       if (option != "") { cout << "There are no valid parameters for the get.group command." << endl; abort = true; }
+                       
+                       if ((globaldata->getSharedFile() == "")) { cout << "You must use the read.otu command to read a groupfile or a sharedfile before you can use the get.group command." << endl; abort = true; }
+                               
+                       if (abort == false) {
+                               //open shared file
+                               sharedfile = globaldata->getSharedFile();
+                               openInputFile(sharedfile, in);
+               
+                               //open output file
+                               outputFile = getRootName(sharedfile) + "bootGroups";
+                               openOutputFile(outputFile, out);
+
+                       }
+               }
        }
        catch(exception& e) {
                cout << "Standard Error: " << e.what() << " has occurred in the GetgroupCommand class Function GetgroupCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
@@ -28,6 +45,27 @@ GetgroupCommand::GetgroupCommand(){
        }       
                        
 }
+//**********************************************************************************************************************
+
+void GetgroupCommand::help(){
+       try {
+               cout << "The get.group command can only be executed after a successful read.otu command." << "\n";
+               //cout << "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 concensus command." << "\n";
+               cout << "You may not use any parameters with the get.group command." << "\n";
+               cout << "The get.group command should be in the following format: " << "\n";
+               cout << "get.group()" << "\n";
+               cout << "Example get.group()." << "\n";
+               
+       }
+       catch(exception& e) {
+               cout << "Standard Error: " << e.what() << " has occurred in the GetgroupCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }
+       catch(...) {
+               cout << "An unknown error has occurred in the GetgroupCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
+               exit(1);
+       }       
+}
 
 //**********************************************************************************************************************
 
@@ -38,9 +76,47 @@ GetgroupCommand::~GetgroupCommand(){
 
 int GetgroupCommand::execute(){
        try {
-               vector<string> groupNames = groupMap->namesOfGroups;    
-               for(int i = 0; i < groupNames.size(); i++)
-                       cout << groupNames[i] << "\n";
+       
+               if (abort == true) { return 0; }
+       
+               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
+               cout << groupN << endl;
+               out << groupN << '\t' << groupN << endl;        
+                       
+               //get rest of line
+               for(int i=0;i<num;i++){
+                       in >> inputData;
+               }
+               
+               if (in.eof() != true) { in >> nextLabel; }
+               
+               //read the rest of the groups info in
+               while ((nextLabel == holdLabel) && (in.eof() != true)) {
+                       in >> groupN >> num;
+                       count++;
+                       
+                       //output next group
+                       cout << groupN << endl;
+                       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();
                return 0;       
        }