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 string lastLabel = SharedList->getLabel();
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(lastLabel) != 1)) {
74 SharedList = input->getSharedListVector(lastLabel); //get new list vector to process
76 lookup = SharedList->getSharedRAbundVector();
77 printSharedData(lookup); //prints info to the .shared file
78 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
80 processedLabels.insert(SharedList->getLabel());
81 userLabels.erase(SharedList->getLabel());
85 lastLabel = SharedList->getLabel();
88 SharedList = input->getSharedListVector(); //get new list vector to process
93 //output error messages about any remaining user labels
94 set<string>::iterator it;
95 bool needToRun = false;
96 for (it = userLabels.begin(); it != userLabels.end(); it++) {
97 //cout << "Your file does not include the label "<< *it;
98 if (processedLabels.count(lastLabel) != 1) {
99 //cout << ". I will use " << lastList->getLabel() << "." << endl;
102 //cout << ". Please refer to " << lastList->getLabel() << "." << endl;
106 //run last line if you need to
107 if (needToRun == true) {
109 SharedList = input->getSharedListVector(lastLabel); //get new list vector to process
111 lookup = SharedList->getSharedRAbundVector();
112 printSharedData(lookup); //prints info to the .shared file
113 for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; }
117 globaldata->gSharedList = NULL;
122 cout << "complete." << endl;
125 catch(exception& e) {
126 cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
130 cout << "An unknown error has occurred in the SharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
135 //**********************************************************************************************************************
136 void SharedCommand::printSharedData(vector<SharedRAbundVector*> thislookup) {
139 //initialize bin values
140 for (int i = 0; i < thislookup.size(); i++) {
141 out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t';
142 thislookup[i]->print(out);
146 catch(exception& e) {
147 cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
151 cout << "An unknown error has occurred in the SharedCommand class function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
157 //**********************************************************************************************************************
159 SharedCommand::~SharedCommand(){
165 //**********************************************************************************************************************