5 * Created by Sarah Westcott on 6/2/09.
6 * Copyright 2009 __MyCompanyName__. All rights reserved.
10 #include "getrabundcommand.h"
12 //**********************************************************************************************************************
14 GetRAbundCommand::GetRAbundCommand(){
16 globaldata = GlobalData::getInstance();
17 filename = getRootName(globaldata->inputFileName) + "rabund";
19 openOutputFile(filename, out);
22 cout << "Standard Error: " << e.what() << " has occurred in the GetRAbundCommand class Function GetRAbundCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
26 cout << "An unknown error has occurred in the GetRAbundCommand class function GetRAbundCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
32 //**********************************************************************************************************************
34 GetRAbundCommand::~GetRAbundCommand(){
37 //**********************************************************************************************************************
39 int GetRAbundCommand::execute(){
44 read = new ReadOTUFile(globaldata->inputFileName);
45 read->read(&*globaldata);
47 input = globaldata->ginput;
48 list = globaldata->gListVector;
49 ListVector* lastList = list;
51 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
52 set<string> processedLabels;
53 set<string> userLabels = globaldata->labels;
54 set<int> userLines = globaldata->lines;
57 while((list != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
59 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(list->getLabel()) == 1){
60 cout << list->getLabel() << '\t' << count << endl;
61 rabund = new RAbundVector();
62 *rabund = (list->getRAbundVector());
66 processedLabels.insert(list->getLabel());
67 userLabels.erase(list->getLabel());
68 userLines.erase(count);
71 if ((anyLabelsToProcess(list->getLabel(), userLabels, "") == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
72 cout << lastList->getLabel() << '\t' << count << endl;
73 rabund = new RAbundVector();
74 *rabund = (lastList->getRAbundVector());
78 processedLabels.insert(lastList->getLabel());
79 userLabels.erase(lastList->getLabel());
82 if (count != 1) { delete lastList; }
85 list = input->getListVector();
89 //output error messages about any remaining user labels
90 set<string>::iterator it;
91 bool needToRun = false;
92 for (it = userLabels.begin(); it != userLabels.end(); it++) {
93 cout << "Your file does not include the label "<< *it;
94 if (processedLabels.count(lastList->getLabel()) != 1) {
95 cout << ". I will use " << lastList->getLabel() << "." << endl;
98 cout << ". Please refer to " << lastList->getLabel() << "." << endl;
102 //run last line if you need to
103 if (needToRun == true) {
104 cout << lastList->getLabel() << '\t' << count << endl;
105 rabund = new RAbundVector();
106 *rabund = (lastList->getRAbundVector());
116 catch(exception& e) {
117 cout << "Standard Error: " << e.what() << " has occurred in the GetRAbundCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
121 cout << "An unknown error has occurred in the GetRAbundCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
126 //**********************************************************************************************************************