X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=readtreecommand.cpp;h=7660643f062df6413e2d0b5fa846ebb798a0301f;hb=2bb9267aa4b4ecdf8488b06605cc9f3f36fa4332;hp=09f899b947bf9bb4b455de86479d34ffa709d46f;hpb=5f44783e6d74a9c207492ac244210c915cadc272;p=mothur.git diff --git a/readtreecommand.cpp b/readtreecommand.cpp index 09f899b..7660643 100644 --- a/readtreecommand.cpp +++ b/readtreecommand.cpp @@ -9,16 +9,18 @@ #include "readtreecommand.h" + //********************************************************************************************************************** -ReadTreeCommand::ReadTreeCommand(string option){ +ReadTreeCommand::ReadTreeCommand(string option) { try { - globaldata = GlobalData::getInstance(); - abort = false; - + abort = false; calledHelp = false; + //allow user to run help - if(option == "help") { 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 Array[] = {"tree","group","name","outputdir","inputdir"}; vector myArray (Array, Array+(sizeof(Array)/sizeof(string))); @@ -44,7 +46,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 +54,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 +62,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; } } @@ -71,81 +73,83 @@ ReadTreeCommand::ReadTreeCommand(string option){ //check for required parameters treefile = validParameter.validFile(parameters, "tree", true); if (treefile == "not open") { abort = true; } - else if (treefile == "not found") { treefile = ""; mothurOut("tree is a required parameter for the read.tree command."); mothurOutEndLine(); abort = true; } - else { globaldata->setTreeFile(treefile); globaldata->setFormat("tree"); } + else if (treefile == "not found") { treefile = ""; m->mothurOut("tree is a required parameter for the read.tree command."); m->mothurOutEndLine(); abort = true; } groupfile = validParameter.validFile(parameters, "group", true); if (groupfile == "not open") { abort = true; } - else if (groupfile == "not found") { groupfile = ""; mothurOut("group is a required parameter for the read.tree command."); mothurOutEndLine(); abort = true; } - else { - globaldata->setGroupFile(groupfile); + 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 + + //read in group map info. + treeMap = new TreeMap(); + for (int i = 0; i < m->Treenames.size(); i++) { treeMap->addSeq(m->Treenames[i], "Group1"); } + + }else { //read in group map info. treeMap = new TreeMap(groupfile); treeMap->readMap(); - globaldata->gTreemap = treeMap; } namefile = validParameter.validFile(parameters, "name", true); if (namefile == "not open") { abort = true; } - else if (namefile == "not found") { treefile = ""; } + else if (namefile == "not found") { namefile = ""; } else { readNamesFile(); } if (abort == false) { filename = treefile; read = new ReadNewickTree(filename); } - + */ } } catch(exception& e) { - errorOut(e, "ReadTreeCommand", "ReadTreeCommand"); + m->errorOut(e, "ReadTreeCommand", "ReadTreeCommand"); exit(1); } } //********************************************************************************************************************** -void ReadTreeCommand::help(){ - try { - mothurOut("The read.tree command must be run before you execute a unifrac.weighted, unifrac.unweighted. \n"); - mothurOut("It also must be run before using the parsimony command, unless you are using the randomtree parameter.\n"); - mothurOut("The read.tree command should be in the following format: read.tree(tree=yourTreeFile, group=yourGroupFile).\n"); - mothurOut("The tree and group parameters are both required.\n"); - mothurOut("Note: No spaces between parameter labels (i.e. tree), '=' and parameters (i.e.yourTreefile).\n\n"); - } - catch(exception& e) { - errorOut(e, "ReadTreeCommand", "help"); - exit(1); - } -} - -//********************************************************************************************************************** - -ReadTreeCommand::~ReadTreeCommand(){ - if (abort == false) { delete read; } -} - -//********************************************************************************************************************** - int ReadTreeCommand::execute(){ try { - if (abort == true) { return 0; } - + if (abort == true) { if (calledHelp) { return 0; } return 2; } + m->mothurOut(getHelpString()); m->mothurOutEndLine(); + /* int readOk; - readOk = read->read(); + readOk = read->read(treeMap); - if (readOk != 0) { mothurOut("Read Terminated."); mothurOutEndLine(); globaldata->gTree.clear(); delete globaldata->gTreemap; return 0; } + if (readOk != 0) { m->mothurOut("Read Terminated."); m->mothurOutEndLine(); globaldata->gTree.clear(); delete globaldata->gTreemap; return 0; } - vector T = globaldata->gTree; + vector T = read->gTree; //assemble users trees for (int i = 0; i < T.size(); i++) { + if (m->control_pressed) { + for (int i = 0; i < T.size(); i++) { delete T[i]; } + globaldata->gTree.clear(); + 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; @@ -154,57 +158,71 @@ int ReadTreeCommand::execute(){ count++; } + if (m->control_pressed) { + for (int i = 0; i < T.size(); i++) { delete T[i]; } + globaldata->gTree.clear(); + delete globaldata->gTreemap; + return 0; + } + //then you did not find it so report it if (count == globaldata->Treenames.size()) { //if it is in your namefile then don't remove map::iterator it = nameMap.find(treeMap->namesOfSeqs[i]); if (it == nameMap.end()) { - mothurOut(treeMap->namesOfSeqs[i] + " is in your groupfile and not in your tree. It will be disregarded."); mothurOutEndLine(); + m->mothurOut(treeMap->namesOfSeqs[i] + " is in your groupfile and not in your tree. It will be disregarded."); m->mothurOutEndLine(); treeMap->removeSeq(treeMap->namesOfSeqs[i]); + i--; //need this because removeSeq removes name from namesOfSeqs } } } + + globaldata->gTreemap = treeMap; } - + */ return 0; } catch(exception& e) { - errorOut(e, "ReadTreeCommand", "execute"); + m->errorOut(e, "ReadTreeCommand", "execute"); exit(1); } } /*****************************************************************/ int ReadTreeCommand::readNamesFile() { try { - globaldata->names.clear(); + /* + m->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); - itNames = globaldata->names.find(first); + numUniquesInName++; + + itNames = m->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 { mothurOut(first + " has already been seen in namefile, disregarding names file."); 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(); - + */ return 0; } catch(exception& e) { - errorOut(e, "ReadTreeCommand", "readNamesFile"); + m->errorOut(e, "ReadTreeCommand", "readNamesFile"); exit(1); } }