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