5 * Created by Sarah Westcott on 1/2/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "sharedcommand.h"
12 //**********************************************************************************************************************
14 SharedCommand::SharedCommand(){
16 globaldata = GlobalData::getInstance();
18 //getting output filename
19 filename = globaldata->inputFileName;
20 filename = getRootName(filename);
21 filename = filename + "shared";
22 openOutputFile(filename, out);
25 cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function SharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
29 cout << "An unknown error has occurred in the SharedCommand class function SharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
34 //**********************************************************************************************************************
36 int SharedCommand::execute(){
39 cout << "creating sharedfile...";
42 string errorOff = "no error";
45 read = new ReadOTUFile(globaldata->inputFileName);
46 read->read(&*globaldata);
48 input = globaldata->ginput;
49 SharedList = globaldata->gSharedList;
50 SharedListVector* lastList = SharedList;
51 vector<SharedRAbundVector*> lookup;
53 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
54 set<string> processedLabels;
55 set<string> userLabels = globaldata->labels;
56 set<int> userLines = globaldata->lines;
59 while((SharedList != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
62 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){
63 lookup = SharedList->getSharedRAbundVector();
64 printSharedData(lookup); //prints info to the .shared file
65 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
67 processedLabels.insert(SharedList->getLabel());
68 userLabels.erase(SharedList->getLabel());
69 userLines.erase(count);
72 if ((anyLabelsToProcess(SharedList->getLabel(), userLabels, errorOff) == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
73 lookup = lastList->getSharedRAbundVector();
74 printSharedData(lookup); //prints info to the .shared file
75 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
77 processedLabels.insert(lastList->getLabel());
78 userLabels.erase(lastList->getLabel());
81 if (count != 1) { delete lastList; }
82 lastList = SharedList;
84 SharedList = input->getSharedListVector(); //get new list vector to process
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 lookup = lastList->getSharedRAbundVector();
105 printSharedData(lookup); //prints info to the .shared file
106 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
110 delete lastList; globaldata->gSharedList = NULL;
115 cout << "complete." << endl;
118 catch(exception& e) {
119 cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
123 cout << "An unknown error has occurred in the SharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
128 //**********************************************************************************************************************
129 void SharedCommand::printSharedData(vector<SharedRAbundVector*> thislookup) {
132 //initialize bin values
133 for (int i = 0; i < thislookup.size(); i++) {
134 out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t';
135 thislookup[i]->print(out);
139 catch(exception& e) {
140 cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
144 cout << "An unknown error has occurred in the SharedCommand class function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
150 //**********************************************************************************************************************
152 SharedCommand::~SharedCommand(){
158 //**********************************************************************************************************************