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();
41 string errorOff = "no error";
44 read = new ReadOTUFile(globaldata->inputFileName);
45 read->read(&*globaldata);
47 input = globaldata->ginput;
48 SharedList = globaldata->gSharedList;
49 SharedListVector* lastList = SharedList;
50 //lookup = SharedList->getSharedRAbundVector();
51 //vector<SharedRAbundVector*> lastLookup = 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;
58 shared = new Shared();
60 while((SharedList != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0) || (userLines.size() != 0))) {
63 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){
65 shared->getSharedVectors(SharedList); //fills sharedGroups with new info and updates sharedVector
66 printSharedData(); //prints info to the .shared file
68 processedLabels.insert(SharedList->getLabel());
69 userLabels.erase(SharedList->getLabel());
70 userLines.erase(count);
73 if ((anyLabelsToProcess(SharedList->getLabel(), userLabels, errorOff) == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
74 shared->getSharedVectors(lastList); //fills sharedGroups with new info and updates sharedVector
75 printSharedData(); //prints info to the .shared file
77 processedLabels.insert(lastList->getLabel());
78 userLabels.erase(lastList->getLabel());
81 if (count != 1) { delete lastList; }
82 lastList = SharedList;
83 SharedList = input->getSharedListVector(); //get new list vector to process
85 //if (count != 1) { for (int i = 0; i < lastLookup.size(); i++) { delete lastLookup[i]; } }
86 //lastLookup = lookup;
87 //if (SharedList != NULL) { lookup = SharedList->getSharedRAbundVector(); }
90 //output error messages about any remaining user labels
91 set<string>::iterator it;
92 bool needToRun = false;
93 for (it = userLabels.begin(); it != userLabels.end(); it++) {
94 //cout << "Your file does not include the label "<< *it;
95 if (processedLabels.count(lastList->getLabel()) != 1) {
96 //cout << ". I will use " << lastList->getLabel() << "." << endl;
99 //cout << ". Please refer to " << lastList->getLabel() << "." << endl;
103 //run last line if you need to
104 if (needToRun == true) {
105 shared->getSharedVectors(lastList); //fills sharedGroups with new info and updates sharedVector
106 printSharedData(); //prints info to the .shared file
115 catch(exception& e) {
116 cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
120 cout << "An unknown error has occurred in the SharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
125 //**********************************************************************************************************************
126 void SharedCommand::printSharedData() {
129 ///for (int i = 0; i < thislookup.size(); i++) {
130 // out << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << '\t';
131 //cout << thislookup[i]->getLabel() << '\t' << thislookup[i]->getGroup() << endl;
132 // thislookup[i]->print(out);
134 //prints out horizontally
135 for (it = shared->sharedGroups.begin(); it != shared->sharedGroups.end(); it++) {
136 out << it->second->getLabel() << "\t" << it->first << "\t"; //prints out label and groupname
137 it->second->print(out); // prints sharedrabundvector
140 catch(exception& e) {
141 cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
145 cout << "An unknown error has occurred in the SharedCommand class function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
151 //**********************************************************************************************************************
153 SharedCommand::~SharedCommand(){
159 //**********************************************************************************************************************