X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=heatmapsimcommand.cpp;h=98739b68291fd42d83d1190a46313886126f02bf;hp=dc67a8d4374ae90aebf182ce80d5474b17431f95;hb=1a20e24ee786195ab0e1cccd4f5aede7a88f3f4e;hpb=aa9238c0a9e6e7aa0ed8b8b606b08ad4fd7dcfe3 diff --git a/heatmapsimcommand.cpp b/heatmapsimcommand.cpp index dc67a8d..98739b6 100644 --- a/heatmapsimcommand.cpp +++ b/heatmapsimcommand.cpp @@ -20,24 +20,99 @@ #include "sharedbraycurtis.h" +//********************************************************************************************************************** +vector HeatMapSimCommand::setParameters(){ + try { + CommandParameter pshared("shared", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none","svg",false,false,true); parameters.push_back(pshared); + CommandParameter pphylip("phylip", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "none","svg",false,false); parameters.push_back(pphylip); + CommandParameter pname("name", "InputTypes", "", "", "namecount", "none", "none","",false,false); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "namecount", "none", "none","",false,false); parameters.push_back(pcount); + CommandParameter pcolumn("column", "InputTypes", "", "", "PhylipColumnShared", "PhylipColumnShared", "ColumnName","svg",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); + + vector myArray; + for (int i = 0; i < parameters.size(); i++) { myArray.push_back(parameters[i].name); } + return myArray; + } + catch(exception& e) { + m->errorOut(e, "HeatMapSimCommand", "setParameters"); + exit(1); + } +} +//********************************************************************************************************************** +string HeatMapSimCommand::getHelpString(){ + try { + string helpString = ""; + ValidCalculators validCalculator; + helpString += "The heatmap.sim command parameters are shared, phylip, column, name, count, 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 a shared file, and you may use the groups, label and calc parameter. \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 += "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"; + return helpString; + } + catch(exception& e) { + m->errorOut(e, "HeatMapSimCommand", "getHelpString"); + exit(1); + } +} +//********************************************************************************************************************** +string HeatMapSimCommand::getOutputPattern(string type) { + try { + string pattern = ""; + + if (type == "svg") { pattern = "[filename],svg"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "HeatMapCommand", "getOutputPattern"); + exit(1); + } +} +//********************************************************************************************************************** +HeatMapSimCommand::HeatMapSimCommand(){ + try { + abort = true; calledHelp = true; + setParameters(); + vector tempOutNames; + outputTypes["svg"] = tempOutNames; + } + catch(exception& e) { + m->errorOut(e, "HeatMapSimCommand", "HeatMapSimCommand"); + exit(1); + } +} //********************************************************************************************************************** HeatMapSimCommand::HeatMapSimCommand(string option) { try { - globaldata = GlobalData::getInstance(); - abort = false; + abort = false; calledHelp = false; allLines = 1; - labels.clear(); - Groups.clear(); - Estimators.clear(); //allow user to run help - if(option == "help") { validCalculator = new ValidCalculators(); help(); abort = true; } + if(option == "help") { help(); abort = true; calledHelp = true; } + else if(option == "citation") { citation(); abort = true; calledHelp = true;} else { - //valid paramters for this command - string AlignArray[] = {"groups","label", "calc","phylip","column","name","outputdir","inputdir"}; - vector myArray (AlignArray, AlignArray+(sizeof(AlignArray)/sizeof(string))); + vector myArray = setParameters(); OptionParser parser(option); map parameters = parser.getParameters(); @@ -50,10 +125,12 @@ HeatMapSimCommand::HeatMapSimCommand(string option) { if (validParameter.isValidParameter(it->first, myArray, it->second) != true) { abort = true; } } - 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 = ""; } + //initialize outputTypes + vector tempOutNames; + outputTypes["svg"] = tempOutNames; + format = ""; + //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 = ""; } @@ -62,7 +139,7 @@ HeatMapSimCommand::HeatMapSimCommand(string option) { it = parameters.find("phylip"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["phylip"] = inputDir + it->second; } } @@ -70,7 +147,7 @@ HeatMapSimCommand::HeatMapSimCommand(string option) { it = parameters.find("column"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["column"] = inputDir + it->second; } } @@ -78,77 +155,134 @@ HeatMapSimCommand::HeatMapSimCommand(string option) { it = parameters.find("name"); //user has given a template file if(it != parameters.end()){ - path = hasPath(it->second); + path = m->hasPath(it->second); //if the user has not given a path then, add inputdir. else leave path alone. if (path == "") { parameters["name"] = inputDir + it->second; } } + + it = parameters.find("shared"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["shared"] = inputDir + it->second; } + } + + it = parameters.find("count"); + //user has given a template file + if(it != parameters.end()){ + path = m->hasPath(it->second); + //if the user has not given a path then, add inputdir. else leave path alone. + if (path == "") { parameters["count"] = inputDir + it->second; } + } } //required parameters phylipfile = validParameter.validFile(parameters, "phylip", true); if (phylipfile == "not open") { abort = true; } else if (phylipfile == "not found") { phylipfile = ""; } - else { format = "phylip"; if (outputDir == "") { outputDir += 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"; if (outputDir == "") { outputDir += 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; 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); } + + countfile = validParameter.validFile(parameters, "count", true); + if (countfile == "not open") { abort = true; countfile = ""; } + else if (countfile == "not found") { countfile = ""; } + else { m->setCountTableFile(countfile); } + if ((countfile != "") && (namefile != "")) { m->mothurOut("You must enter ONLY ONE of the following: count or name."); m->mothurOutEndLine(); abort = true; } //error checking on files - if ((globaldata->getSharedFile() == "") && ((phylipfile == "") && (columnfile == ""))) { m->mothurOut("You must run the read.otu command or provide a distance file before running the heatmap.sim command."); m->mothurOutEndLine(); abort = true; } + if ((sharedfile == "") && ((phylipfile == "") && (columnfile == ""))) { + sharedfile = m->getSharedFile(); + if (sharedfile != "") { format = "shared"; inputfile = sharedfile; m->mothurOut("Using " + sharedfile + " as input file for the shared parameter."); m->mothurOutEndLine(); } + else { + //is there are current file available for either of these? + //give priority to column, then phylip + columnfile = m->getColumnFile(); + if (columnfile != "") { format = "column"; inputfile = columnfile; m->mothurOut("Using " + columnfile + " as input file for the column parameter."); m->mothurOutEndLine(); } + else { + phylipfile = m->getPhylipFile(); + if (phylipfile != "") { format = "phylip"; inputfile = phylipfile; m->mothurOut("Using " + phylipfile + " as input file for the phylip parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("No valid current files. You must provide a shared or phylip or column file."); m->mothurOutEndLine(); + abort = true; + } + } + } + } 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; } if (columnfile != "") { - if (namefile == "") { m->mothurOut("You need to provide a namefile if you are going to use the column format."); m->mothurOutEndLine(); abort = true; } + if (namefile == "") { + namefile = m->getNameFile(); + if (namefile != "") { m->mothurOut("Using " + namefile + " as input file for the name parameter."); m->mothurOutEndLine(); } + else { + countfile = m->getCountTableFile(); + if (countfile != "") { m->mothurOut("Using " + countfile + " as input file for the count parameter."); m->mothurOutEndLine(); } + else { + m->mothurOut("You need to provide a name or count file if you are going to use the column format."); m->mothurOutEndLine(); + abort = true; + } + } + } } - if (format == "") { format = "shared"; } + //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... - if (format == "shared") { - if (outputDir == "") { outputDir += hasPath(globaldata->getSharedFile()); } - - label = validParameter.validFile(parameters, "label", false); - if (label == "not found") { label = ""; } - else { - if(label != "all") { splitAtDash(label, labels); allLines = 0; } - else { allLines = 1; } - } - - //if the user has not specified any labels use the ones from read.otu - if (label == "") { - allLines = globaldata->allLines; - labels = globaldata->labels; - } + + label = validParameter.validFile(parameters, "label", false); + if (label == "not found") { label = ""; } + else { + if(label != "all") { m->splitAtDash(label, labels); allLines = 0; } + else { allLines = 1; } + } - calc = validParameter.validFile(parameters, "calc", false); - if (calc == "not found") { calc = "jest-thetayc"; } - else { - if (calc == "default") { calc = "jest-thetayc"; } - } - splitAtDash(calc, Estimators); + calc = validParameter.validFile(parameters, "calc", false); + if (calc == "not found") { calc = "jest-thetayc"; } + else { + 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 { - splitAtDash(groups, Groups); - globaldata->Groups = Groups; - } + groups = validParameter.validFile(parameters, "groups", false); + if (groups == "not found") { groups = ""; } + else { + m->splitAtDash(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; iisValidCalculator("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") { @@ -184,63 +318,22 @@ HeatMapSimCommand::HeatMapSimCommand(string option) { exit(1); } } - -//********************************************************************************************************************** - -void HeatMapSimCommand::help(){ - try { - m->mothurOut("The heatmap.sim command can only be executed after a successful read.otu command, or by providing a distance file.\n"); - m->mothurOut("The heatmap.sim command parameters are phylip, column, name, groups, calc and label. No parameters are required.\n"); - m->mothurOut("There are two ways to use the heatmap.sim command. The first is with the read.otu command. \n"); - m->mothurOut("With the read.otu command you may use the groups, label and calc parameters. \n"); - m->mothurOut("The groups parameter allows you to specify which of the groups in your groupfile you would like included in your heatmap.\n"); - m->mothurOut("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"); - m->mothurOut("The heatmap.sim command should be in the following format: heatmap.sim(groups=yourGroups, calc=yourCalc, label=yourLabels).\n"); - m->mothurOut("Example heatmap.sim(groups=A-B-C, calc=jabund).\n"); - m->mothurOut("The default value for groups is all the groups in your groupfile, and all labels in your inputfile will be used.\n"); - validCalculator->printCalc("heat", cout); - m->mothurOut("The default value for calc is jclass-thetayc.\n"); - m->mothurOut("The heatmap.sim command outputs a .svg file for each calculator you choose at each label you specify.\n"); - m->mothurOut("The second way to use the heatmap.sim command is with a distance file representing the distance bewteen your groups. \n"); - m->mothurOut("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"); - m->mothurOut("The heatmap.sim command should be in the following format: heatmap.sim(phylip=yourDistanceFile).\n"); - m->mothurOut("Example heatmap.sim(phylip=amazonGroups.dist).\n"); - m->mothurOut("Note: No spaces between parameter labels (i.e. groups), '=' and parameters (i.e.yourGroups).\n\n"); - - } - catch(exception& e) { - m->errorOut(e, "HeatMapSimCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -HeatMapSimCommand::~HeatMapSimCommand(){} - //********************************************************************************************************************** int HeatMapSimCommand::execute(){ try { - if (abort == true) { return 0; } + if (abort == true) { if (calledHelp) { return 0; } return 2; } - heatmap = new HeatMapSim(outputDir); + heatmap = new HeatMapSim(outputDir, inputfile, fontsize); if (format == "shared") { runCommandShared(); - }else if (format == "phylip") { - globaldata->inputFileName = phylipfile; - runCommandDist(); - }else if (format == "column") { - globaldata->inputFileName = columnfile; - runCommandDist(); - } + }else{ runCommandDist(); } delete heatmap; - delete validCalculator; - if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { remove(outputNames[i].c_str()); } 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(); @@ -261,38 +354,34 @@ int HeatMapSimCommand::runCommandShared() { //if the users entered no valid calculators don't execute command if (heatCalculators.size() == 0) { m->mothurOut("No valid calculators."); m->mothurOutEndLine(); return 0; } - //you have groups - read = new ReadOTUFile(globaldata->inputFileName); - read->read(&*globaldata); - - input = globaldata->ginput; + input = new InputData(sharedfile, "sharedfile"); lookup = input->getSharedRAbundVectors(); string lastLabel = lookup[0]->getLabel(); - + if (lookup.size() < 2) { m->mothurOut("You have not provided enough valid groups. I cannot run the command."); m->mothurOutEndLine(); return 0;} //if the users enters label "0.06" and there is no "0.06" in their file use the next lowest label. set processedLabels; set userLabels = labels; - if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->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 read; delete input; globaldata->ginput = NULL; for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } globaldata->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){ m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); vector outfilenames = heatmap->getPic(lookup, heatCalculators); - for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } + for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } processedLabels.insert(lookup[0]->getLabel()); userLabels.erase(lookup[0]->getLabel()); } - if ((anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { + if ((m->anyLabelsToProcess(lookup[0]->getLabel(), userLabels, "") == true) && (processedLabels.count(lastLabel) != 1)) { string saveLabel = lookup[0]->getLabel(); for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } @@ -300,7 +389,7 @@ int HeatMapSimCommand::runCommandShared() { m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); vector outfilenames = heatmap->getPic(lookup, heatCalculators); - for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } + for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } processedLabels.insert(lookup[0]->getLabel()); userLabels.erase(lookup[0]->getLabel()); @@ -315,11 +404,12 @@ int HeatMapSimCommand::runCommandShared() { //get next line to process for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } - lookup = input->getSharedRAbundVectors(); + lookup = input->getSharedRAbundVectors(); + } - if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { delete input; m->clearGroups(); return 0; } //output error messages about any remaining user labels set::iterator it; @@ -334,7 +424,7 @@ int HeatMapSimCommand::runCommandShared() { } } - if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { delete input; m->clearGroups(); return 0; } //run last label if you need to if (needToRun == true) { @@ -343,19 +433,18 @@ int HeatMapSimCommand::runCommandShared() { m->mothurOut(lookup[0]->getLabel()); m->mothurOutEndLine(); vector outfilenames = heatmap->getPic(lookup, heatCalculators); - for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); } + for(int i = 0; i < outfilenames.size(); i++) { outputNames.push_back(outfilenames[i]); outputTypes["svg"].push_back(outfilenames[i]); } for (int i = 0; i < lookup.size(); i++) { delete lookup[i]; } } - if (m->control_pressed) { delete read; delete input; globaldata->ginput = NULL; globaldata->Groups.clear(); return 0; } + if (m->control_pressed) { delete input; m->clearGroups(); return 0; } //reset groups parameter - globaldata->Groups.clear(); - - delete input; globaldata->ginput = NULL; - delete read; - + m->clearGroups(); + + delete input; + return 0; } catch(exception& e) { @@ -374,7 +463,7 @@ int HeatMapSimCommand::runCommandDist() { //read distance file and create distance vector and names vector if (format == "phylip") { //read phylip file - openInputFile(phylipfile, in); + m->openInputFile(phylipfile, in); string name; int numSeqs; @@ -422,7 +511,7 @@ int HeatMapSimCommand::runCommandDist() { if (m->control_pressed) { return 0; } for(int j=0;j> matrix[i][j]; } - gobble(in); + m->gobble(in); } }else { double dist; @@ -436,53 +525,70 @@ int HeatMapSimCommand::runCommandDist() { in >> dist; matrix[i][j] = dist; matrix[j][i] = dist; } - gobble(in); + m->gobble(in); } } in.close(); }else { //read names file - NameAssignment* nameMap = new NameAssignment(namefile); - nameMap->readMap(); - - //put names in order in vector - for (int i = 0; i < nameMap->size(); i++) { - names.push_back(nameMap->get(i)); - } - - //resize matrix - matrix.resize(nameMap->size()); - for (int i = 0; i < nameMap->size(); i++) { - matrix[i].resize(nameMap->size(), 0.0); - } + NameAssignment* nameMap; + CountTable ct; + if (namefile != "") { + nameMap = new NameAssignment(namefile); + nameMap->readMap(); + + //put names in order in vector + for (int i = 0; i < nameMap->size(); i++) { + names.push_back(nameMap->get(i)); + } + }else if (countfile != "") { + nameMap = NULL; + ct.readTable(countfile); + names = ct.getNamesOfSeqs(); + } + //resize matrix + matrix.resize(names.size()); + for (int i = 0; i < names.size(); i++) { + matrix[i].resize(names.size(), 0.0); + } + //read column file string first, second; double dist; - openInputFile(columnfile, in); + m->openInputFile(columnfile, in); while (!in.eof()) { - in >> first >> second >> dist; gobble(in); + in >> first >> second >> dist; m->gobble(in); if (m->control_pressed) { return 0; } - map::iterator itA = nameMap->find(first); - map::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); } - - //save distance - matrix[itA->second][itB->second] = dist; - matrix[itB->second][itA->second] = dist; + if (namefile != "") { + map::iterator itA = nameMap->find(first); + map::iterator itB = nameMap->find(second); + + 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; + matrix[itB->second][itA->second] = dist; + }else if (countfile != "") { + int itA = ct.get(first); + int itB = ct.get(second); + matrix[itA][itB] = dist; + matrix[itB][itA] = dist; + } } in.close(); - delete nameMap; + if (namefile != "") { delete nameMap; } } - - outputNames.push_back(heatmap->getPic(matrix, names)); //vector>, vector + + string outputFileName = heatmap->getPic(matrix, names); + outputNames.push_back(outputFileName); //vector>, vector + outputTypes["svg"].push_back(outputFileName); return 0; }