]> git.donarmstrong.com Git - mothur.git/blob - getgroupcommand.cpp
fixed multiple bugs for 1.4 release
[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(){
14         try {
15                 globaldata = GlobalData::getInstance();
16                 
17                 //open shared file
18                 sharedfile = globaldata->getSharedFile();
19                 openInputFile(sharedfile, in);
20                 
21                 //open output file
22                 outputFile = getRootName(globaldata->inputFileName) + "bootGroups";
23                 openOutputFile(outputFile, out);
24         }
25         catch(exception& e) {
26                 cout << "Standard Error: " << e.what() << " has occurred in the GetgroupCommand class Function GetgroupCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
27                 exit(1);
28         }
29         catch(...) {
30                 cout << "An unknown error has occurred in the GetgroupCommand class function GetgroupCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
31                 exit(1);
32         }       
33                         
34 }
35
36 //**********************************************************************************************************************
37
38 GetgroupCommand::~GetgroupCommand(){
39 }
40
41 //**********************************************************************************************************************
42
43 int GetgroupCommand::execute(){
44         try {
45                 int num, inputData, count;
46                 count = 0;  
47                 string holdLabel, nextLabel, groupN, label;
48                 
49                 //read in first row since you know there is at least 1 group.
50                 in >> label >> groupN >> num;
51                 holdLabel = label;
52                 
53                 //output first group
54                 cout << groupN << endl;
55                 out << groupN << '\t' << groupN << endl;        
56                         
57                 //get rest of line
58                 for(int i=0;i<num;i++){
59                         in >> inputData;
60                 }
61                 
62                 if (in.eof() != true) { in >> nextLabel; }
63                 
64                 //read the rest of the groups info in
65                 while ((nextLabel == holdLabel) && (in.eof() != true)) {
66                         in >> groupN >> num;
67                         count++;
68                         
69                         //output next group
70                         cout << groupN << endl;
71                         out << groupN << '\t' << groupN << endl;                                
72                         
73                         //fill vector.  
74                         for(int i=0;i<num;i++){
75                                 in >> inputData;
76                         }
77                         
78                         if (in.eof() != true) { in >> nextLabel; }
79                 }
80                 
81                 out.close();
82                 return 0;       
83         }
84
85         catch(exception& e) {
86                 cout << "Standard Error: " << e.what() << " has occurred in the GetgroupCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
87                 exit(1);
88         }
89         catch(...) {
90                 cout << "An unknown error has occurred in the GetgroupCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
91                 exit(1);
92         }       
93 }
94
95