]> git.donarmstrong.com Git - mothur.git/blob - getgroupcommand.cpp
broke up globaldata and moved error checking and help into commands
[mothur.git] / getgroupcommand.cpp
1 /*
2  *  getgroupcommand.cpp
3  *  Mothur
4  *
5  *  Created by Thomas Ryabin on 2/2/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "getgroupcommand.h"
11
12 //**********************************************************************************************************************
13 GetgroupCommand::GetgroupCommand(string option){
14         try {
15                 globaldata = GlobalData::getInstance();
16                 abort = false;
17                 
18                 //allow user to run help
19                 if(option == "help") { help(); abort = true; }
20                 
21                 else {
22                         if (option != "") { cout << "There are no valid parameters for the get.group command." << endl; abort = true; }
23                         
24                         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; }
25                                 
26                         if (abort == false) {
27                                 //open shared file
28                                 sharedfile = globaldata->getSharedFile();
29                                 openInputFile(sharedfile, in);
30                 
31                                 //open output file
32                                 outputFile = getRootName(sharedfile) + "bootGroups";
33                                 openOutputFile(outputFile, out);
34
35                         }
36                 }
37         }
38         catch(exception& e) {
39                 cout << "Standard Error: " << e.what() << " has occurred in the GetgroupCommand class Function GetgroupCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
40                 exit(1);
41         }
42         catch(...) {
43                 cout << "An unknown error has occurred in the GetgroupCommand class function GetgroupCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
44                 exit(1);
45         }       
46                         
47 }
48 //**********************************************************************************************************************
49
50 void GetgroupCommand::help(){
51         try {
52                 cout << "The get.group command can only be executed after a successful read.otu command." << "\n";
53                 //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";
54                 cout << "You may not use any parameters with the get.group command." << "\n";
55                 cout << "The get.group command should be in the following format: " << "\n";
56                 cout << "get.group()" << "\n";
57                 cout << "Example get.group()." << "\n";
58                 
59         }
60         catch(exception& e) {
61                 cout << "Standard Error: " << e.what() << " has occurred in the GetgroupCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
62                 exit(1);
63         }
64         catch(...) {
65                 cout << "An unknown error has occurred in the GetgroupCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
66                 exit(1);
67         }       
68 }
69
70 //**********************************************************************************************************************
71
72 GetgroupCommand::~GetgroupCommand(){
73 }
74
75 //**********************************************************************************************************************
76
77 int GetgroupCommand::execute(){
78         try {
79         
80                 if (abort == true) { return 0; }
81         
82                 int num, inputData, count;
83                 count = 0;  
84                 string holdLabel, nextLabel, groupN, label;
85                 
86                 //read in first row since you know there is at least 1 group.
87                 in >> label >> groupN >> num;
88                 holdLabel = label;
89                 
90                 //output first group
91                 cout << groupN << endl;
92                 out << groupN << '\t' << groupN << endl;        
93                         
94                 //get rest of line
95                 for(int i=0;i<num;i++){
96                         in >> inputData;
97                 }
98                 
99                 if (in.eof() != true) { in >> nextLabel; }
100                 
101                 //read the rest of the groups info in
102                 while ((nextLabel == holdLabel) && (in.eof() != true)) {
103                         in >> groupN >> num;
104                         count++;
105                         
106                         //output next group
107                         cout << groupN << endl;
108                         out << groupN << '\t' << groupN << endl;                                
109                         
110                         //fill vector.  
111                         for(int i=0;i<num;i++){
112                                 in >> inputData;
113                         }
114                         
115                         if (in.eof() != true) { in >> nextLabel; }
116                 }
117                 
118                 out.close();
119                 return 0;       
120         }
121
122         catch(exception& e) {
123                 cout << "Standard Error: " << e.what() << " has occurred in the GetgroupCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
124                 exit(1);
125         }
126         catch(...) {
127                 cout << "An unknown error has occurred in the GetgroupCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
128                 exit(1);
129         }       
130 }
131
132