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