X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=readtreecommand.cpp;h=edfdf3b77e0d85ff51afce83323d0204ab987a66;hb=89f19f9c6ab89c2f6c7c6921a328ae87bce6f8e3;hp=60654489ce6a1a848eb0dc9743f43e64b832a639;hpb=aa9238c0a9e6e7aa0ed8b8b606b08ad4fd7dcfe3;p=mothur.git diff --git a/readtreecommand.cpp b/readtreecommand.cpp index 6065448..edfdf3b 100644 --- a/readtreecommand.cpp +++ b/readtreecommand.cpp @@ -9,6 +9,41 @@ #include "readtreecommand.h" +//********************************************************************************************************************** +vector ReadTreeCommand::getValidParameters(){ + try { + string Array[] = {"tree","group","name","outputdir","inputdir"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ReadTreeCommand", "getValidParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ReadTreeCommand::getRequiredParameters(){ + try { + string Array[] = {"tree"}; + vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ReadTreeCommand", "getRequiredParameters"); + exit(1); + } +} +//********************************************************************************************************************** +vector ReadTreeCommand::getRequiredFiles(){ + try { + vector myArray; + return myArray; + } + catch(exception& e) { + m->errorOut(e, "ReadTreeCommand", "getRequiredFiles"); + exit(1); + } +} //********************************************************************************************************************** ReadTreeCommand::ReadTreeCommand(string option) { try { @@ -44,7 +79,7 @@ ReadTreeCommand::ReadTreeCommand(string option) { it = parameters.find("tree"); //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["tree"] = inputDir + it->second; } } @@ -52,7 +87,7 @@ ReadTreeCommand::ReadTreeCommand(string option) { it = parameters.find("group"); //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["group"] = inputDir + it->second; } } @@ -60,7 +95,7 @@ ReadTreeCommand::ReadTreeCommand(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; } } @@ -76,8 +111,20 @@ ReadTreeCommand::ReadTreeCommand(string option) { groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { abort = true; } - else if (groupfile == "not found") { groupfile = ""; m->mothurOut("group is a required parameter for the read.tree command."); m->mothurOutEndLine(); abort = true; } - else { + else if (groupfile == "not found") { + groupfile = ""; + + m->mothurOut("You have not provided a group file. I am assumming all sequence are from the same group."); m->mothurOutEndLine(); + + if (treefile != "") { Tree* tree = new Tree(treefile); delete tree; } //extracts names from tree to make faked out groupmap + + globaldata->setGroupFile(groupfile); + //read in group map info. + treeMap = new TreeMap(); + for (int i = 0; i < globaldata->Treenames.size(); i++) { treeMap->addSeq(globaldata->Treenames[i], "Group1"); } + globaldata->gTreemap = treeMap; + + }else { globaldata->setGroupFile(groupfile); //read in group map info. treeMap = new TreeMap(groupfile); @@ -108,8 +155,10 @@ void ReadTreeCommand::help(){ try { m->mothurOut("The read.tree command must be run before you execute a unifrac.weighted, unifrac.unweighted. \n"); m->mothurOut("It also must be run before using the parsimony command, unless you are using the randomtree parameter.\n"); + m->mothurOut("The read.tree command parameters are tree, group and name.\n"); m->mothurOut("The read.tree command should be in the following format: read.tree(tree=yourTreeFile, group=yourGroupFile).\n"); - m->mothurOut("The tree and group parameters are both required.\n"); + m->mothurOut("The tree and group parameters are both required, if no group file is given then one group is assumed.\n"); + m->mothurOut("The name parameter allows you to enter a namefile.\n"); m->mothurOut("Note: No spaces between parameter labels (i.e. tree), '=' and parameters (i.e.yourTreefile).\n\n"); } catch(exception& e) { @@ -147,12 +196,21 @@ int ReadTreeCommand::execute(){ delete globaldata->gTreemap; return 0; } - + T[i]->assembleTree(); } + + //if you provide a namefile we will use the numNames in the namefile as long as the number of unique match the tree names size. + int numNamesInTree; + if (namefile != "") { + if (numUniquesInName == globaldata->Treenames.size()) { numNamesInTree = nameMap.size(); } + else { numNamesInTree = globaldata->Treenames.size(); } + }else { numNamesInTree = globaldata->Treenames.size(); } + + //output any names that are in group file but not in tree - if (globaldata->Treenames.size() < treeMap->getNumSeqs()) { + if (numNamesInTree < treeMap->getNumSeqs()) { for (int i = 0; i < treeMap->namesOfSeqs.size(); i++) { //is that name in the tree? int count = 0; @@ -180,8 +238,10 @@ int ReadTreeCommand::execute(){ } } } + + globaldata->gTreemap = treeMap; } - + return 0; } catch(exception& e) { @@ -193,26 +253,29 @@ int ReadTreeCommand::execute(){ int ReadTreeCommand::readNamesFile() { try { globaldata->names.clear(); + numUniquesInName = 0; ifstream in; - openInputFile(namefile, in); + m->openInputFile(namefile, in); string first, second; map::iterator itNames; while(!in.eof()) { - in >> first >> second; gobble(in); + in >> first >> second; m->gobble(in); + numUniquesInName++; + itNames = globaldata->names.find(first); if (itNames == globaldata->names.end()) { globaldata->names[first] = second; //we need a list of names in your namefile to use above when removing extra seqs above so we don't remove them vector dupNames; - splitAtComma(second, dupNames); + m->splitAtComma(second, dupNames); - for (int i = 0; i < dupNames.size(); i++) { nameMap[dupNames[i]] = dupNames[i]; } - }else { m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); globaldata->names.clear(); return 1; } + for (int i = 0; i < dupNames.size(); i++) { nameMap[dupNames[i]] = dupNames[i]; if ((groupfile == "") && (i != 0)) { globaldata->gTreemap->addSeq(dupNames[i], "Group1"); } } + }else { m->mothurOut(first + " has already been seen in namefile, disregarding names file."); m->mothurOutEndLine(); in.close(); globaldata->names.clear(); namefile = ""; return 1; } } in.close();