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();
26 for (i=0; i<globaldata->Estimators.size(); i++) {
27 if (validCalculator->isValidCalculator("sharedrarefaction", globaldata->Estimators[i]) == true) {
28 if (globaldata->Estimators[i] == "sharedobserved") {
29 rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"shared.rarefaction", "")));
34 //reset calc for next command
35 globaldata->setCalc("");
39 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
43 cout << "An unknown error has occurred in the RareFactSharedCommand class function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
49 //**********************************************************************************************************************
51 RareFactSharedCommand::~RareFactSharedCommand(){
58 //**********************************************************************************************************************
60 int RareFactSharedCommand::execute(){
64 //if the users entered no valid calculators don't execute command
65 if (rDisplays.size() == 0) { return 0; }
67 if (format == "sharedfile") {
68 read = new ReadPhilFile(globaldata->inputFileName);
69 read->read(&*globaldata);
71 input = globaldata->ginput;
72 order = input->getSharedOrderVector();
74 //you are using a list and a groupfile
75 read = new ReadPhilFile(globaldata->inputFileName);
76 read->read(&*globaldata);
78 input = globaldata->ginput;
79 SharedList = globaldata->gSharedList;
80 order = SharedList->getSharedOrderVector();
85 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
86 //create collectors curve
87 rCurve = new Rarefact(order, rDisplays);
88 convert(globaldata->getFreq(), freq);
89 convert(globaldata->getIters(), nIters);
90 rCurve->getSharedCurve(freq, nIters);
94 cout << order->getLabel() << '\t' << count << endl;
97 //get next line to process
98 if (format == "sharedfile") {
99 order = input->getSharedOrderVector();
101 //you are using a list and a groupfile
102 SharedList = input->getSharedListVector(); //get new list vector to process
103 if (SharedList != NULL) {
104 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
113 for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; }
115 //reset groups parameter
116 globaldata->Groups.clear(); globaldata->setGroups("");
120 catch(exception& e) {
121 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
125 cout << "An unknown error has occurred in the RareFactSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
131 //**********************************************************************************************************************
133 void RareFactSharedCommand::setGroups() {
135 //if the user has not entered specific groups to analyze then do them all
136 if (globaldata->Groups.size() != 0) {
137 if (globaldata->Groups[0] != "all") {
138 //check that groups are valid
139 for (int i = 0; i < globaldata->Groups.size(); i++) {
140 if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
141 cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
142 // erase the invalid group from globaldata->Groups
143 globaldata->Groups.erase(globaldata->Groups.begin()+i);
147 //if the user only entered invalid groups
148 if ((globaldata->Groups.size() == 0) || (globaldata->Groups.size() == 1)) {
149 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;
150 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
151 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
154 }else{//user has enter "all" and wants the default groups
155 globaldata->Groups.clear();
156 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
157 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
159 globaldata->setGroups("");
162 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
163 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
168 catch(exception& e) {
169 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
173 cout << "An unknown error has occurred in the RareFactSharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
178 /***********************************************************/