X-Git-Url: https://git.donarmstrong.com/?p=mothur.git;a=blobdiff_plain;f=parsimonycommand.cpp;h=64d249831ad56f5501dd6dd4d44f17bda35daf78;hp=50e1bfa7e590d6e2fa47b4c184700b440cdb9621;hb=bd27c2b0612942815b7417c79f7ee41f669a2a34;hpb=0caf3fbabaa3ece404f8ce77f4c883dc5b1bf1dc diff --git a/parsimonycommand.cpp b/parsimonycommand.cpp index 50e1bfa..64d2498 100644 --- a/parsimonycommand.cpp +++ b/parsimonycommand.cpp @@ -13,15 +13,16 @@ //********************************************************************************************************************** vector ParsimonyCommand::setParameters(){ try { - CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none",false,true); parameters.push_back(ptree); - CommandParameter pgroup("group", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pgroup); - CommandParameter pname("name", "InputTypes", "", "", "none", "none", "none",false,false); parameters.push_back(pname); - CommandParameter pgroups("groups", "String", "", "", "", "", "",false,false); parameters.push_back(pgroups); - CommandParameter prandom("random", "String", "", "", "", "", "",false,false); parameters.push_back(prandom); - CommandParameter piters("iters", "Number", "", "1000", "", "", "",false,false); parameters.push_back(piters); - CommandParameter pprocessors("processors", "Number", "", "1", "", "", "",false,false); parameters.push_back(pprocessors); - CommandParameter pinputdir("inputdir", "String", "", "", "", "", "",false,false); parameters.push_back(pinputdir); - CommandParameter poutputdir("outputdir", "String", "", "", "", "", "",false,false); parameters.push_back(poutputdir); + CommandParameter ptree("tree", "InputTypes", "", "", "none", "none", "none","parsimony-psummary",false,true,true); parameters.push_back(ptree); + CommandParameter pname("name", "InputTypes", "", "", "NameCount", "none", "none","",false,false,true); parameters.push_back(pname); + CommandParameter pcount("count", "InputTypes", "", "", "NameCount-CountGroup", "none", "none","",false,false,true); parameters.push_back(pcount); + CommandParameter pgroup("group", "InputTypes", "", "", "CountGroup", "none", "none","",false,false,true); parameters.push_back(pgroup); + CommandParameter pgroups("groups", "String", "", "", "", "", "","",false,false); parameters.push_back(pgroups); + CommandParameter prandom("random", "String", "", "", "", "", "","",false,false); parameters.push_back(prandom); + CommandParameter piters("iters", "Number", "", "1000", "", "", "","",false,false); parameters.push_back(piters); + CommandParameter pprocessors("processors", "Number", "", "1", "", "", "","",false,false,true); parameters.push_back(pprocessors); + 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); } @@ -36,7 +37,7 @@ vector ParsimonyCommand::setParameters(){ string ParsimonyCommand::getHelpString(){ try { string helpString = ""; - helpString += "The parsimony command parameters are tree, group, name, random, groups, processors and iters. tree parameter is required unless you have valid current tree file or are using random.\n"; + helpString += "The parsimony command parameters are tree, group, name, count, random, groups, processors and iters. tree parameter is required unless you have valid current tree file or are using random.\n"; helpString += "The groups parameter allows you to specify which of the groups in your groupfile you would like analyzed. You must enter at least 1 valid group.\n"; helpString += "The group names are separated by dashes. The iters parameter allows you to specify how many random trees you would like compared to your tree.\n"; helpString += "The parsimony command should be in the following format: parsimony(random=yourOutputFilename, groups=yourGroups, iters=yourIters).\n"; @@ -52,7 +53,22 @@ string ParsimonyCommand::getHelpString(){ exit(1); } } - +//********************************************************************************************************************** +string ParsimonyCommand::getOutputPattern(string type) { + try { + string pattern = ""; + + if (type == "parsimony") { pattern = "[filename],parsimony"; } + else if (type == "psummary") { pattern = "[filename],psummary"; } + else { m->mothurOut("[ERROR]: No definition for type " + type + " output pattern.\n"); m->control_pressed = true; } + + return pattern; + } + catch(exception& e) { + m->errorOut(e, "ParsimonyCommand", "getOutputPattern"); + exit(1); + } +} //********************************************************************************************************************** ParsimonyCommand::ParsimonyCommand(){ try { @@ -124,6 +140,14 @@ ParsimonyCommand::ParsimonyCommand(string option) { //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("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; } + } } outputDir = validParameter.validFile(parameters, "outputdir", false); if (outputDir == "not found"){ outputDir = ""; } @@ -151,6 +175,20 @@ ParsimonyCommand::ParsimonyCommand(string option) { if (namefile == "not open") { namefile = ""; abort = true; } else if (namefile == "not found") { namefile = ""; } else { m->setNameFile(namefile); } + + countfile = validParameter.validFile(parameters, "count", true); + if (countfile == "not open") { countfile = ""; abort = true; } + else if (countfile == "not found") { countfile = ""; } + else { m->setCountTableFile(countfile); } + + if ((namefile != "") && (countfile != "")) { + m->mothurOut("[ERROR]: you may only use one of the following: name or count."); m->mothurOutEndLine(); abort = true; + } + + if ((groupfile != "") && (countfile != "")) { + m->mothurOut("[ERROR]: you may only use one of the following: group or count."); m->mothurOutEndLine(); abort=true; + } + } //if the user changes the output directory command factory will send this info to us in the output parameter @@ -172,10 +210,12 @@ ParsimonyCommand::ParsimonyCommand(string option) { m->setProcessors(temp); m->mothurConvert(temp, processors); - if (namefile == "") { - vector files; files.push_back(treefile); - parser.getNameFile(files); - } + if (countfile=="") { + if (namefile == "") { + vector files; files.push_back(treefile); + parser.getNameFile(files); + } + } } @@ -198,17 +238,22 @@ int ParsimonyCommand::execute() { m->setTreeFile(treefile); - TreeReader* reader = new TreeReader(treefile, groupfile, namefile); + TreeReader* reader; + if (countfile == "") { reader = new TreeReader(treefile, groupfile, namefile); } + else { reader = new TreeReader(treefile, countfile); } T = reader->getTrees(); - tmap = T[0]->getTreeMap(); + ct = T[0]->getCountTable(); delete reader; if(outputDir == "") { outputDir += m->hasPath(treefile); } - output = new ColumnFile(outputDir + m->getSimpleName(treefile) + ".parsimony", itersString); - outputNames.push_back(outputDir + m->getSimpleName(treefile) + ".parsimony"); - outputTypes["parsimony"].push_back(outputDir + m->getSimpleName(treefile) + ".parsimony"); + map variables; + variables["[filename]"] = outputDir + m->getSimpleName(treefile) + "."; + + output = new ColumnFile(getOutputFileName("parsimony",variables), itersString); + outputNames.push_back(getOutputFileName("parsimony",variables)); + outputTypes["parsimony"].push_back(getOutputFileName("parsimony",variables)); - sumFile = outputDir + m->getSimpleName(treefile) + ".psummary"; + sumFile = getOutputFileName("psummary",variables); m->openOutputFile(sumFile, outSum); outputNames.push_back(sumFile); outputTypes["psummary"].push_back(sumFile); @@ -224,7 +269,7 @@ int ParsimonyCommand::execute() { //set users groups to analyze SharedUtil util; vector mGroups = m->getGroups(); - vector tGroups = tmap->getNamesOfGroups(); + vector tGroups = ct->getNamesOfGroups(); util.setGroups(mGroups, tGroups, allGroups, numGroups, "parsimony"); //sets the groups the user wants to analyze util.getCombos(groupComb, mGroups, numComp); m->setGroups(mGroups); @@ -239,7 +284,7 @@ int ParsimonyCommand::execute() { if (m->control_pressed) { delete reading; delete output; - delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } + delete ct; for (int i = 0; i < T.size(); i++) { delete T[i]; } if (randomtree == "") { outSum.close(); } for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->clearGroups(); @@ -264,7 +309,7 @@ int ParsimonyCommand::execute() { if (m->control_pressed) { delete reading; delete output; - delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } + delete ct; for (int i = 0; i < T.size(); i++) { delete T[i]; } if (randomtree == "") { outSum.close(); } for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); m->clearGroups(); @@ -293,7 +338,7 @@ int ParsimonyCommand::execute() { for (int j = 0; j < iters; j++) { //create new tree with same num nodes and leaves as users - randT = new Tree(tmap); + randT = new Tree(ct); //create random relationships between nodes randT->assembleRandomTree(); @@ -305,7 +350,7 @@ int ParsimonyCommand::execute() { delete reading; delete output; delete randT; if (randomtree == "") { outSum.close(); } for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); - delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } + delete ct; for (int i = 0; i < T.size(); i++) { delete T[i]; } m->clearGroups(); return 0; } @@ -334,13 +379,13 @@ int ParsimonyCommand::execute() { for (int j = 0; j < iters; j++) { //create new tree with same num nodes and leaves as users - randT = new Tree(tmap); + randT = new Tree(ct); //create random relationships between nodes randT->assembleRandomTree(); if (m->control_pressed) { - delete reading; delete output; delete randT; delete tmap; + delete reading; delete output; delete randT; delete ct; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } @@ -349,7 +394,7 @@ int ParsimonyCommand::execute() { randomData = pars.getValues(randT, processors, outputDir); if (m->control_pressed) { - delete reading; delete output; delete randT; delete tmap; + delete reading; delete output; delete randT; delete ct; for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0; } @@ -403,7 +448,7 @@ int ParsimonyCommand::execute() { if (m->control_pressed) { delete reading; delete output; - delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } + delete ct; for (int i = 0; i < T.size(); i++) { delete T[i]; } if (randomtree == "") { outSum.close(); } for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0; @@ -416,7 +461,7 @@ int ParsimonyCommand::execute() { printParsimonyFile(); if (randomtree == "") { printUSummaryFile(); } - delete output; delete tmap; for (int i = 0; i < T.size(); i++) { delete T[i]; } + delete output; delete ct; for (int i = 0; i < T.size(); i++) { delete T[i]; } if (m->control_pressed) { for (int i = 0; i < outputNames.size(); i++) { m->mothurRemove(outputNames[i]); } outputTypes.clear(); return 0;} @@ -508,7 +553,7 @@ void ParsimonyCommand::getUserInput() { try { //create treemap - tmap = new TreeMap(); + ct = new CountTable(); m->mothurOut("Please enter the number of groups you would like to analyze: "); cin >> numGroups; @@ -518,30 +563,32 @@ void ParsimonyCommand::getUserInput() { count = 1; numEachGroup.resize(numGroups, 0); - + set nameMap; + map groupMap; + set gps; + for (int i = 1; i <= numGroups; i++) { m->mothurOut("Please enter the number of sequences in group " + toString(i) + ": "); cin >> num; m->mothurOutJustToLog(toString(num)); m->mothurOutEndLine(); - - //set tmaps seqsPerGroup - tmap->seqsPerGroup[toString(i)] = num; - tmap->addGroup(toString(i)); + gps.insert(toString(i)); + //set tmaps namesOfSeqs for (int j = 0; j < num; j++) { - tmap->namesOfSeqs.push_back(toString(count)); - tmap->treemap[toString(count)].groupname = toString(i); + groupMap[toString(count)] = toString(i); + nameMap.insert(toString(count)); count++; } } - + ct->createTable(nameMap, groupMap, gps); + //clears buffer so next command doesn't have error string s; getline(cin, s); - m->Treenames = tmap->namesOfSeqs; - + m->Treenames = ct->getNamesOfSeqs(); + m->runParse = false; } catch(exception& e) { m->errorOut(e, "ParsimonyCommand", "getUserInput");