]> git.donarmstrong.com Git - mothur.git/blob - rarefactsharedcommand.cpp
fixed memory leak in rarefact
[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 #include "sharednseqs.h"
13
14 //**********************************************************************************************************************
15
16 RareFactSharedCommand::RareFactSharedCommand(){
17         try {
18                 globaldata = GlobalData::getInstance();
19                 string fileNameRoot;
20                 fileNameRoot = getRootName(globaldata->inputFileName);
21                 format = globaldata->getFormat();
22                 validCalculator = new ValidCalculators();
23                 util = new SharedUtil();
24                                 
25                 int i;
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", "")));
32                                 }
33
34                         }
35                 }
36                 
37                 //reset calc for next command
38                 globaldata->setCalc("");
39
40         }
41         catch(exception& e) {
42                 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
43                 exit(1);
44         }
45         catch(...) {
46                 cout << "An unknown error has occurred in the RareFactSharedCommand class function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
47                 exit(1);
48         }       
49                         
50 }
51
52 //**********************************************************************************************************************
53
54 RareFactSharedCommand::~RareFactSharedCommand(){
55         delete order;
56         delete input;
57         delete rCurve;
58         delete read;
59         delete util;
60 }
61
62 //**********************************************************************************************************************
63
64 int RareFactSharedCommand::execute(){
65         try {
66                 int count = 1;
67                 
68                 //if the users entered no valid calculators don't execute command
69                 if (rDisplays.size() == 0) { return 0; }
70
71                 read = new ReadOTUFile(globaldata->inputFileName);      
72                 read->read(&*globaldata); 
73                         
74                 input = globaldata->ginput;
75                 order = input->getSharedOrderVector();
76                                 
77                 //set users groups
78                 util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "rarefact");
79                 
80                 while(order != NULL){
81                 
82                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
83                                 //create collectors curve
84                                 rCurve = new Rarefact(order, rDisplays);
85                                 convert(globaldata->getFreq(), freq);
86                                 convert(globaldata->getIters(), nIters);
87                                 rCurve->getSharedCurve(freq, nIters);
88                         
89                                 delete rCurve;
90                         
91                                 cout << order->getLabel() << '\t' << count << endl;
92                         }
93                         
94                         //get next line to process
95                         delete order;
96                         order = input->getSharedOrderVector();
97                         count++;
98                 }
99         
100                 for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }       
101                 
102                 //reset groups parameter
103                 globaldata->Groups.clear();  globaldata->setGroups("");
104
105                 return 0;
106         }
107         catch(exception& e) {
108                 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
109                 exit(1);
110         }
111         catch(...) {
112                 cout << "An unknown error has occurred in the RareFactSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
113                 exit(1);
114         }       
115 }
116
117
118 //**********************************************************************************************************************