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"
12 #include "sharednseqs.h"
14 //**********************************************************************************************************************
16 RareFactSharedCommand::RareFactSharedCommand(){
18 globaldata = GlobalData::getInstance();
20 fileNameRoot = getRootName(globaldata->inputFileName);
21 format = globaldata->getFormat();
22 validCalculator = new ValidCalculators();
25 for (i=0; i<globaldata->Estimators.size(); i++) {
26 if (validCalculator->isValidCalculator("sharedrarefaction", globaldata->Estimators[i]) == true) {
27 if (globaldata->Estimators[i] == "sharedobserved") {
28 rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"shared.rarefaction", "")));
29 }else if (globaldata->Estimators[i] == "sharednseqs") {
30 rDisplays.push_back(new RareDisplay(new SharedNSeqs(), new SharedThreeColumnFile(fileNameRoot+"shared.r_nseqs", "")));
36 //reset calc for next command
37 globaldata->setCalc("");
41 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
45 cout << "An unknown error has occurred in the RareFactSharedCommand class function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
51 //**********************************************************************************************************************
53 RareFactSharedCommand::~RareFactSharedCommand(){
60 //**********************************************************************************************************************
62 int RareFactSharedCommand::execute(){
66 //if the users entered no valid calculators don't execute command
67 if (rDisplays.size() == 0) { return 0; }
69 if (format == "sharedfile") {
70 read = new ReadPhilFile(globaldata->inputFileName);
71 read->read(&*globaldata);
73 input = globaldata->ginput;
74 order = input->getSharedOrderVector();
76 //you are using a list and a groupfile
77 read = new ReadPhilFile(globaldata->inputFileName);
78 read->read(&*globaldata);
80 input = globaldata->ginput;
81 SharedList = globaldata->gSharedList;
82 order = SharedList->getSharedOrderVector();
90 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
91 //create collectors curve
92 rCurve = new Rarefact(order, rDisplays);
93 convert(globaldata->getFreq(), freq);
94 convert(globaldata->getIters(), nIters);
95 rCurve->getSharedCurve(freq, nIters);
99 cout << order->getLabel() << '\t' << count << endl;
102 //get next line to process
103 if (format == "sharedfile") {
104 order = input->getSharedOrderVector();
106 //you are using a list and a groupfile
107 SharedList = input->getSharedListVector(); //get new list vector to process
108 if (SharedList != NULL) {
109 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
118 for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; }
120 //reset groups parameter
121 globaldata->Groups.clear(); globaldata->setGroups("");
125 catch(exception& e) {
126 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
130 cout << "An unknown error has occurred in the RareFactSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
136 //**********************************************************************************************************************
138 void RareFactSharedCommand::setGroups() {
140 //if the user has not entered specific groups to analyze then do them all
141 if (globaldata->Groups.size() != 0) {
142 if (globaldata->Groups[0] != "all") {
143 //check that groups are valid
144 for (int i = 0; i < globaldata->Groups.size(); i++) {
145 if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
146 cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
147 // erase the invalid group from globaldata->Groups
148 globaldata->Groups.erase(globaldata->Groups.begin()+i);
152 //if the user only entered invalid groups
153 if ((globaldata->Groups.size() == 0) || (globaldata->Groups.size() == 1)) {
154 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;
155 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
156 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
159 }else{//user has enter "all" and wants the default groups
160 globaldata->Groups.clear();
161 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
162 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
164 globaldata->setGroups("");
167 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
168 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
173 catch(exception& e) {
174 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
178 cout << "An unknown error has occurred in the RareFactSharedCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
183 /***********************************************************/