]> git.donarmstrong.com Git - mothur.git/blob - heatmapcommand.cpp
added heatmap command
[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         }
22         catch(exception& e) {
23                 cout << "Standard Error: " << e.what() << " has occurred in the HeatMapCommand class Function HeatMapCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
24                 exit(1);
25         }
26         catch(...) {
27                 cout << "An unknown error has occurred in the HeatMapCommand class function HeatMapCommand. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
28                 exit(1);
29         }       
30 }
31 //**********************************************************************************************************************
32
33 HeatMapCommand::~HeatMapCommand(){
34         delete input;
35         delete read;
36         delete heatmap;
37 }
38
39 //**********************************************************************************************************************
40
41 int HeatMapCommand::execute(){
42         try {
43                 int count = 1;  
44                 
45                 if (format == "sharedfile") {
46                         //you have groups
47                         read = new ReadPhilFile(globaldata->inputFileName);     
48                         read->read(&*globaldata); 
49                         
50                         input = globaldata->ginput;
51                         order = input->getSharedOrderVector();
52                 }else if (format == "shared") {
53                         //you are using a list and a groupfile
54                         read = new ReadPhilFile(globaldata->inputFileName);     
55                         read->read(&*globaldata); 
56                 
57                         input = globaldata->ginput;
58                         SharedList = globaldata->gSharedList;
59                         order = SharedList->getSharedOrderVector();
60                 }else if (format == "list") {
61                         //you are using just a list file and have only one group
62                         read = new ReadPhilFile(globaldata->inputFileName);     
63                         read->read(&*globaldata); 
64                 
65                         ordersingle = globaldata->gorder;
66                         input = globaldata->ginput;
67                 }
68
69                 
70                 if (format != "list") { 
71                         
72                         setGroups();
73                         
74                         while(order != NULL){
75                 
76                                 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(order->getLabel()) == 1){                       
77         
78                                         cout << order->getLabel() << '\t' << count << endl;
79                                         heatmap->getPic(order);
80
81                                 }
82                                                 
83                                 //get next line to process
84                                 if (format == "sharedfile") {
85                                         order = input->getSharedOrderVector();
86                                 }else {
87                                         //you are using a list and a groupfile
88                                         SharedList = input->getSharedListVector(); //get new list vector to process
89                                         if (SharedList != NULL) {
90                                                 order = SharedList->getSharedOrderVector(); //gets new order vector with group info.
91                                         }else {
92                                                 break;
93                                         }
94                                 }
95                                 count++;
96                         }
97                         
98                         //reset groups parameter
99                         globaldata->Groups.clear();  globaldata->setGroups("");
100                         
101                 }else{
102                         while(ordersingle != NULL){
103                 
104                                 if(globaldata->allLines == 1 || globaldata->lines.count(count) == 1 || globaldata->labels.count(ordersingle->getLabel()) == 1){                 
105         
106                                         cout << ordersingle->getLabel() << '\t' << count << endl;
107                                         heatmap->getPic(ordersingle);
108                                         
109                                 }
110                                 
111                                 ordersingle = (input->getOrderVector());
112                                 count++;
113                         }
114                 }
115                 
116                 return 0;
117         }
118         catch(exception& e) {
119                 cout << "Standard Error: " << e.what() << " has occurred in the HeatMapCommand class Function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
120                 exit(1);
121         }
122         catch(...) {
123                 cout << "An unknown error has occurred in the HeatMapCommand class function execute. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
124                 exit(1);
125         }               
126 }
127
128 //**********************************************************************************************************************
129 void HeatMapCommand::setGroups() {
130         try {
131                 //if the user has not entered specific groups to analyze then do them all
132                 if (globaldata->Groups.size() != 0) {
133                         if (globaldata->Groups[0] != "all") {
134                                 //check that groups are valid
135                                 for (int i = 0; i < globaldata->Groups.size(); i++) {
136                                         if (globaldata->gGroupmap->isValidGroup(globaldata->Groups[i]) != true) {
137                                                 cout << globaldata->Groups[i] << " is not a valid group, and will be disregarded." << endl;
138                                                 // erase the invalid group from globaldata->Groups
139                                                 globaldata->Groups.erase(globaldata->Groups.begin()+i);
140                                         }
141                                 }
142                         
143                                 //if the user only entered invalid groups
144                                 if (globaldata->Groups.size() == 0) { 
145                                         cout << "When using the groups parameter you must have at least 1 valid groups. I will run the command using all the groups in your groupfile." << endl; 
146                                         for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
147                                                 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
148                                         }
149                                 }
150                         }else{//user has enter "all" and wants the default groups
151                                 globaldata->Groups.clear();
152                                 for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
153                                         globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
154                                 }
155                                 globaldata->setGroups("");
156                         }
157                 }else {
158                         for (int i = 0; i < globaldata->gGroupmap->namesOfGroups.size(); i++) {
159                                 globaldata->Groups.push_back(globaldata->gGroupmap->namesOfGroups[i]);
160                         }
161                 }
162                 
163         }
164         catch(exception& e) {
165                 cout << "Standard Error: " << e.what() << " has occurred in the HeatMapCommand class Function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
166                 exit(1);
167         }
168         catch(...) {
169                 cout << "An unknown error has occurred in the HeatMapCommand class function setGroups. Please contact Pat Schloss at pschloss@microbio.umass.edu." << "\n";
170                 exit(1);
171         }               
172
173 }
174 /***********************************************************/
175