]> git.donarmstrong.com Git - mothur.git/blob - heatmapcommand.cpp
working on pam
[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 vector<string> HeatMapCommand::setParameters(){ 
14         try {
15                 CommandParameter plist("list", "InputTypes", "", "", "LRSS", "LRSS", "none","svg",false,false,true); parameters.push_back(plist);
16                 CommandParameter prabund("rabund", "InputTypes", "", "", "LRSS", "LRSS", "none","svg",false,false); parameters.push_back(prabund);
17                 CommandParameter psabund("sabund", "InputTypes", "", "", "LRSS", "LRSS", "none","svg",false,false); parameters.push_back(psabund);
18                 CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none","svg",false,false,true); parameters.push_back(pshared); 
19                 CommandParameter prelabund("relabund", "InputTypes", "", "", "LRSS", "LRSS", "none","svg",false,false); parameters.push_back(prelabund);
20                 CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups);
21                 CommandParameter pscale("scale", "Multiple", "log10-log2-linear", "log10", "", "", "","",false,false); parameters.push_back(pscale);
22                 CommandParameter psorted("sorted", "Multiple", "none-shared-topotu-topgroup", "shared", "", "", "","",false,false); parameters.push_back(psorted);
23                 CommandParameter pnumotu("numotu", "Number", "", "0", "", "", "","",false,false); parameters.push_back(pnumotu);
24                 CommandParameter pfontsize("fontsize", "Number", "", "24", "", "", "","",false,false); parameters.push_back(pfontsize);
25                 CommandParameter plabel("label", "String", "", "", "", "", "","",false,false); parameters.push_back(plabel);
26                 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(pinputdir);
27                 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "","",false,false); parameters.push_back(poutputdir);
28                 
29                 vector<string> myArray;
30                 for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
31                 return myArray;
32         }
33         catch(exception& e) {
34                 m->errorOut(e, "HeatMapCommand", "setParameters");
35                 exit(1);
36         }
37 }
38 //**********************************************************************************************************************
39 string HeatMapCommand::getHelpString(){ 
40         try {
41                 string helpString = "";
42                 helpString += "The heatmap.bin command parameters are shared, relabund, list, rabund, sabund, groups, sorted, scale, numotu, fontsize and label.  shared, relabund, list, rabund or sabund is required unless you have a valid current file.\n";
43                 helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like included in your heatmap.\n";
44                 helpString += "The sorted parameter allows you to order the otus displayed, default=shared, meaning display the shared otus first. Other options for sorted are none, meaning the exact representation of your otus, \n";
45                 helpString += "topotu, meaning the otus with the greatest abundance when totaled across groups, topgroup, meaning the top otus for each group. \n";
46                 helpString += "The scale parameter allows you to choose the range of color your bin information will be displayed with.\n";
47                 helpString += "The numotu parameter allows you to display only the top N otus, by default all the otus are displayed. You could choose to look at the top 10, by setting numotu=10. The default for sorted is topotu when numotu is used.\n";
48                 helpString += "The group names are separated by dashes. The label parameter allows you to select what distance levels you would like a heatmap created for, and are also separated by dashes.\n";
49                 helpString += "The fontsize parameter allows you to adjust the font size of the picture created, default=24.\n";
50                 helpString += "The heatmap.bin command should be in the following format: heatmap.bin(groups=yourGroups, sorted=yourSorted, label=yourLabels).\n";
51                 helpString += "Example heatmap.bin(groups=A-B-C, sorted=none, scale=log10).\n";
52                 helpString += "The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n";
53                 helpString += "The default value for scale is log10; your other options are log2 and linear.\n";
54                 helpString += "The heatmap.bin command outputs a .svg file for each label you specify.\n";
55                 helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n";
56                 return helpString;
57         }
58         catch(exception& e) {
59                 m->errorOut(e, "HeatMapCommand", "getHelpString");
60                 exit(1);
61         }
62 }
63
64 //**********************************************************************************************************************
65 string HeatMapCommand::getOutputPattern(string type) {
66     try {
67         string pattern = "";
68         
69         if (type == "svg") {  pattern = "[filename],svg"; } 
70         else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true;  }
71         
72         return pattern;
73     }
74     catch(exception& e) {
75         m->errorOut(e, "HeatMapCommand", "getOutputPattern");
76         exit(1);
77     }
78 }
79
80 //**********************************************************************************************************************
81 HeatMapCommand::HeatMapCommand(){       
82         try {
83                 abort = true; calledHelp = true; 
84                 setParameters();
85                 vector<string> tempOutNames;
86                 outputTypes["svg"] = tempOutNames;
87         }
88         catch(exception& e) {
89                 m->errorOut(e, "HeatMapCommand", "HeatMapCommand");
90                 exit(1);
91         }
92 }
93 //**********************************************************************************************************************
94
95 HeatMapCommand::HeatMapCommand(string option) {
96         try {
97                 abort = false; calledHelp = false;   
98                 allLines = 1;
99                 
100                 //allow user to run help
101                 if(option == "help") { help(); abort = true; calledHelp = true; }
102                 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
103                 
104                 else {
105                         vector<string> myArray = setParameters();
106                         
107                         OptionParser parser(option);
108                         map<string,string> parameters = parser.getParameters();
109                         map<string,string>::iterator it;
110                         
111                         ValidParameters validParameter;
112                         
113                         //check to make sure all parameters are valid for command
114                         for (it = parameters.begin(); it != parameters.end(); it++) { 
115                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
116                         }
117                         
118                         //initialize outputTypes
119                         vector<string> tempOutNames;
120                         outputTypes["svg"] = tempOutNames;
121                 
122                         //if the user changes the input directory command factory will send this info to us in the output parameter 
123                         string inputDir = validParameter.validFile(parameters, "inputdir", false);              
124                         if (inputDir == "not found"){   inputDir = "";          }
125                         else {
126                                 string path;
127                                 it = parameters.find("shared");
128                                 //user has given a template file
129                                 if(it != parameters.end()){ 
130                                         path = m->hasPath(it->second);
131                                         //if the user has not given a path then, add inputdir. else leave path alone.
132                                         if (path == "") {       parameters["shared"] = inputDir + it->second;           }
133                                 }
134                                 
135                                 it = parameters.find("rabund");
136                                 //user has given a template file
137                                 if(it != parameters.end()){ 
138                                         path = m->hasPath(it->second);
139                                         //if the user has not given a path then, add inputdir. else leave path alone.
140                                         if (path == "") {       parameters["rabund"] = inputDir + it->second;           }
141                                 }
142                                 
143                                 it = parameters.find("sabund");
144                                 //user has given a template file
145                                 if(it != parameters.end()){ 
146                                         path = m->hasPath(it->second);
147                                         //if the user has not given a path then, add inputdir. else leave path alone.
148                                         if (path == "") {       parameters["sabund"] = inputDir + it->second;           }
149                                 }
150                                 
151                                 it = parameters.find("list");
152                                 //user has given a template file
153                                 if(it != parameters.end()){ 
154                                         path = m->hasPath(it->second);
155                                         //if the user has not given a path then, add inputdir. else leave path alone.
156                                         if (path == "") {       parameters["list"] = inputDir + it->second;             }
157                                 }
158                                 
159                                 it = parameters.find("relabund");
160                                 //user has given a template file
161                                 if(it != parameters.end()){ 
162                                         path = m->hasPath(it->second);
163                                         //if the user has not given a path then, add inputdir. else leave path alone.
164                                         if (path == "") {       parameters["relabund"] = inputDir + it->second;         }
165                                 }
166                         }
167                         
168                         //check for required parameters
169                         listfile = validParameter.validFile(parameters, "list", true);
170                         if (listfile == "not open") { abort = true; }
171                         else if (listfile == "not found") { listfile = ""; }
172                         else {  format = "list"; inputfile = listfile; m->setListFile(listfile); }
173                         
174                         sabundfile = validParameter.validFile(parameters, "sabund", true);
175                         if (sabundfile == "not open") {  abort = true; }        
176                         else if (sabundfile == "not found") { sabundfile = ""; }
177                         else {  format = "sabund"; inputfile = sabundfile; m->setSabundFile(sabundfile); }
178                         
179                         rabundfile = validParameter.validFile(parameters, "rabund", true);
180                         if (rabundfile == "not open") {  abort = true; }        
181                         else if (rabundfile == "not found") { rabundfile = ""; }
182                         else {  format = "rabund"; inputfile = rabundfile; m->setRabundFile(rabundfile); }
183                         
184                         sharedfile = validParameter.validFile(parameters, "shared", true);
185                         if (sharedfile == "not open") { abort = true; } 
186                         else if (sharedfile == "not found") { sharedfile = ""; }
187                         else {  format = "sharedfile"; inputfile = sharedfile; m->setSharedFile(sharedfile); }
188                         
189                         relabundfile = validParameter.validFile(parameters, "relabund", true);
190                         if (relabundfile == "not open") {  abort = true; }      
191                         else if (relabundfile == "not found") { relabundfile = ""; }
192                         else {  format = "relabund"; inputfile = relabundfile; m->setRelAbundFile(relabundfile); }
193                         
194                         
195                         if ((sharedfile == "") && (listfile == "") && (rabundfile == "") && (sabundfile == "") && (relabundfile == "")) { 
196                                 //is there are current file available for any of these?
197                                 //give priority to shared, then list, then rabund, then sabund
198                                 //if there is a current shared file, use it
199                                 sharedfile = m->getSharedFile(); 
200                                 if (sharedfile != "") { inputfile = sharedfile; format = "sharedfile"; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
201                                 else { 
202                                         listfile = m->getListFile(); 
203                                         if (listfile != "") { inputfile = listfile; format = "list"; m->mothurOut("Using " + listfile + " as input file for the list parameter."); m->mothurOutEndLine(); }
204                                         else { 
205                                                 rabundfile = m->getRabundFile(); 
206                                                 if (rabundfile != "") { inputfile = rabundfile; format = "rabund"; m->mothurOut("Using " + rabundfile + " as input file for the rabund parameter."); m->mothurOutEndLine(); }
207                                                 else { 
208                                                         sabundfile = m->getSabundFile(); 
209                                                         if (sabundfile != "") { inputfile = sabundfile; format = "sabund"; m->mothurOut("Using " + sabundfile + " as input file for the sabund parameter."); m->mothurOutEndLine(); }
210                                                         else { 
211                                                                 relabundfile = m->getRelAbundFile(); 
212                                                                 if (relabundfile != "") { inputfile = relabundfile; format = "relabund"; m->mothurOut("Using " + relabundfile + " as input file for the relabund parameter."); m->mothurOutEndLine(); }
213                                                                 else { 
214                                                                         m->mothurOut("No valid current files. You must provide a list, sabund, rabund, relabund or shared file."); m->mothurOutEndLine(); 
215                                                                         abort = true;
216                                                                 }
217                                                         }
218                                                 }
219                                         }
220                                 }
221                         }
222                         
223                         
224                         //if the user changes the output directory command factory will send this info to us in the output parameter 
225                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = m->hasPath(inputfile);              }
226                         
227                         //check for optional parameter and set defaults
228                         // ...at some point should added some additional type checking...
229                         label = validParameter.validFile(parameters, "label", false);                   
230                         if (label == "not found") { label = ""; }
231                         else { 
232                                 if(label != "all") {  m->splitAtDash(label, labels);  allLines = 0;  }
233                                 else { allLines = 1;  }
234                         }
235                         
236                         
237                         groups = validParameter.validFile(parameters, "groups", false);                 
238                         if (groups == "not found") { groups = ""; }
239                         else { 
240                                 m->splitAtDash(groups, Groups);
241                                 m->setGroups(Groups);
242                         }
243                         
244                         string temp = validParameter.validFile(parameters, "numotu", false);            if (temp == "not found") { temp = "0"; }
245                         m->mothurConvert(temp, numOTU);
246                         
247                         temp = validParameter.validFile(parameters, "fontsize", false);                         if (temp == "not found") { temp = "24"; }
248                         m->mothurConvert(temp, fontSize);
249                         
250                         sorted = validParameter.validFile(parameters, "sorted", false);                         
251                         if (sorted == "not found") { 
252                                 //if numOTU is used change default
253                                 if (numOTU != 0) { sorted = "topotu"; }
254                                 else { sorted = "shared"; }
255                         }
256                  
257                         scale = validParameter.validFile(parameters, "scale", false);                           if (scale == "not found") { scale = "log10"; }
258                         
259                         if ((sorted != "none") && (sorted != "shared") && (sorted != "topotu") && (sorted != "topgroup")) { m->mothurOut(sorted + " is not a valid sorting option. Sorted options are: none, shared, topotu, topgroup"); m->mothurOutEndLine(); abort=true;  }
260                 }
261
262         }
263         catch(exception& e) {
264                 m->errorOut(e, "HeatMapCommand", "HeatMapCommand");
265                 exit(1);
266         }
267 }
268 //**********************************************************************************************************************
269
270 int HeatMapCommand::execute(){
271         try {
272         
273                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
274                 
275                 heatmap = new HeatMap(sorted, scale, numOTU, fontSize, outputDir, inputfile);
276
277                 string lastLabel;
278                 input = new InputData(inputfile, format);
279                 
280                 if (format == "sharedfile") {
281                         //you have groups
282                         lookup = input->getSharedRAbundVectors();
283                         lastLabel = lookup[0]->getLabel();
284         
285                 }else if ((format == "list") || (format == "rabund") || (format == "sabund")) {
286                         //you are using just a list file and have only one group
287                         rabund = input->getRAbundVector();
288                         lastLabel = rabund->getLabel();
289                 }else if (format == "relabund") {
290                         //you have groups
291                         lookupFloat = input->getSharedRAbundFloatVectors();
292                         lastLabel = lookupFloat[0]->getLabel();
293                 }
294                 
295                 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
296                 set<string> processedLabels;
297                 set<string> userLabels = labels;
298
299                 if (format == "sharedfile") {   
300                 
301                         //as long as you are not at the end of the file or done wih the lines you want
302                         while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
303                                 if (m->control_pressed) {
304                                         for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
305                                         for (int i = 0; i < outputNames.size(); i++) {  if (outputNames[i] != "control") {  m->mothurRemove(outputNames[i]);  } } outputTypes.clear();
306                                         m->clearGroups(); 
307                                         delete input; delete heatmap; return 0;
308                                 }
309                 
310                                 if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){                  
311         
312                                         m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
313                                         string outputFileName = heatmap->getPic(lookup);
314                                         outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName);
315                                         
316                                         processedLabels.insert(lookup[0]->getLabel());
317                                         userLabels.erase(lookup[0]->getLabel());
318                                 }
319                                 
320                                 if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
321                                         string saveLabel = lookup[0]->getLabel();
322                         
323                                         for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }  
324                         
325                                         lookup = input->getSharedRAbundVectors(lastLabel);
326                                         m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
327                                         
328                                         string outputFileName = heatmap->getPic(lookup);
329                                         outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName);
330                                         
331                                         processedLabels.insert(lookup[0]->getLabel());
332                                         userLabels.erase(lookup[0]->getLabel());
333                                         
334                                         //restore real lastlabel to save below
335                                         lookup[0]->setLabel(saveLabel);
336                                 }
337                                 
338                                 lastLabel = lookup[0]->getLabel();
339                                 //prevent memory leak
340                                 for (int i = 0; i < lookup.size(); i++) {  delete lookup[i]; lookup[i] = NULL; }
341                                                         
342                                 //get next line to process
343                                 lookup = input->getSharedRAbundVectors();                               
344                         }
345                         
346                         
347                         if (m->control_pressed) {
348                                 for (int i = 0; i < outputNames.size(); i++) {  if (outputNames[i] != "control") {  m->mothurRemove(outputNames[i]);  } } outputTypes.clear();
349                                 m->clearGroups(); 
350                                 delete input; delete heatmap; return 0;
351                         }
352
353                         //output error messages about any remaining user labels
354                         set<string>::iterator it;
355                         bool needToRun = false;
356                         for (it = userLabels.begin(); it != userLabels.end(); it++) {  
357                                 m->mothurOut("Your file does not include the label " + *it); 
358                                 if (processedLabels.count(lastLabel) != 1) {
359                                         m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
360                                         needToRun = true;
361                                 }else {
362                                         m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
363                                 }
364                         }
365                 
366                         //run last label if you need to
367                         if (needToRun == true)  {
368                                 for (int i = 0; i < lookup.size(); i++) { if (lookup[i] != NULL) { delete lookup[i]; } }  
369                                 lookup = input->getSharedRAbundVectors(lastLabel);
370                                 
371                                 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
372                                 string outputFileName = heatmap->getPic(lookup);
373                                 outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName);
374                                 for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }
375                         }
376                 
377                         //reset groups parameter
378                         m->clearGroups();  
379                         
380                 }else if ((format == "list") || (format == "rabund") || (format == "sabund")) {
381         
382                         while((rabund != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
383                                 if (m->control_pressed) {   
384                                         for (int i = 0; i < outputNames.size(); i++) {  if (outputNames[i] != "control") {  m->mothurRemove(outputNames[i]);  } } outputTypes.clear();
385                                         delete rabund;  delete input; delete heatmap; return 0; 
386                                 }
387
388                                 if(allLines == 1 || labels.count(rabund->getLabel()) == 1){                     
389         
390                                         m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
391                                         string outputFileName = heatmap->getPic(rabund);
392                                         outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName);
393                                         
394                                         processedLabels.insert(rabund->getLabel());
395                                         userLabels.erase(rabund->getLabel());
396                                 }
397                                 
398                                 if ((m->anyLabelsToProcess(rabund->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
399                                         string saveLabel = rabund->getLabel();
400                                         
401                                         delete rabund;
402                                         rabund = input->getRAbundVector(lastLabel);
403                                         m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
404                                         
405                                         string outputFileName = heatmap->getPic(rabund);
406                                         outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName);
407                                         
408                                         processedLabels.insert(rabund->getLabel());
409                                         userLabels.erase(rabund->getLabel());
410                                         
411                                         //restore real lastlabel to save below
412                                         rabund->setLabel(saveLabel);
413                                 }               
414                                 
415                                                                 
416                                                                 
417                                 lastLabel = rabund->getLabel();                 
418                                 delete rabund;
419                                 rabund = input->getRAbundVector();
420                         }
421                         
422                         if (m->control_pressed) {
423                                 for (int i = 0; i < outputNames.size(); i++) {  if (outputNames[i] != "control") {  m->mothurRemove(outputNames[i]);  } } outputTypes.clear();
424                                 delete input; delete heatmap; return 0;
425                         }
426
427                         //output error messages about any remaining user labels
428                         set<string>::iterator it;
429                         bool needToRun = false;
430                         for (it = userLabels.begin(); it != userLabels.end(); it++) {  
431                                 m->mothurOut("Your file does not include the label " + *it); 
432                                 if (processedLabels.count(lastLabel) != 1) {
433                                         m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
434                                         needToRun = true;
435                                 }else {
436                                         m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
437                                 }
438                         }
439                 
440                         //run last label if you need to
441                         if (needToRun == true)  {
442                 
443                                 if (rabund != NULL) {   delete rabund;  }
444                                 rabund = input->getRAbundVector(lastLabel);
445                                 m->mothurOut(rabund->getLabel()); m->mothurOutEndLine();
446                                         
447                                 string outputFileName = heatmap->getPic(rabund);
448                                 outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName);
449                                 delete rabund; 
450                         }
451                 
452                 }else {
453                 
454                         //as long as you are not at the end of the file or done wih the lines you want
455                         while((lookupFloat[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
456                                 if (m->control_pressed) {
457                                         for (int i = 0; i < lookupFloat.size(); i++) {  delete lookupFloat[i];  }
458                                         for (int i = 0; i < outputNames.size(); i++) {  if (outputNames[i] != "control") {  m->mothurRemove(outputNames[i]);  } } outputTypes.clear();
459                                         m->clearGroups(); 
460                                         delete input; delete heatmap; return 0;
461                                 }
462                 
463                                 if(allLines == 1 || labels.count(lookupFloat[0]->getLabel()) == 1){                     
464         
465                                         m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine();
466                                         string outputFileName = heatmap->getPic(lookupFloat);
467                                         outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName);
468                                         
469                                         processedLabels.insert(lookupFloat[0]->getLabel());
470                                         userLabels.erase(lookupFloat[0]->getLabel());
471                                 }
472                                 
473                                 if ((m->anyLabelsToProcess(lookupFloat[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
474                                         string saveLabel = lookupFloat[0]->getLabel();
475                                 
476                                         for (int i = 0; i < lookupFloat.size(); i++) {  delete lookupFloat[i];  }  
477                                         lookupFloat = input->getSharedRAbundFloatVectors(lastLabel);
478                                         m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine();
479                                         
480                                         string outputFileName = heatmap->getPic(lookupFloat);
481                                         outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName);
482                                         
483                                         processedLabels.insert(lookupFloat[0]->getLabel());
484                                         userLabels.erase(lookupFloat[0]->getLabel());
485                                         
486                                         //restore real lastlabel to save below
487                                         lookupFloat[0]->setLabel(saveLabel);
488                                 }
489                                 
490                                 lastLabel = lookupFloat[0]->getLabel();
491                                 //prevent memory leak
492                                 for (int i = 0; i < lookupFloat.size(); i++) {  delete lookupFloat[i]; lookupFloat[i] = NULL; }
493                                                         
494                                 //get next line to process
495                                 lookupFloat = input->getSharedRAbundFloatVectors();                             
496                         }
497                         
498                         
499                         if (m->control_pressed) {
500                                 for (int i = 0; i < outputNames.size(); i++) {  if (outputNames[i] != "control") {  m->mothurRemove(outputNames[i]);  } } outputTypes.clear();
501                                 m->clearGroups(); 
502                                 delete input; delete heatmap; return 0;
503                         }
504
505                         //output error messages about any remaining user labels
506                         set<string>::iterator it;
507                         bool needToRun = false;
508                         for (it = userLabels.begin(); it != userLabels.end(); it++) {  
509                                 m->mothurOut("Your file does not include the label " + *it); 
510                                 if (processedLabels.count(lastLabel) != 1) {
511                                         m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
512                                         needToRun = true;
513                                 }else {
514                                         m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
515                                 }
516                         }
517                 
518                         //run last label if you need to
519                         if (needToRun == true)  {
520                                 for (int i = 0; i < lookupFloat.size(); i++) { if (lookupFloat[i] != NULL) { delete lookupFloat[i]; } }  
521                                 lookupFloat = input->getSharedRAbundFloatVectors(lastLabel);
522                                 
523                                 m->mothurOut(lookupFloat[0]->getLabel()); m->mothurOutEndLine();
524                                 string outputFileName = heatmap->getPic(lookupFloat);
525                                 outputNames.push_back(outputFileName); outputTypes["svg"].push_back(outputFileName);
526                                 for (int i = 0; i < lookupFloat.size(); i++) {  delete lookupFloat[i];  }
527                         }
528                 
529                         //reset groups parameter
530                         m->clearGroups();  
531
532                 }
533                 
534                 delete input; 
535                 delete heatmap;
536                 
537                 if (m->control_pressed) {
538                         for (int i = 0; i < outputNames.size(); i++) {  if (outputNames[i] != "control") {  m->mothurRemove(outputNames[i]);  } } outputTypes.clear(); return 0;
539                 }
540                 
541                 m->mothurOutEndLine();
542                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
543                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
544                 m->mothurOutEndLine();
545
546                 return 0;
547         }
548         catch(exception& e) {
549                 m->errorOut(e, "HeatMapCommand", "execute");
550                 exit(1);
551         }
552 }
553
554 //**********************************************************************************************************************
555
556