]> git.donarmstrong.com Git - mothur.git/blob - rarefactsharedcommand.cpp
Initial revision
[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, groups;
19                 fileNameRoot = getRootName(globaldata->inputFileName);
20                 groupmap = globaldata->gGroupmap;
21                 
22                 //initialize groups for label
23                 groups = "";
24                 for (int i = 0; i < groupmap->namesOfGroups.size(); i++) {
25                         groups = groups + groupmap->namesOfGroups[i];
26                 }
27                 
28                 int i;
29                 for (i=0; i<globaldata->sharedRareEstimators.size(); i++) {
30                         if (globaldata->sharedRareEstimators[i] == "sharedobserved") { 
31                                 rDisplays.push_back(new RareDisplay(new SharedSobs(), new SharedThreeColumnFile(fileNameRoot+"sharedObserved", groups)));
32                         }
33                 }
34         }
35         catch(exception& e) {
36                 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
37                 exit(1);
38         }
39         catch(...) {
40                 cout << "An unknown error has occurred in the RareFactSharedCommand class function RareFactSharedCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
41                 exit(1);
42         }       
43                         
44 }
45
46 //**********************************************************************************************************************
47
48 RareFactSharedCommand::~RareFactSharedCommand(){
49         delete order;
50         delete input;
51         delete rCurve;
52         delete read;
53 }
54
55 //**********************************************************************************************************************
56
57 int RareFactSharedCommand::execute(){
58         try {
59                 int count = 1;
60                 read = new ReadPhilFile(globaldata->inputFileName);     
61                 read->read(&*globaldata); 
62                 
63                 input = globaldata->ginput;
64                 list = globaldata->glist;
65                 order = list->getSharedOrderVector();
66                 
67                 while(order != NULL){
68                 
69                         if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){
70                                 //create collectors curve
71                                 rCurve = new Rarefact(order, rDisplays);
72                                 convert(globaldata->getFreq(), freq);
73                                 convert(globaldata->getIters(), nIters);
74                                 rCurve->getSharedCurve(freq, nIters);
75                         
76                                 delete rCurve;
77                         
78                                 cout << order->getLabel() << '\t' << count << endl;
79                         }
80                         
81                         list = input->getListVector(); //get new list vector to process
82                         if (list != NULL) {
83                                 order = list->getSharedOrderVector(); //gets new order vector with group info.
84                                 count++;
85                         }else {
86                                 break;
87                         }
88                 
89                 }
90         
91                 for(int i=0;i<rDisplays.size();i++){    delete rDisplays[i];    }       
92                 return 0;
93         }
94         catch(exception& e) {
95                 cout << "Standard Error: " << e.what() << " has occurred in the RareFactSharedCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
96                 exit(1);
97         }
98         catch(...) {
99                 cout << "An unknown error has occurred in the RareFactSharedCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
100                 exit(1);
101         }       
102 }
103
104
105 //**********************************************************************************************************************