]> git.donarmstrong.com Git - mothur.git/blob - heatmapsimcommand.cpp
added load.logfile command. changed summary.single output for subsample=t.
[mothur.git] / heatmapsimcommand.cpp
1 /*
2  *  heatmapsimcommand.cpp
3  *  Mothur
4  *
5  *  Created by Sarah Westcott on 6/8/09.
6  *  Copyright 2009 Schloss Lab UMASS Amherst. All rights reserved.
7  *
8  */
9
10 #include "heatmapsimcommand.h"
11 #include "sharedjabund.h"
12 #include "sharedsorabund.h"
13 #include "sharedjclass.h"
14 #include "sharedsorclass.h"
15 #include "sharedjest.h"
16 #include "sharedsorest.h"
17 #include "sharedthetayc.h"
18 #include "sharedthetan.h"
19 #include "sharedmorisitahorn.h"
20 #include "sharedbraycurtis.h"
21
22
23 //**********************************************************************************************************************
24 vector<string> HeatMapSimCommand::setParameters(){      
25         try {
26                 CommandParameter pshared("shared", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none",false,false); parameters.push_back(pshared);        
27                 CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none",false,false); parameters.push_back(pphylip);
28                 CommandParameter pname("name", "InputTypes", "", "", "none", "none", "ColumnName",false,false); parameters.push_back(pname);
29                 CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "ColumnName",false,false); parameters.push_back(pcolumn);          
30                 CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
31                 CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
32                 CommandParameter pcalc("calc", "Multiple", "jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-morisitahorn-braycurtis", "jest-thetayc", "", "", "",true,false); parameters.push_back(pcalc);
33                 CommandParameter pfontsize("fontsize", "Number", "", "24", "", "", "",false,false); parameters.push_back(pfontsize);
34                 CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
35                 CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
36                 
37                 vector<string> myArray;
38                 for (int i = 0; i < parameters.size(); i++) {   myArray.push_back(parameters[i].name);          }
39                 return myArray;
40         }
41         catch(exception& e) {
42                 m->errorOut(e, "HeatMapSimCommand", "setParameters");
43                 exit(1);
44         }
45 }
46 //**********************************************************************************************************************
47 string HeatMapSimCommand::getHelpString(){      
48         try {
49                 string helpString = "";
50                 ValidCalculators validCalculator;
51                 helpString += "The heatmap.sim command parameters are shared, phylip, column, name, groups, calc, fontsize and label.  shared or phylip or column and name are required unless valid current files exist.\n";
52                 helpString += "There are two ways to use the heatmap.sim command. The first is with the read.otu command. \n";
53                 helpString += "With the read.otu command you may use the groups, label and calc parameters. \n";
54                 helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like included in your heatmap.\n";
55                 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 is also separated by dashes.\n";
56                 helpString += "The fontsize parameter allows you to adjust the font size of the picture created, default=24.\n";
57                 helpString += "The heatmap.sim command should be in the following format: heatmap.sim(groups=yourGroups, calc=yourCalc, label=yourLabels).\n";
58                 helpString += "Example heatmap.sim(groups=A-B-C, calc=jabund).\n";
59                 helpString += "The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n";
60                 helpString +=  validCalculator.printCalc("heat");
61                 helpString += "The default value for calc is jclass-thetayc.\n";
62                 helpString += "The heatmap.sim command outputs a .svg file for each calculator you choose at each label you specify.\n";
63                 helpString += "The second way to use the heatmap.sim command is with a distance file representing the distance bewteen your groups. \n";
64                 helpString += "Using the command this way, the phylip or column parameter are required, and only one may be used.  If you use a column file the name filename is required. \n";
65                 helpString += "The heatmap.sim command should be in the following format: heatmap.sim(phylip=yourDistanceFile).\n";
66                 helpString += "Example heatmap.sim(phylip=amazonGroups.dist).\n";
67                 helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n";
68                 return helpString;
69         }
70         catch(exception& e) {
71                 m->errorOut(e, "HeatMapSimCommand", "getHelpString");
72                 exit(1);
73         }
74 }
75 //**********************************************************************************************************************
76
77 string HeatMapSimCommand::getOutputFileNameTag(string type, string inputName=""){       
78         try {
79         string outputFileName = "";
80                 map<string, vector<string> >::iterator it;
81         
82         //is this a type this command creates
83         it = outputTypes.find(type);
84         if (it == outputTypes.end()) {  m->mothurOut("[ERROR]: this command doesn't create a " + type + " output file.\n"); }
85         else {
86             if (type == "svg")            {   outputFileName =  "svg";   }
87             else { m->mothurOut("[ERROR]: No definition for type " + type + " output file tag.\n"); m->control_pressed = true;  }
88         }
89         return outputFileName;
90         }
91         catch(exception& e) {
92                 m->errorOut(e, "HeatMapSimCommand", "getOutputFileNameTag");
93                 exit(1);
94         }
95 }
96
97 //**********************************************************************************************************************
98 HeatMapSimCommand::HeatMapSimCommand(){ 
99         try {
100                 abort = true; calledHelp = true; 
101                 setParameters();
102                 vector<string> tempOutNames;
103                 outputTypes["svg"] = tempOutNames;
104         }
105         catch(exception& e) {
106                 m->errorOut(e, "HeatMapSimCommand", "HeatMapSimCommand");
107                 exit(1);
108         }
109 }
110 //**********************************************************************************************************************
111
112 HeatMapSimCommand::HeatMapSimCommand(string option)  {
113         try {
114                 abort = false; calledHelp = false;   
115                 allLines = 1;
116                         
117                 //allow user to run help
118                 if(option == "help") {  help(); abort = true; calledHelp = true; }
119                 else if(option == "citation") { citation(); abort = true; calledHelp = true;}
120                 
121                 else {
122                         vector<string> myArray = setParameters();
123                         
124                         OptionParser parser(option);
125                         map<string,string> parameters = parser.getParameters();
126                         
127                         ValidParameters validParameter;
128                         map<string,string>::iterator it;
129                         
130                         //check to make sure all parameters are valid for command
131                         for (it = parameters.begin(); it != parameters.end(); it++) { 
132                                 if (validParameter.isValidParameter(it->first, myArray, it->second) != true) {  abort = true;  }
133                         }
134                         
135                         //initialize outputTypes
136                         vector<string> tempOutNames;
137                         outputTypes["svg"] = tempOutNames;
138                         
139                         format = "";
140                                 
141                         //if the user changes the input directory command factory will send this info to us in the output parameter 
142                         string inputDir = validParameter.validFile(parameters, "inputdir", false);              
143                         if (inputDir == "not found"){   inputDir = "";          }
144                         else {
145                                 string path;
146                                 it = parameters.find("phylip");
147                                 //user has given a template file
148                                 if(it != parameters.end()){ 
149                                         path = m->hasPath(it->second);
150                                         //if the user has not given a path then, add inputdir. else leave path alone.
151                                         if (path == "") {       parameters["phylip"] = inputDir + it->second;           }
152                                 }
153                                 
154                                 it = parameters.find("column");
155                                 //user has given a template file
156                                 if(it != parameters.end()){ 
157                                         path = m->hasPath(it->second);
158                                         //if the user has not given a path then, add inputdir. else leave path alone.
159                                         if (path == "") {       parameters["column"] = inputDir + it->second;           }
160                                 }
161                                 
162                                 it = parameters.find("name");
163                                 //user has given a template file
164                                 if(it != parameters.end()){ 
165                                         path = m->hasPath(it->second);
166                                         //if the user has not given a path then, add inputdir. else leave path alone.
167                                         if (path == "") {       parameters["name"] = inputDir + it->second;             }
168                                 }
169                                 
170                                 it = parameters.find("shared");
171                                 //user has given a template file
172                                 if(it != parameters.end()){ 
173                                         path = m->hasPath(it->second);
174                                         //if the user has not given a path then, add inputdir. else leave path alone.
175                                         if (path == "") {       parameters["shared"] = inputDir + it->second;           }
176                                 }
177                         }
178
179                         //required parameters
180                         phylipfile = validParameter.validFile(parameters, "phylip", true);
181                         if (phylipfile == "not open") { abort = true; }
182                         else if (phylipfile == "not found") { phylipfile = ""; }        
183                         else {  format = "phylip";      inputfile = phylipfile; m-> setPhylipFile(phylipfile); if (outputDir == "") { outputDir += m->hasPath(phylipfile); }  }
184                         
185                         columnfile = validParameter.validFile(parameters, "column", true);
186                         if (columnfile == "not open") { abort = true; } 
187                         else if (columnfile == "not found") { columnfile = ""; }
188                         else {  format = "column";      inputfile = columnfile; m->setColumnFile(columnfile); if (outputDir == "") { outputDir += m->hasPath(columnfile); } }
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 = "shared";      inputfile = sharedfile; m->setSharedFile(sharedfile); if (outputDir == "") { outputDir += m->hasPath(sharedfile); } }
194                         
195                         namefile = validParameter.validFile(parameters, "name", true);
196                         if (namefile == "not open") { abort = true; }   
197                         else if (namefile == "not found") { namefile = ""; }
198                         else { m->setNameFile(namefile); }
199                         
200                         
201                         //error checking on files                       
202                         if ((sharedfile == "") && ((phylipfile == "") && (columnfile == "")))   { 
203                                 sharedfile = m->getSharedFile(); 
204                                 if (sharedfile != "") { format = "shared"; inputfile = sharedfile; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); }
205                                 else { 
206                                         //is there are current file available for either of these?
207                                         //give priority to column, then phylip
208                                         columnfile = m->getColumnFile(); 
209                                         if (columnfile != "") {  format = "column"; inputfile = columnfile; m->mothurOut("Using " + columnfile + " as input file for the column parameter."); m->mothurOutEndLine(); }
210                                         else { 
211                                                 phylipfile = m->getPhylipFile(); 
212                                                 if (phylipfile != "") { format = "phylip";  inputfile = phylipfile; m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); }
213                                                 else { 
214                                                         m->mothurOut("No valid current files. You must provide a shared or phylip or column file."); m->mothurOutEndLine(); 
215                                                         abort = true;
216                                                 }
217                                         }
218                                 }
219                         }
220                         else if ((phylipfile != "") && (columnfile != "")) { m->mothurOut("When running the heatmap.sim command with a distance file you may not use both the column and the phylip parameters."); m->mothurOutEndLine(); abort = true; }
221                         
222                         if (columnfile != "") {
223                                 if (namefile == "") { 
224                                         namefile = m->getNameFile(); 
225                                         if (namefile != "") {  m->mothurOut("Using " + namefile + " as input file for the name parameter."); m->mothurOutEndLine(); }
226                                         else { 
227                                                 m->mothurOut("You need to provide a namefile if you are going to use the column format."); m->mothurOutEndLine(); 
228                                                 abort = true; 
229                                         }       
230                                 }
231                         }
232                         
233                         
234                         //if the user changes the output directory command factory will send this info to us in the output parameter 
235                         outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = m->hasPath(inputfile);              }
236
237                         //check for optional parameter and set defaults
238                         // ...at some point should added some additional type checking...
239                                                         
240                         label = validParameter.validFile(parameters, "label", false);                   
241                         if (label == "not found") { label = ""; }
242                         else { 
243                                 if(label != "all") {  m->splitAtDash(label, labels);  allLines = 0;  }
244                                 else { allLines = 1;  }
245                         }
246                                 
247                         calc = validParameter.validFile(parameters, "calc", false);                     
248                         if (calc == "not found") { calc = "jest-thetayc";  }
249                         else { 
250                                 if (calc == "default")  {  calc = "jest-thetayc";  }
251                         }
252                         m->splitAtDash(calc, Estimators);
253                         if (m->inUsersGroups("citation", Estimators)) { 
254                                 ValidCalculators validCalc; validCalc.printCitations(Estimators); 
255                                 //remove citation from list of calcs
256                                 for (int i = 0; i < Estimators.size(); i++) { if (Estimators[i] == "citation") {  Estimators.erase(Estimators.begin()+i); break; } }
257                         }
258                                 
259                         groups = validParameter.validFile(parameters, "groups", false);                 
260                         if (groups == "not found") { groups = ""; }
261                         else { 
262                                 m->splitAtDash(groups, Groups);
263                                 m->setGroups(Groups);
264                         }
265                         
266                         string temp = validParameter.validFile(parameters, "fontsize", false);                          if (temp == "not found") { temp = "24"; }
267                         m->mothurConvert(temp, fontsize);
268                         
269                         if (abort == false) {
270                                 ValidCalculators validCalculator;
271                         
272                                 int i;
273                                 for (i=0; i<Estimators.size(); i++) {
274                                         if (validCalculator.isValidCalculator("heat", Estimators[i]) == true) { 
275                                                 if (Estimators[i] == "jabund") {        
276                                                         heatCalculators.push_back(new JAbund());
277                                                 }else if (Estimators[i] == "sorabund") { 
278                                                         heatCalculators.push_back(new SorAbund());
279                                                 }else if (Estimators[i] == "jclass") { 
280                                                         heatCalculators.push_back(new Jclass());
281                                                 }else if (Estimators[i] == "sorclass") { 
282                                                         heatCalculators.push_back(new SorClass());
283                                                 }else if (Estimators[i] == "jest") { 
284                                                         heatCalculators.push_back(new Jest());
285                                                 }else if (Estimators[i] == "sorest") { 
286                                                         heatCalculators.push_back(new SorEst());
287                                                 }else if (Estimators[i] == "thetayc") { 
288                                                         heatCalculators.push_back(new ThetaYC());
289                                                 }else if (Estimators[i] == "thetan") { 
290                                                         heatCalculators.push_back(new ThetaN());
291                                                 }else if (Estimators[i] == "morisitahorn") { 
292                                                         heatCalculators.push_back(new MorHorn());
293                                                 }else if (Estimators[i] == "braycurtis") { 
294                                                         heatCalculators.push_back(new BrayCurtis());
295                                                 }
296                                         }
297                                 }
298                                 
299                         }
300                 }
301
302                                 
303
304         }
305         catch(exception& e) {
306                 m->errorOut(e, "HeatMapSimCommand", "HeatMapSimCommand");
307                 exit(1);
308         }
309 }
310 //**********************************************************************************************************************
311
312 int HeatMapSimCommand::execute(){
313         try {
314         
315                 if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
316                 
317                 heatmap = new HeatMapSim(outputDir, inputfile, fontsize);
318                 
319                 if (format == "shared") {
320                         runCommandShared();
321                 }else{  runCommandDist();       }
322                 
323                 delete heatmap;
324                 
325                 if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        m->mothurRemove(outputNames[i]);  } outputTypes.clear(); return 0; }
326                 
327                 m->mothurOutEndLine();
328                 m->mothurOut("Output File Names: "); m->mothurOutEndLine();
329                 for (int i = 0; i < outputNames.size(); i++) {  m->mothurOut(outputNames[i]); m->mothurOutEndLine();    }
330                 m->mothurOutEndLine();
331                 
332                 return 0;
333         }
334         catch(exception& e) {
335                 m->errorOut(e, "HeatMapSimCommand", "execute");
336                 exit(1);
337         }
338 }
339
340 //**********************************************************************************************************************
341 int HeatMapSimCommand::runCommandShared() {
342         try {
343                 //if the users entered no valid calculators don't execute command
344                 if (heatCalculators.size() == 0) { m->mothurOut("No valid calculators."); m->mothurOutEndLine(); return 0; }
345                 
346                 input = new InputData(sharedfile, "sharedfile");
347                 lookup = input->getSharedRAbundVectors();
348                 string lastLabel = lookup[0]->getLabel();
349                         
350                 if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups.  I cannot run the command."); m->mothurOutEndLine(); return 0;}
351                                 
352                 //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label.
353                 set<string> processedLabels;
354                 set<string> userLabels = labels;
355                 
356                 if (m->control_pressed) {  delete input;  for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }  m->clearGroups(); return 0; }
357                 
358                 //as long as you are not at the end of the file or done wih the lines you want
359                 while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
360                         
361                         if (m->control_pressed) { delete input;  for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } m->clearGroups(); return 0; }
362
363                         if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){                  
364         
365                                 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
366                                 vector<string> outfilenames = heatmap->getPic(lookup, heatCalculators);
367                                 for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]);  outputTypes["svg"].push_back(outfilenames[i]); }
368                                         
369                                 processedLabels.insert(lookup[0]->getLabel());
370                                 userLabels.erase(lookup[0]->getLabel());
371                         }
372                                 
373                         if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) {
374                                 string saveLabel = lookup[0]->getLabel();
375                         
376                                 for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
377                                 lookup = input->getSharedRAbundVectors(lastLabel);                              
378
379                                 m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
380                                 vector<string> outfilenames = heatmap->getPic(lookup, heatCalculators);
381                                 for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]);  }
382                                         
383                                 processedLabels.insert(lookup[0]->getLabel());
384                                 userLabels.erase(lookup[0]->getLabel());
385                                 
386                                 //restore real lastlabel to save below
387                                 lookup[0]->setLabel(saveLabel);
388                         }
389                                 
390                         //prevent memory leak
391                          
392                         lastLabel = lookup[0]->getLabel();                      
393
394                         //get next line to process
395                         for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
396                         lookup = input->getSharedRAbundVectors();
397
398                 }
399                 
400                         
401                 if (m->control_pressed) {  delete input;  m->clearGroups();  return 0; }
402
403                 //output error messages about any remaining user labels
404                 set<string>::iterator it;
405                 bool needToRun = false;
406                 for (it = userLabels.begin(); it != userLabels.end(); it++) {  
407                         m->mothurOut("Your file does not include the label " + *it); 
408                         if (processedLabels.count(lastLabel) != 1) {
409                                 m->mothurOut(". I will use " + lastLabel + "."); m->mothurOutEndLine();
410                                 needToRun = true;
411                         }else {
412                                 m->mothurOut(". Please refer to " + lastLabel + "."); m->mothurOutEndLine();
413                         }
414                 }
415                 
416                 if (m->control_pressed) {  delete input;  m->clearGroups(); return 0; }
417                 
418                 //run last label if you need to
419                 if (needToRun == true)  {
420                         for (int i = 0; i < lookup.size(); i++) {  if (lookup[i] != NULL) { delete lookup[i]; } } 
421                         lookup = input->getSharedRAbundVectors(lastLabel);                              
422
423                         m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine();
424                         vector<string> outfilenames = heatmap->getPic(lookup, heatCalculators);
425                         for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]);  }
426                         
427                         for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
428                 }
429                 
430                 if (m->control_pressed) {  delete input;  m->clearGroups(); return 0; }
431                         
432                 //reset groups parameter
433                 m->clearGroups();  
434                         
435                 delete input;  
436         
437                 return 0;
438         }
439         catch(exception& e) {
440                 m->errorOut(e, "HeatMapSimCommand", "runCommandShared");
441                 exit(1);
442         }
443 }
444 //**********************************************************************************************************************
445 int HeatMapSimCommand::runCommandDist() {
446         try {
447         
448                 vector< vector<double> > matrix;
449                 vector<string> names;
450                 ifstream in;
451                 
452                 //read distance file and create distance vector and names vector
453                 if (format == "phylip") {
454                         //read phylip file
455                         m->openInputFile(phylipfile, in);
456                         
457                         string name;
458                         int numSeqs;
459                         in >> numSeqs >> name; 
460                         
461                         //save name
462                         names.push_back(name);
463                 
464                         //resize the matrix and fill with zeros
465                         matrix.resize(numSeqs); 
466                         for(int i = 0; i < numSeqs; i++) {
467                                 matrix[i].resize(numSeqs, 0.0);
468                         }
469                                         
470                         //determine if matrix is square or lower triangle
471                         //if it is square read the distances for the first sequence
472                         char d;
473                         bool square;
474                         while((d=in.get()) != EOF){
475                                 
476                                 //is d a number meaning its square
477                                 if(isalnum(d)){ 
478                                         square = true;
479                                         in.putback(d);
480                                         
481                                         for(int i=0;i<numSeqs;i++){
482                                                 in >> matrix[0][i];
483                                         }
484                                         break;
485                                 }
486                                 
487                                 //is d a line return meaning its lower triangle
488                                 if(d == '\n'){
489                                         square = false;
490                                         break;
491                                 }
492                         }
493                         
494                         //read rest of matrix
495                         if (square == true) { 
496                                 for(int i=1;i<numSeqs;i++){
497                                         in >> name;             
498                                         names.push_back(name);
499                                         
500                                         if (m->control_pressed) { return 0; }
501                                         
502                                         for(int j=0;j<numSeqs;j++) { in >> matrix[i][j];  }
503                                         m->gobble(in);
504                                 }
505                         }else { 
506                                 double dist;
507                                 for(int i=1;i<numSeqs;i++){
508                                         in >> name;     
509                                         names.push_back(name);  
510                                         
511                                         if (m->control_pressed) { return 0; }
512                                         
513                                         for(int j=0;j<i;j++){
514                                                 in >> dist;
515                                                 matrix[i][j] = dist;  matrix[j][i] = dist;
516                                         }
517                                         m->gobble(in);
518                                 }
519                         }
520                         in.close();
521                 }else {
522                         //read names file
523                         NameAssignment* nameMap = new NameAssignment(namefile);
524                         nameMap->readMap();
525                         
526                         //put names in order in vector
527                         for (int i = 0; i < nameMap->size(); i++) {
528                                 names.push_back(nameMap->get(i));
529                         }
530                         
531                         //resize matrix
532                         matrix.resize(nameMap->size());
533                         for (int i = 0; i < nameMap->size(); i++) {
534                                 matrix[i].resize(nameMap->size(), 0.0);
535                         }
536                         
537                         //read column file
538                         string first, second;
539                         double dist;
540                         m->openInputFile(columnfile, in);
541                         
542                         while (!in.eof()) {
543                                 in >> first >> second >> dist; m->gobble(in);
544                                 
545                                 if (m->control_pressed) { return 0; }
546                                 
547                                 map<string, int>::iterator itA = nameMap->find(first);
548                                 map<string, int>::iterator itB = nameMap->find(second);
549                                 
550                                 if(itA == nameMap->end()){  m->mothurOut("AAError: Sequence '" + first + "' was not found in the names file, please correct\n"); exit(1);  }
551                                 if(itB == nameMap->end()){  m->mothurOut("ABError: Sequence '" + second + "' was not found in the names file, please correct\n"); exit(1);  }
552                                 
553                                 //save distance
554                                 matrix[itA->second][itB->second] = dist;
555                                 matrix[itB->second][itA->second] = dist;
556                         }
557                         in.close();
558                         
559                         delete nameMap;
560                 }
561                 
562                 
563                 string outputFileName = heatmap->getPic(matrix, names);
564                 outputNames.push_back(outputFileName); //vector<vector<double>>, vector<string>
565                 outputTypes["svg"].push_back(outputFileName);
566                 
567                 return 0;
568         }
569         catch(exception& e) {
570                 m->errorOut(e, "HeatMapSimCommand", "runCommandDist");
571                 exit(1);
572         }
573 }
574 //**********************************************************************************************************************
575
576
577
578
579
580