2 * rarefactsharedcommand.cpp
5 * Created by Sarah Westcott on 1/6/09.
6 * Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
10 #include "rarefactsharedcommand.h"
11 #include "sharedsobs.h"
13 //**********************************************************************************************************************
15 RareFactSharedCommand::RareFactSharedCommand(){
17 globaldata = GlobalData::getInstance();
19 fileNameRoot = getRootName(globaldata->inputFileName);
20 format = globaldata->getFormat();
21 validCalculator = new ValidCalculators();
24 for (i=0; i<globaldata->Estimators.size(); i++) {
25 if (validCalculator->isValidCalculator("sharedrarefaction", globaldata->Estimators[i]) == true) {
26 if (globaldata->Estimators[i] == "sharedobserved") {
27 rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"shared.rarefaction", "")));
32 //reset calc for next command
33 globaldata->setCalc("");
37 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
41 cout << "An unknown error has occurred in the RareFactSharedCommand class function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
47 //**********************************************************************************************************************
49 RareFactSharedCommand::~RareFactSharedCommand(){
56 //**********************************************************************************************************************
58 int RareFactSharedCommand::execute(){
62 //if the users entered no valid calculators don't execute command
63 if (rDisplays.size() == 0) { return 0; }
65 if (format == "sharedfile") {
66 read = new ReadPhilFile(globaldata->inputFileName);
67 read->read(&*globaldata);
69 input = globaldata->ginput;
70 order = input->getSharedOrderVector();
72 //you are using a list and a groupfile
73 read = new ReadPhilFile(globaldata->inputFileName);
74 read->read(&*globaldata);
76 input = globaldata->ginput;
77 SharedList = globaldata->gSharedList;
78 order = SharedList->getSharedOrderVector();
86 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
87 //create collectors curve
88 rCurve = new Rarefact(order, rDisplays);
89 convert(globaldata->getFreq(), freq);
90 convert(globaldata->getIters(), nIters);
91 rCurve->getSharedCurve(freq, nIters);
95 cout << order->getLabel() << '\t' << count << endl;
98 //get next line to process
99 if (format == "sharedfile") {
100 order = input->getSharedOrderVector();
102 //you are using a list and a groupfile
103 SharedList = input->getSharedListVector(); //get new list vector to process
104 if (SharedList != NULL) {
105 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
114 for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; }
116 //reset groups parameter
117 globaldata->Groups.clear(); globaldata->setGroups("");
121 catch(exception& e) {
122 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
126 cout << "An unknown error has occurred in the RareFactSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
132 //**********************************************************************************************************************
134 void RareFactSharedCommand::setGroups() {
136 //if the user has not entered specific groups to analyze then do them all
137 if (globaldata->Groups.size() != 0) {
138 if (globaldata->Groups[0] != "all") {
139 //check that groups are valid
140 for (int i = 0; i < globaldata->Groups.size(); i++) {
141 if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
142 cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
143 // erase the invalid group from globaldata->Groups
144 globaldata->Groups.erase(globaldata->Groups.begin()+i);
148 //if the user only entered invalid groups
149 if ((globaldata->Groups.size() == 0) || (globaldata->Groups.size() == 1)) {
150 cout << "When using the groups parameter you must have at least 2 valid groups. I will run the command using all the groups in your groupfile." << endl;
151 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
152 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
155 }else{//user has enter "all" and wants the default groups
156 globaldata->Groups.clear();
157 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
158 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
160 globaldata->setGroups("");
163 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
164 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
169 catch(exception& e) {
170 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
174 cout << "An unknown error has occurred in the RareFactSharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
179 /***********************************************************/