]> git.donarmstrong.com Git - mothur.git/blob - heatmapcommand.cpp
pds fixes of heatmap and some other minor stuff
[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                 util = new SharedUtil();
21                 
22         }
23         catch(exception& e) {
24                 cout << "Standard Error: " << e.what() << " has occurred in the HeatMapCommand class Function HeatMapCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
25                 exit(1);
26         }
27         catch(...) {
28                 cout << "An unknown error has occurred in the HeatMapCommand class function HeatMapCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
29                 exit(1);
30         }       
31 }
32 //**********************************************************************************************************************
33
34 HeatMapCommand::~HeatMapCommand(){
35         delete input;
36         delete read;
37         delete heatmap;
38         delete util;
39 }
40
41 //**********************************************************************************************************************
42
43 int HeatMapCommand::execute(){
44         try {
45                 int count = 1;  
46                 
47                 if (format == "sharedfile") {
48                         //you have groups
49                         read = new ReadPhilFile(globaldata->inputFileName);     
50                         read->read(&*globaldata); 
51                         
52                         input = globaldata->ginput;
53                         order = input->getSharedOrderVector();
54                 }else if (format == "shared") {
55                         //you are using a list and a groupfile
56                         read = new ReadPhilFile(globaldata->inputFileName);     
57                         read->read(&*globaldata); 
58                 
59                         input = globaldata->ginput;
60                         SharedList = globaldata->gSharedList;
61                         order = SharedList->getSharedOrderVector();
62                 }else if (format == "list") {
63                         //you are using just a list file and have only one group
64                         read = new ReadPhilFile(globaldata->inputFileName);     
65                         read->read(&*globaldata); 
66                         
67                         ordersingle = globaldata->gorder;
68                         input = globaldata->ginput;
69                 }
70                 
71                 if (format != "list") { 
72                 
73                         util->setGroups(globaldata->Groups, globaldata->gGroupmap->namesOfGroups, "heat");
74                         globaldata->setGroups("");
75
76
77                         while(order != NULL){
78                 
79                                 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){                       
80         
81                                         cout << order->getLabel() << '\t' << count << endl;
82                                         heatmap->getPic(order);
83
84                                 }
85                                                 
86                                 //get next line to process
87                                 if (format == "sharedfile") {
88                                         order = input->getSharedOrderVector();
89                                 }else {
90                                         //you are using a list and a groupfile
91                                         SharedList = input->getSharedListVector(); //get new list vector to process
92                                         if (SharedList != NULL) {
93                                                 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
94                                         }else {
95                                                 break;
96                                         }
97                                 }
98                                 count++;
99                         }
100                         
101                         //reset groups parameter
102                         globaldata->Groups.clear();  
103                         
104                 }else{
105                         while(ordersingle != NULL){
106                 
107                                 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(ordersingle->getLabel()) == 1){                 
108         
109                                         cout << ordersingle->getLabel() << '\t' << count << endl;
110                                         heatmap->getPic(ordersingle);
111                                         
112                                 }
113                                 
114                                 ordersingle = (input->getOrderVector());
115                                 count++;
116                         }
117                 }
118                 
119                 return 0;
120         }
121         catch(exception& e) {
122                 cout << "Standard Error: " << e.what() << " has occurred in the HeatMapCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
123                 exit(1);
124         }
125         catch(...) {
126                 cout << "An unknown error has occurred in the HeatMapCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
127                 exit(1);
128         }               
129 }
130
131 //**********************************************************************************************************************
132
133