]> git.donarmstrong.com Git - mothur.git/blob - getlabelcommand.cpp
added [ERROR] flag if command aborts
[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 vector<string> GetlabelCommand::getValidParameters(){   
14         try {
15                 string Array[] =  {"outputdir","inputdir"};
16                 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
17                 return myArray;
18         }
19         catch(exception& e) {
20                 m->errorOut(e, "GetlabelCommand", "getValidParameters");
21                 exit(1);
22         }
23 }
24 //**********************************************************************************************************************
25 vector<string> GetlabelCommand::getRequiredParameters(){        
26         try {
27                 vector<string> myArray;
28                 return myArray;
29         }
30         catch(exception& e) {
31                 m->errorOut(e, "GetlabelCommand", "getRequiredParameters");
32                 exit(1);
33         }
34 }
35 //**********************************************************************************************************************
36 vector<string> GetlabelCommand::getRequiredFiles(){     
37         try {
38                 string Array[] =  {"list","rabund","sabund", "or"};
39                 vector<string> myArray (Array, Array+(sizeof(Array)/sizeof(string)));
40                 return myArray;
41         }
42         catch(exception& e) {
43                 m->errorOut(e, "GetlabelCommand", "getRequiredFiles");
44                 exit(1);
45         }
46 }
47 //**********************************************************************************************************************
48
49 GetlabelCommand::GetlabelCommand(string option)  {
50         try {
51                 globaldata = GlobalData::getInstance();
52                 abort = false; calledHelp = false;   
53                 
54                 //allow user to run help
55                 if(option == "help") { help(); abort = true; calledHelp = true; }
56                 
57                 else {
58                         if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { m->mothurOut("You must read a list, sabund or rabund before you can use the get.label command."); m->mothurOutEndLine(); abort = true; }                         
59                 }
60
61         }
62         catch(exception& e) {
63                 m->errorOut(e, "GetlabelCommand", "GetlabelCommand");
64                 exit(1);
65         }
66 }
67 //**********************************************************************************************************************
68
69 void GetlabelCommand::help(){
70         try {
71                 m->mothurOut("The get.label command can only be executed after a successful read.otu command.\n");
72                 m->mothurOut("You may not use any parameters with the get.label command.\n");
73                 m->mothurOut("The get.label command should be in the following format: \n");
74                 m->mothurOut("get.label()\n");
75                 m->mothurOut("Example get.label().\n");
76         }
77         catch(exception& e) {
78                 m->errorOut(e, "GetlabelCommand", "help");
79                 exit(1);
80         }
81 }
82
83 //**********************************************************************************************************************
84
85 GetlabelCommand::~GetlabelCommand(){
86 }
87
88 //**********************************************************************************************************************
89
90 int GetlabelCommand::execute(){
91         try {
92                 
93                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
94                 
95                 filename = globaldata->inputFileName;
96                 ifstream in;
97                 m->openInputFile(filename, in);
98                 string label;
99                 int numBins = 0;
100                 int count = -1;
101                 while(in.good()) {
102                         
103                         if (m->control_pressed) { in.close();  return 0; }
104                         
105                         if(count > numBins)
106                                 count = 0;
107                         if(count == 0) {
108                                 m->mothurOut(label); m->mothurOutEndLine();
109                                 in >> numBins;
110                         }
111                         in >> label;
112                         count++;
113                 }       
114                 
115                 in.close();
116                 return 0;       
117         }
118
119         catch(exception& e) {
120                 m->errorOut(e, "GetlabelCommand", "execute");
121                 exit(1);
122         }
123 }
124