5 * Created by Sarah Westcott on 6/2/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "getsabundcommand.h"
12 //**********************************************************************************************************************
14 GetSAbundCommand::GetSAbundCommand(){
16 globaldata = GlobalData::getInstance();
17 filename = getRootName(globaldata->inputFileName) + "sabund";
19 openOutputFile(filename, out);
22 cout << "Standard Error: " << e.what() << " has occurred in the GetSAbundCommand class Function GetSAbundCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
26 cout << "An unknown error has occurred in the GetSAbundCommand class function GetSAbundCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
32 //**********************************************************************************************************************
34 GetSAbundCommand::~GetSAbundCommand(){
37 //**********************************************************************************************************************
39 int GetSAbundCommand::execute(){
43 //using order vector so you don't have to distinguish between the list and rabund files
44 read = new ReadOTUFile(globaldata->inputFileName);
45 read->read(&*globaldata);
47 order = globaldata->gorder;
49 input = globaldata->ginput;
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((order != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
59 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
60 cout << order->getLabel() << '\t' << count << endl;
61 sabund = new SAbundVector();
62 *sabund = (order->getSAbundVector());
66 processedLabels.insert(order->getLabel());
67 userLabels.erase(order->getLabel());
68 userLines.erase(count);
71 if ((anyLabelsToProcess(order->getLabel(), userLabels, "") == true) && (processedLabels.count(lastOrder->getLabel()) != 1)) {
72 cout << lastOrder->getLabel() << '\t' << count << endl;
73 sabund = new SAbundVector();
74 *sabund = (lastOrder->getSAbundVector());
78 processedLabels.insert(lastOrder->getLabel());
79 userLabels.erase(lastOrder->getLabel());
82 if (count != 1) { delete lastOrder; }
85 order = (input->getOrderVector());
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(lastOrder->getLabel()) != 1) {
95 cout << ". I will use " << lastOrder->getLabel() << "." << endl;
98 cout << ". Please refer to " << lastOrder->getLabel() << "." << endl;
102 //run last line if you need to
103 if (needToRun == true) {
104 cout << lastOrder->getLabel() << '\t' << count << endl;
105 sabund = new SAbundVector();
106 *sabund = (lastOrder->getSAbundVector());
116 catch(exception& e) {
117 cout << "Standard Error: " << e.what() << " has occurred in the GetSAbundCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
121 cout << "An unknown error has occurred in the GetSAbundCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
126 //**********************************************************************************************************************