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(){
38 globaldata = GlobalData::getInstance();
40 string errorOff = "no error";
43 read = new ReadOTUFile(globaldata->inputFileName);
44 read->read(&*globaldata);
45 input = globaldata->ginput;
46 SharedList = globaldata->gSharedList;
47 SharedListVector* lastList = SharedList;
49 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
50 set<string> processedLabels;
51 set<string> userLabels = globaldata->labels;
52 set<int> userLines = globaldata->lines;
54 shared = new Shared();
56 while((SharedList != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
59 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){
61 shared->getSharedVectors(SharedList); //fills sharedGroups with new info and updates sharedVector
62 printSharedData(); //prints info to the .shared file
64 processedLabels.insert(SharedList->getLabel());
65 userLabels.erase(SharedList->getLabel());
66 userLines.erase(count);
69 if ((anyLabelsToProcess(SharedList->getLabel(), userLabels, errorOff) == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
70 shared->getSharedVectors(lastList); //fills sharedGroups with new info and updates sharedVector
71 printSharedData(); //prints info to the .shared file
73 processedLabels.insert(lastList->getLabel());
74 userLabels.erase(lastList->getLabel());
77 if (count != 1) { delete lastList; }
78 lastList = SharedList;
80 SharedList = input->getSharedListVector(); //get new list vector to process
83 //output error messages about any remaining user labels
84 set<string>::iterator it;
85 bool needToRun = false;
86 for (it = userLabels.begin(); it != userLabels.end(); it++) {
87 //cout << "Your file does not include the label "<< *it;
88 if (processedLabels.count(lastList->getLabel()) != 1) {
89 //cout << ". I will use " << lastList->getLabel() << "." << endl;
92 //cout << ". Please refer to " << lastList->getLabel() << "." << endl;
96 //run last line if you need to
97 if (needToRun == true) {
98 shared->getSharedVectors(lastList); //fills sharedGroups with new info and updates sharedVector
99 printSharedData(); //prints info to the .shared file
107 catch(exception& e) {
108 cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
112 cout << "An unknown error has occurred in the SharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
117 //**********************************************************************************************************************
118 void SharedCommand::printSharedData() {
120 //prints out horizontally
121 for (it = shared->sharedGroups.begin(); it != shared->sharedGroups.end(); it++) {
122 out << it->second->getLabel() << "\t" << it->first << "\t"; //prints out label and groupname
123 it->second->print(out); // prints sharedrabundvector
126 catch(exception& e) {
127 cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
131 cout << "An unknown error has occurred in the SharedCommand class function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
137 //**********************************************************************************************************************
139 SharedCommand::~SharedCommand(){
145 //**********************************************************************************************************************