]> git.donarmstrong.com Git - mothur.git/blob - heatmapcommand.cpp
speed up rarefaction.shared
[mothur.git] / heatmapcommand.cpp
1 /*
2  *  heatmapcommand.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 3/25/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "heatmapcommand.h"
11
12
13 //**********************************************************************************************************************
14
15 HeatMapCommand::HeatMapCommand(){
16         try {
17                 globaldata = GlobalData::getInstance();
18                 heatmap = new HeatMap();
19                 format = globaldata->getFormat();
20         }
21         catch(exception& e) {
22                 cout << "Standard Error: " << e.what() << " has occurred in the HeatMapCommand class Function HeatMapCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
23                 exit(1);
24         }
25         catch(...) {
26                 cout << "An unknown error has occurred in the HeatMapCommand class function HeatMapCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
27                 exit(1);
28         }       
29 }
30 //**********************************************************************************************************************
31
32 HeatMapCommand::~HeatMapCommand(){
33         delete input;
34         delete read;
35         delete heatmap;
36 }
37
38 //**********************************************************************************************************************
39
40 int HeatMapCommand::execute(){
41         try {
42                 int count = 1;  
43         
44                 if (format == "sharedfile") {
45                         //you have groups
46                         read = new ReadOTUFile(globaldata->inputFileName);      
47                         read->read(&*globaldata); 
48                         
49                         input = globaldata->ginput;
50                         lookup = input->getSharedRAbundVectors();
51                 }else if (format == "list") {
52                         //you are using just a list file and have only one group
53                         read = new ReadOTUFile(globaldata->inputFileName);      
54                         read->read(&*globaldata); 
55                         
56                         rabund = globaldata->rabund;
57                         input = globaldata->ginput;             
58                 }
59                 
60                 if (format != "list") { 
61                 
62                         while(lookup[0] != NULL){
63                 
64                                 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(lookup[0]->getLabel()) == 1){                   
65         
66                                         cout << lookup[0]->getLabel() << '\t' << count << endl;
67                                         heatmap->getPic(lookup);
68                                 }
69                                 
70                                 //prevent memory leak
71                                 for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
72                                 
73                                 //get next line to process
74                                 lookup = input->getSharedRAbundVectors();                               
75                                 count++;
76                         }
77                         
78                         //reset groups parameter
79                         globaldata->Groups.clear();  
80                         
81                 }else{
82                 
83                         while(rabund != NULL){
84                 
85                                 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(rabund->getLabel()) == 1){                      
86         
87                                         cout << rabund->getLabel() << '\t' << count << endl;
88                                         heatmap->getPic(rabund);
89                                 }
90                                 
91                                 delete rabund;
92                                 rabund = input->getRAbundVector();
93                                 count++;
94                         }
95                 }
96                 
97                 globaldata->setGroups("");
98                 return 0;
99         }
100         catch(exception& e) {
101                 cout << "Standard Error: " << e.what() << " has occurred in the HeatMapCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
102                 exit(1);
103         }
104         catch(...) {
105                 cout << "An unknown error has occurred in the HeatMapCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
106                 exit(1);
107         }               
108 }
109
110 //**********************************************************************************************************************
111
112