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;
53 shared = new Shared();
55 while((SharedList != NULL) && ((globaldata->allLines == 1) || (userLabels.size() != 0))) {
58 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(SharedList->getLabel()) == 1){
60 shared->getSharedVectors(SharedList); //fills sharedGroups with new info and updates sharedVector
61 printSharedData(); //prints info to the .shared file
63 processedLabels.insert(SharedList->getLabel());
64 userLabels.erase(SharedList->getLabel());
67 if ((anyLabelsToProcess(SharedList->getLabel(), userLabels, errorOff) == true) && (processedLabels.count(lastList->getLabel()) != 1)) {
68 shared->getSharedVectors(lastList); //fills sharedGroups with new info and updates sharedVector
69 printSharedData(); //prints info to the .shared file
71 processedLabels.insert(lastList->getLabel());
72 userLabels.erase(lastList->getLabel());
75 if (count != 1) { delete lastList; }
76 lastList = SharedList;
78 SharedList = input->getSharedListVector(); //get new list vector to process
81 //output error messages about any remaining user labels
82 set<string>::iterator it;
83 bool needToRun = false;
84 for (it = userLabels.begin(); it != userLabels.end(); it++) {
85 //cout << "Your file does not include the label "<< *it;
86 if (processedLabels.count(lastList->getLabel()) != 1) {
87 //cout << ". I will use " << lastList->getLabel() << "." << endl;
90 //cout << ". Please refer to " << lastList->getLabel() << "." << endl;
94 //run last line if you need to
95 if (needToRun == true) {
96 shared->getSharedVectors(lastList); //fills sharedGroups with new info and updates sharedVector
97 printSharedData(); //prints info to the .shared file
105 catch(exception& e) {
106 cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
110 cout << "An unknown error has occurred in the SharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
115 //**********************************************************************************************************************
116 void SharedCommand::printSharedData() {
118 //prints out horizontally
119 for (it = shared->sharedGroups.begin(); it != shared->sharedGroups.end(); it++) {
120 out << it->second->getLabel() << "\t" << it->first << "\t"; //prints out label and groupname
121 it->second->print(out); // prints sharedrabundvector
124 catch(exception& e) {
125 cout << "Standard Error: " << e.what() << " has occurred in the SharedCommand class Function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
129 cout << "An unknown error has occurred in the SharedCommand class function printSharedData. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
135 //**********************************************************************************************************************
137 SharedCommand::~SharedCommand(){
143 //**********************************************************************************************************************