]> git.donarmstrong.com Git - mothur.git/blob - getlabelcommand.cpp
added logfile feature
[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 != "") { mothurOut("There are no valid parameters for the get.label command."); mothurOutEndLine(); abort = true; }
24                         
25                         if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { mothurOut("You must read a list, sabund or rabund before you can use the get.label command."); mothurOutEndLine(); abort = true; }                               
26                 }
27
28         }
29         catch(exception& e) {
30                 errorOut(e, "GetlabelCommand", "GetlabelCommand");
31                 exit(1);
32         }
33 }
34 //**********************************************************************************************************************
35
36 void GetlabelCommand::help(){
37         try {
38                 mothurOut("The get.label command can only be executed after a successful read.otu command.\n");
39                 mothurOut("You may not use any parameters with the get.label command.\n");
40                 mothurOut("The get.label command should be in the following format: \n");
41                 mothurOut("get.label()\n");
42                 mothurOut("Example get.label().\n");
43         }
44         catch(exception& e) {
45                 errorOut(e, "GetlabelCommand", "help");
46                 exit(1);
47         }
48 }
49
50 //**********************************************************************************************************************
51
52 GetlabelCommand::~GetlabelCommand(){
53 }
54
55 //**********************************************************************************************************************
56
57 int GetlabelCommand::execute(){
58         try {
59                 
60                 if (abort == true) { return 0; }
61                 
62                 filename = globaldata->inputFileName;
63                 ifstream in;
64                 openInputFile(filename, in);
65                 string label;
66                 int numBins = 0;
67                 int count = -1;
68                 while(in.good()) {
69                         if(count > numBins)
70                                 count = 0;
71                         if(count == 0) {
72                                 mothurOut(label); mothurOutEndLine();
73                                 in >> numBins;
74                         }
75                         in >> label;
76                         count++;
77                 }       
78                 
79                 in.close();
80                 return 0;       
81         }
82
83         catch(exception& e) {
84                 errorOut(e, "GetlabelCommand", "execute");
85                 exit(1);
86         }
87 }
88