]> git.donarmstrong.com Git - mothur.git/blob - rarefactsharedcommand.cpp
rarefaction.shared() fixed bug
[mothur.git] / rarefactsharedcommand.cpp
1 /*
2  *  rarefactsharedcommand.cpp
3  *  Dotur
4  *
5  *  Created by Sarah Westcott on 1/6/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "rarefactsharedcommand.h"
11 #include "sharedsobs.h"
12
13 //**********************************************************************************************************************
14
15 RareFactSharedCommand::RareFactSharedCommand(){
16         try {
17                 globaldata = GlobalData::getInstance();
18                 string fileNameRoot;
19                 fileNameRoot = getRootName(globaldata->inputFileName);
20                                 
21                 int i;
22                 for (i=0; i<globaldata->sharedRareEstimators.size(); i++) {
23                         if (globaldata->sharedRareEstimators[i] == "sharedobserved") { 
24                                 rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"shared.rarefaction", "")));
25                         }
26                 }
27         }
28         catch(exception& e) {
29                 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
30                 exit(1);
31         }
32         catch(...) {
33                 cout << "An unknown error has occurred in the RareFactSharedCommand class function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
34                 exit(1);
35         }       
36                         
37 }
38
39 //**********************************************************************************************************************
40
41 RareFactSharedCommand::~RareFactSharedCommand(){
42         delete order;
43         delete input;
44         delete rCurve;
45         delete read;
46 }
47
48 //**********************************************************************************************************************
49
50 int RareFactSharedCommand::execute(){
51         try {
52                 int count = 1;
53                 read = new ReadPhilFile(globaldata->inputFileName);     
54                 read->read(&*globaldata); 
55                 
56                 input = globaldata->ginput;
57                 SharedList = globaldata->gSharedList;
58                 order = SharedList->getSharedOrderVector();
59                 
60                 while(order != NULL){
61                 
62                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
63                                 //create collectors curve
64                                 rCurve = new Rarefact(order, rDisplays);
65                                 convert(globaldata->getFreq(), freq);
66                                 convert(globaldata->getIters(), nIters);
67                                 rCurve->getSharedCurve(freq, nIters);
68                         
69                                 delete rCurve;
70                         
71                                 cout << order->getLabel() << '\t' << count << endl;
72                         }
73                         
74                         SharedList = input->getSharedListVector(); //get new list vector to process
75                         if (SharedList != NULL) {
76                                 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
77                                 count++;
78                         }else {
79                                 break;
80                         }
81                 
82                 }
83         
84                 for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }       
85                 return 0;
86         }
87         catch(exception& e) {
88                 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
89                 exit(1);
90         }
91         catch(...) {
92                 cout << "An unknown error has occurred in the RareFactSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
93                 exit(1);
94         }       
95 }
96
97
98 //**********************************************************************************************************************