]> git.donarmstrong.com Git - mothur.git/blob - getlinecommand.cpp
800f9d816eab2230d2f543321d0ddb5c97e1ee63
[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 != "") { cout << "There are no valid parameters for the get.line command." << endl; abort = true; }
23                         
24                         if ((globaldata->getListFile() == "") && (globaldata->getRabundFile() == "") && (globaldata->getSabundFile() == "")) { cout << "You must read a list, sabund or rabund before you can use the get.line command." << endl; abort = true; }                               
25                 }
26
27         }
28         catch(exception& e) {
29                 cout << "Standard Error: " << e.what() << " has occurred in the GetlineCommand class Function GetlineCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
30                 exit(1);
31         }
32         catch(...) {
33                 cout << "An unknown error has occurred in the GetlineCommand class function GetlineCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
34                 exit(1);
35         }       
36                         
37 }
38 //**********************************************************************************************************************
39
40 void GetlineCommand::help(){
41         try {
42                 cout << "The get.line command can only be executed after a successful read.otu command." << "\n";
43                 cout << "You may not use any parameters with the get.line command." << "\n";
44                 cout << "The get.line command should be in the following format: " << "\n";
45                 cout << "get.line()" << "\n";
46                 cout << "Example get.line()." << "\n";
47         }
48         catch(exception& e) {
49                 cout << "Standard Error: " << e.what() << " has occurred in the GetlineCommand class Function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
50                 exit(1);
51         }
52         catch(...) {
53                 cout << "An unknown error has occurred in the GetlineCommand class function help. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
54                 exit(1);
55         }       
56 }
57
58 //**********************************************************************************************************************
59
60 GetlineCommand::~GetlineCommand(){
61 }
62
63 //**********************************************************************************************************************
64
65 int GetlineCommand::execute(){
66         try {
67         
68                 if (abort == true) { return 0; }
69         
70                 ifstream in;
71                 openInputFile(globaldata->inputFileName, in);
72                 string label;
73                 int numBins = 0;
74                 int count = -1;
75                 int line = 1;
76                 while(in.good()) {
77                         if(count > numBins)
78                                 count = 0;
79                         if(count == 0) {
80                                 cout << line << "\n";
81                                 in >> numBins;
82                                 line++;
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 GetlineCommand 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 GetlineCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
98                 exit(1);
99         }       
100 }
101
102
103