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();
23 util = new SharedUtil();
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", "")));
30 }else if (globaldata->Estimators[i] == "sharednseqs") {
31 rDisplays.push_back(new RareDisplay(new SharedNSeqs(), new SharedThreeColumnFile(fileNameRoot+"shared.r_nseqs", "")));
37 //reset calc for next command
38 globaldata->setCalc("");
42 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
46 cout << "An unknown error has occurred in the RareFactSharedCommand class function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
52 //**********************************************************************************************************************
54 RareFactSharedCommand::~RareFactSharedCommand(){
62 //**********************************************************************************************************************
64 int RareFactSharedCommand::execute(){
68 //if the users entered no valid calculators don't execute command
69 if (rDisplays.size() == 0) { return 0; }
71 if (format == "sharedfile") {
72 read = new ReadPhilFile(globaldata->inputFileName);
73 read->read(&*globaldata);
75 input = globaldata->ginput;
76 order = input->getSharedOrderVector();
78 //you are using a list and a groupfile
79 read = new ReadPhilFile(globaldata->inputFileName);
80 read->read(&*globaldata);
82 input = globaldata->ginput;
83 SharedList = globaldata->gSharedList;
84 order = SharedList->getSharedOrderVector();
88 util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "rarefact");
92 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
93 //create collectors curve
94 rCurve = new Rarefact(order, rDisplays);
95 convert(globaldata->getFreq(), freq);
96 convert(globaldata->getIters(), nIters);
97 rCurve->getSharedCurve(freq, nIters);
101 cout << order->getLabel() << '\t' << count << endl;
104 //get next line to process
105 if (format == "sharedfile") {
106 order = input->getSharedOrderVector();
108 //you are using a list and a groupfile
109 SharedList = input->getSharedListVector(); //get new list vector to process
110 if (SharedList != NULL) {
111 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
120 for(int i=0;i<rDisplays.size();i++){ delete rDisplays[i]; }
122 //reset groups parameter
123 globaldata->Groups.clear(); globaldata->setGroups("");
127 catch(exception& e) {
128 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
132 cout << "An unknown error has occurred in the RareFactSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
138 //**********************************************************************************************************************