]> git.donarmstrong.com Git - mothur.git/blob - getgroupcommand.cpp
added logfile feature
[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 != "") { mothurOut("There are no valid parameters for the get.group command."); mothurOutEndLine(); abort = true; }
23                         
24                         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; }
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                 errorOut(e, "GetgroupCommand", "GetgroupCommand");
40                 exit(1);
41         }
42 }
43 //**********************************************************************************************************************
44
45 void GetgroupCommand::help(){
46         try {
47                 mothurOut("The get.group command can only be executed after a successful read.otu command.\n");
48                 //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 concensus command.\n");
49                 mothurOut("You may not use any parameters with the get.group command.\n");
50                 mothurOut("The get.group command should be in the following format: \n");
51                 mothurOut("get.group()\n");
52                 mothurOut("Example get.group().\n");
53                 
54         }
55         catch(exception& e) {
56                 errorOut(e, "GetgroupCommand", "help");
57                 exit(1);
58         }
59 }
60
61 //**********************************************************************************************************************
62
63 GetgroupCommand::~GetgroupCommand(){
64 }
65
66 //**********************************************************************************************************************
67
68 int GetgroupCommand::execute(){
69         try {
70         
71                 if (abort == true) { return 0; }
72         
73                 int num, inputData, count;
74                 count = 0;  
75                 string holdLabel, nextLabel, groupN, label;
76                 
77                 //read in first row since you know there is at least 1 group.
78                 in >> label >> groupN >> num;
79                 holdLabel = label;
80                 
81                 //output first group
82                 mothurOut(groupN); mothurOutEndLine();
83                 out << groupN << '\t' << groupN << endl;        
84                         
85                 //get rest of line
86                 for(int i=0;i<num;i++){
87                         in >> inputData;
88                 }
89                 
90                 if (in.eof() != true) { in >> nextLabel; }
91                 
92                 //read the rest of the groups info in
93                 while ((nextLabel == holdLabel) && (in.eof() != true)) {
94                         in >> groupN >> num;
95                         count++;
96                         
97                         //output next group
98                         mothurOut(groupN); mothurOutEndLine();
99                         out << groupN << '\t' << groupN << endl;                                
100                         
101                         //fill vector.  
102                         for(int i=0;i<num;i++){
103                                 in >> inputData;
104                         }
105                         
106                         if (in.eof() != true) { in >> nextLabel; }
107                 }
108                 
109                 in.close();
110                 out.close();
111                 return 0;       
112         }
113
114         catch(exception& e) {
115                 errorOut(e, "GetgroupCommand", "execute");
116                 exit(1);
117         }
118 }
119
120