]> git.donarmstrong.com Git - mothur.git/blobdiff - heatmapsimcommand.cpp
added check to make sure shhh.flows child processes finish properly. added subsamplin...
[mothur.git] / heatmapsimcommand.cpp
index 5a84391813b768b33ed55f3dbc50d612f01111f2..de35075e98ee938e67f1880cada0ebfb1e0ba26a 100644 (file)
 //**********************************************************************************************************************
 vector<string> HeatMapSimCommand::setParameters(){     
        try {
-               CommandParameter pshared("shared", "InputTypes", "", "", "LRSS", "LRSS", "none",false,false); parameters.push_back(pshared);    
-               CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "none",false,false); parameters.push_back(pphylip);
+               CommandParameter pshared("shared", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none",false,false); parameters.push_back(pshared);        
+               CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none",false,false); parameters.push_back(pphylip);
                CommandParameter pname("name", "InputTypes", "", "", "none", "none", "ColumnName",false,false); parameters.push_back(pname);
-               CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumn", "PhylipColumn", "ColumnName",false,false); parameters.push_back(pcolumn);              
+               CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "ColumnName",false,false); parameters.push_back(pcolumn);          
                CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups);
                CommandParameter plabel("label", "String", "", "", "", "", "",false,false); parameters.push_back(plabel);
                CommandParameter pcalc("calc", "Multiple", "jabund-sorabund-jclass-sorclass-jest-sorest-thetayc-thetan-morisitahorn-braycurtis", "jest-thetayc", "", "", "",true,false); parameters.push_back(pcalc);
+               CommandParameter pfontsize("fontsize", "Number", "", "24", "", "", "",false,false); parameters.push_back(pfontsize);
                CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir);
                CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir);
                
