]> git.donarmstrong.com Git - mothur.git/blob - getlabelcommand.cpp
fixed some bugs
[mothur.git] / getlabelcommand.cpp
1 /*
2  *  GetlabelCommand.cpp
3  *  Mothur
4  *
5  *  Created by Thomas Ryabin on 1/30/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "getlabelcommand.h"
11
12 //**********************************************************************************************************************
13
14 GetlabelCommand::GetlabelCommand(string option){
15         try {
16                 globaldata = GlobalData::getInstance();
17                 abort = false;
18                 
19                 //allow user to run help
20                 if(option == "help") { help(); abort = true; }
21                 
22                 else {
23                         if (option != "") { cout << "There are no valid parameters for the get.label command." << endl; abort = true; }
24                         
25                         if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a list, sabund or rabund before you can use the get.label command." << endl; abort = true; }                              
26                 }
27
28         }
29         catch(exception& e) {
30                 cout << "Standard Error: " << e.what() << " has occurred in the GetlabelCommand class Function GetlabelCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
31                 exit(1);
32         }
33         catch(...) {
34                 cout << "An unknown error has occurred in the GetlabelCommand class function GetlabelCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
35                 exit(1);
36         }       
37                         
38 }
39 //**********************************************************************************************************************
40
41 void GetlabelCommand::help(){
42         try {
43                 cout << "The get.label command can only be executed after a successful read.otu command." << "\n";
44                 cout << "You may not use any parameters with the get.label command." << "\n";
45                 cout << "The get.label command should be in the following format: " << "\n";
46                 cout << "get.label()" << "\n";
47                 cout << "Example get.label()." << "\n";
48         }
49         catch(exception& e) {
50                 cout << "Standard Error: " << e.what() << " has occurred in the GetlabelCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
51                 exit(1);
52         }
53         catch(...) {
54                 cout << "An unknown error has occurred in the GetlabelCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
55                 exit(1);
56         }       
57 }
58
59 //**********************************************************************************************************************
60
61 GetlabelCommand::~GetlabelCommand(){
62 }
63
64 //**********************************************************************************************************************
65
66 int GetlabelCommand::execute(){
67         try {
68                 
69                 if (abort == true) { return 0; }
70                 
71                 filename = globaldata->inputFileName;
72                 ifstream in;
73                 openInputFile(filename, in);
74                 string label;
75                 int numBins = 0;
76                 int count = -1;
77                 while(in.good()) {
78                         if(count > numBins)
79                                 count = 0;
80                         if(count == 0) {
81                                 cout << label << "\n";
82                                 in >> numBins;
83                         }
84                         in >> label;
85                         count++;
86                 }       
87                 
88                 in.close();
89                 return 0;       
90         }
91
92         catch(exception& e) {
93                 cout << "Standard Error: " << e.what() << " has occurred in the GetlabelCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
94                 exit(1);
95         }
96         catch(...) {
97                 cout << "An unknown error has occurred in the GetlabelCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
98                 exit(1);
99         }       
100 }
101