@@ -46,22 +47,24 @@ vector<string> HeatMapSimCommand::setParameters(){
 string HeatMapSimCommand::getHelpString(){     
        try {
                string helpString = "";
-               helpString += "The heatmap.sim command parameters are shared, phylip, column, name, groups, calc and label.  shared or phylip or column and name are required unless valid current files exist.\n";
+               ValidCalculators validCalculator;
+               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";
                helpString += "There are two ways to use the heatmap.sim command. The first is with the read.otu command. \n";
                helpString += "With the read.otu command you may use the groups, label and calc parameters. \n";
                helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like included in your heatmap.\n";
                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";
+               helpString += "The fontsize parameter allows you to adjust the font size of the picture created, default=24.\n";
                helpString += "The heatmap.sim command should be in the following format: heatmap.sim(groups=yourGroups, calc=yourCalc, label=yourLabels).\n";
                helpString += "Example heatmap.sim(groups=A-B-C, calc=jabund).\n";
                helpString += "The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n";
-               helpString +=  validCalculator->printCalc("heat");
+               helpString +=  validCalculator.printCalc("heat");
                helpString += "The default value for calc is jclass-thetayc.\n";
                helpString += "The heatmap.sim command outputs a .svg file for each calculator you choose at each label you specify.\n";
                helpString += "The second way to use the heatmap.sim command is with a distance file representing the distance bewteen your groups. \n";
                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";
                helpString += "The heatmap.sim command should be in the following format: heatmap.sim(phylip=yourDistanceFile).\n";
                helpString += "Example heatmap.sim(phylip=amazonGroups.dist).\n";
-               helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n";
+               helpString += "Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n";
                return helpString;
        }
        catch(exception& e) {
@@ -90,7 +93,8 @@ HeatMapSimCommand::HeatMapSimCommand(string option)  {
                allLines = 1;
                        
                //allow user to run help
-               if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; calledHelp = true; }
+               if(option == "help") {  help(); abort = true; calledHelp = true; }
+               else if(option == "citation") { citation(); abort = true; calledHelp = true;}
                
                else {
                        vector<string> myArray = setParameters();
@@ -111,9 +115,7 @@ HeatMapSimCommand::HeatMapSimCommand(string option)  {
                        outputTypes["svg"] = tempOutNames;
                        
                        format = "";
-                       //if the user changes the output directory command factory will send this info to us in the output parameter 
-                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = "";         }
-                       
+                               
                        //if the user changes the input directory command factory will send this info to us in the output parameter 
                        string inputDir = validParameter.validFile(parameters, "inputdir", false);              
                        if (inputDir == "not found"){   inputDir = "";          }
@@ -156,21 +158,22 @@ HeatMapSimCommand::HeatMapSimCommand(string option)  {
                        phylipfile = validParameter.validFile(parameters, "phylip", true);
                        if (phylipfile == "not open") { abort = true; }
                        else if (phylipfile == "not found") { phylipfile = ""; }        
-                       else {  format = "phylip";      inputfile = phylipfile; if (outputDir == "") { outputDir += m->hasPath(phylipfile); }  }
+                       else {  format = "phylip";      inputfile = phylipfile; m-> setPhylipFile(phylipfile); if (outputDir == "") { outputDir += m->hasPath(phylipfile); }  }
                        
                        columnfile = validParameter.validFile(parameters, "column", true);
                        if (columnfile == "not open") { abort = true; } 
                        else if (columnfile == "not found") { columnfile = ""; }
-                       else {  format = "column";      inputfile = columnfile; if (outputDir == "") { outputDir += m->hasPath(columnfile); } }
+                       else {  format = "column";      inputfile = columnfile; m->setColumnFile(columnfile); if (outputDir == "") { outputDir += m->hasPath(columnfile); } }
                        
                        sharedfile = validParameter.validFile(parameters, "shared", true);
                        if (sharedfile == "not open") { abort = true; } 
                        else if (sharedfile == "not found") { sharedfile = ""; }
-                       else {  format = "shared";      inputfile = sharedfile;  if (outputDir == "") { outputDir += m->hasPath(sharedfile); } }
+                       else {  format = "shared";      inputfile = sharedfile; m->setSharedFile(sharedfile); if (outputDir == "") { outputDir += m->hasPath(sharedfile); } }
                        
                        namefile = validParameter.validFile(parameters, "name", true);
                        if (namefile == "not open") { abort = true; }   
                        else if (namefile == "not found") { namefile = ""; }
+                       else { m->setNameFile(namefile); }
                        
                        
                        //error checking on files                       
@@ -205,6 +208,10 @@ HeatMapSimCommand::HeatMapSimCommand(string option)  {
                                }
                        }
                        
+                       
+                       //if the user changes the output directory command factory will send this info to us in the output parameter 
+                       outputDir = validParameter.validFile(parameters, "outputdir", false);           if (outputDir == "not found"){  outputDir = m->hasPath(inputfile);              }
+
                        //check for optional parameter and set defaults
                        // ...at some point should added some additional type checking...
                                                        
@@ -221,21 +228,28 @@ HeatMapSimCommand::HeatMapSimCommand(string option)  {
                                if (calc == "default")  {  calc = "jest-thetayc";  }
                        }
                        m->splitAtDash(calc, Estimators);
+                       if (m->inUsersGroups("citation", Estimators)) { 
+                               ValidCalculators validCalc; validCalc.printCitations(Estimators); 
+                               //remove citation from list of calcs
+                               for (int i = 0; i < Estimators.size(); i++) { if (Estimators[i] == "citation") {  Estimators.erase(Estimators.begin()+i); break; } }
+                       }
                                
                        groups = validParameter.validFile(parameters, "groups", false);                 
                        if (groups == "not found") { groups = ""; }
                        else { 
                                m->splitAtDash(groups, Groups);
-                               m->Groups = Groups;
+                               m->setGroups(Groups);
                        }
                        
+                       string temp = validParameter.validFile(parameters, "fontsize", false);                          if (temp == "not found") { temp = "24"; }
+                       m->mothurConvert(temp, fontsize);
                        
                        if (abort == false) {
-                               validCalculator = new ValidCalculators();
+                               ValidCalculators validCalculator;
                        
                                int i;
                                for (i=0; i<Estimators.size(); i++) {
-                                       if (validCalculator->isValidCalculator("heat", Estimators[i]) == true) { 
+                                       if (validCalculator.isValidCalculator("heat", Estimators[i]) == true) { 
                                                if (Estimators[i] == "jabund") {        
                                                        heatCalculators.push_back(new JAbund());
                                                }else if (Estimators[i] == "sorabund") { 
@@ -278,16 +292,15 @@ int HeatMapSimCommand::execute(){
        
                if (abort == true) { if (calledHelp) { return 0; }  return 2;   }
                
-               heatmap = new HeatMapSim(outputDir, inputfile);
+               heatmap = new HeatMapSim(outputDir, inputfile, fontsize);
                
                if (format == "shared") {
                        runCommandShared();
                }else{  runCommandDist();       }
                
                delete heatmap;
-               delete validCalculator;
                
-               if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        remove(outputNames[i].c_str());  } outputTypes.clear(); return 0; }
+               if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) {        m->mothurRemove(outputNames[i]);  } outputTypes.clear(); return 0; }
                
                m->mothurOutEndLine();
                m->mothurOut("Output File Names: "); m->mothurOutEndLine();
@@ -318,12 +331,12 @@ int HeatMapSimCommand::runCommandShared() {
                set<string> processedLabels;
                set<string> userLabels = labels;
                
-               if (m->control_pressed) {  delete input;  for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }  m->Groups.clear(); return 0; }
+               if (m->control_pressed) {  delete input;  for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  }  m->clearGroups(); return 0; }
                
                //as long as you are not at the end of the file or done wih the lines you want
                while((lookup[0] != NULL) && ((allLines == 1) || (userLabels.size() != 0))) {
                        
-                       if (m->control_pressed) { delete input;  for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } m->Groups.clear(); return 0; }
+                       if (m->control_pressed) { delete input;  for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } m->clearGroups(); return 0; }
 
                        if(allLines == 1 || labels.count(lookup[0]->getLabel()) == 1){                  
        
@@ -363,7 +376,7 @@ int HeatMapSimCommand::runCommandShared() {
                }
                
                        
-               if (m->control_pressed) {  delete input;  m->Groups.clear();  return 0; }
+               if (m->control_pressed) {  delete input;  m->clearGroups();  return 0; }
 
                //output error messages about any remaining user labels
                set<string>::iterator it;
@@ -378,7 +391,7 @@ int HeatMapSimCommand::runCommandShared() {
                        }
                }
                
-               if (m->control_pressed) {  delete input;  m->Groups.clear(); return 0; }
+               if (m->control_pressed) {  delete input;  m->clearGroups(); return 0; }
                
                //run last label if you need to
                if (needToRun == true)  {
@@ -392,10 +405,10 @@ int HeatMapSimCommand::runCommandShared() {
                        for (int i = 0; i < lookup.size(); i++) {  delete lookup[i];  } 
                }
                
-               if (m->control_pressed) {  delete input;  m->Groups.clear(); return 0; }
+               if (m->control_pressed) {  delete input;  m->clearGroups(); return 0; }
                        
                //reset groups parameter
-               m->Groups.clear();  
+               m->clearGroups();  
                        
                delete input;  
        
@@ -512,8 +525,8 @@ int HeatMapSimCommand::runCommandDist() {
                                map<string, int>::iterator itA = nameMap->find(first);
                                map<string, int>::iterator itB = nameMap->find(second);
                                
-                               if(itA == nameMap->end()){  cerr << "AAError: Sequence '" << first << "' was not found in the names file, please correct\n"; exit(1);  }
-                               if(itB == nameMap->end()){  cerr << "ABError: Sequence '" << second << "' was not found in the names file, please correct\n"; exit(1);  }
+                               if(itA == nameMap->end()){  m->mothurOut("AAError: Sequence '" + first + "' was not found in the names file, please correct\n"); exit(1);  }
+                               if(itB == nameMap->end()){  m->mothurOut("ABError: Sequence '" + second + "' was not found in the names file, please correct\n"); exit(1);  }
                                
                                //save distance
                                matrix[itA->second][itB->second] = dist;